brave-hair-402
03/07/2023, 10:35 AMBUILD
files. Is there a way to define this base image in only one place and reuse it across all my BUILD
files? I've considered using environmental variables, but I'm not sure if that's the best approach. Does anyone have any suggestions on how to achieve this?refined-addition-53644
03/07/2023, 10:41 AMbrave-hair-402
03/07/2023, 10:42 AMrefined-addition-53644
03/07/2023, 10:43 AMdocker_environment
, you can use ___defaults___
https://www.pantsbuild.org/docs/targets#field-default-valuesbrave-hair-402
03/07/2023, 10:46 AMrefined-addition-53644
03/07/2023, 10:47 AMrefined-addition-53644
03/07/2023, 10:51 AMdef base_docker_image(**kwargs):
kwargs["base_image"] = base_image
return your_docker_target(**kwargs)
brave-hair-402
03/07/2023, 10:57 AMdef lambda_docker(name, handler, repository, registries, image_tags, **kwargs):
entry_point, handler_fun = handler.split(":")
entry_app, _ = entry_point.split(".")
entry_dir = build_file_dir().parts[-1]
pex_binary(
name="bin-srcs",
entry_point=entry_point,
layout="packed",
include_requirements=False,
include_tools=True,
)
pex_binary(
name="bin-deps",
entry_point=entry_point,
dependencies=["3rdparty/python:poetry#awslambdaric"],
layout="packed",
include_sources=False,
include_tools=True,
)
base_image = "python:3.10.10-slim-bullseye@sha256:fcf375288c9348c9708cc7ea3d511b512224219fdc164b6960b3ce85288e1cbf"
docker_image(
name=name,
repository=repository,
dependencies=[":bin-srcs", ":bin-deps"],
registries=registries,
image_tags=image_tags,
instructions=[
f"FROM {base_image} as deps",
f"COPY {'.'.join(build_file_dir().parts) + '/' + 'bin-deps.pex'} /bin-deps.pex",
"RUN PEX_TOOLS=1 /usr/local/bin/python3.10 /bin-deps.pex venv --scope=deps --compile /app",
f"FROM {base_image} as srcs",
f"COPY {'.'.join(build_file_dir().parts) + '/' + 'bin-srcs.pex'} /bin-srcs.pex",
"RUN PEX_TOOLS=1 /usr/local/bin/python3.10 /bin-srcs.pex venv --scope=srcs --compile /app",
f"FROM {base_image}",
"COPY --from=deps /app /app",
"COPY --from=srcs /app /app",
"WORKDIR /app",
'ENTRYPOINT [ "/app/bin/python", "-m", "awslambdaric" ]',
f'CMD ["{entry_dir}.{entry_app}.{handler_fun}"]',
],
source=None,
)
refined-addition-53644
03/07/2023, 10:58 AMbrave-hair-402
03/07/2023, 11:00 AM+docker_environment(
+ name="lambda_docker_env",
+ platform="linux_x86_64",
+ image="python:3.10.10-slim-bullseye@sha256:fcf375288c9348c9708cc7ea3d511b512224219fdc164b6960b3ce85288e1cbf",
)
brave-hair-402
03/07/2023, 11:02 AMrefined-addition-53644
03/07/2023, 11:06 AM[docker]
build_args = [
"BASE_IMAGE=value1",
]
# Dockerfile
ARG BASE_IMAGE
FROM $BASE_IMAGE
But that doesn’t help with docker_environment
refined-addition-53644
03/07/2023, 11:09 AMdocker_environment
without pushing it to some docker registry private or public.
Otherwise you could create a default docker_image
target with this base image and use that everywhereenough-analyst-54434
03/07/2023, 11:14 AM./pants
script and scie-pants (pants
) support sourcing a .pants.bootstrap
file and gathering exported env vars from there. See https://github.com/pantsbuild/pants/discussions/17633
If using scie-pants (pants
) the more efficient and standard .env
files are supported as well. See: https://github.com/pantsbuild/scie-pants#featuresbrave-hair-402
03/07/2023, 11:15 AMbrave-hair-402
03/07/2023, 11:22 AMenough-analyst-54434
03/07/2023, 11:24 AMenv("X", "optional default")
is supported in 2.15.0 or just 2.16.x.enough-analyst-54434
03/07/2023, 11:25 AMbrave-hair-402
03/07/2023, 11:25 AMenough-analyst-54434
03/07/2023, 11:27 AMenough-analyst-54434
03/07/2023, 11:28 AMbroad-processor-92400
03/07/2023, 7:12 PM