-
Notifications
You must be signed in to change notification settings - Fork 79
feat: Add custom Docker build for package registry #1554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fred-maussion
wants to merge
11
commits into
elastic:main
Choose a base branch
from
fred-maussion:cmd-distribution-scripts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−0
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c89ecfd
Add custom Docker build for package registry
fred-maussion 1d71b8f
Bump github.com/cloudflare/circl in /cmd/distribution (#1566)
dependabot[bot] 419be27
Bump github.com/google/go-querystring in /cmd/distribution (#1565)
dependabot[bot] c1cc954
Update Go runtime to 1.25.7 (#1560)
ycombinator 6f82dff
Revert use of waitgroup.Go (#1567)
jsoriano 5571c49
feat: Add custom Docker registry build and move package example
fred-maussion 944d898
Merge branch 'elastic:main' into cmd-distribution-scripts
fred-maussion e972287
fix: Rename package file to .yaml, adapt path, add pointer to distrib…
fred-maussion 8e56e98
fix: changed GO_VERSION default value
fred-maussion 2d1d4c6
fix: changed build docker build to map GO_VERSION dynamic value
fred-maussion 32512ff
fix: revert ELASTIC_APM_ACTIVE documentation
fred-maussion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # This image contains the package-registry binary AND a pre-warmed set of packages. | ||
|
|
||
| ARG GO_VERSION=1.25.7 | ||
| ARG BUILDER_IMAGE=golang | ||
| ARG RUNNER_IMAGE=cgr.dev/chainguard/wolfi-base | ||
|
|
||
| # STAGE 1: Build the 'distribution' tool | ||
| FROM --platform=${BUILDPLATFORM:-linux} ${BUILDER_IMAGE}:${GO_VERSION} AS distribution-builder | ||
| WORKDIR /src | ||
| COPY . . | ||
| ARG TARGETPLATFORM | ||
| # Build the distribution binary inside its own directory | ||
| RUN make -C cmd/distribution release-${TARGETPLATFORM:-linux/amd64} | ||
|
|
||
|
|
||
| # STAGE 2: Run the 'distribution' tool to download packages | ||
| FROM distribution-builder AS packager | ||
| # Copy the custom configuration for the packages we want | ||
| COPY ./cmd/distribution/examples/custom-packages.yaml . | ||
| # Run the tool. It will create the packages in 'build/distribution/' | ||
| RUN ./cmd/distribution/distribution ./cmd/distribution/examples/custom-packages.yaml | ||
|
|
||
|
|
||
| # STAGE 3: Build the final 'package-registry' binary | ||
| FROM --platform=${BUILDPLATFORM:-linux} ${BUILDER_IMAGE}:${GO_VERSION} AS registry-builder | ||
| WORKDIR /src | ||
| COPY . . | ||
| ARG TARGETPLATFORM | ||
| # Build the main package-registry binary from the root directory | ||
| RUN make release-${TARGETPLATFORM:-linux/amd64} | ||
|
|
||
|
|
||
| # STAGE 4: Final image assembly | ||
| FROM ${RUNNER_IMAGE} | ||
|
|
||
| # Get dependencies (same as original Dockerfile) | ||
| # Mailcap is installed to get mime types information. | ||
| RUN if grep -q "Red Hat" /etc/os-release ; then \ | ||
| microdnf install -y mailcap zip rsync && \ | ||
| microdnf clean all ; \ | ||
| else \ | ||
| apk update && \ | ||
| apk add mailcap zip rsync curl && \ | ||
| rm -rf /var/cache/apk/* ; \ | ||
| fi | ||
|
|
||
| WORKDIR /package-registry | ||
|
|
||
| # Copy the main binary from the 'registry-builder' stage | ||
| COPY --from=registry-builder /src/package-registry . | ||
|
|
||
| # --- THIS IS THE KEY STEP --- | ||
| # Copy the downloaded packages from the 'packager' stage into the final image | ||
| # The registry is configured to look for packages in '/packages/package-registry/' | ||
| COPY --from=packager /src/build/distribution/. /packages/package-registry/ | ||
|
|
||
| # Get in config which expects packages in /packages | ||
| COPY config.docker.yml ./config.yml | ||
|
|
||
| # Run as non-root user | ||
| USER 1000 | ||
|
|
||
| # Start registry when container is run an expose it on port 8080 | ||
| EXPOSE 8080 | ||
| ENTRYPOINT ["./package-registry"] | ||
|
|
||
| # Make sure it's accessible from outside the container | ||
| ENV EPR_ADDRESS=0.0.0.0:8080 | ||
|
|
||
| HEALTHCHECK --interval=1s --retries=30 CMD curl --silent --fail localhost:8080/health || exit 1 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Base address of the Package Registry | ||
fred-maussion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| address: "https://epr.elastic.co" | ||
|
|
||
| # Queries are executed with each one of the parameters of the matrix. | ||
| matrix: | ||
| - spec.max: 3.5 | ||
| - prerelease: true | ||
| spec.max: 3.5 | ||
|
|
||
| # Queries to execute to discover packages >8.18.0 & >9.0.0. | ||
| queries: | ||
| - kibana.version: 8.18.0 | ||
| spec.max: 3.4 | ||
| - kibana.version: 9.0.0 | ||
| spec.min: 2.3 | ||
| spec.max: 3.4 | ||
|
|
||
|
|
||
| actions: | ||
| - print: | ||
| - download: | ||
| destination: ./build/distribution | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if it could be possible to avoid duplicating the Dockerfile that builds the package-registry (stages 3 and 4 of this Dockerfile).
What about using in this Dockerfile the latest docker image of the Package Registry released or a known docker image? It could be set via a build argument so it can be set in the CLI while building the container too.
Given that, maybe this multi-stage Dockerfile could be updated to just 3 stages:
And in the README, the instructions could be updated to be like:
This is an example based on tags, but the user building this custom image could be setting directly a specific docker EPR image tag.
WDYT @fred-maussion ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be interesting to keep GO_VERSION and EPR_RUNNER_IMAGE to be without value to force setting those values as build arguments in the
docker buildcommand: