Build Telegram API server #229
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Telegram API server | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 2 */7 * *" | |
jobs: | |
build: | |
runs-on: ubuntu-20.04 | |
name: Build amd64 and arm64 images | |
steps: | |
- name: Checkout API repo | |
uses: actions/checkout@v2 | |
with: | |
repository: 'tdlib/telegram-bot-api' | |
path: '/home/runner/work/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api' | |
- name: Checkout Dockerfile | |
uses: actions/checkout@v2 | |
with: | |
repository: 'lukaszraczylo/tdlib-telegram-bot-api-docker' | |
path: '/home/runner/work/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api-docker/docker' | |
- name: Apply Dockerfile | |
run: | | |
cp /home/runner/work/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api-docker/docker/Dockerfile /home/runner/work/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api/Dockerfile | |
- name: Get release sha and run number | |
id: get_sha | |
run: | | |
echo "GITHUB_SHA=$(echo ${GITHUB_SHA::8})" >> $GITHUB_ENV | |
echo "GITHUB_RUN_ID=$(echo ${GITHUB_RUN_NUMBER})" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v1 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to GHCR | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GCHR_PAT }} | |
- name: Prepare for push | |
id: prep | |
run: | | |
DOCKER_IMAGE=ghcr.io/${{ github.repository_owner }}/tdlib-telegram-bot-api-docker/telegram-api-server | |
VERSION=edge | |
if [[ $GITHUB_REF == refs/tags/* ]]; then | |
VERSION=${GITHUB_REF#refs/tags/v} | |
fi | |
if [ "${{ github.event_name }}" = "schedule" ]; then | |
VERSION=nightly | |
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 | |
TG_API_VERSION=$(grep "project(TelegramBotApi" /home/runner/work/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api/CMakeLists.txt | awk '{print $3}') | |
TAGS="$TAGS,$DOCKER_IMAGE:${{ env.GITHUB_SHA }},$DOCKER_IMAGE:1.0.${{ env.GITHUB_RUN_ID }},$DOCKER_IMAGE:latest,$DOCKER_IMAGE:api-$TG_API_VERSION" | |
echo ::set-output name=tags::${TAGS} | |
# lowercase the branch name | |
BRANCH=$(echo ${GITHUB_REF##*/} | tr '[A-Z]' '[a-z]') | |
LABELS="org.opencontainers.image.revision=$GITHUB_SHA" | |
LABELS="$LABELS,org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" | |
LABELS="$LABELS,org.opencontainers.image.version=$VERSION" | |
LABELS="$LABELS,com.github.repo.branch=$BRANCH" | |
LABELS="$LABELS,com.github.repo.dockerfile=Dockerfile" | |
echo ::set-output name=labels::${LABELS} | |
BUILD_ARGS="BRANCH=$BRANCH" | |
echo ::set-output name=args::${BUILD_ARGS} | |
- name: Tag names | |
run: echo ${{ steps.prep.outputs.tags }} | |
- name: Build and push | |
id: docker_build | |
timeout-minutes: 900 | |
uses: docker/build-push-action@v2 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: /home/runner/work/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api | |
file: /home/runner/work/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api-docker/tdlib-telegram-bot-api/Dockerfile | |
platforms: linux/arm64,linux/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.prep.outputs.tags }} | |
build-args: ${{ steps.prep.outputs.args }} | |
labels: ${{ steps.prep.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |