diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 1f0d290..ac685e4 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,27 +1,33 @@ -name: Build & Push Notification Service Docker Image +name: Ricash CI - Build & Push Docker Image on: + pull_request: + branches: [ develop, main ] push: - branches: ["main"] + branches: [ develop, main ] permissions: contents: read packages: write +env: + REGISTRY: ghcr.io + ORG: ricash-org + SERVICE_NAME: notification-service + IMAGE_NAME: ghcr.io/ricash-org/notification-service + jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 + # ๐Ÿ” Login GHCR - name: Login to GHCR uses: docker/login-action@v3 with: @@ -29,11 +35,25 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build & Push - uses: docker/build-push-action@v5 - with: - context: . - push: true - platforms: linux/amd64,linux/arm64 - file: ./Dockerfile - tags: ghcr.io/ricash-org/notification-service:latest + # ๐Ÿงช PR โ†’ build only (no push) + - name: Build Docker image (PR) + if: github.event_name == 'pull_request' + run: | + docker build \ + -t $IMAGE_NAME:pr-${{ github.event.pull_request.number }} \ + . + + # ๐Ÿš€ develop โ†’ push dev + - name: Build & Push (develop) + if: github.ref == 'refs/heads/develop' + run: | + docker build -t $IMAGE_NAME:dev . + docker push $IMAGE_NAME:dev + + # ๐Ÿš€ main โ†’ push prod (sha) + - name: Build & Push (main) + if: github.ref == 'refs/heads/main' + run: | + SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7) + docker build -t $IMAGE_NAME:sha-$SHORT_SHA . + docker push $IMAGE_NAME:sha-$SHORT_SHA