From f219effc33154334e95663eee73ff1b9e0b4fa7c Mon Sep 17 00:00:00 2001 From: ismail Date: Sun, 19 Apr 2026 11:36:40 +0300 Subject: [PATCH] Add CI pipeline for Docker image builds --- .dockerignore | 1 + .gitea/workflows/build.yml | 61 ++++++++++++++++++++++++++++++++++++++ build-and-push.sh | 37 ++++++++--------------- 3 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 .gitea/workflows/build.yml diff --git a/.dockerignore b/.dockerignore index fb5b60a..12598e3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ .git .gitignore +.gitea/ .opencode/ .qwen/ .ruff_cache/ diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..ee24dec --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,61 @@ +name: Build and Push Docker Image + +on: + push: + branches: [main, staging] + tags: ["v*"] + +env: + REGISTRY: gitea.tenhal.sa + IMAGE_NAME: marwan/hh + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ gitea.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Determine tags + id: meta + run: | + IMAGE="${REGISTRY}/${IMAGE_NAME}" + BRANCH="${GITHUB_REF_NAME}" + SHA=$(echo "${GITHUB_SHA}" | cut -c1-7) + + TAGS="" + + if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then + VERSION="${GITHUB_REF_NAME}" + TAGS="${IMAGE}:${VERSION}" + echo "Building release: ${VERSION}" + elif [[ "${BRANCH}" == "main" ]]; then + TAGS="${IMAGE}:latest,${IMAGE}:${SHA}" + echo "Building main: latest + ${SHA}" + elif [[ "${BRANCH}" == "staging" ]]; then + TAGS="${IMAGE}:staging,${IMAGE}:staging-${SHA}" + echo "Building staging: staging + staging-${SHA}" + fi + + echo "tags=${TAGS}" >> "$GITHUB_OUTPUT" + echo "Pushing tags: ${TAGS}" + + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache + cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max diff --git a/build-and-push.sh b/build-and-push.sh index 197baad..c036fec 100755 --- a/build-and-push.sh +++ b/build-and-push.sh @@ -1,47 +1,34 @@ #!/bin/bash set -e +# Manual fallback — CI normally handles this via .gitea/workflows/build.yml +# Usage: ./build-and-push.sh [tag] +# ./build-and-push.sh staging +# ./build-and-push.sh v1.0.0 + REGISTRY="gitea.tenhal.sa/marwan/hh" TAG=${1:-staging} echo "========================================" -echo " PX360 Build & Push" +echo " PX360 Manual Build & Push (fallback)" echo " Tag: $REGISTRY:$TAG" echo " $(date '+%Y-%m-%d %H:%M:%S')" echo "========================================" +echo "" +echo "NOTE: CI normally handles this. Only use if CI is unavailable." +echo "" -if ! docker login "$REGISTRY" 2>/dev/null; then - echo "" - echo "Login required. Enter your Gitea credentials:" - echo " Username: your Gitea username" - echo " Password: your Gitea token (Settings > Applications > Access Tokens)" - echo "" - docker login "$REGISTRY" -fi +docker login gitea.tenhal.sa echo "" echo "[1/3] Building image..." docker build -t "$REGISTRY:$TAG" . -SHORT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") -if [ "$SHORT_SHA" != "unknown" ]; then - docker tag "$REGISTRY:$TAG" "$REGISTRY:$SHORT_SHA" - echo " Also tagged: $REGISTRY:$SHORT_SHA" -fi - echo "" echo "[2/3] Pushing to registry..." docker push "$REGISTRY:$TAG" -if [ "$SHORT_SHA" != "unknown" ]; then - docker push "$REGISTRY:$SHORT_SHA" -fi echo "" -echo "[3/3] Done!" +echo "[3/3] Done! Pushed: $REGISTRY:$TAG" echo "" -echo "Images pushed:" -echo " $REGISTRY:$TAG" -[ "$SHORT_SHA" != "unknown" ] && echo " $REGISTRY:$SHORT_SHA" -echo "" -echo "Deploy to staging: ./deploy.staging.sh $TAG" -echo "Deploy to prod: ./deploy.prod.sh $TAG" +echo "Deploy: ./deploy.staging.sh $TAG (or ./deploy.prod.sh $TAG)"