brash-student-40401
10/25/2022, 7:55 PMdocker_image
target is very simple:
docker_image(
name="app",
image_tags=["{build_args.GIT_COMMIT}", "latest"],
registries=["{build_args.REGISTRY}"],
)
then I have Github run it using ./pants --docker-build-args="[GIT_COMMIT=${GITHUB_SHA::7}, REGISTRY=${{ steps.login-ecr.outputs.registry }}]" package src/services/app/Dockerfile
. The error is in the đź§µ, my guess is I have the syntax wrong in my package statement but I can't figure it out.brash-student-40401
10/25/2022, 7:55 PMException message: Error computing value for --build-args in scope 'docker' (may also be from PANTS_* environment variables).
39
Caused by:
40
The value cannot be evaluated as a literal expression: SyntaxError('invalid syntax', ('<string>', 1, 12, '[GIT_COMMIT=f716139, REGISTRY=***.<http://dkr.ecr.us-west-2.amazonaws.com|dkr.ecr.us-west-2.amazonaws.com>]'))
41
Given raw value:
42
1: [GIT_COMMIT=f716139, REGISTRY=***.<http://dkr.ecr.us-west-2.amazonaws.com|dkr.ecr.us-west-2.amazonaws.com>]
45
witty-crayon-22786
10/25/2022, 7:57 PMlist
literalswitty-crayon-22786
10/25/2022, 7:58 PM./pants --docker-build-args='["GIT_COMMIT=${GITHUB_SHA::7}", "REGISTRY=${{ steps.login-ecr.outputs.registry }}"]' package src/services/app/Dockerfile
witty-crayon-22786
10/25/2022, 7:58 PMwitty-crayon-22786
10/25/2022, 7:59 PM"[\"GIT_COMMIT=${GITHUB_SHA::7}\", \"REGISTRY=${{ steps.login-ecr.outputs.registry }}\"]"
?witty-crayon-22786
10/25/2022, 8:00 PM./pants --docker-build-args="GIT_COMMIT=${GITHUB_SHA::7}" --docker-build-args="REGISTRY=${{ steps.login-ecr.outputs.registry }}" package src/services/app/Dockerfile
… which looks much cleaner in this case i thinkbrash-student-40401
10/25/2022, 8:30 PMProcessExecutionFailure: Process 'Building docker image {build_args.REGISTRY}/dandelion:2bf4e5e +1 additional tag.' failed with exit code 125.
stdout:
stderr:
invalid argument "{build_args.REGISTRY}/dandelion:2bf4e5e" for "-t, --tag" flag: invalid reference format
See 'docker build --help'.
brash-student-40401
10/25/2022, 8:31 PMbrash-student-40401
10/25/2022, 8:32 PMwitty-crayon-22786
10/25/2022, 8:47 PMcurved-television-6568
10/25/2022, 8:51 PMregistries
field does not support string interpolation as the image_tags
field does. It’s not super clear, but mentioned in the docs: https://www.pantsbuild.org/v2.12/docs/reference-docker_image#codeimage_tagscode
tag may use placeholders in curly braces to be interpolated. The placeholders are derived from various sources, such as the Dockerfile instructions and build args.That snippet about placeholders is missing for the registries field, indicating it does not support it. Sorry for the confusion.
brash-student-40401
10/25/2022, 8:52 PMcurved-television-6568
10/25/2022, 8:53 PMcurved-television-6568
10/25/2022, 8:54 PMbrash-student-40401
10/25/2022, 8:54 PMbrash-student-40401
10/25/2022, 8:54 PMcurved-television-6568
10/25/2022, 8:54 PMbrash-student-40401
10/25/2022, 8:57 PMpants.toml
you mean? Something like this:
[docker.registries.company-ecr]
address = {build_args.REGISTRY}
Do the curly braces work there?brash-student-40401
10/25/2022, 8:58 PM{build_args.ARG_NAME}: Each defined Docker build arg is available for interpolation under the build_args. prefix.
in the docs)curved-television-6568
10/25/2022, 8:59 PM╰─❯ ./pants --docker-registries='{"default":{"address":"foo.bar"}}' package testprojects/src/python/docker:test-example
â ¤ 7.76s Building docker image foo.bar/test-example:1.2.5
brash-student-40401
10/25/2022, 8:59 PMbrash-student-40401
10/25/2022, 9:27 PMbest-midnight-81002
05/10/2024, 9:53 PM[docker]
build_args = ["namebase", "aws_account", "aws_region"]
[docker.registries.legacy-prod]
address = "{build_args.aws_account}.dkr.ecr.{build_args.aws_region}.<http://amazonaws.com|amazonaws.com>"
repository = "{build_args.namebase}"
best-midnight-81002
05/10/2024, 10:06 PMpolite-art-93959
05/10/2024, 11:13 PMpolite-art-93959
05/10/2024, 11:14 PMenv(...)
best-midnight-81002
05/12/2024, 9:06 PM.pants.bootstrap
and it may help for other things 🙂 in this case we have args passed in from terraform. I think in this specific case we still run into the problem that the registry address doesn't interpolate curly-brace values.best-midnight-81002
05/13/2024, 5:34 PM--docker-registries=...
on the command line) is my configuration is now split across two places: pants.toml and my CI script