Open Ftonans opened 1 hour ago
Checked the CI logs:
#11 18.86 go build -ldflags="-X 'github.com/rramiachraf/dumb/data.Version=`git rev-parse --short HEAD`' -s -w"
#11 18.86 fatal: not a git repository (or any of the parent directories): .git
It seems .git directory is not copied or non existent in builder
We need to include .git folder so the build includes the git hash.
We can achieve this by building with BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
Like this building locally: docker build . --build-arg BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 -t dumb
Or we can use ADD --keep-git-dir=true
instead of COPY
.
The first options seems to be better, but I think we should add a command, that removes the .git/ directory after the build completes.
So we basically need to update CI to use this build argument. This is probably looks like this:
- name: Build and push platform specific images
uses: docker/build-push-action@v6
with:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: ${{ matrix.platform }}
tags: ${{ steps.image-metadata.outputs.tags }}
build-args:
- BUILDKIT_CONTEXT_KEEP_GIT_DIR=1
Or we can use context in as stated here.
And add to Dockerfile remove instruction after 22nd line:
RUN rm -r .git
I am not sure if these are the ideal ways to solve it.
I think the best way is to replace COPY
on 10th line to ADD --keep-git-dir=true
. This way we don't have to change CI configurations and we will keep the final image clear and concise.
For some reason Dumb Docker image doesn't show its commit hash in the footer.
~If Docker image is build locally, it works fine.~ If build without Docker, it works fine.
I'm actually not sure what's the problem, but my instance, https://dumb.hyperreal.coffee/, https://dumb.ducks.party/ seems to experience this problem.