Skip to content

Docker Build

Docker Build #588

Workflow file for this run

name: Docker Build
on:
push:
branches:
- main
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
pull_request:
jobs:
build:
name: Build Image
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout current repo
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: docker/login-action@v3
if: github.event_name != 'pull_request'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Checkout telegram-bot-api repo
uses: actions/checkout@v4
with:
repository: tdlib/telegram-bot-api
path: telegram-bot-api
submodules: recursive
- name: Set ENV Variables
run: |
IMG="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')"
telegram_bot_api_revision=$(cd telegram-bot-api && git rev-parse --short HEAD)
tg_server_version=$(cat telegram-bot-api/CMakeLists.txt | grep TelegramBotApi | cut -d " " -f3)
echo "BUILD_VER=$tg_server_version-$telegram_bot_api_revision" >> $GITHUB_ENV
echo "IMAGE=${IMG}" >> $GITHUB_ENV
echo "BUILD_DATE=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
echo "GIT_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV
echo "GIT_REF=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ env.IMAGE }}:latest
ghcr.io/${{ env.IMAGE }}:${{ env.BUILD_VER }}
${{ env.IMAGE }}:latest
${{ env.IMAGE }}:${{ env.BUILD_VER }}
labels: |
org.opencontainers.image.authors=${{ github.repository_owner }}
org.opencontainers.image.created=${{ env.BUILD_DATE }}
org.opencontainers.image.description=Created from commit ${{ env.GIT_SHA }} and ref ${{ env.GIT_REF }}
org.opencontainers.image.ref.name=${{ env.GIT_REF }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ env.BUILD_VER }}
update-description:
name: Update DockerHub Description
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
automerge-dependabot-pr:
needs: build
uses: divkix/reusable-workflows/.github/workflows/automerge-dependabot-pr.yml@main