diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 3e088e96..7c1909f8 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,32 +1,50 @@ -name: docker +name: Docker on: push: - branches: - - "main" + branches: [main] + tags: ['v*'] + pull_request: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: - docker: + build: runs-on: ubuntu-latest + permissions: + contents: read + packages: write strategy: matrix: - platform: - - linux/amd64 - - linux/arm64 + platform: [linux/amd64, linux/arm64] steps: - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Login to Docker Hub - uses: docker/login-action@v3 + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - uses: docker/build-push-action@v6 + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - id: meta + uses: docker/metadata-action@v5 with: - # Only push on the master branch - push: ${{ github.ref == 'refs/heads/master' }} + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + - uses: docker/build-push-action@v6 + with: + context: . platforms: ${{ matrix.platform }} - tags: ${{ secrets.DOCKERHUB_USERNAME }}/adaptive-lighting:latest + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max