diff --git a/.gitea/workflows/docker-build.yml b/.gitea/workflows/docker-build.yml index 2c1539e..a57a7f6 100644 --- a/.gitea/workflows/docker-build.yml +++ b/.gitea/workflows/docker-build.yml @@ -10,6 +10,7 @@ on: env: BACKEND_IMAGE: imap-client-backend FRONTEND_IMAGE: imap-client-frontend + DOCKER_BUILDKIT: "1" # Uses local Gitea registry: //:tag jobs: @@ -23,22 +24,18 @@ jobs: id: repo shell: bash run: | - set -e + set -euo pipefail RAW_REPO="${GITHUB_REPOSITORY:-${GITEA_REPOSITORY:-}}" if [ -z "$RAW_REPO" ]; then echo "Missing GITHUB_REPOSITORY/GITEA_REPOSITORY"; exit 1; fi OWNER="${RAW_REPO%%/*}"; REPO="${RAW_REPO#*/}" REG_HOST_RAW="${GITEA_SERVER_URL:-${GITHUB_SERVER_URL:-}}" if [ -z "$REG_HOST_RAW" ]; then echo "Missing GITEA_SERVER_URL/GITHUB_SERVER_URL"; exit 1; fi REG_HOST="${REG_HOST_RAW#http://}"; REG_HOST="${REG_HOST#https://}"; REG_HOST="${REG_HOST%%/*}" - # Allow explicit override via secrets or env + # Override if needed (set secret/env to git.thumeit.com[:port]) OVERRIDE="${{ secrets.GITEA_REGISTRY_HOST }}"; [ -z "$OVERRIDE" ] && OVERRIDE="${GITEA_REGISTRY_HOST}" [ -z "$OVERRIDE" ] && OVERRIDE="${{ secrets.REGISTRY_HOST }}" [ -z "$OVERRIDE" ] && OVERRIDE="${REGISTRY_HOST}" - if [ "$REG_HOST" = "gitea" ] && [ -n "$OVERRIDE" ]; then - echo "Replacing unresolved host 'gitea' with override '$OVERRIDE'" - REG_HOST="$OVERRIDE" - fi - REG_HOST="git.thumeit.com"; + if [ "$REG_HOST" = "gitea" ] && [ -n "$OVERRIDE" ]; then REG_HOST="$OVERRIDE"; fi echo "owner=$OWNER" >> $GITHUB_OUTPUT echo "repo=$REPO" >> $GITHUB_OUTPUT echo "host=$REG_HOST" >> $GITHUB_OUTPUT @@ -46,74 +43,79 @@ jobs: - name: Prepare tags id: meta + shell: bash run: | + set -euo pipefail SHA_TAG=sha-${GITHUB_SHA::7} echo "sha_tag=$SHA_TAG" >> $GITHUB_OUTPUT - if [[ "$GITHUB_REF" =~ refs/heads/(main|master)$ ]]; then echo "latest_tag=latest" >> $GITHUB_OUTPUT; fi - if [[ "$GITHUB_REF" == refs/tags/v* ]]; then VERSION_TAG=${GITHUB_REF#refs/tags/}; echo "version_tag=$VERSION_TAG" >> $GITHUB_OUTPUT; fi + [[ "$GITHUB_REF" =~ refs/heads/(main|master)$ ]] && echo "latest_tag=latest" >> $GITHUB_OUTPUT || true + if [[ "$GITHUB_REF" == refs/tags/v* ]]; then + VERSION_TAG=${GITHUB_REF#refs/tags/} + echo "version_tag=$VERSION_TAG" >> $GITHUB_OUTPUT + fi - name: Show build plan run: | echo "Registry host: ${{ steps.repo.outputs.host }}" echo "Namespace: ${{ steps.repo.outputs.owner }}" - echo "Images: ${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${BACKEND_IMAGE} and frontend" + echo "Backend image: ${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${BACKEND_IMAGE}" + echo "Frontend image: ${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${FRONTEND_IMAGE}" - name: Login (optional) id: login + shell: bash run: | - set -e + set -euo pipefail HOST="${{ steps.repo.outputs.host }}" if [ -n "${{ secrets.CR_USERNAME }}" ] && [ -n "${{ secrets.CR_PASSWORD }}" ]; then - echo "${{ secrets.CR_PASSWORD }}" | docker login "git.thumeit.com" -u "${{ secrets.CR_USERNAME }}" --password-stdin + echo "${{ secrets.CR_PASSWORD }}" | docker login "$HOST" -u "${{ secrets.CR_USERNAME }}" --password-stdin echo "authenticated=1" >> $GITHUB_OUTPUT; exit 0 fi if [ -n "${{ secrets.GITEA_REGISTRY_TOKEN }}" ]; then - ACTOR="${GITHUB_ACTOR:-${GITEA_ACTOR:-$OWNER}}" - echo "${{ secrets.GITEA_REGISTRY_TOKEN }}" | docker login "git.thumeit.com" -u "$ACTOR" --password-stdin + ACTOR="${GITHUB_ACTOR:-${GITEA_ACTOR:-${{ steps.repo.outputs.owner }}}}" + echo "${{ secrets.GITEA_REGISTRY_TOKEN }}" | docker login "$HOST" -u "$ACTOR" --password-stdin echo "authenticated=1" >> $GITHUB_OUTPUT; exit 0 fi - echo "No credentials; will skip push."; echo "authenticated=0" >> $GITHUB_OUTPUT + echo "No credentials; push will be skipped." + echo "authenticated=0" >> $GITHUB_OUTPUT - - name: Build backend + - name: Docker build (backend) + id: build_backend + shell: bash run: | + set -euo pipefail BASE="${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${BACKEND_IMAGE}" - docker build -t ${BASE}:${{ steps.meta.outputs.sha_tag }} ./backend - [ -n "${{ steps.meta.outputs.latest_tag }}" ] && docker tag ${BASE}:${{ steps.meta.outputs.sha_tag }} ${BASE}:latest - [ -n "${{ steps.meta.outputs.version_tag }}" ] && docker tag ${BASE}:${{ steps.meta.outputs.sha_tag }} ${BASE}:${{ steps.meta.outputs.version_tag }} - - - name: Build frontend - run: | - BASE="${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${FRONTEND_IMAGE}" - docker build -t ${BASE}:${{ steps.meta.outputs.sha_tag }} ./frontend - [ -n "${{ steps.meta.outputs.latest_tag }}" ] && docker tag ${BASE}:${{ steps.meta.outputs.sha_tag }} ${BASE}:latest - [ -n "${{ steps.meta.outputs.version_tag }}" ] && docker tag ${BASE}:${{ steps.meta.outputs.sha_tag }} ${BASE}:${{ steps.meta.outputs.version_tag }} - - - name: Push images - if: github.event_name != 'pull_request' - run: | - if [ "${{ steps.login.outputs.authenticated }}" != "1" ]; then - echo "Skipping push (unauthenticated)"; exit 0; fi - for IMG in ${BACKEND_IMAGE} ${FRONTEND_IMAGE}; do - BASE="${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${IMG}" - docker push ${BASE}:${{ steps.meta.outputs.sha_tag }} - [ -n "${{ steps.meta.outputs.latest_tag }}" ] && docker push ${BASE}:latest - [ -n "${{ steps.meta.outputs.version_tag }}" ] && docker push ${BASE}:${{ steps.meta.outputs.version_tag }} - done - BASE="${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${FRONTEND_IMAGE}" - docker build -t ${BASE}:${{ steps.meta.outputs.sha_tag }} ./frontend + docker build --progress=plain -t ${BASE}:${{ steps.meta.outputs.sha_tag }} ./backend if [ -n "${{ steps.meta.outputs.latest_tag }}" ]; then docker tag ${BASE}:${{ steps.meta.outputs.sha_tag }} ${BASE}:latest; fi if [ -n "${{ steps.meta.outputs.version_tag }}" ]; then docker tag ${BASE}:${{ steps.meta.outputs.sha_tag }} ${BASE}:${{ steps.meta.outputs.version_tag }}; fi - - name: Push images - if: github.event_name != 'pull_request' + - name: Docker build (frontend) + id: build_frontend + shell: bash run: | - if [ "${{ steps.login.outputs.authenticated }}" != "1" ]; then - echo "Skipping push attempt (not authenticated). Provide CR_USERNAME/CR_PASSWORD or GITEA_REGISTRY_TOKEN to enable." - exit 0 - fi + set -euo pipefail + BASE="${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${FRONTEND_IMAGE}" + docker build --progress=plain -t ${BASE}:${{ steps.meta.outputs.sha_tag }} ./frontend + if [ -n "${{ steps.meta.outputs.latest_tag }}" ]; then docker tag ${BASE}:${{ steps.meta.outputs.sha_tag }} ${BASE}:latest; fi + if [ -n "${{ steps.meta.outputs.version_tag }}" ]; then docker tag ${BASE}:${{ steps.meta.outputs.sha_tag }} ${BASE}:${{ steps.meta.outputs.version_tag }}; fi + + - name: Docker push (both images) + id: push_images + if: github.event_name != 'pull_request' && steps.login.outputs.authenticated == '1' + shell: bash + run: | + set -euo pipefail for IMG in ${BACKEND_IMAGE} ${FRONTEND_IMAGE}; do BASE="${{ steps.repo.outputs.host }}/${{ steps.repo.outputs.owner }}/${IMG}" docker push ${BASE}:${{ steps.meta.outputs.sha_tag }} - if [ -n "${{ steps.meta.outputs.latest_tag }}" ]; then docker push ${BASE}:latest; fi - if [ -n "${{ steps.meta.outputs.version_tag }}" ]; then docker push ${BASE}:${{ steps.meta.outputs.version_tag }}; fi + [ -n "${{ steps.meta.outputs.latest_tag }}" ] && docker push ${BASE}:latest || true + [ -n "${{ steps.meta.outputs.version_tag }}" ] && docker push ${BASE}:${{ steps.meta.outputs.version_tag }} || true done + + - name: Summary + if: always() + run: | + echo "Build backend: ${{ steps.build_backend.outcome }}" + echo "Build frontend: ${{ steps.build_frontend.outcome }}" + echo "Login: ${{ steps.login.outcome }} (auth=${{ steps.login.outputs.authenticated }})" + echo "Push images: ${{ steps.push_images.outcome || 'skipped' }}"