2020-11-09 16:17:37 +01:00
|
|
|
name: Docker multi-arch build and push
|
2020-11-06 01:42:25 +01:00
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
pull_request:
|
|
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
2020-11-09 16:17:37 +01:00
|
|
|
name: Build Docker image (${{ matrix.arch }})
|
2020-11-06 01:42:25 +01:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
2020-11-09 16:17:37 +01:00
|
|
|
IMAGE_TAG: ghcr.io/${{ github.repository_owner }}/tdlightbotapi
|
2020-11-09 16:53:08 +01:00
|
|
|
IMAGE_TAG_DH: ${{ secrets.DOCKERHUB_OWNER }}/tdlightbotapi
|
2020-11-09 16:17:37 +01:00
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
arch: [linux/386, linux/amd64, linux/arm/v6, linux/arm/v7, linux/arm64, linux/ppc64le]
|
2020-11-06 01:42:25 +01:00
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout current repo
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
with:
|
2020-11-09 16:17:37 +01:00
|
|
|
submodules: "recursive"
|
2020-11-06 01:42:25 +01:00
|
|
|
|
2020-11-08 13:40:45 +01:00
|
|
|
- name: Get version
|
2020-11-06 01:42:25 +01:00
|
|
|
run: |
|
2020-11-08 13:40:45 +01:00
|
|
|
# Get latest commit short hash
|
|
|
|
HASH_VERSION=$(git rev-parse --short HEAD)
|
2020-11-06 01:42:25 +01:00
|
|
|
|
2020-11-08 13:40:45 +01:00
|
|
|
# Strip git ref prefix from version
|
|
|
|
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
|
|
|
|
|
|
|
# Strip "v" prefix from tag name
|
|
|
|
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
|
|
|
|
|
|
|
|
# Use Docker `latest` tag convention
|
|
|
|
[ "$VERSION" == "master" ] && VERSION=latest
|
|
|
|
|
2020-11-09 16:17:37 +01:00
|
|
|
# Convert IMAGE_TAG, HASH_VERSION and VERSION to lowercase (repository name must be lowercase)
|
|
|
|
IMAGE_TAG=$(echo "$IMAGE_TAG" | awk '{print tolower($0)}')
|
|
|
|
IMAGE_TAG_DH=$(echo "$IMAGE_TAG_DH" | awk '{print tolower($0)}')
|
2020-11-08 13:40:45 +01:00
|
|
|
HASH_VERSION=$(echo "$HASH_VERSION" | awk '{print tolower($0)}')
|
|
|
|
VERSION=$(echo "$VERSION" | awk '{print tolower($0)}')
|
2020-11-09 16:17:37 +01:00
|
|
|
ARCH=${{ matrix.arch }}
|
|
|
|
SAFE_ARCH=${ARCH///} # linux/amd64 -> linuxamd64
|
2020-11-06 01:42:25 +01:00
|
|
|
|
2020-11-08 13:40:45 +01:00
|
|
|
# Store variable for future use
|
2020-11-09 16:17:37 +01:00
|
|
|
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
|
|
|
|
echo "IMAGE_TAG_DH=$IMAGE_TAG_DH" >> $GITHUB_ENV
|
2020-11-08 13:40:45 +01:00
|
|
|
echo "HASH_VERSION=$HASH_VERSION" >> $GITHUB_ENV
|
|
|
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
2020-11-09 16:17:37 +01:00
|
|
|
echo "SAFE_ARCH=$SAFE_ARCH" >> $GITHUB_ENV
|
2020-11-06 01:42:25 +01:00
|
|
|
|
2020-11-08 13:40:45 +01:00
|
|
|
# Print debug info
|
|
|
|
echo "hash version: $HASH_VERSION"
|
|
|
|
echo "version: $VERSION"
|
2020-11-09 16:17:37 +01:00
|
|
|
echo "safe arch: $SAFE_ARCH"
|
|
|
|
|
|
|
|
# Save env to file
|
|
|
|
cat $GITHUB_ENV > github.env
|
|
|
|
|
|
|
|
- name: Upload environment info as artifact
|
|
|
|
uses: actions/upload-artifact@v2
|
|
|
|
with:
|
|
|
|
name: github_env
|
|
|
|
path: github.env
|
|
|
|
|
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@v1
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
|
|
|
|
- name: Cache Docker layers
|
|
|
|
uses: actions/cache@v2
|
|
|
|
with:
|
|
|
|
path: /tmp/.buildx-cache
|
|
|
|
key: ${{ runner.os }}-buildx-${{ env.SAFE_ARCH }}-${{ github.sha }}
|
|
|
|
restore-keys: |
|
|
|
|
${{ runner.os }}-buildx-${{ env.SAFE_ARCH }}-
|
|
|
|
|
|
|
|
- name: Login to ghcr registry
|
|
|
|
uses: docker/login-action@v1
|
2020-11-25 00:29:28 +01:00
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
2020-11-09 16:17:37 +01:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ secrets.GH_USERNAME }}
|
|
|
|
password: ${{ secrets.GH_ACCESS_TOKEN }}
|
|
|
|
|
|
|
|
- name: Login to Docker Hub registry
|
|
|
|
uses: docker/login-action@v1
|
2020-11-25 00:29:28 +01:00
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
2020-11-09 16:17:37 +01:00
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
|
2020-11-06 01:42:25 +01:00
|
|
|
|
|
|
|
- name: Build image
|
2020-11-09 16:17:37 +01:00
|
|
|
uses: docker/build-push-action@v2
|
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
file: ./Dockerfile
|
|
|
|
cache-from: type=local,src=/tmp/.buildx-cache
|
|
|
|
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache
|
|
|
|
platforms: ${{ matrix.arch }}
|
|
|
|
push: false
|
|
|
|
load: true
|
|
|
|
tags: |
|
|
|
|
tdlightbotapi:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }}
|
|
|
|
|
|
|
|
- name: Tag and push image
|
2020-11-25 00:29:28 +01:00
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
2020-11-06 01:42:25 +01:00
|
|
|
run: |
|
2020-11-09 16:17:37 +01:00
|
|
|
docker tag tdlightbotapi:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }} ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }}
|
|
|
|
docker tag tdlightbotapi:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }} ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-${{ env.SAFE_ARCH }}
|
|
|
|
docker tag tdlightbotapi:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }} ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }}
|
|
|
|
docker tag tdlightbotapi:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }} ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-${{ env.SAFE_ARCH }}
|
|
|
|
docker push ${{ env.IMAGE_TAG}}:${{ env.HASH_VERSION}}-${{ env.SAFE_ARCH }}
|
|
|
|
docker push ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-${{ env.SAFE_ARCH }}
|
|
|
|
docker push ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }}
|
|
|
|
docker push ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-${{ env.SAFE_ARCH }}
|
2020-11-06 01:42:25 +01:00
|
|
|
|
2020-11-09 16:17:37 +01:00
|
|
|
- name: Save image as tar archive
|
2020-11-25 00:29:28 +01:00
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
2020-11-06 01:42:25 +01:00
|
|
|
run: |
|
2020-11-09 16:17:37 +01:00
|
|
|
docker save ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }} -o ${{ env.SAFE_ARCH }}.tar
|
|
|
|
|
2020-11-24 15:23:00 +01:00
|
|
|
- name: Save image as tar archive (pull request)
|
|
|
|
if: ${{ github.event_name == 'pull_request' }}
|
|
|
|
run: |
|
|
|
|
docker save tdlightbotapi:${{ env.HASH_VERSION }}-${{ env.SAFE_ARCH }} -o ${{ env.SAFE_ARCH }}.tar
|
|
|
|
|
2020-11-09 16:17:37 +01:00
|
|
|
- name: Upload image as artifact
|
|
|
|
uses: actions/upload-artifact@v2
|
|
|
|
with:
|
|
|
|
name: image_${{ env.SAFE_ARCH }}
|
|
|
|
path: ${{ env.SAFE_ARCH }}.tar
|
2020-11-06 01:42:25 +01:00
|
|
|
|
2020-11-09 16:17:37 +01:00
|
|
|
push-manifest:
|
|
|
|
name: Create and push multi-arch Docker manifest
|
|
|
|
runs-on: ubuntu-latest
|
2020-11-25 00:29:28 +01:00
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
2020-11-09 16:17:37 +01:00
|
|
|
env:
|
|
|
|
DOCKER_CLI_EXPERIMENTAL: enabled
|
|
|
|
needs: build
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Download artifacts
|
|
|
|
uses: actions/download-artifact@v2
|
|
|
|
|
|
|
|
- name: Load environment info and built images
|
2020-11-06 01:42:25 +01:00
|
|
|
run: |
|
2020-11-09 16:17:37 +01:00
|
|
|
cat github_env/github.env > $GITHUB_ENV
|
|
|
|
docker load --input image_linux386/linux386.tar
|
|
|
|
docker load --input image_linuxamd64/linuxamd64.tar
|
|
|
|
docker load --input image_linuxarmv6/linuxarmv6.tar
|
|
|
|
docker load --input image_linuxarmv7/linuxarmv7.tar
|
|
|
|
docker load --input image_linuxarm64/linuxarm64.tar
|
|
|
|
docker load --input image_linuxppc64le/linuxppc64le.tar
|
|
|
|
|
|
|
|
- name: Login to ghcr registry
|
|
|
|
uses: docker/login-action@v1
|
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ secrets.GH_USERNAME }}
|
|
|
|
password: ${{ secrets.GH_ACCESS_TOKEN }}
|
2020-11-08 13:40:45 +01:00
|
|
|
|
2020-11-09 16:17:37 +01:00
|
|
|
- name: Login to Docker Hub registry
|
|
|
|
uses: docker/login-action@v1
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
|
|
|
|
|
|
|
|
- name: Create and push manifest
|
2020-11-08 13:40:45 +01:00
|
|
|
run: |
|
2020-11-09 16:17:37 +01:00
|
|
|
# -- Push to ghcr.io
|
|
|
|
docker manifest create ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }} \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linux386 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxamd64 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarmv6 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarmv7 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarm64 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxppc64le
|
|
|
|
docker manifest push ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}
|
|
|
|
|
|
|
|
# Tag images as VERSION (like 'latest')
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linux386 ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linux386
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxamd64 ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxamd64
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarmv6 ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxarmv6
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarmv7 ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxarmv7
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarm64 ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxarm64
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxppc64le ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxppc64le
|
|
|
|
|
|
|
|
docker manifest create ${{ env.IMAGE_TAG }}:${{ env.VERSION }} \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linux386 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxamd64 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxarmv6 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxarmv7 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxarm64 \
|
|
|
|
--amend ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-linuxppc64le
|
|
|
|
docker manifest push ${{ env.IMAGE_TAG }}:${{ env.VERSION }}
|
|
|
|
|
|
|
|
# -- Push to Docker Hub
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linux386 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linux386
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxamd64 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxamd64
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarmv6 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarmv6
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarmv7 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarmv7
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarm64 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarm64
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxppc64le ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxppc64le
|
|
|
|
|
|
|
|
docker manifest create ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }} \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}-linux386 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}-linuxamd64 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}-linuxarmv6 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}-linuxarmv7 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}-linuxarm64 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}-linuxppc64le
|
|
|
|
docker manifest push ${{ env.IMAGE_TAG_DH }}:${{ env.HASH_VERSION }}
|
|
|
|
|
|
|
|
# Tag images as VERSION (like 'latest')
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linux386 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linux386
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxamd64 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxamd64
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarmv6 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarmv6
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarmv7 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarmv7
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxarm64 ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarm64
|
|
|
|
docker tag ${{ env.IMAGE_TAG }}:${{ env.HASH_VERSION }}-linuxppc64le ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxppc64le
|
|
|
|
|
|
|
|
docker manifest create ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }} \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linux386 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxamd64 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarmv6 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarmv7 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxarm64 \
|
|
|
|
--amend ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}-linuxppc64le
|
|
|
|
docker manifest push ${{ env.IMAGE_TAG_DH }}:${{ env.VERSION }}
|