Skip to content

fix details resource #106

fix details resource

fix details resource #106

name: Frontend Docker Publish
on:
push:
branches: ["main"]
tags: ["v*.*.*"]
paths:
- "src/**"
- "angular.json"
- "package.json"
- "package-lock.json"
- "docker/angular-frontend.Dockerfile"
- "docker/nginx.conf"
- ".github/workflows/frontend-docker-publish.yml"
workflow_dispatch:
permissions:
contents: read
packages: write
env:
DOCKER_REPO: ${{ secrets.DOCKERHUB_USER }}/codecampus-frontend
GHCR_OWNER: ${{ github.repository_owner }}
DOCKERFILE_PATH: docker/angular-frontend.Dockerfile
PLATFORMS: linux/amd64
jobs:
###
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Derive tags (Docker Hub + GHCR)
id: meta
shell: bash
run: |
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"
HUB="${DOCKER_REPO}:${VERSION}"$'\n'"${DOCKER_REPO}:latest"
GHCR="ghcr.io/${OWNER_LC}/codecampus-frontend:${VERSION}"$'\n'"ghcr.io/${OWNER_LC}/codecampus-frontend:latest"
else
SHA_TAG="${GITHUB_SHA::12}"
echo "IMAGE_TAG=${SHA_TAG}" >> "$GITHUB_ENV"
HUB="${DOCKER_REPO}:${SHA_TAG}"$'\n'"${DOCKER_REPO}:latest"
GHCR="ghcr.io/${OWNER_LC}/codecampus-frontend:${SHA_TAG}"$'\n'"ghcr.io/${OWNER_LC}/codecampus-frontend:latest"
fi
# 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: 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: .
file: ${{ env.DOCKERFILE_PATH }}
platforms: ${{ env.PLATFORMS }}
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max