2

A typical go docker pattern is this:

# cache modules
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN make

This will create a (cached) layer for downloaded packages before compiling the actual sources. It would be great to not only download but also compile the packages before adding the application to further speed up repeated builds.

How would one force-compile all downloaded packages irrespective of the parent application?

1

1 Answer 1

-1

The goal of using go mod download in docker build, is to avoid waiting for the dependencies' sources to be compiled. Since you want to avoid that beahviour, you can replace that line with

RUN go get -d -v
3
  • I‘m happy not waiting for the download, but I also don‘t want to wait for the compile. Doesn‘t seem -d does that.
    – andig
    Mar 2, 2020 at 20:56
  • The way you formulated your question was misleading force-compile all downloaded packages So what you really want is to cache the compilation of your application's sources, if no changes were made to your source files, correct?
    – amine
    Mar 3, 2020 at 6:41
  • No. I want to cache compilation of downloaded packages that my application depends on if such is possible. The idea is that when go.mod doesn't change the packages won't change and hence intermediate compilation results are still usable even if my app's code changes. Maybe such intermediate results (like obj files) don't exist.
    – andig
    Mar 4, 2020 at 7:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.