Skip to content

Commit

Permalink
chore: improve docker github action
Browse files Browse the repository at this point in the history
  • Loading branch information
tchapi committed Jan 14, 2024
1 parent 4218e83 commit 5761811
Showing 1 changed file with 61 additions and 32 deletions.
93 changes: 61 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,88 @@
name: Publish Docker image

on:
workflow_dispatch:
release:
types: [published]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
push_to_registry:
name: Push Docker image to GitHub Packages
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Prepare tags
id: prepare_tags
run: |
REPOSITORY=ghcr.io
DOCKER_IMAGE=tchapi/davis
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
fi
TAGS="${REPOSITORY}/${DOCKER_IMAGE}:${VERSION}"
if [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${REPOSITORY}/${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
uses: actions/checkout@v4
# -
# name: Prepare tags
# id: prepare_tags
# run: |
# REPOSITORY=ghcr.io
# DOCKER_IMAGE=tchapi/davis
# VERSION=edge
# if [[ $GITHUB_REF == refs/tags/* ]]; then
# VERSION=${GITHUB_REF#refs/tags/}
# fi
# TAGS="${REPOSITORY}/${DOCKER_IMAGE}:${VERSION}"
# if [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${REPOSITORY}/${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
# fi
# echo "version=${VERSION}" >> $GITHUB_OUTPUT
# echo "tags=${TAGS}" >> $GITHUB_OUTPUT
# echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
name: Login to GitHub Container Registry (${{ env.REGISTRY }})
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

-
name: Docker meta
# if: github.event_name == 'push' || github.event_name == 'pull_request' && github.event.pull_request. ... ==
id: meta
uses: docker/metadata-action@v5
env:
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index,manifest-descriptor,index-descriptor
with:
context: git
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# type=sha
tags: |
type=semver,pattern=test{{version}}
type=edge,branch=${{ github.ref_name }}
-
name: Build and Push to GitHub Packages
id: docker_build
uses: docker/build-push-action@v3
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
platforms: linux/amd64 #,linux/arm64
file: docker/Dockerfile
pull: true
push: true
tags: ${{ steps.prepare_tags.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prepare_tags.outputs.created }}
org.opencontainers.image.version=${{ steps.prepare_tags.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
annotations: ${{ steps.meta.outputs.annotations }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},annotation-org.opencontainers.image.description=My multi-arch image
# tags: ${{ steps.prepare_tags.outputs.tags }}
# labels: |
# org.opencontainers.image.source=${{ github.event.repository.html_url }}
# org.opencontainers.image.created=${{ steps.prepare_tags.outputs.created }}
# org.opencontainers.image.version=${{ steps.prepare_tags.outputs.version }}
# org.opencontainers.image.revision=${{ github.sha }}

0 comments on commit 5761811

Please sign in to comment.