-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
62 lines (51 loc) · 2.07 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
ARG HOMEDIR=/opt/app
ARG WALG_TARGET=pg
ARG USER=101
ARG GROUP=103
# Build the manager binary
FROM rust:1.70.0-alpine3.18 AS builder
ARG WALG_TARGET
ARG WALG_VERSION=v2.0.1
ARG APP_NAME
ARG APP_VERSION
ARG LOG_PKG_PATH
ARG APP_PKG_PATH
ARG WALG_DOWNLOAD_URL=https://github.com/wal-g/wal-g/releases/download
ARG HOMEDIR
WORKDIR /workspace
COPY src/ src/
COPY Cargo.lock Cargo.lock
COPY Cargo.toml Cargo.toml
COPY log4rs.yml log4rs.yml
RUN ls -al /workspace/src
# Build
RUN apk add --no-cache musl-dev && \
rustup target add x86_64-unknown-linux-musl && \
cargo build --release --locked --target=x86_64-unknown-linux-musl
# Download wal-g binary
RUN wget -qO- ${WALG_DOWNLOAD_URL}/${WALG_VERSION}/wal-g-${WALG_TARGET}-ubuntu-20.04-amd64.tar.gz | tar xvz && \
mv wal-g-${WALG_TARGET}-ubuntu-20.04-amd64 target/x86_64-unknown-linux-musl/release/wal-g-postgres
RUN mkdir -p ${HOMEDIR} && \
echo "app:x:${USER}:app" >> /etc/group && \
echo "app:x:${USER}:${GROUP}:app user:${HOMEDIR}:/sbin/nologin" >> /etc/passwd && \
chown app:app target/x86_64-unknown-linux-musl/release/wal-g-exporter && \
chown app:app target/x86_64-unknown-linux-musl/release/wal-g-postgres && \
chown -R app:app ${HOMEDIR} && \
chmod -R g+rw ${HOMEDIR} && \
chmod u+rwx target/x86_64-unknown-linux-musl/release/wal-g-exporter && \
chmod u+rwx target/x86_64-unknown-linux-musl/release/wal-g-postgres
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/base:latest
ARG HOMEDIR
ARG WALG_TARGET
ARG USER
ARG GROUP
COPY --chown=${USER}:${GROUP} --from=builder ${HOMEDIR} ${HOMEDIR}
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /workspace/target/x86_64-unknown-linux-musl/release/wal-g-exporter /usr/bin/wal-g-exporter
COPY --from=builder /workspace/target/x86_64-unknown-linux-musl/release/wal-g-postgres /usr/bin/wal-g-${WALG_TARGET}
COPY --from=builder /workspace/log4rs.yml ${HOMEDIR}/
WORKDIR ${HOMEDIR}
USER ${USER}
ENTRYPOINT ["/usr/bin/wal-g-exporter"]