Skip to content

Commit bf69c85

Browse files
feat: add building option to build images base on distroless image
Signed-off-by: WaterWhisperer <[email protected]>
1 parent 7f1da17 commit bf69c85

File tree

6 files changed

+117
-12
lines changed

6 files changed

+117
-12
lines changed

docker/buildx/centos/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM centos:7 as builder
1+
FROM centos:7 AS builder
22

33
ARG CARGO_PROFILE
44
ARG FEATURES
55
ARG OUTPUT_DIR
66

7-
ENV LANG en_US.utf8
7+
ENV LANG=en_US.utf8
88
WORKDIR /greptimedb
99

1010
# Install dependencies
@@ -22,7 +22,7 @@ RUN unzip protoc-3.15.8-linux-x86_64.zip -d /usr/local/
2222
# Install Rust
2323
SHELL ["/bin/bash", "-c"]
2424
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
25-
ENV PATH /usr/local/bin:/root/.cargo/bin/:$PATH
25+
ENV PATH=/usr/local/bin:/root/.cargo/bin/:$PATH
2626

2727
# Build the project in release mode.
2828
RUN --mount=target=.,rw \
@@ -33,7 +33,7 @@ RUN --mount=target=.,rw \
3333
TARGET_DIR=/out/target
3434

3535
# Export the binary to the clean image.
36-
FROM centos:7 as base
36+
FROM centos:7 AS base
3737

3838
ARG OUTPUT_DIR
3939

@@ -45,7 +45,7 @@ RUN yum install -y epel-release \
4545

4646
WORKDIR /greptime
4747
COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/
48-
ENV PATH /greptime/bin/:$PATH
48+
ENV PATH=/greptime/bin/:$PATH
4949

5050
ENV MALLOC_CONF="prof:true,prof_active:false"
5151

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
FROM ubuntu:22.04 AS builder
2+
3+
ARG CARGO_PROFILE
4+
ARG FEATURES
5+
ARG OUTPUT_DIR
6+
7+
ENV LANG=en_US.utf8
8+
WORKDIR /greptimedb
9+
10+
RUN apt-get update && \
11+
DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common
12+
13+
# Install dependencies.
14+
RUN --mount=type=cache,target=/var/cache/apt \
15+
apt-get update && apt-get install -y \
16+
libssl-dev \
17+
protobuf-compiler \
18+
curl \
19+
git \
20+
build-essential \
21+
pkg-config
22+
23+
# Install Rust.
24+
SHELL ["/bin/bash", "-c"]
25+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
26+
ENV PATH=/root/.cargo/bin/:$PATH
27+
28+
# Build the project in release mode.
29+
RUN --mount=target=. \
30+
--mount=type=cache,target=/root/.cargo/registry \
31+
make build \
32+
CARGO_PROFILE=${CARGO_PROFILE} \
33+
FEATURES=${FEATURES} \
34+
TARGET_DIR=/out/target
35+
36+
FROM ubuntu:22.04 AS libs
37+
38+
ARG TARGETARCH
39+
40+
# Copy required library dependencies based on architecture
41+
RUN if [ "$TARGETARCH" = "amd64" ]; then \
42+
cp /lib/x86_64-linux-gnu/libz.so.1.2.11 /lib/x86_64-linux-gnu/libz.so.1; \
43+
elif [ "$TARGETARCH" = "arm64" ]; then \
44+
cp /lib/aarch64-linux-gnu/libz.so.1.2.11 /lib/aarch64-linux-gnu/libz.so.1; \
45+
else \
46+
echo "Unsupported architecture: $TARGETARCH" && exit 1; \
47+
fi
48+
49+
# Export the binary to the clean distroless image.
50+
FROM gcr.io/distroless/cc-debian12:latest AS base
51+
52+
ARG OUTPUT_DIR
53+
ARG TARGETARCH
54+
55+
# Copy required library dependencies
56+
COPY --from=libs /lib /lib
57+
COPY --from=busybox:stable /bin/busybox /bin/busybox
58+
59+
WORKDIR /greptime
60+
COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/greptime
61+
ENV PATH=/greptime/bin/:$PATH
62+
63+
ENV MALLOC_CONF="prof:true,prof_active:false"
64+
65+
ENTRYPOINT ["greptime"]

docker/buildx/ubuntu/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
FROM ubuntu:22.04 as builder
1+
FROM ubuntu:22.04 AS builder
22

33
ARG CARGO_PROFILE
44
ARG FEATURES
55
ARG OUTPUT_DIR
66

7-
ENV LANG en_US.utf8
7+
ENV LANG=en_US.utf8
88
WORKDIR /greptimedb
99

1010
RUN apt-get update && \
@@ -23,7 +23,7 @@ RUN --mount=type=cache,target=/var/cache/apt \
2323
# Install Rust.
2424
SHELL ["/bin/bash", "-c"]
2525
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path --default-toolchain none -y
26-
ENV PATH /root/.cargo/bin/:$PATH
26+
ENV PATH=/root/.cargo/bin/:$PATH
2727

2828
# Build the project in release mode.
2929
RUN --mount=target=. \
@@ -35,7 +35,7 @@ RUN --mount=target=. \
3535

3636
# Export the binary to the clean image.
3737
# TODO(zyy17): Maybe should use the more secure container image.
38-
FROM ubuntu:22.04 as base
38+
FROM ubuntu:22.04 AS base
3939

4040
ARG OUTPUT_DIR
4141

@@ -45,7 +45,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get \
4545

4646
WORKDIR /greptime
4747
COPY --from=builder /out/target/${OUTPUT_DIR}/greptime /greptime/bin/
48-
ENV PATH /greptime/bin/:$PATH
48+
ENV PATH=/greptime/bin/:$PATH
4949

5050
ENV MALLOC_CONF="prof:true,prof_active:false"
5151

docker/ci/centos/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ARG TARGETARCH
1313

1414
ADD $TARGETARCH/greptime /greptime/bin/
1515

16-
ENV PATH /greptime/bin/:$PATH
16+
ENV PATH=/greptime/bin/:$PATH
1717

1818
ENV MALLOC_CONF="prof:true,prof_active:false"
1919

docker/ci/distroless/Dockerfile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM ubuntu:22.04 AS libs
2+
3+
ARG TARGETARCH
4+
5+
# Copy required library dependencies based on architecture
6+
# TARGETARCH values: amd64, arm64
7+
# Ubuntu library paths: x86_64-linux-gnu, aarch64-linux-gnu
8+
RUN if [ "$TARGETARCH" = "amd64" ]; then \
9+
mkdir -p /output/x86_64-linux-gnu && \
10+
cp /lib/x86_64-linux-gnu/libz.so.1.2.11 /output/x86_64-linux-gnu/libz.so.1; \
11+
elif [ "$TARGETARCH" = "arm64" ]; then \
12+
mkdir -p /output/aarch64-linux-gnu && \
13+
cp /lib/aarch64-linux-gnu/libz.so.1.2.11 /output/aarch64-linux-gnu/libz.so.1; \
14+
else \
15+
echo "Unsupported architecture: $TARGETARCH" && exit 1; \
16+
fi
17+
18+
FROM gcr.io/distroless/cc-debian12:latest
19+
20+
# The root path under which contains all the dependencies to build this Dockerfile.
21+
ARG DOCKER_BUILD_ROOT=.
22+
# The binary name of GreptimeDB executable.
23+
# Defaults to "greptime", but sometimes in other projects it might be different.
24+
ARG TARGET_BIN=greptime
25+
26+
ARG TARGETARCH
27+
28+
# Copy required library dependencies
29+
COPY --from=libs /output /lib
30+
COPY --from=busybox:stable /bin/busybox /bin/busybox
31+
32+
ADD $TARGETARCH/$TARGET_BIN /greptime/bin/
33+
34+
ENV PATH=/greptime/bin/:$PATH
35+
36+
ENV TARGET_BIN=$TARGET_BIN
37+
38+
ENV MALLOC_CONF="prof:true,prof_active:false"
39+
40+
ENTRYPOINT ["greptime"]

docker/ci/ubuntu/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ARG TARGETARCH
1414

1515
ADD $TARGETARCH/$TARGET_BIN /greptime/bin/
1616

17-
ENV PATH /greptime/bin/:$PATH
17+
ENV PATH=/greptime/bin/:$PATH
1818

1919
ENV TARGET_BIN=$TARGET_BIN
2020

0 commit comments

Comments
 (0)