diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 6f472c7..68d5fd1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -3,17 +3,49 @@ name: Docker on: push: branches: [ master ] + tags: [ 'v*.*.*' ] pull_request: branches: [ master ] -jobs: +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} - build: - name: Build +jobs: + build-and-push: + name: Build and Push runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: - - name: Check out code - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=sha,format=long + type=ref,event=branch + type=ref,event=pr + type=raw,value=latest,enable={{is_default_branch}} - - name: Build - run: docker compose build + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}