-
Notifications
You must be signed in to change notification settings - Fork 433
feat: add building option to build images base on distroless image #7240
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
Merged
+117
−12
Merged
Changes from all commits
Commits
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
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,65 @@ | ||
| FROM ubuntu:22.04 AS builder | ||
|
|
||
| ARG CARGO_PROFILE | ||
| ARG FEATURES | ||
| ARG OUTPUT_DIR | ||
|
|
||
| ENV LANG=en_US.utf8 | ||
| WORKDIR /greptimedb | ||
|
|
||
| RUN apt-get update && \ | ||
| DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common | ||
|
|
||
| # Install dependencies. | ||
| RUN --mount=type=cache,target=/var/cache/apt \ | ||
| apt-get update && apt-get install -y \ | ||
| libssl-dev \ | ||
| protobuf-compiler \ | ||
| curl \ | ||
| git \ | ||
| build-essential \ | ||
| pkg-config | ||
|
|
||
| # Install Rust. | ||
| SHELL ["/bin/bash", "-c"] | ||
| RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y | ||
| ENV PATH=/root/.cargo/bin/:$PATH | ||
|
|
||
| # Build the project in release mode. | ||
| RUN --mount=target=. \ | ||
| --mount=type=cache,target=/root/.cargo/registry \ | ||
| make build \ | ||
| CARGO_PROFILE=${CARGO_PROFILE} \ | ||
| FEATURES=${FEATURES} \ | ||
| TARGET_DIR=/out/target | ||
|
|
||
| FROM ubuntu:22.04 AS libs | ||
|
|
||
| ARG TARGETARCH | ||
|
|
||
| # Copy required library dependencies based on architecture | ||
| RUN if [ "$TARGETARCH" = "amd64" ]; then \ | ||
| cp /lib/x86_64-linux-gnu/libz.so.1.2.11 /lib/x86_64-linux-gnu/libz.so.1; \ | ||
| elif [ "$TARGETARCH" = "arm64" ]; then \ | ||
| cp /lib/aarch64-linux-gnu/libz.so.1.2.11 /lib/aarch64-linux-gnu/libz.so.1; \ | ||
| else \ | ||
| echo "Unsupported architecture: $TARGETARCH" && exit 1; \ | ||
| fi | ||
|
|
||
| # Export the binary to the clean distroless image. | ||
| FROM gcr.io/distroless/cc-debian12:latest AS base | ||
|
|
||
| ARG OUTPUT_DIR | ||
| ARG TARGETARCH | ||
|
|
||
| # Copy required library dependencies | ||
| COPY --from=libs /lib /lib | ||
| COPY --from=busybox:stable /bin/busybox /bin/busybox | ||
|
|
||
| WORKDIR /greptime | ||
| COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/greptime | ||
| ENV PATH=/greptime/bin/:$PATH | ||
WaterWhisperer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ENV MALLOC_CONF="prof:true,prof_active:false" | ||
|
|
||
| ENTRYPOINT ["greptime"] | ||
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
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,40 @@ | ||
| FROM ubuntu:22.04 AS libs | ||
|
|
||
| ARG TARGETARCH | ||
|
|
||
| # Copy required library dependencies based on architecture | ||
| # TARGETARCH values: amd64, arm64 | ||
| # Ubuntu library paths: x86_64-linux-gnu, aarch64-linux-gnu | ||
| RUN if [ "$TARGETARCH" = "amd64" ]; then \ | ||
| mkdir -p /output/x86_64-linux-gnu && \ | ||
| cp /lib/x86_64-linux-gnu/libz.so.1.2.11 /output/x86_64-linux-gnu/libz.so.1; \ | ||
| elif [ "$TARGETARCH" = "arm64" ]; then \ | ||
| mkdir -p /output/aarch64-linux-gnu && \ | ||
| cp /lib/aarch64-linux-gnu/libz.so.1.2.11 /output/aarch64-linux-gnu/libz.so.1; \ | ||
| else \ | ||
| echo "Unsupported architecture: $TARGETARCH" && exit 1; \ | ||
| fi | ||
|
|
||
| FROM gcr.io/distroless/cc-debian12:latest | ||
|
|
||
| # The root path under which contains all the dependencies to build this Dockerfile. | ||
| ARG DOCKER_BUILD_ROOT=. | ||
| # The binary name of GreptimeDB executable. | ||
| # Defaults to "greptime", but sometimes in other projects it might be different. | ||
| ARG TARGET_BIN=greptime | ||
|
|
||
| ARG TARGETARCH | ||
|
|
||
| # Copy required library dependencies | ||
| COPY --from=libs /output /lib | ||
| COPY --from=busybox:stable /bin/busybox /bin/busybox | ||
|
|
||
| ADD $TARGETARCH/$TARGET_BIN /greptime/bin/ | ||
|
|
||
| ENV PATH=/greptime/bin/:$PATH | ||
|
|
||
| ENV TARGET_BIN=$TARGET_BIN | ||
WaterWhisperer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ENV MALLOC_CONF="prof:true,prof_active:false" | ||
|
|
||
| ENTRYPOINT ["greptime"] | ||
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
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.