Use Docker meta action to handle tags and labels

This commit is contained in:
CrazyMax
2020-10-30 17:58:01 +01:00
parent 0c8e2241d7
commit cf0b5c01e2
2 changed files with 25 additions and 44 deletions

View File

@@ -3,7 +3,7 @@ name: build
on:
push:
branches:
- 'master'
- '**'
- 'v*'
tags:
- 'v*'
@@ -84,28 +84,21 @@ jobs:
docker:
runs-on: ubuntu-latest
needs: go
env:
DOCKERHUB_SLUG: crazymax/diun
steps:
-
name: Checkout
uses: actions/checkout@v2.3.3
-
name: Prepare
id: prep
run: |
DOCKER_IMAGE=crazymax/diun
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
echo ::set-output name=docker_image::${DOCKER_IMAGE}
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=vcs_ref::${GITHUB_SHA::8}
name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: ${{ env.DOCKERHUB_SLUG }}
tag-edge: true
tag-match: v(.*)
tag-match-group: 1
-
name: Set up QEMU
uses: docker/setup-qemu-action@v1
@@ -128,19 +121,23 @@ jobs:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
push: ${{ github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/')) }}
tags: ${{ steps.prep.outputs.tags }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker_meta.outputs.tags }}
build-args: |
VERSION=${{ steps.prep.outputs.version }}
BUILD_DATE=${{ steps.prep.outputs.build_date }}
VCS_REF=${{ steps.prep.outputs.vcs_ref }}
labels: |
${{ steps.docker_meta.outputs.labels }}
org.opencontainers.image.title=Diun
org.opencontainers.image.description=Docker image update notifier
org.opencontainers.image.vendor=CrazyMax
-
name: Check manifest
if: github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/'))
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect ${{ steps.prep.outputs.docker_image }}:${{ steps.prep.outputs.version }}
docker buildx imagetools inspect ${{ env.DOCKERHUB_SLUG }}:${{ steps.docker_meta.outputs.version }}
-
name: Check pull
if: github.event_name != 'pull_request' && (endsWith(github.ref, github.event.repository.default_branch) || startsWith(github.ref, 'refs/tags/'))
name: Inspect
if: github.event_name != 'pull_request'
run: |
docker pull ${{ steps.prep.outputs.docker_image }}:${{ steps.prep.outputs.version }}
docker pull ${{ env.DOCKERHUB_SLUG }}:${{ steps.docker_meta.outputs.version }}
docker image inspect ${{ env.DOCKERHUB_SLUG }}:${{ steps.docker_meta.outputs.version }}

View File

@@ -1,8 +1,6 @@
FROM --platform=${BUILDPLATFORM:-linux/amd64} tonistiigi/xx:golang AS xgo
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13-alpine AS builder
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION=dev
ENV CGO_ENABLED 0
@@ -28,21 +26,7 @@ RUN go env
RUN go build -ldflags "-w -s -X 'main.version=${VERSION}'" -v -o diun cmd/main.go
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:latest
ARG BUILD_DATE
ARG VCS_REF
ARG VERSION
LABEL maintainer="CrazyMax" \
org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.url="https://github.com/crazy-max/diun" \
org.opencontainers.image.source="https://github.com/crazy-max/diun" \
org.opencontainers.image.version=$VERSION \
org.opencontainers.image.revision=$VCS_REF \
org.opencontainers.image.vendor="CrazyMax" \
org.opencontainers.image.title="Diun" \
org.opencontainers.image.description="Docker image update notifier" \
org.opencontainers.image.licenses="MIT"
LABEL maintainer="CrazyMax"
RUN apk --update --no-cache add \
ca-certificates \