diff --git a/.github/workflows/build-and-upload-docker-image.yml b/.github/workflows/build-and-upload-docker-image.yml new file mode 100644 index 0000000..f4a665c --- /dev/null +++ b/.github/workflows/build-and-upload-docker-image.yml @@ -0,0 +1,57 @@ +name: Create and publish Docker image + +on: + push: + workflow_dispatch: +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + attestations: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Get next version + uses: reecetech/version-increment@2023.10.2 + id: version + with: + scheme: calver + increment: patch + + - name: Print version + run: echo "Version is ${{ steps.version.outputs.version }}" + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + if: "contains(github.ref, 'master') && github.event_name != 'pull_request'" + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest + + - name: Build and push Docker image preview + if: "github.ref != 'refs/heads/master'" + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} \ No newline at end of file