Skip to content

Commit

Permalink
GitHub build workflow for the docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
andrius committed Jan 21, 2024
1 parent c01ac71 commit 7c1826e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# vim: set filetype=yaml ts=2 sw=2 sts=2 et:
---
name: "Build docker images"

on:
push:

schedule:
# https://crontab.guru/every-week
- cron: "0 0 * * 0"

defaults:
run:
shell: bash -euxo pipefail {0}

jobs:
build-docker:
name: "Build docker images"
timeout-minutes: 30
runs-on: ubuntu-latest
permissions:
packages: write

steps:
- uses: actions/checkout@v4

- name: Log in to GitHub docker registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io --username $ --password-stdin

- name: Setup docker builer instance
run: |
BUILDX="$(docker buildx create)"
echo "BUILDX=${BUILDX}" >> "${GITHUB_ENV}"
docker buildx use "${BUILDX}"
- name: Build docker images
run: |
IMAGE_NAME="ghcr.io/${{ github.repository }}"
GIT_REF="$( echo -n "${{ github.ref }}" | awk '{ gsub(/^refs\/heads\//, ""); print }' )"
# Convert GIT_REF to lowercase;
# replace non-latin alphabet and special symobls to the '-';
# assign docker image tag 'latest' for master and main branches
TAG="$( \
echo -n "${GIT_REF}" | awk '{
gsub(/[^0-9A-Za-z]/, "-")
gsub(/^master|^main/, "latest")
print
}' \
)"
# Convert it to the lowercase
TAG="${TAG,,}"
# Timestamp in YYYYMMDD format for the additional docker image tag
TIMESTAMP="$(date +%Y%m%d)"
docker buildx build \
--push \
--platform "linux/amd64,linux/arm64" \
--pull \
--tag "${IMAGE_NAME}:test" \
--tag "${IMAGE_NAME}:${TAG}-${TIMESTAMP}" \
--file ./Dockerfile \
.
# Removes buildx on local machine if developer does use act tool
- name: Remove docker builder instance
if: always()
run: |
if [ "${BUILDX}" != "" ]; then
docker buildx rm "${BUILDX}"
fi
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM python:3-slim

LABEL "org.opencontainers.image.authors"="[email protected],[email protected]"
LABEL "org.opencontainers.image.source"="https://github.com/upfitai/ai-service-nodejs"
LABEL "org.opencontainers.image.description"="CHATGPT"
LABEL "org.opencontainers.image.authors"="41898282+github-actions[bot]@users.noreply.github.com"
LABEL "org.opencontainers.image.source"="https://github.com/andrius/chatgpt-cli"
LABEL "org.opencontainers.image.description"="chatgpt-cli client"

WORKDIR /app
COPY . ./
Expand Down

0 comments on commit 7c1826e

Please sign in to comment.