Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 49 additions & 11 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,77 @@
version: 2
updates:
# NPM (Angular app)
# (Angular app)
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "daily"
time: "02:00"
timezone: "Asia/Bangkok"
open-pull-requests-limit: 10
target-branch: "main"
labels: ["dependencies", "npm"]
allow:
- dependency-type: "direct"
- dependency-type: "all"
open-pull-requests-limit: 10
labels: ["dependencies", "npm", "frontend"]
ignore:
# ví dụ giữ cố định major của Angular 19
- dependency-name: "@angular/*"
versions: [">=20"]
update-types: ["version-update:semver-major"]
groups:
angular-core:
patterns: ["@angular/*", "zone.js"]
update-types: ["minor", "patch"]
tooling-and-tests:
patterns: ["typescript","karma*","jasmine*","@types/*","cypress"]
update-types: ["minor", "patch"]
ui-and-md:
patterns: ["highlight.js","marked","github-markdown-css","apexcharts","ng-apexcharts","ngx-*"]
update-types: ["minor", "patch"]
codemirror-suite:
patterns: ["codemirror","@codemirror/*"]
update-types: ["minor", "patch"]

# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "monday"
time: "03:00"
timezone: "Asia/Bangkok"
time: "03:00"
timezone: "Asia/Bangkok"
target-branch: "main"
labels: ["dependencies", "github-actions"]
open-pull-requests-limit: 10

# Docker base images (Nginx, Node…)
# Docker images (Nginx, Node…)
- package-ecosystem: "docker"
directory: "/docker"
schedule:
interval: "weekly"
day: "tuesday"
time: "04:00"
timezone: "Asia/Bangkok"
target-branch: "main"
labels: ["dependencies", "docker"]
open-pull-requests-limit: 10
registries:
- dockerhub
- ghcr
groups:
nginx-node-base:
patterns: ["nginx","node"]
update-types: ["minor", "patch"]
dotnet-base:
patterns: ["mcr.microsoft.com/dotnet/*"]
update-types: ["minor", "patch"]
jre-maven:
patterns: ["eclipse-temurin:*","maven:*"]
update-types: ["minor", "patch"]

registries:
dockerhub:
type: docker-registry
url: https://index.docker.io/v1/
username: ${{secrets.DOCKERHUB_USER}}
password: ${{secrets.DOCKERHUB_TOKEN}}
ghcr:
type: docker-registry
url: https://ghcr.io
username: ${{secrets.GHCR_USERNAME}}
password: ${{secrets.GHCR_TOKEN}}
5 changes: 3 additions & 2 deletions .github/workflows/ci-sonar-angular.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- "sonar-project.properties"
pull_request:

###
permissions:
contents: read
pull-requests: write
Expand All @@ -31,7 +32,7 @@ jobs:
fetch-depth: 0 # Sonar cần full history để tính blame

- name: Set up JDK (for Sonar scanner)
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: "21"
Expand Down Expand Up @@ -79,7 +80,7 @@ jobs:
# --- SonarQube self-hosted (nếu bạn set SONAR_HOST_URL) ---
- name: SonarQube Scan (self-hosted)
if: ${{ env.SONAR_HOST_URL != '' }}
uses: SonarSource/sonarqube-scan-action@v4
uses: SonarSource/sonarqube-scan-action@v5.3.1
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_FRONTEND }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Dependabot Auto-merge

on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: write
pull-requests: write

jobs:
automerge:
if: github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest

steps:
- name: Fetch Dependabot metadata
id: meta
uses: dependabot/fetch-metadata@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Auto-approve patch/minor
if: |
steps.meta.outputs.update-type == 'version-update:semver-patch' ||
steps.meta.outputs.update-type == 'version-update:semver-minor'
uses: hmarr/auto-approve-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Enable PR auto-merge (squash) for patch/minor
if: |
steps.meta.outputs.update-type == 'version-update:semver-patch' ||
steps.meta.outputs.update-type == 'version-update:semver-minor'
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: squash
8 changes: 7 additions & 1 deletion .github/workflows/deploy-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,20 @@ jobs:
fi
}

# docker login (nếu có)
# docker login Docker Hub (nếu có)
if [ -n "${DOCKERHUB_USER:-}" ] && [ -n "${DOCKERHUB_TOKEN:-}" ]; then
echo "docker login Docker Hub..."
echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USER" --password-stdin
else
echo "Thiếu DOCKERHUB_USER/DOCKERHUB_TOKEN trong .env (image public thì vẫn OK)."
fi

# docker login GHCR (nếu có)
if [ -n "${GHCR_USERNAME:-}" ] && [ -n "${GHCR_TOKEN:-}" ]; then
echo "docker login GHCR..."
echo "$GHCR_TOKEN" | docker login ghcr.io -u "$GHCR_USERNAME" --password-stdin
fi

echo "Pull image frontend tag ${IMAGE_TAG}…"
compose -f docker-compose.prod-frontend.yml --env-file .env pull

Expand Down
52 changes: 36 additions & 16 deletions .github/workflows/frontend-docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ permissions:

env:
DOCKER_REPO: ${{ secrets.DOCKERHUB_USER }}/codecampus-frontend
GHCR_OWNER: ${{ github.repository_owner }}
DOCKERFILE_PATH: docker/angular-frontend.Dockerfile
PLATFORMS: linux/amd64

Expand All @@ -28,40 +29,59 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3

- name: Set up Buildx
uses: docker/setup-buildx-action@v3

- name: Derive tags
- name: Derive tags (Docker Hub + GHCR)
id: meta
shell: bash
run: |
TAGS=""
set -euo pipefail

# Hạ lowercase owner (an toàn POSIX)
OWNER_LC="$(printf '%s' "${GHCR_OWNER}" | tr '[:upper:]' '[:lower:]')"
echo "OWNER_LC=${OWNER_LC}" >> "$GITHUB_ENV"

if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
VERSION="${GITHUB_REF_NAME#v}"
echo "IMAGE_TAG=${VERSION}" >> $GITHUB_ENV
TAGS="${{ env.DOCKER_REPO }}:${VERSION}"
echo "IMAGE_TAG=${VERSION}" >> "$GITHUB_ENV"
HUB="${DOCKER_REPO}:${VERSION}"
GHCR="ghcr.io/${OWNER_LC}/codecampus-frontend:${VERSION}"
else
SHA_TAG="${GITHUB_SHA::12}"
echo "IMAGE_TAG=${SHA_TAG}" >> $GITHUB_ENV
TAGS="${{ env.DOCKER_REPO }}:${SHA_TAG}"
echo "IMAGE_TAG=${SHA_TAG}" >> "$GITHUB_ENV"
HUB="${DOCKER_REPO}:${SHA_TAG}"
GHCR="ghcr.io/${OWNER_LC}/codecampus-frontend:${SHA_TAG}"
if [ "${GITHUB_REF_NAME}" = "main" ]; then
TAGS="${TAGS},${{ env.DOCKER_REPO }}:latest"
HUB="${HUB}"$'\n'"${DOCKER_REPO}:latest"
GHCR="${GHCR}"$'\n'"ghcr.io/${OWNER_LC}/codecampus-frontend:latest"
fi
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT

# Xuất output "tags" dạng đa dòng
{
echo "tags<<__TAGS__"
printf '%s\n' "$HUB"
printf '%s\n' "$GHCR"
echo "__TAGS__"
} >> "$GITHUB_OUTPUT"

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build & Push
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build & Push (Docker Hub + GHCR)
uses: docker/build-push-action@v6
with:
context: .
Expand Down
1 change: 1 addition & 0 deletions config/local-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "IP_SERVER": "http://localhost:8888/api" }
1 change: 1 addition & 0 deletions config/server-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "IP_SERVER": "http://72.60.41.133:8888/api" }
4 changes: 2 additions & 2 deletions docker-compose.prod-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
container_name: codecampus-frontend
image: ${DOCKERHUB_USER}/codecampus-frontend:${IMAGE_TAG:-latest}
restart: unless-stopped
ports: [ "4200:4200" ]
networks: [ backend ]
ports: ["4200:80"]
networks: [backend]

networks:
backend:
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proxy.conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/api": {
"target": "https://192.168.1.220:8888",
"target": "https://localhost:8888",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
Expand Down
3 changes: 3 additions & 0 deletions public/assets/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"IP_SERVER": "http://localhost:8888/api"
}
1 change: 1 addition & 0 deletions public/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "apiUrl": "http://localhost:8888/api" }
3 changes: 0 additions & 3 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export const environment = {
production: true,
IP_SERVER: 'http://72.60.41.133:8888/api',
IP_SERVER_NO_SSL: 'http://192.168.1.220:8000/api',
IP_SERVER_RADMIN: 'http://26.100.147.137:8888/api',
IP_LOCAL: 'http://localhost:8081/api',
};
9 changes: 9 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@ import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { App } from './app/app';

// // Load runtime config trước khi bootstrap
// fetch('/assets/config.json')
// .then((response) => response.json())
// .then((config) => {
// (window as any).env = config;
// return bootstrapApplication(App, appConfig);
// })
// .catch((err) => console.error(err));

bootstrapApplication(App, appConfig).catch((err) => console.error(err));
Loading