Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Add build parameters to docker app build command #697

Merged
merged 1 commit into from
Oct 18, 2019

Conversation

glours
Copy link
Contributor

@glours glours commented Oct 16, 2019

- What I did
Pass --build-arg parameter to buildx to build service images

- How I did it
Add a --build-arg flag
Check a build arg isn't defined twice
Replace build arg defined in compose file & pass the list of args to buildx for generating service images

- How to verify it

  • Test main workflow
    run docker --debug app build e2e/testdata/build/ --build-arg REPLACE_BY_BUILD_ARG=plop
    check you see the following trace in the debug output in the worker section of the com.docker.app.invocation-image
"BuildArgs": {
  >          "REPLACE_BY_BUILD_ARG": "plop",
  >          "STATIC_ARG": "static"
  >       },

Find the worker image sha256 & then do a docker image inspect with the given sha & make sure to have

"Labels": {
                "com.docker.labelled.arg": "plop",
                "com.docker.labelled.optional": "static"
            }
  • Test error message

run docker app build e2e/testdata/build/single.dockerapp --build-arg REPLACE_BY_BUILD_ARG=plop --build-arg REPLACE_BY_BUILD_ARG and check you have the following error message '--build-arg REPLACE_BY_BUILD_ARG' is defined twice

- A picture of a cute animal (not mandatory but encouraged)
image

@glours glours force-pushed the add_build_arg_option branch 6 times, most recently from 6d3e088 to 52d1328 Compare October 16, 2019 18:27
@codecov
Copy link

codecov bot commented Oct 16, 2019

Codecov Report

Merging #697 into master will decrease coverage by 0.22%.
The diff coverage is 72.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #697      +/-   ##
==========================================
- Coverage   72.08%   71.85%   -0.23%     
==========================================
  Files          62       56       -6     
  Lines        3496     2931     -565     
==========================================
- Hits         2520     2106     -414     
+ Misses        653      552     -101     
+ Partials      323      273      -50
Impacted Files Coverage Δ
internal/commands/build/compose.go 82.85% <100%> (ø) ⬆️
internal/commands/build/build.go 61.07% <63.63%> (+0.2%) ⬆️
internal/commands/build/types.go 69.23% <76%> (+0.48%) ⬆️
internal/commands/run.go 65.71% <0%> (-10.38%) ⬇️
internal/store/digest.go 83.33% <0%> (-8.34%) ⬇️
internal/commands/pull.go 69.23% <0%> (-7.92%) ⬇️
internal/commands/image/list.go 81.81% <0%> (-7.19%) ⬇️
internal/commands/update.go 58.18% <0%> (-4.98%) ⬇️
internal/commands/push.go 45.22% <0%> (-3.83%) ⬇️
internal/commands/root.go 78.88% <0%> (-3.57%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c622dcf...1ee6dd3. Read the comment docs.

e2e/build_test.go Outdated Show resolved Hide resolved
@glours glours marked this pull request as ready for review October 17, 2019 11:15
Copy link
Member

@rumpl rumpl left a comment

Choose a reason for hiding this comment

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

LGTM!

@silvin-lubecki
Copy link
Contributor

@glours can you rebase? 🦁

@eunomie
Copy link
Member

eunomie commented Oct 17, 2019

Is it possible to add some information to the PR description?

@@ -70,3 +76,30 @@ func transformBuildConfig(data interface{}) (interface{}, error) {
return data, errors.Errorf("invalid type %T for service build", value)
}
}

func transformBuildArgsArray(array []string, sep string, allowNil bool) map[string]string {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to pass the separator and allowNil as this method is called only once with fixed values?
Why not something like mapBuildArgs or buildArgsToMap? Something that exposes the intention in the method name, transform is not very clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@glours
Copy link
Contributor Author

glours commented Oct 17, 2019

@eunomie PR description updated, sorry for that

for _, value := range array {
parts := strings.SplitN(value, "=", 2)
key := parts[0]
switch {
Copy link
Member

Choose a reason for hiding this comment

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

Why a switch here and not a

if len(parts) == 1 {
         result[key] = ""
} else {
        result[key] = parts[1]
}

that does the same thing but maybe more easy to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with switch 😅
else is bad, mkay?

Copy link
Member

Choose a reason for hiding this comment

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

If else is bad you can write:

result[key] = ""
if len(parts) != 1 {
        result[key] = parts[1]
}

Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

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

LGTM

@silvin-lubecki silvin-lubecki merged commit 8d6c935 into docker:master Oct 18, 2019
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.

5 participants