diff --git a/.github/workflows/build-push-docker.yaml b/.github/workflows/build-push-docker.yaml new file mode 100644 index 0000000..ae1e336 --- /dev/null +++ b/.github/workflows/build-push-docker.yaml @@ -0,0 +1,61 @@ +name: Build Docker image and push to GHCR + +on: + # Can be triggered manually + workflow_dispatch: + # Runs automatically on pushes (merges) to the branch + push: + branches: + - master + +# Allow one concurrent build +concurrency: build-and-push + +# Least required permissions +permissions: + contents: read + packages: write + +env: + # Has to be in form ghcr.io/USER/REPO_NAME + # github.repository is exactly USER/REPO_NAME part + IMAGE_NAME: ghcr.io/${{ github.repository }} + +jobs: + build: + timeout-minutes: 5 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Login to GHCR + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push + uses: docker/build-push-action@v3 + with: + builder: ${{ steps.buildx.outputs.name }} + + # Build options + context: ./ + file: ./Dockerfile + tags: ${{ env.IMAGE_NAME }}:latest + + # Push the result to the registry + push: true + + # Cache layers in the registry + cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache + cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max + + # Label to link the resulting package to the current repository + labels: | + org.opencontainers.image.source=${{ github.repositoryUrl }}