diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e165beb..0a4a3f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,11 +5,16 @@ on: push: branches: - main + tags: + - "v*" concurrency: group: ci-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + jobs: backend: name: Backend tests @@ -88,6 +93,7 @@ jobs: docker: name: Docker build runs-on: ubuntu-latest + if: ${{ !startsWith(github.ref, 'refs/tags/') }} needs: - backend - frontend @@ -108,3 +114,53 @@ jobs: tags: upopoy:ci cache-from: type=gha cache-to: type=gha,mode=max + + docker-push: + name: Docker image publish + runs-on: ubuntu-latest + if: ${{ startsWith(github.ref, 'refs/tags/') }} + needs: + - backend + - frontend + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Prepare image name + id: image + shell: bash + run: echo "name=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT" + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ steps.image.outputs.name }} + tags: | + type=ref,event=tag + type=sha,prefix=sha- + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build application image + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max