2020-11-06 01:42:25 +01:00
|
|
|
name: Docker Build + Image Push
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
pull_request:
|
|
|
|
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
name: Build Image
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
2020-11-06 22:13:50 +01:00
|
|
|
REGISTRY: ghcr.io
|
|
|
|
IMAGE_TAG: ghcr.io/tdlight-team/tdlightbotapi
|
2020-11-06 01:42:25 +01:00
|
|
|
|
|
|
|
steps:
|
|
|
|
- name: Checkout current repo
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
with:
|
2020-11-06 12:24:36 +01:00
|
|
|
submodules: "recursive"
|
2020-11-06 01:42:25 +01:00
|
|
|
|
2020-11-06 18:30:09 +01:00
|
|
|
- name: Get version
|
2020-11-06 01:42:25 +01:00
|
|
|
run: |
|
2020-11-06 19:53:47 +01:00
|
|
|
# Get latest commit short hash
|
|
|
|
HASH_VERSION=$(git rev-parse --short HEAD)
|
|
|
|
|
2020-11-06 18:30:09 +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
|
|
|
|
|
|
|
|
# Convert IMAGE_ID and VERSION to lowercase (repository name must be lowercase)
|
|
|
|
IMAGE_ID=$(echo "$IMAGE_ID" | awk '{print tolower($0)}')
|
2020-11-06 19:53:47 +01:00
|
|
|
HASH_VERSION=$(echo "$HASH_VERSION" | awk '{print tolower($0)}')
|
2020-11-06 18:30:09 +01:00
|
|
|
VERSION=$(echo "$VERSION" | awk '{print tolower($0)}')
|
|
|
|
|
|
|
|
# Store variable for future use
|
2020-11-06 19:55:38 +01:00
|
|
|
echo "HASH_VERSION=$HASH_VERSION" >> $GITHUB_ENV
|
2020-11-06 18:31:54 +01:00
|
|
|
echo "VERSION=$VERSION" >> $GITHUB_ENV
|
2020-11-06 19:53:47 +01:00
|
|
|
|
|
|
|
# Print debug info
|
|
|
|
echo "hash version: $HASH_VERSION"
|
2020-11-06 18:30:09 +01:00
|
|
|
echo "version: $VERSION"
|
2020-11-06 01:42:25 +01:00
|
|
|
|
|
|
|
- name: Build image
|
|
|
|
run: |
|
|
|
|
docker build \
|
2020-11-06 22:13:50 +01:00
|
|
|
--cache-from $IMAGE_TAG:latest \
|
2020-11-06 19:53:47 +01:00
|
|
|
--tag $IMAGE_TAG:$HASH_VERSION \
|
2020-11-06 19:58:41 +01:00
|
|
|
--tag $IMAGE_TAG:$VERSION \
|
2020-11-06 01:42:25 +01:00
|
|
|
.
|
|
|
|
|
|
|
|
- name: Login to registry
|
|
|
|
run: |
|
2020-11-06 18:30:09 +01:00
|
|
|
echo "${{ secrets.GH_ACCESS_TOKEN }}" | docker login $REGISTRY -u ${{ github.actor }} --password-stdin
|
2020-11-06 01:42:25 +01:00
|
|
|
|
|
|
|
- name: Push images
|
|
|
|
run: |
|
2020-11-06 18:30:09 +01:00
|
|
|
docker push $IMAGE_TAG:$VERSION
|
2020-11-06 22:13:50 +01:00
|
|
|
docker push $IMAGE_TAG:$HASH_VERSION
|
2020-11-06 18:30:09 +01:00
|
|
|
|
|
|
|
- name: Logout from registry
|
|
|
|
run: |
|
|
|
|
docker logout $REGISTRY
|