Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

plugin/docker: add multi-stage target config #1992

Merged
merged 1 commit into from
Oct 6, 2021

Conversation

radriaanse
Copy link
Contributor

@radriaanse radriaanse commented Aug 5, 2021

Docker and Img can stop the build at the specified target stage.
If not set the full Dockerfile will be build.

Closes: #1969

@hashicorp-cla
Copy link

hashicorp-cla commented Aug 5, 2021

CLA assistant check
All committers have signed the CLA.

@radriaanse radriaanse changed the title Docker and Img can stop the build at the specified target stage. plugin/docker: add multi-stage target config Aug 5, 2021
@briancain briancain requested a review from a team August 10, 2021 21:29
@radriaanse
Copy link
Contributor Author

Noticed that the CI was failing on website-mdx, but when I ran make gen/website-mdx as suggest I got a ton of changes with single->double quote and indenting.
Not sure if something on my end, but I've just skipped 'em and only included builder-docker.mdx.

@krantzinator
Copy link
Contributor

@radriaanse can you add a changelog entry? You'll see lots of examples in our .changelog dir. I'd mark this one as an improvement. The title of the file should be 1992.txt to match the PR number.

@briancain
Copy link
Member

@radriaanse - ah yes, we should document how to set this up. Right now we have a node package that trims out all of the extra single quote/double quote changes from running that command from our website team. Kind of a weird situation, but just committing the docker plugin markdown looks fine to me! 👍🏻

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening the PR to add this @radriaanse! I've left a few comments just to fix the variable casing for target. A question I had was what happens when we pass --target "" to docker or img? Does it act like a no-op and ignore the flag?

builtin/docker/builder.go Outdated Show resolved Hide resolved
builtin/docker/builder.go Outdated Show resolved Hide resolved
builtin/docker/img.go Outdated Show resolved Hide resolved
builtin/docker/img.go Outdated Show resolved Hide resolved
Docker and Img can stop the build at the specified target stage.
If not set the full Dockerfile will be build.

Closes: hashicorp#1969
@radriaanse
Copy link
Contributor Author

Wooeps, I've missed that; fixed! @briancain

A question I had was what happens when we pass --target "" to docker or img? Does it act like a no-op and ignore the flag?

Yes it does indeed just ignore it / builds all stages:

FROM docker.io/library/alpine as stage1
ENV a=1

FROM stage1 as stage2
ENV a=2

Without a target parameter:

waypoint [1969-docker-target●] ./waypoint build
✓ Initializing Docker client...
✓ Building image...
 │ Step 2/4 : ENV a=1
 │  ---> Using cache
 │  ---> 9c52a1f1e65c
 │ Step 3/4 : FROM stage1 as stage2
 │  ---> 9c52a1f1e65c
 │ Step 4/4 : ENV a=2
 │  ---> Using cache
 │  ---> 4499cfcd9e74
 │ Successfully built 4499cfcd9e74
 │ Successfully tagged waypoint.local/1992:latest
✓ Injecting Waypoint Entrypoint...

With a target parameter:

waypoint [1969-docker-target●] ./waypoint build
✓ Initializing Docker client...
✓ Building image...
 │ Step 1/2 : FROM docker.io/library/alpine:3.13.5 as stage1
 │  ---> 6dbb9cc54074
 │ Step 2/2 : ENV a=1
 │  ---> Using cache
 │  ---> 9c52a1f1e65c
 │ Successfully built 9c52a1f1e65c
 │ Successfully tagged waypoint.local/1992:latest
✓ Injecting Waypoint Entrypoint...

on the CLI

waypoint [1969-docker-target●] docker build -f test.Dockerfile --target "" .
Sending build context to Docker daemon  325.5MB
Step 1/4 : FROM docker.io/library/alpine:3.13.5 as stage1
 ---> 6dbb9cc54074
Step 2/4 : ENV a=1
 ---> Using cache
 ---> 9c52a1f1e65c
Step 3/4 : FROM stage1 as stage2
 ---> 9c52a1f1e65c
Step 4/4 : ENV a=2
 ---> Using cache
 ---> 4499cfcd9e74
Successfully built 4499cfcd9e74
waypoint [1969-docker-target●] img build -f test.Dockerfile -t docker.io/radriaanse/imgstage --target "" .
Building docker.io/radriaanse/imgstage:latest
Setting up the rootfs... this may take a bit.
WARN[0000] using host network as the default            
[+] Building 1.4s (2/3)                                                                                                                                                                                                                                                                                                                                                                              
[+] Building 1.5s (6/6) FINISHED                                                                                                                                                                                                                                                                                                                                                                     
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                                                               0.0s
 => => transferring context: 34B                                                                                                                                                                                                                                                                                                                                                                0.0s
 => [internal] load build definition from test.Dockerfile                                                                                                                                                                                                                                                                                                                                       0.1s
 => => transferring dockerfile: 36B                                                                                                                                                                                                                                                                                                                                                             0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                                                                                                                                                                                                                                1.3s
 => CACHED [stage1 1/1] FROM docker.io/library/alpine@sha256:eb3e4e175ba6d212ba1d6e04fc0782916c08e1c9d7b45892e9796141b1d379ae                                                                                                                                                                                                                                                                   0.0s
 => => resolve docker.io/library/alpine@sha256:eb3e4e175ba6d212ba1d6e04fc0782916c08e1c9d7b45892e9796141b1d379ae                                                                                                                                                                                                                                                                                 0.0s
 => exporting to image                                                                                                                                                                                                                                                                                                                                                                          0.0s
 => => exporting layers                                                                                                                                                                                                                                                                                                                                                                         0.0s
 => => exporting manifest sha256:e0a74fbb475af1987799e25c915f1d7b450e609fd0009ccdb7fac18276ef5f2b                                                                                                                                                                                                                                                                                               0.0s
 => => exporting config sha256:341ca9a9cc40f27c74ba687660ce5512979e49c6c9b5e95327cae32a6f776c0d                                                                                                                                                                                                                                                                                                 0.0s
 => => naming to docker.io/radriaanse/imgstage:latest                                                                                                                                                                                                                                                                                                                                           0.0s
 => exporting cache                                                                                                                                                                                                                                                                                                                                                                             0.0s
 => => preparing build cache for export                                                                                                                                                                                                                                                                                                                                                         0.0s
Successfully built docker.io/radriaanse/imgstage:latest

waypoint [1969-docker-target●] img save docker.io/radriaanse/imgstage:latest | docker load
bc276c40b172: Loading layer [==================================================>]  2.813MB/2.813MB
Loaded image: radriaanse/imgstage:latest

waypoint [1969-docker-target●] docker run --rm docker.io/radriaanse/imgstage env | grep 'a='
a=2

@izaaklauer izaaklauer added this to the 0.5.x milestone Aug 11, 2021
@evanphx evanphx merged commit a2da396 into hashicorp:main Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Docker build target stage
6 participants