thousands-plumber-33255
11/24/2022, 11:29 AMdocker_image
target:
1. How can I target a Dockerfile with the source
fild that is not relative to the BUILD file or any subdirectoy but is one level up, i.e. ../Dockerfile
?
2. I have seen that in a BUILD file I can reference values from the pants.toml
like repository="{build_argsREPO_URL}"
. Is it possible to get the name of the directory where the BUILD file is located in, such that I can do something like: extra_build_args=["{THIS_DIRECTORY_NAME}"]
?nutritious-hair-72580
11/24/2022, 12:39 PMsrc/main/docker/my-image:target-name
curved-television-6568
11/24/2022, 12:39 PMbuild_file_dir()
as a function call. If embedded in a string value, use f-string f"some text {build_file_dir()} more text"
docker_image
target, is that feasible for you?thousands-plumber-33255
11/24/2022, 2:25 PM/services
Dockerfile
/serviceA
/serviceB
All services share the same Dockerfile and the BUILD file for each service looks like this:
docker_image(
name="service-a-image",
source="../Dockerfile",
dependencies=[":lambda", "//:entrypoint"],
repository="{build_args.REPO_URL}",
image_tags=["latest"],
# TODO: can this solved another way? it is due to the lambda.zip
context_root="",
extra_build_args=[f"SERVICE={build_file_dir()}]
)
python_awslambda(
name="lambda",
runtime="python3.8",
handler="lambda_handler.py:handler",
)
python_sources()
Any idea how to restructure this? There will be a few services which will have a different docker_image target as they need another dockerfile, but for most of them it looks the same.curved-television-6568
11/24/2022, 2:39 PM# services/BUILD
service_image(
name="service-a-image",
service="serviceA",
)
service_image(
name="service-b-image",
service="serviceB",
)
# pants macro file
def service_image(name, service, **kwargs):
path = f"{build_file_dir()}/{service}"
docker_image(
name=name,
source="Dockerfile", # may be left out now as it's default
dependencies=[f"{path}:lambda", "//:entrypoint"],
extra_build_args=[f"SERVICE={path}"],
...,
**kwargs
)
only concern being if Pants will complain about multiple owners for the `Dockerfile`…?thousands-plumber-33255
11/24/2022, 3:25 PMREPO_URL
, add this as entry to build_args
in pants.toml
, then use repository="{build_args.REPO_URL}"
in the macro.service_image
targets at the same time?curved-television-6568
11/24/2022, 3:55 PM./pants run
is an interactive process and support a single target only.docker-compose
but I’ve not seen/done anything in that area with pants (yet?)experimental_run_shell_command
for instance). On a recent version of Pants, there are docker image metadata available in the dist
folder with details on all the image names etc, useful for building the docker run command…thousands-plumber-33255
11/24/2022, 5:20 PM./pants --target-type=service_image | \
xargs ./pants package
curved-television-6568
11/26/2022, 1:14 PM