Original title was "Manually defining artifacts results in default copy of all project files"
Correct case
Using the copies: [variantref] pattern in a variant works as expected: Instead of the application and support files being copied in using COPY . ., a set of multi-stage artifacts are defined using COPY --from=[variantref].
version: v3 base: docker-registry.wikimedia.org/wikimedia-stretch:latest lives: in: /go/src/gerrit.wikimedia.org/r/blubber variants: build: base: golang:1.9-stretch test: includes: [build] runs: { insecurely: true } builder: command: [go, get, -u, golang.org/x/lint/golint] entrypoint: [make, test] prep: includes: [build] builder: command: [make, blubberoid] requirements: [.] production: copies: prep entrypoint: [./blubberoid]
Resulting Dockerfile (irrelevant lines omited):
FROM golang:1.9-stretch AS prep WORKDIR "/go/src/gerrit.wikimedia.org/r/blubber" COPY --chown=65533:65533 [".", "."] FROM docker-registry.wikimedia.org/wikimedia-stretch:latest AS production COPY --chown=65533:65533 --from=prep ["/go/src/gerrit.wikimedia.org/r/blubber", "/go/src/gerrit.wikimedia.org/r/blubber"] COPY --chown=65533:65533 --from=prep ["/opt/lib", "/opt/lib"]
Errant case
However, in a use case where you only want a subset of artifacts (e.g. for Blubberoid we only need one static binary), manually specifying that subset of artifacts results in unexpected behavior: All application files are now copied over as well and there's no current way to omit them.
(irrelevant lines from previous example omitted)
variants: production: lives: { in: /srv/service } artifacts: - from: prep source: "/go/src/gerrit.wikimedia.org/r/blubber/blubberoid" destination: "./" entrypoint: [./blubberoid]
Resulting Dockerfile (irrelevant lines omitted):
FROM golang:1.9-stretch AS prep WORKDIR "/go/src/gerrit.wikimedia.org/r/blubber" COPY --chown=65533:65533 [".", "."] FROM docker-registry.wikimedia.org/wikimedia-stretch:latest AS production WORKDIR "/srv/service" COPY --chown=65533:65533 [".", "."] COPY --chown=65533:65533 --from=prep ["/go/src/gerrit.wikimedia.org/r/blubber/blubberoid", "./"]
In this case, I don't want the second to last line, the COPY . . but there's no way to omit it.