I have tried several way to add image_tags on dock...
# general
c
I have tried several way to add image_tags on docker publishing. But it seems hard to set correctly. Am I mssing something?
Copy code
docker_image(
    name="payhere_dashboard",
    source="Dockerfile.dashboard",
    repository="{build_args.REPOSITORY}",
    registries=["----<http://.dkr.ecr.ap-northeast-2.amazonaws.com|.dkr.ecr.ap-northeast-2.amazonaws.com>"],
    image_tags=["latest", "{build_args.GIT_COMMIT}"],
)
ci.yaml command
Copy code
run: |
          GIT_COMMIT=$(git rev-parse HEAD) ./pants publish \
          --docker-build-args='[ \
            "REGISTRY=${ECR_REGISTRY}", \
            "GIT_COMMIT=${GIT_COMMIT}", \
            "REPOSITORY=stg/dashboard", \
          ]' payhere/app_services/dashboard:dashboard
pants.toml
Copy code
[docker]
build_args = ["IMAGE_TAG", "COMMIT_REF", "GIT_COMMIT"]
here is the error trace.
Copy code
Engine traceback:
  in `publish` goal

DockerImageTagValueError: Invalid value for the `image_tags` field of the `docker_image` target at payhere/app_services/dashboard:dashboard: '{build_args.GIT_COMMIT}'.

The placeholder 'GIT_COMMIT' is unknown. Try with one of: build_args, pants, tags.
👀 1
1
c
Hi, apologies for the trouble. The issue here is shell quoting (and misleading/incomplete error message). If GIT_COMMIT was unknown as hinted by your message the error would say something like
The build arg 'GIT_COMMIT' is undefined. Defined build args are: REGISTRY, REPOSITORY.
Here it is the value of the expanded `{build_arg.GIT_COMMIT}`that is
${GIT_COMMIT}
and that is what is unknown (and unintended too of course). Your shell command in
ci.yaml
uses single quotes and in single quotes env var substitution is disabled.
c
Thanks for explanation. so, how can I change this?
c
Build args use same named env vars by default, so you can lean into that. You may need to include the vars you want to use this way in
[docker].env
though (still name only)
I usually put all of this in the configuration so only setting the actual env var is left as an outside thing (on the command line or in
.pants.bootstrap
or else where)
c
Could you give me some example?
c
ok let me follow up.
Copy code
# BUILD
docker_image(name="img", tags=[env("TAG", "default")])
this is also working?
Copy code
# .pants.bootstrap

# Ensure GIT_COMMIT is set and exported
: ${GIT_COMMIT:=$(git rev-parse HEAD)}
export GIT_COMMIT
Copy code
docker_image(
    name="dashboard",
    source="Dockerfile.dashboard",
    repository="{build_args.REPOSITORY}",
    registries=["<http://168779575847.dkr.ecr.ap-northeast-2.amazonaws.com|168779575847.dkr.ecr.ap-northeast-2.amazonaws.com>"],
    image_tags=["latest", "{build_args.GIT_COMMIT}"],
)
Copy code
Engine traceback:
  in `publish` goal

DockerImageTagValueError: Invalid value for the `image_tags` field of the `docker_image` target at payhere/app_services/dashboard:payhere_dashboard: '{build_args.GIT_COMMIT}'.

The placeholder 'GIT_COMMIT' is unknown. Try with one of: build_args, pants, tags.
still the same...
c
So, the value of your GIT_COMMIT is still suspect. suggest inspecting configuration and env for any lingering exported values. Also printing the value of GIT_COMMIT during a pants run could be instructive (can add a echo statement to the pants script if you still use it, for instance)
c
when I echo GIT_COMMIT, no value returns
Copy code
echo $COMMIT_REF
  ./pants publish \
  --docker-build-args='[ \
    "REGISTRY=${ECR_REGISTRY}", \
    "COMMIT_REF=${COMMIT_REF}", \
    "REPOSITORY=stg/payhere-dashboard", \
  ]' payhere/app_services/dashboard:payhere_dashboard
  shell: /usr/bin/bash -e {0}
  env:
    COMMIT_REF: 0b51931d0bee432e67f3e0ea6c9b305baad5c9c4
Although I changed to COMMIT_REF, I got similar error.
Copy code
Engine traceback:
  in `publish` goal

DockerImageTagValueError: Invalid value for the `image_tags` field of the `docker_image` target at payhere/app_services/dashboard:payhere_dashboard: '{build_args.COMMIT_REF}'.

The placeholder 'COMMIT_REF' is unknown. Try with one of: build_args, pants, tags.
I have changed double quote and single quote. Now it works as expected.
👍 1
c
https://pantsbuild.slack.com/archives/C046T6T9U/p1676296369315199?thread_ts=1676292672.358099&amp;cid=C046T6T9U Sorry, missed this one. Yes that’ll work when using Pants v2.16.0.dev5 or newer.
c
Do you think moving to dev version is ok? I am using
2.15.0rc3
It is not stable version as well. But I heard the stable version is coming soon.
c
There’s been a few instabilities being worked out recently so I guess it comes down to how you use Pants. Can’t really give straight answer to that, other than you may try see how it works out and report if you encounter any issues. That would be helpful and appreciated 🙂
c
i see thanks a lot @curved-television-6568 !