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: use Go version as defined in the package #187

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

florianl
Copy link
Contributor

Debian does provide a different Go version than set in go.mod. Install Go from upstream instead of Debian packages.

Debian does provide a different Go version than set in go.mod. Install Go
from upstream instead of Debian packages.

Signed-off-by: Florian Lehner <florian.lehner@elastic.co>
@florianl florianl requested review from a team as code owners October 14, 2024 08:52
@@ -8,11 +8,20 @@ RUN cross_debian_arch=$(uname -m | sed -e 's/aarch64/amd64/' -e 's/x86_64/arm64
cross_pkg_arch=$(uname -m | sed -e 's/aarch64/x86-64/' -e 's/x86_64/aarch64/'); \
apt-get update -y && \
apt-get dist-upgrade -y && \
apt-get install -y wget make git clang-16 golang unzip \
apt-get install -y wget make git clang-16 unzip libc6-dev g++ gcc pkgconf \
Copy link
Contributor Author

@florianl florianl Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libc6-dev, g++, gcc+ and pkgconf where installed previously by the package golang and are required dependencies for cgo - see https://packages.debian.org/trixie/golang-1.23-go

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still better do it explicitly to be independent of golang dependencies, which may change in the future. Explicitly naming the packages also serves as a documentation/reference. Also, it doesn't cost extra time when these packages are already installed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nevermind, misread your comment.


RUN echo "export PATH=\"\$PATH:\$(go env GOPATH)/bin\"" >> ~/.bashrc
# Append to /etc/profile for login shells
RUN echo 'export PATH="/usr/local/go/bin:$PATH"' >> /etc/profile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the debian docker in via the file /etc/profile the environment variable is overwritten with this approach:

if [ "$(id -u)" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH

Appending export PATH ... here makes sure, that the Go executable is available for every user of this docker image.

Copy link
Contributor

@rockdaboot rockdaboot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and tested successfully, thanks.

Dockerfile Outdated Show resolved Hide resolved
Co-authored-by: Christos Kalkanis <christos.kalkanis@elastic.co>
@florianl florianl merged commit 13a01a8 into main Oct 15, 2024
23 checks passed
@florianl florianl deleted the flo-docker-go-version branch October 15, 2024 05:39
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

Successfully merging this pull request may close these issues.

4 participants