2024-01-05 11:15:49 +00:00
|
|
|
name: Docker multi-arch build and push
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
2024-01-05 15:55:44 +00:00
|
|
|
branches:
|
|
|
|
- master
|
2024-01-07 13:31:06 +00:00
|
|
|
schedule:
|
|
|
|
- cron: '20 4 * * *'
|
2024-01-05 11:15:49 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
name: Build Docker image (${{ matrix.arch }})
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
2024-01-06 08:37:23 +00:00
|
|
|
IMAGE_TAG: ${{ secrets.DOCKERHUB_OWNER }}/telegram-bot-api
|
2024-06-09 21:23:58 +00:00
|
|
|
ALPINE_VERSION: 3.20
|
2024-01-05 11:15:49 +00:00
|
|
|
strategy:
|
|
|
|
matrix:
|
2024-01-05 15:55:44 +00:00
|
|
|
arch:
|
|
|
|
- linux/386
|
|
|
|
- linux/amd64
|
|
|
|
- linux/arm/v6
|
|
|
|
- linux/arm/v7
|
|
|
|
- linux/arm64
|
|
|
|
- linux/ppc64le
|
2024-01-05 11:15:49 +00:00
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout current repo
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: actions/checkout@v4.1.6
|
2024-01-05 11:15:49 +00:00
|
|
|
|
|
|
|
- name: Checkout upstream repo
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: actions/checkout@v4.1.6
|
2024-01-05 11:15:49 +00:00
|
|
|
with:
|
|
|
|
repository: tdlib/telegram-bot-api
|
|
|
|
path: telegram-bot-api
|
|
|
|
submodules: recursive
|
|
|
|
|
|
|
|
- name: Get version
|
|
|
|
run: |
|
|
|
|
# Get latest commit short hash
|
|
|
|
HASH_VERSION=$(git rev-parse --short HEAD)
|
|
|
|
|
|
|
|
# Get real version from the code
|
|
|
|
VERSION=$(cat telegram-bot-api/CMakeLists.txt | grep TelegramBotApi | cut -d " " -f3)
|
|
|
|
|
|
|
|
# Convert IMAGE_TAG, HASH_VERSION and VERSION to lowercase (repository name must be lowercase)
|
|
|
|
IMAGE_TAG=$(echo "$IMAGE_TAG" | awk '{print tolower($0)}')
|
|
|
|
VERSION=$(echo "$VERSION" | awk '{print tolower($0)}')
|
|
|
|
ARCH=${{ matrix.arch }}
|
|
|
|
SAFE_ARCH=${ARCH///} # linux/amd64 -> linuxamd64
|
|
|
|
|
|
|
|
# Store variable for future use
|
|
|
|
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
|
|
|
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
|
|
|
echo "SAFE_ARCH=$SAFE_ARCH" >> $GITHUB_ENV
|
|
|
|
|
|
|
|
# Print debug info
|
|
|
|
echo "version: $VERSION"
|
|
|
|
echo "safe arch: $SAFE_ARCH"
|
|
|
|
|
|
|
|
# Save env to file
|
|
|
|
cat $GITHUB_ENV > github.env
|
|
|
|
|
|
|
|
- name: Upload environment info as artifact
|
2024-06-09 21:23:58 +00:00
|
|
|
uses: actions/upload-artifact@v4.3.3
|
2024-06-09 21:31:23 +00:00
|
|
|
if: matrix.arch == 'linux/amd64' # Run this step only once per all matrix builds
|
2024-01-05 11:15:49 +00:00
|
|
|
with:
|
|
|
|
name: github_env
|
|
|
|
path: github.env
|
|
|
|
|
|
|
|
- name: Set up QEMU
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: docker/setup-qemu-action@v3.0.0
|
2024-01-05 11:15:49 +00:00
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: docker/setup-buildx-action@v3.3.0
|
2024-01-05 11:15:49 +00:00
|
|
|
|
|
|
|
- name: Cache Docker layers
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: actions/cache@v4.0.2
|
2024-01-05 11:15:49 +00:00
|
|
|
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 Docker Hub registry
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: docker/login-action@v3.2.0
|
2024-01-05 11:15:49 +00:00
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKERHUB_LOGIN }}
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Build image
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: docker/build-push-action@v5.3.0
|
2024-01-05 11:15:49 +00:00
|
|
|
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 }}
|
2024-01-07 13:31:06 +00:00
|
|
|
build-args: |
|
|
|
|
ALPINE_VERSION=${{ env.ALPINE_VERSION }}
|
2024-01-05 11:15:49 +00:00
|
|
|
push: false
|
|
|
|
load: true
|
|
|
|
tags: |
|
2024-01-06 08:39:37 +00:00
|
|
|
${{ env.IMAGE_TAG }}:${{ env.VERSION }}-${{ env.SAFE_ARCH }}
|
2024-01-05 11:15:49 +00:00
|
|
|
|
|
|
|
- name: Tag and push image
|
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
|
|
|
run: |
|
|
|
|
docker push ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-${{ env.SAFE_ARCH }}
|
|
|
|
|
|
|
|
- name: Save image as tar archive
|
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
|
|
|
run: |
|
2024-01-06 08:39:37 +00:00
|
|
|
docker save ${{ env.IMAGE_TAG }}:${{ env.VERSION }}-${{ env.SAFE_ARCH }} -o ${{ env.SAFE_ARCH }}.tar
|
2024-01-05 11:15:49 +00:00
|
|
|
|
|
|
|
- name: Upload image as artifact
|
2024-06-09 21:23:58 +00:00
|
|
|
uses: actions/upload-artifact@v4.3.0
|
2024-01-05 11:15:49 +00:00
|
|
|
with:
|
|
|
|
name: image_${{ env.SAFE_ARCH }}
|
|
|
|
path: ${{ env.SAFE_ARCH }}.tar
|
|
|
|
|
|
|
|
push-manifest:
|
|
|
|
name: Create and push multi-arch Docker manifest
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: ${{ github.event_name != 'pull_request' }}
|
|
|
|
env:
|
|
|
|
DOCKER_CLI_EXPERIMENTAL: enabled
|
|
|
|
needs: build
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Download artifacts
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: actions/download-artifact@v4.1.7
|
2024-01-05 11:15:49 +00:00
|
|
|
|
|
|
|
- name: Load environment info and built images
|
|
|
|
run: |
|
|
|
|
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
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: docker/login-action@v3.2.0
|
2024-01-05 11:15:49 +00:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Login to Docker Hub registry
|
2024-06-08 14:17:12 +00:00
|
|
|
uses: docker/login-action@v3.2.0
|
2024-01-05 11:15:49 +00:00
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKERHUB_LOGIN }}
|
|
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
|
|
|
|
- name: Create and push manifest
|
|
|
|
run: |
|
2024-01-06 08:37:23 +00:00
|
|
|
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 }}
|
|
|
|
|
|
|
|
docker manifest create ${{ env.IMAGE_TAG }}:latest \
|
|
|
|
--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 }}:latest
|