Use commit hash to tag container images #175
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker build | |
on: | |
push: | |
branches: | |
- 'main' | |
pull_request: | |
workflow_dispatch: | |
jobs: | |
docker-build: | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Block workflow_dispatch on main branch | |
if: github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' | |
run: | | |
echo "This workflow can not be triggered with workflow_dispatch on the main branch" | |
exit 1 | |
- | |
name: Checkout | |
uses: actions/checkout@v2.3.5 | |
- | |
name: Docker meta | |
id: docker_meta | |
uses: crazy-max/ghaction-docker-meta@v3.6.0 | |
with: | |
images: ghcr.io/${{ github.repository }} | |
tags: | | |
type=sha | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v1.2.0 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1.6.0 | |
- | |
name: Cache Docker layers | |
uses: actions/cache@v2.1.6 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- | |
name: Login to GitHub Container Registry | |
uses: docker/login-action@v1.10.0 | |
if: github.event_name != 'pull_request' | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- | |
name: Build and push | |
uses: docker/build-push-action@v2.7.0 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64 | |
cache-from: type=local,src=/tmp/.buildx-cache | |
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.docker_meta.outputs.tags }} | |
labels: ${{ steps.docker_meta.outputs.labels }} |