Skip to content

Build & Release

Build & Release #881

Workflow file for this run

name: "Build & Release"
# This worflow needs those secrets:
#
# DOCKERPASSWORD = Docker Hub token
on:
schedule:
- cron: '3 3 * * *'
push:
branches:
- 'master'
- 'main'
env:
PLATFORMS: "linux/amd64,linux/arm/v7,linux/arm64" # Build for which platforms
DOCKER_USER: "tdeutsch" # Which user to use to login to DockerHub
#####
# To rebuild someone else's repo, do this:
#
# - New env REPOSITORY: "githubuser/githubrepo"
# - Add this to the checkout:
# with:
# repository: ${{ env.REPOSITORY }}
# - One may also need to disable hadolint, due to the quality of others Dockerfile
#####
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/[email protected]
-
name: Generate Build-Args
id: build-args
run: |
# echo ::set-output name=build-arg1::"buildarg1"
# echo ::set-output name=build-arg2::"buildarg2"
-
name: Bump version and push tag if needed
id: tag_version
if: github.event_name == 'push'
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
-
name: Create a GitHub release if new version
uses: actions/create-release@v1
if: ${{ steps.tag_version.outputs.new_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
-
name: Prepare
id: prep
run: |
IMAGENAME=$(echo ${{ github.repository }} | sed 's/${{ github.repository_owner }}\/docker-//g')
IMAGEPREFIX="ghcr.io/${{ github.repository_owner }}"
IMAGE="${IMAGEPREFIX}/${IMAGENAME}"
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=devel
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
if [[ "${{ steps.tag_version.outputs.new_tag }}" != "" ]]; then
VERSION=${{ steps.tag_version.outputs.new_tag }}
fi
TAGS="${IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${IMAGE}:${MINOR},${IMAGE}:${MAJOR},${IMAGE}:latest"
# elif [ "${{ github.event_name }}" = "push" ]; then
# TAGS="$TAGS,${IMAGE}:sha-${GITHUB_SHA::8}"
fi
TAGS="$(echo $TAGS | sed 's|ghcr.io/tuxpeople|docker.io/tdeutsch|g'),$TAGS"
echo ${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=imagename::${IMAGENAME}
echo ::set-output name=version::${VERSION}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
-
name: Hadolint
uses: brpaz/[email protected]
with:
dockerfile: Dockerfile
-
name: Set up QEMU
uses: docker/[email protected]
-
name: Set up Docker Buildx
uses: docker/[email protected]
-
name: Login to GHCR
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Login to Dockerhub
uses: docker/login-action@v2
if: github.event_name != 'pull_request'
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKERPASSWORD }}
-
name: Build and push
id: docker_build
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
${{ steps.build-args.outputs.build-arg1 }}
${{ steps.build-args.outputs.build-arg2 }}
labels: |
org.opencontainers.image.title=${{ steps.prep.outputs.imagename }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.version=${{ steps.prep.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
-
# name: Copy to Docker Hub
# id: copy_images
# run: |
# for i in $(echo ${{ steps.prep.outputs.tags }} | sed "s/,/ /g")
# do
# GHTAG=$(echo $i | sed "s/ghcr.io/docker.io/g" | sed "s/${{ github.repository_owner }}/${{ env.DOCKER_USER }}/g")
# skopeo copy --all --src-creds=${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }} --dest-creds=${{ env.DOCKER_USER }}:${{ secrets.DOCKERPASSWORD }} docker://${i} docker://${GHTAG}
# done
# -
name: Docker Hub Description
uses: peter-evans/[email protected]
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKERPASSWORD }}
repository: "${{ env.DOCKER_USER }}/${{ steps.prep.outputs.imagename }}"
short-description: ${{ github.event.repository.description }}