Add Docker semver tagging for new multiarch image (#503)

This commit is contained in:
Matthias 2022-02-11 09:40:08 +01:00 committed by GitHub
parent 476a048350
commit 12f4134f77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,4 @@
name: Publish Docker Image (new)
on:
repository_dispatch:
workflow_dispatch:
@ -6,116 +7,64 @@ on:
types:
- completed
- requested
push:
branches:
- "**"
tags:
- "v*.*.*"
pull_request:
branches:
- "main"
env:
IMAGE_NAME: lycheeverse/lychee-dev
DOCKER_PLATFORMS: linux/amd64,linux/arm64/v8
DOCKERFILE: Dockerfile-CI.Dockerfile
name: Publish Docker Image (new)
jobs:
build:
name: Build and test Docker images
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
# this is needed because we restart the docker daemon for experimental
# support
options: "--restart always"
env:
# Export environment variables for all stages.
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_DEPLOY_IMAGES: true
# //TEMP replace with correct repo once we are happy with tags
DOCKER_REPO: lycheeverse/lychee-dev
DOCKER_PLATFORMS: linux/amd64,linux/arm64/v8
steps:
- name: Checkout code
- name: Checkout
uses: actions/checkout@v2
# Enable docker daemon experimental support (for 'pull --platform').
- name: Enable experimental support
run: |
config='/etc/docker/daemon.json'
if [[ -e "$config" ]]; then
sudo sed -i -e 's/{/{ "experimental": true, /' "$config"
else
echo '{ "experimental": true }' | sudo tee "$config"
fi
sudo systemctl restart docker
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
# list of Docker images to use as base name for tags
images: |
${{ env.IMAGE_NAME }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx (local builds)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
- name: Set up env vars
run: |
set -vx
# Export environment variable for later stages.
if echo "$GITHUB_REF" | grep -q '^refs/heads/'; then
# Pushes to (master) branch - deploy 'latest'.
echo "TAG=latest" >> $GITHUB_ENV
elif echo "$GITHUB_REF" | grep -q '^refs/tags/'; then
# Pushes tag - deploy tag name.
echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
else
# Use commit SHA for PR
echo "TAG=${GITHUB_SHA::8}" >> $GITHUB_ENV
fi
- name: Build and push to local registry
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile-CI.Dockerfile
platforms: ${{ env.DOCKER_PLATFORMS }}
push: true
tags: localhost:5000/${{ env.DOCKER_REPO }}:${{ env.TAG }}
- name: Test docker images locally
run: |
for platform in ${DOCKER_PLATFORMS/,/ }; do
image="localhost:5000/${DOCKER_REPO}:${TAG}"
msg="Testing docker image $image on platform $platform"
line="${msg//?/=}"
printf "\n${line}\n${msg}\n${line}\n"
docker pull -q --platform "$platform" "$image"
echo -n "Image architecture: "
docker run --platform "$platform" --rm --entrypoint /bin/sh "$image" -c 'uname -m'
version=$(docker run --platform "$platform" --rm "$image" --version)
echo "lychee version: $version"
if [[ $TAG != "latest" ]] &&
[[ $TAG != "$version" ]] &&
! echo "$version" | grep -q "$TAG"; then
echo "Version mismatch: lychee $version tagged as $TAG"
exit 1
fi
done
- name: Check GitHub settings
if: >
github.event_name == 'push' &&
(github.ref == 'refs/heads/master' ||
startsWith(github.ref, 'refs/tags/')) &&
github.repository == 'lycheeverse/lychee'
run: |
missing=()
[[ -n "${{ secrets.DOCKER_USERNAME }}" ]] || missing+=(DOCKER_USERNAME)
[[ -n "${{ secrets.DOCKER_PASSWORD }}" ]] || missing+=(DOCKER_PASSWORD)
for i in "${missing[@]}"; do
echo "Missing github secret: $i"
done
(( ${#missing[@]} == 0 )) || exit 1
echo "DOCKER_DEPLOY_IMAGES=true" >> $GITHUB_ENV
- name: Login to DockerHub
if: ${{ env.DOCKER_DEPLOY_IMAGES == 'true' }}
if: ${{ github.repository_owner == 'lycheeverse' }}
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push images to DockerHub
if: ${{ env.DOCKER_DEPLOY_IMAGES == 'true' }}
run: |
image_src="${DOCKER_REPO}:${TAG}"
image_dst="${{ env.DOCKER_REPO }}:${TAG}"
msg="Copy multi-arch docker images to DockerHub ($image)"
line="${msg//?/=}"
printf "\n${line}\n${msg}\n${line}\n"
skopeo copy --all --src-tls-verify=0 docker://localhost:5000/$image_src docker://docker.io/$image_dst
- name: Push Image
if: ${{ github.repository_owner == 'lycheeverse' }}
uses: docker/build-push-action@v2
with:
context: .
file: ${{ env.DOCKERFILE }}
platforms: ${{ env.DOCKER_PLATFORMS }}
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}