Wednesday, August 15, 2018

Swift build always build whole package in Docker

Leave a Comment

When using a Dockerfile like this one:

FROM swift:latest RUN mkdir foo && cd foo && swift package init RUN cd foo && swift build && swift build RUN cd foo && swift build 

when the 3rd step is run, swift build will only compile the app once, as the second execution will just use the already build objects, and the output will be a single Compile Swift Module 'foo' (1 sources)

When running the 4th step, though, it seems to ignore whatever was already build, and rebuild the whole thing again, although nothing was changed and there was no clean. I've tried running a RUN ls /foo/.build && ls /tmp and everything seems to be in place.

What I'm trying to achieve in reality, is setup my image so I first clone the project from git, build it (so this "base" layer is cached by docker), then COPY in any change from the local machine and built just the new updates, but this end up building the whole project 2 times.

Any idea?

Edit: here's what my actual Dockerfile looks like:

FROM swift:latest RUN git clone git@foo.com/foo.git RUN cd /foo && swift build COPY . /foo RUN cd /foo && swift build 

so ideally the first 3 layers will stay cached, and the last 2 would only build new changes, instead it ends up rebuilding the whole project

1 Answers

Answers 1

You need to validate that swift build is indeed capable to build incremental changes first (meaning, "in general", without involving docker)

A thread like "Compile Time Incredibly Slow" (using XCode, even with the option ""Xcode will not rebuild an entire target when only small changes have occurred." does not inspire confidence.

If swift build does rebuild everything, no amount of layer cache will avoid a full rebuild.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment