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