From 8a010dbcc7521837b784a6f18f1360bce355954b Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Sun, 27 Aug 2023 23:32:56 +0200 Subject: [PATCH] docker: pass in build-args, add $NOW --- .github/workflows/docker.yml | 12 +++++++++++- Dockerfile | 12 ++++++++---- docker-entrypoint.sh | 3 ++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 01781f8..8903c55 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -20,6 +20,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - + name: Set environment variables + run: | + echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + echo "NOW=$(date +'%Y-%m-%dT%H:%M:%S')" >> $GITHUB_ENV - name: Set up QEMU uses: docker/setup-qemu-action@v2 @@ -29,6 +34,7 @@ jobs: - name: Login to Docker Hub uses: docker/login-action@v2 + if: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN }} with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} @@ -44,8 +50,12 @@ jobs: uses: docker/build-push-action@v4 with: context: . - platforms: linux/amd64,linux/arm64 # ,linux/arm/v7 push: true + build-args: | + COMMIT=${{ github.sha }} + BRANCH=${{ env.BRANCH }} + NOW=${{ env.NOW }} + platforms: linux/amd64,linux/arm64 # ,linux/arm/v7 tags: | voglerr/free-games-claimer:latest ghcr.io/vogler/free-games-claimer:latest diff --git a/Dockerfile b/Dockerfile index 82bb263..67a5e89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -60,19 +60,23 @@ COPY . . RUN dos2unix *.sh && chmod +x *.sh COPY docker-entrypoint.sh /usr/local/bin/ +ARG COMMIT="" +ARG BRANCH="" +ARG NOW="" +ENV COMMIT=${COMMIT} +ENV BRANCH=${BRANCH} +ENV NOW=${NOW} + LABEL org.opencontainers.image.title="free-games-claimer" \ org.opencontainers.image.name="free-games-claimer" \ org.opencontainers.image.description="Automatically claims free games on the Epic Games Store, Amazon Prime Gaming and GOG" \ org.opencontainers.image.url="https://github.com/vogler/free-games-claimer" \ org.opencontainers.image.source="https://github.com/vogler/free-games-claimer" \ - org.opencontainers.image.revision=${COMMIT_SHA} \ + org.opencontainers.image.revision=${COMMIT} \ org.opencontainers.image.ref.name=${BRANCH} \ org.opencontainers.image.base.name="ubuntu:jammy" \ org.opencontainers.image.version="latest" -ENV COMMIT_SHA=${COMMIT_SHA} -ENV BRANCH=${BRANCH} - # Configure VNC via environment variables: ENV VNC_PORT 5900 ENV NOVNC_PORT 6080 diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index cfdac7e..2b5ddee 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,8 +2,9 @@ set -eo pipefail # exit on error, error on any fail in pipe (not just last cmd); add -x to print each cmd; see gist bash_strict_mode.md -echo "Version: https://github.com/vogler/free-games-claimer/tree/${COMMIT_SHA}" +echo "Version: https://github.com/vogler/free-games-claimer/tree/${COMMIT}" [ ! -z $BRANCH ] && [ $BRANCH != "main" ] && echo "Branch: ${BRANCH}" +echo "Build: $NOW" # Remove chromium profile lock. # When running in docker and then killing it, on the next run chromium displayed a dialog to unlock the profile which made the script time out.