From 266192c59986dec1064bdf8a063b124897732b18 Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 7 Sep 2021 06:06:04 -0500 Subject: [PATCH] ci: fix docker image not including git hash. Fix the Docker image not including the git hash of the build. On DockerHub we had to set it with a build hook, but now with Github we set it as part of the build-push-action. --- .github/workflows/test.yaml | 3 +++ hooks/README.md | 27 --------------------------- hooks/build | 13 ------------- 3 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 hooks/README.md delete mode 100755 hooks/build diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 3179a6dd1..bc62d8b4b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -68,6 +68,9 @@ jobs: cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max + build-args: | + SOURCE_COMMIT=${{ github.sha }} + test: runs-on: ubuntu-latest needs: docker diff --git a/hooks/README.md b/hooks/README.md deleted file mode 100644 index e95c20bd6..000000000 --- a/hooks/README.md +++ /dev/null @@ -1,27 +0,0 @@ -The directory contains hooks used by Docker Hub when building images: - - Docker Hub allows you to override and customize the `build`, `test` and `push` - commands during automated build and test processes using hooks. For - example, you might use a build hook to set build arguments used only during - the build process. (You can also set up custom build phase hooks to perform - actions in between these commands.) - - Use these hooks with caution. The contents of these hook files replace the - basic `docker` commands, so you must include a similar build, test or push - command in the hook or your automated process does not complete. - - To override these phases, create a folder called `hooks` in your source code - repository at the same directory level as your Dockerfile. Create a file - called `hooks/build`, `hooks/test`, or `hooks/push` and include commands that the - builder process can execute, such as `docker` and `bash` commands (prefixed - appropriately with `#!/bin/bash`). - - These hooks will be running on an instance of Amazon Linux 2, a distro - based on Ubuntu, which includes interpreters such as Perl and Python and - utilities such as git or curl. Please check the link above for the full - list. - -# See also - -* https://docs.docker.com/docker-hub/builds/advanced -* https://stackoverflow.com/questions/59057978/passing-source-commit-to-dockerfile-commands-on-docker-hub diff --git a/hooks/build b/hooks/build deleted file mode 100755 index 6a848ba81..000000000 --- a/hooks/build +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# This file is used to add the Git commit hash to the Docker image when the -# image is built by Docker Hub. -# -# https://docs.docker.com/docker-hub/builds/advanced/ -# https://stackoverflow.com/questions/59057978/passing-source-commit-to-dockerfile-commands-on-docker-hub -# -# SOURCE_COMMIT: the SHA1 hash of the commit being tested. -# DOCKERFILE_PATH: the dockerfile currently being built. -# IMAGE_NAME: the name and tag of the Docker repository being built. (This variable is a combination of DOCKER_REPO:DOCKER_TAG.) - -docker build --build-arg SOURCE_COMMIT=$SOURCE_COMMIT -f $DOCKERFILE_PATH -t $IMAGE_NAME .