Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker image don't include commit hash #72

Closed
vlnst opened this issue Oct 4, 2024 · 4 comments
Closed

Docker image don't include commit hash #72

vlnst opened this issue Oct 4, 2024 · 4 comments

Comments

@vlnst
Copy link
Contributor

vlnst commented Oct 4, 2024

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.

@vlnst
Copy link
Contributor Author

vlnst commented Oct 4, 2024

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

@vlnst
Copy link
Contributor Author

vlnst commented Oct 4, 2024

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.

@vlnst
Copy link
Contributor Author

vlnst commented Oct 4, 2024

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 only 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.

@vlnst
Copy link
Contributor Author

vlnst commented Oct 4, 2024

And in this case it would be great to update the Go version and dependencies.

I've tried rewriting the Docker image to use Debian based version of Go since this is what go devs recommend because this is what they tell about alpine based images:

This variant is highly experimental, and not officially supported by the Go project (see golang/go#19938⁠ for details).

The main caveat to note is that it does use musl libc⁠
instead of glibc and friends⁠, which can lead to unexpected behavior. See this Hacker News comment thread⁠ for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.

but in the end it was too much hassle and I needed to rewrite the Makefile, since dash (Debian default shell) was failing on &>, also needed to statically link the binary since it was linking dynamically to the glibc... I think it is okay the way it is right now.

I would only update go version, dependencies and removed curl (I guess certificates are needed, in this case we can use ca-certificates instead of curl package)

Also, there is trailing space on 9th line in Makefile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants