Comments (16)
I think cgo might require gcc, so I'm not sure if it's "safe" to remove in all cases.
from golang.
Aah, you are right.
If we leave libc6 and gcc in there image shrinks to 406.7MB
Not a huge gain... but also nice to be explicit about the build-deps instead of installing build-essential.
from golang.
That sounds good to me.
I got it to 385MB by adding rm -r /var/lib/apt/lists/*
after the apt-get install
lines. I can have a PR shortly, if you would like. The only drawback I see is that all the golang versions had a common layer and now will all be different, but your proposed changes are what we have been doing in the other images.
FROM debian:wheezy
ENV GOLANG_VERSION 1.3.1
# Go building deps and SCMs for "go get"
RUN apt-get update && apt-get install -y \
ca-certificates curl gcc libc6-dev \
bzr git mercurial \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sSL http://golang.org/dl/go$GOLANG_VERSION.src.tar.gz \
| tar -v -C /usr/src -xz \
&& cd /usr/src/go/src && ./make.bash --no-clean 2>&1 \
&& apt-get purge -y curl \
&& apt-get autoremove -y
ENV PATH /usr/src/go/bin:$PATH
RUN mkdir -p /go/src
ENV GOPATH /go
ENV PATH /go/bin:$PATH
WORKDIR /go
from golang.
Maybe instead of combining all the command with &&
, we could have a script in the context that does the same w/ set -e
.
from golang.
What benefit would that provide except less predictable cache behavior and
now two places to look to see how the image was built?
Also, what affect (if any) does this refactor have on our cross builds?
from golang.
@tianon how does that make it less predictable?
My understanding is that:
In one case, if the .sh change the layer is invalidated.
In the other, if the line change the layer is invalidated.
from golang.
It's less predictable because "mtime" is included in the "if the .sh is
changed" calculation, which is changed on every fresh "git clone" (which is
exactly how these images are built). It's predictable for individual users
on their own systems, but not for the official image build system, is what
I meant.
from golang.
I am testing the cross builds and have one more adjustment (for packages that are not uninstalled).
FROM debian:wheezy
RUN apt-get update && apt-get install -y \
ca-certificates gcc libc6-dev \
bzr git mercurial \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
ENV GOLANG_VERSION 1.3.1
# Go building deps and SCMs for "go get"
RUN apt-get update && apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sSL http://golang.org/dl/go$GOLANG_VERSION.src.tar.gz \
| tar -v -C /usr/src -xz \
&& cd /usr/src/go/src && ./make.bash --no-clean 2>&1 \
&& apt-get purge -y curl \
&& apt-get autoremove -y
ENV PATH /usr/src/go/bin:$PATH
RUN mkdir -p /go/src
ENV GOPATH /go
ENV PATH /go/bin:$PATH
WORKDIR /go
from golang.
@tianon: got it, and that's not true for the Dockerfile
where each line is actually considered even if mtime
has changed.
I didn't realize that the "official build system" was leveraging caching, I just assumed it was using --no-cache
.
from golang.
@yosifkit I'm confused why there is 2x apt-get update
. Can't we have one big shell expression and remove /var/lib/apt/lists at the end?
from golang.
They are in separate RUN
's because I was trying to optimize the docker cache so that all the go versions can depend on the same layer (since we were not removing any of those packages).
from golang.
@yosifkit oh, make sense sorry for the noise, but this does come at the expense of 1 additional apt-get update
, right?
Maybe the size of curl is negligible enough that you could leave it in the image and get read of the apt-
stuff in the second case?
from golang.
Yes there is one additional apt-get update
. Even though the size or curl itself is minimal (~1MB), by cleaning up build dependencies after install we will set precedent for further official images to keep them as tidy as possible.
Semi-unrelated question: is ca-certificates necessary, or can we clean it up with curl?
from golang.
Go does use it if your app hits SSL, so I think we need to keep that one.
from golang.
I have a PR for the changes discussed here. I decided to leave the curl since it made a smaller amount of changes.
from golang.
Yeah, I think that's fair, especially at only 1MB (and since curl is so
useful).
from golang.
Related Issues (20)
- Add patch binary to golang images HOT 1
- README should mention about Go telemetry HOT 2
- [regression] cgo/boringssl builds not working on alpine 3.19 HOT 4
- cwe vulnerabilities golang:1.21.5-alpine3.18 -19 HOT 3
- golang:1.21.5 on linux/arm/v6 : no match for platform in manifest HOT 7
- Docker Scout reports CVE's HOT 1
- go tool pprof not working HOT 3
- Resolve common CVEs HOT 4
- `golang:1.21.7` does not have an `linux/amd64` image HOT 3
- `golang:1.22.0-bullseye` `linux/amd64` reports dpkg architecture `i386` HOT 6
- golang:1.22-alpine is linux/386 instead of linux/amd64 HOT 2
- incorrect version of gcc HOT 4
- Despite build passed, amd64 is missing on golang:1.22.0-alpine3.18 HOT 2
- Add go-task to this imge HOT 1
- Tags keep flip-flopping between two digests HOT 3
- CVE-2023-28531 openSSH < 9.3 HOT 3
- CVE-2024-2961 for glibc HOT 1
- Some architectures missing from `golang:alpine3.20` HOT 5
- GLIBC_2.xx not found HOT 1
- armv5(arm32v5) and armv6(arm32v6) images for 1.22 branch HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from golang.