fix: deploy only when pushed to main #199
Workflow file for this run
This file contains 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 and Publish Docker Image | |
on: | |
push: | |
branches: | |
- '**' | |
tags: | |
- "v*" | |
jobs: | |
# define job to build and publish docker image | |
build-and-push-docker-image: | |
strategy: | |
matrix: | |
app: [admin-server, api-server, auth-server, image-server, cms-server] | |
include: | |
- app: api-server | |
build-target: release-with-packages | |
name: '[${{ matrix.app }}] Build & push image' | |
runs-on: ubuntu-latest | |
outputs: | |
image_tag: ${{ steps.image_output.outputs.image_tag }} | |
env: | |
IMAGE: '${{ github.repository_owner }}/${{ matrix.app }}' | |
APP: ${{ matrix.app }} | |
BUILD_TARGET: release | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- if: ${{ matrix.build-target }} | |
name: Set correct build target | |
run: echo "BUILD_TARGET=${{ matrix.build-target}}" >> $GITHUB_ENV | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.IMAGE }} | |
tags: | | |
# branch event | |
type=ref,event=branch,suffix=-{{sha}} | |
# tag event | |
type=ref,event=tag | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build image and push to GitHub Container Registry | |
id: docker_build | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: 'ghcr.io/${{ steps.meta.outputs.tags }}' | |
build-args: | | |
APP=${{ matrix.app }} | |
- name: Add image output | |
id: image_output | |
run: echo "image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT" | |
display_images_in_action: | |
name: Display images in Github Action | |
runs-on: ubuntu-latest | |
needs: build-and-push-docker-image | |
steps: | |
- name: Display images in Github Action | |
run: | | |
echo "**New images 🐳** | |
| App | Image | | |
|---|---| | |
| admin-server | \`ghcr.io/${{ github.repository_owner}}/admin-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` | | |
| api-server | \`ghcr.io/${{ github.repository_owner}}/api-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` | | |
| cms-server | \`ghcr.io/${{ github.repository_owner}}/cms-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` | | |
| auth-server | \`ghcr.io/${{ github.repository_owner}}/auth-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` | | |
| image-server | \`ghcr.io/${{ github.repository_owner}}/image-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}\` |" >> $GITHUB_STEP_SUMMARY |