update docker build workflow #3
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 CD | |
on: | |
push: | |
branches: | |
- "main" | |
tags: | |
- "*" | |
paths: | |
- "**.rs" | |
- "Cargo.lock" | |
- "Dockerfile" | |
- ".github/workflows/docker.yml" | |
workflow_dispatch: | |
env: | |
REGISTRY: ghcr.io | |
# github.repository as <account>/<repo> | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
docker: | |
name: Build Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Log in to ghcr | |
uses: docker/login-action@v1 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
id: meta | |
uses: docker/metadata-action@v3.6.0 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=sha,format=long,enable=${{ github.ref_type != 'tag' }} | |
type=ref,event=branch | |
type=semver,pattern={{raw}},enable=${{ github.ref_type == 'tag' }} | |
type=raw,value=latest,enable=${{ github.event.ref =='refs/heads/main'}} | |
flavor: latest=false | |
- name: Build & Push | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |