feat: update deployment workflow to include latest image tag for main… #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build & Deploy | |
| on: | |
| push: | |
| branches: [main] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }} | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| - run: npm ci | |
| - run: npx prisma generate --schema=apps/api/prisma/schema.prisma | |
| - run: npm run typecheck | |
| - run: npm run lint | |
| - run: npm run test | |
| build-and-push: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| outputs: | |
| image_tag: ${{ steps.meta.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GHCR_TOKEN }} | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.IMAGE_PREFIX }}/stackdify-api,${{ env.IMAGE_PREFIX }}/stackdify-web | |
| tags: | | |
| type=sha,prefix=sha- | |
| type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} | |
| - name: Build & push API image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: apps/api/Dockerfile | |
| push: true | |
| tags: ${{ env.IMAGE_PREFIX }}/stackdify-api:latest,${{ env.IMAGE_PREFIX }}/stackdify-api:sha-${{ github.sha }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Build & push Web image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: apps/web/Dockerfile | |
| push: true | |
| tags: ${{ env.IMAGE_PREFIX }}/stackdify-web:latest,${{ env.IMAGE_PREFIX }}/stackdify-web:sha-${{ github.sha }} | |
| build-args: NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |