Update docker.yml, Dockerfile, and docker-entrypoint.sh

This commit is contained in:
Andrea Cavalli 2020-11-08 13:40:45 +01:00
parent 4af4c5a73c
commit d376aa22ec
3 changed files with 80 additions and 18 deletions

View File

@ -12,7 +12,8 @@ jobs:
name: Build Image
runs-on: ubuntu-latest
env:
IMAGE_id: docker.pkg.github.com/${{ github.repository }}/${{ github.repository }}
REGISTRY: ghcr.io
IMAGE_TAG: ghcr.io/tdlight-team/tdlightbotapi
steps:
- name: Checkout current repo
@ -20,33 +21,50 @@ jobs:
with:
submodules: "recursive"
- name: Get Version
- name: Get version
run: |
# get telegram bot api version
telegram_bot_api_version=$(git rev-parse --short HEAD)
# Get latest commit short hash
HASH_VERSION=$(git rev-parse --short HEAD)
# get tdlib version
tdlib_version=$(cd td && git rev-parse --short HEAD)
# 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
# Convert IMAGE_ID and VERSION to lowercase (repository name must be lowercase)
IMAGE_ID=$(echo "$IMAGE_ID" | awk '{print tolower($0)}')
HASH_VERSION=$(echo "$HASH_VERSION" | awk '{print tolower($0)}')
VERSION=$(echo "$VERSION" | awk '{print tolower($0)}')
# concat tdlib and telegram bot api version
version=$telegram_bot_api_version-$tdlib_version
# Store variable for future use
echo "HASH_VERSION=$HASH_VERSION" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
# store variable for future use
echo "version=$version" >> $GITHUB_ENV
# Print debug info
echo "hash version: $HASH_VERSION"
echo "version: $VERSION"
- name: Build image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/${{ github.repository }}
docker build \
--tag tdlight-team/tdlight-telegram-bot-api:latest \
--tag tdlight-team/tdlight-telegram-bot-api:$version \
--cache-from $IMAGE_TAG:latest \
--tag $IMAGE_TAG:$HASH_VERSION \
--tag $IMAGE_TAG:$VERSION \
.
- name: Login to registry
run: |
echo "${{ secrets.GITHUB_ACCESS_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
echo "${{ secrets.GH_ACCESS_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
- name: Push images
run: |
docker push $IMAGE_ID:$version
docker push $IMAGE_TAG:$VERSION
docker push $IMAGE_TAG:$HASH_VERSION
- name: Logout from registry
run: |
docker logout $REGISTRY

View File

@ -17,10 +17,11 @@ RUN cmake --build . --target install --
FROM alpine:3.12.1
RUN apk --no-cache add libstdc++
RUN apk --no-cache add libstdc++ curl
COPY --from=builder /usr/local/bin/telegram-bot-api /usr/local/bin/telegram-bot-api
COPY docker-entrypoint.sh /docker-entrypoint.sh
HEALTHCHECK CMD curl -f http://localhost:8082/ || exit 1
ENTRYPOINT ["/usr/local/bin/telegram-bot-api -s 8082"]
ENTRYPOINT ["/docker-entrypoint.sh"]

43
docker-entrypoint.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
set -e
LOGS_DIR="/var/log/telegram-bot-api"
LOG_FILENAME="telegram-bot-api.log"
WORK_DIR="/etc/telegram-bot-api"
TEMP_DIR="/tmp/telegram-bot-api"
if [ -n "${1}" ]; then
exec "${*}"
fi
mkdir -p "${LOGS_DIR}"
mkdir -p "${WORK_DIR}"
mkdir -p "${TEMP_DIR}"
DEFAULT_ARGS="--http-port 8081 --http-stat-port=8082 --dir=${WORK_DIR} --temp-dir=${TEMP_DIR} --log=${LOGS_DIR}/${LOG_FILENAME}"
CUSTOM_ARGS=""
if [ -n "$TELEGRAM_FILTER" ]; then
CUSTOM_ARGS="${CUSTOM_ARGS} --filter=$TELEGRAM_FILTER"
fi
if [ -n "$TELEGRAM_MAX_WEBHOOK_CONNECTIONS" ]; then
CUSTOM_ARGS="${CUSTOM_ARGS} --max-webhook-connections=$TELEGRAM_MAX_WEBHOOK_CONNECTIONS"
fi
if [ -n "$TELEGRAM_VERBOSITY" ]; then
CUSTOM_ARGS="${CUSTOM_ARGS} --verbosity=$TELEGRAM_VERBOSITY"
fi
if [ -n "$TELEGRAM_MAX_CONNECTIONS" ]; then
CUSTOM_ARGS="${CUSTOM_ARGS} --max-connections=$TELEGRAM_MAX_CONNECTIONS"
fi
if [ -n "$TELEGRAM_PROXY" ]; then
CUSTOM_ARGS="${CUSTOM_ARGS} --proxy=$TELEGRAM_PROXY"
fi
if [ -n "$TELEGRAM_LOCAL" ]; then
CUSTOM_ARGS="${CUSTOM_ARGS} --local"
fi
COMMAND="telegram-bot-api ${DEFAULT_ARGS}${CUSTOM_ARGS}"
echo "$COMMAND"
# shellcheck disable=SC2086
exec $COMMAND