happy-sundown-654
10/23/2024, 5:38 PMpants package
in my github workflows? Ideally I would just need to rebuild only the docker images where changes exist?brief-branch-21752
10/23/2024, 5:56 PM--changed-since=origin/main --changed-dependents=transitive
. So for example pants --changed-since=origin/main --changed-dependents=transitive package
.
One detail to sort out is how you plan on versioning your artifacts. Many ways to do this and it depends on what your specific constraints are. You can use .pants.bootstrap
to generate versions and pass that in as a build arg and use it for the image tag. Example of what it would look like in pants.toml
[docker]
build_args = [
"VERSION_DOCKER",
]
And then in your docker_image
tags = [
"{build_args.VERSION_DOCKER}"
]
brief-branch-21752
10/23/2024, 5:57 PMhappy-sundown-654
10/23/2024, 5:57 PMpants --docker-build-args="['VERSION=$IMAGE_TAG']" package ::
happy-sundown-654
10/23/2024, 6:04 PMbrief-branch-21752
10/23/2024, 6:07 PMhappy-sundown-654
10/23/2024, 6:07 PMhappy-sundown-654
10/23/2024, 6:08 PMpants --changed-since=origin/main --changed-dependents=transitive publish ::
brief-branch-21752
10/23/2024, 6:09 PM::
at the end since the changed arguments become your selector.happy-sundown-654
10/23/2024, 6:22 PMhappy-sundown-654
10/23/2024, 6:23 PMbrief-branch-21752
10/23/2024, 6:37 PMbrief-branch-21752
10/23/2024, 6:37 PMhappy-sundown-654
10/23/2024, 6:38 PMhappy-sundown-654
10/23/2024, 6:38 PM...
registries=["{build_args.REGISTRY}"],
it results in this:
ProcessExecutionFailure: Process 'Building docker image {build_args.REGISTRY}/echo:latest +1 additional tag.' failed with exit code 1.
brief-branch-21752
10/23/2024, 6:38 PM{build_args.VERSION_DOCKER}
brief-branch-21752
10/23/2024, 6:38 PMhappy-sundown-654
10/23/2024, 6:39 PMpants --docker-build-args="['VERSION=v0.0.1', 'REGISTRY=hello']" publish apps/echo:echo
brief-branch-21752
10/23/2024, 6:40 PMpants.toml
file (this is for GCP Artifact Registry):
[docker.registries.your-name]
address = "us-central1-docker.pkg.dev"
default = true
extra_image_tags = ["{build_args.VERSION_DOCKER}"]
happy-sundown-654
10/23/2024, 6:41 PMbrief-branch-21752
10/23/2024, 6:42 PMhappy-sundown-654
10/23/2024, 6:42 PMhappy-sundown-654
10/23/2024, 6:42 PMbrief-branch-21752
10/23/2024, 6:49 PMregistries
doesn't allow getting values form build_args. An alternative is to get it from the environment which would have a syntax like (not tested) env.REGISTRY
.happy-sundown-654
10/23/2024, 6:51 PMhappy-sundown-654
10/23/2024, 6:53 PM--docker-registries
happy-sundown-654
10/23/2024, 7:14 PMDockerfile.echo:3
--------------------
1 | FROM python:3.11-slim
2 | COPY --from=echo-srcs /bin/app /bin/app
3 | >>> COPY --from=echo-deps /bin/app /bin/app
4 | EXPOSE 8080
5 | ENTRYPOINT ["/bin/app/pex", "--port", "8080", "--host", "0.0.0.0"]
--------------------
ERROR: failed to solve: echo-deps: failed to resolve source metadata for <http://docker.io/library/echo-deps:latest|docker.io/library/echo-deps:latest>: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
here's the part of my BUILD
file that is relevant:
docker_image(
name = "echo-deps",
skip_push=True,
image_tags=["latest", "{build_args.VERSION}"],
instructions = [
f"FROM {BASE_IMAGE}",
"COPY apps.echo/_binary-deps.pex /bin/build/_binary-deps.pex",
"RUN PEX_TOOLS=1 /usr/local/bin/python3.11 /bin/build/_binary-deps.pex venv --scope=deps --compile /bin/app",
],
dependencies=[":_binary-deps"],
)
docker_image(
name = "echo-srcs",
skip_push=True,
image_tags=["latest", "{build_args.VERSION}"],
instructions = [
f"FROM {BASE_IMAGE}",
"COPY apps.echo/_binary-srcs.pex /bin/build/_binary-srcs.pex",
"RUN PEX_TOOLS=1 /usr/local/bin/python3.11 /bin/build/_binary-srcs.pex venv --scope=srcs --compile /bin/app",
],
dependencies=[":_binary-srcs"],
)
# <https://www.pantsbuild.org/blog/2022/08/02/optimizing-python-docker-deploys-using-pants>
docker_image(
name = "echo",
image_tags=["latest", "{build_args.VERSION}"],
dependencies=[":echo-srcs", ":echo-deps"],
instructions = [
f"FROM {BASE_IMAGE}",
"COPY --from=echo-srcs /bin/app /bin/app",
"COPY --from=echo-deps /bin/app /bin/app",
"EXPOSE 8080",
'ENTRYPOINT ["/bin/app/pex", "--port", "8080", "--host", "0.0.0.0"]',
]
)
happy-sundown-654
10/23/2024, 7:14 PMbrief-branch-21752
10/23/2024, 7:20 PMhappy-sundown-654
10/23/2024, 7:21 PMhappy-sundown-654
10/23/2024, 7:35 PM--from={default_registry_name}/echo-srcs
but I guess that's not ideal so the previous docker_images need a pattern to not add the default somehowbrief-branch-21752
10/23/2024, 7:39 PMhappy-sundown-654
10/23/2024, 7:40 PM--docker-default-repository
so that my final image pushes to the registry properly
The rest are also built with that name (which I do not want)