-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
45 lines (35 loc) · 1.61 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
FROM --platform=$BUILDPLATFORM clux/muslrust:stable AS builder
ARG TARGETPLATFORM
WORKDIR /volume
# Install cross-compilation tools for musl
RUN apt-get update && apt-get install -y \
musl-tools wget \
&& wget https://musl.cc/aarch64-linux-musl-cross.tgz \
&& tar -xf aarch64-linux-musl-cross.tgz -C /usr \
&& rm aarch64-linux-musl-cross.tgz
# Install cross-compilation target
RUN rustup target add aarch64-unknown-linux-musl x86_64-unknown-linux-musl
COPY Cargo.* .
COPY src src
RUN --mount=type=cache,target=/volume/target \
--mount=type=cache,target=/root/.cargo/registry \
if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
ARCHITECTURE=x86_64; \
cargo build --release --bin gitops-operator --target x86_64-unknown-linux-musl; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
ARCHITECTURE=aarch64; \
PATH="/usr/aarch64-linux-musl-cross/bin:$PATH" \
CC_aarch64_unknown_linux_musl=aarch64-linux-musl-gcc \
AR_aarch64_unknown_linux_musl=aarch64-linux-musl-ar \
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc \
cargo build --release --bin gitops-operator --target aarch64-unknown-linux-musl; \
else \
ARCHITECTURE=x86_64; \
cargo build --release --bin gitops-operator --target x86_64-unknown-linux-musl; \
fi && \
mv /volume/target/$ARCHITECTURE-unknown-linux-musl/release/gitops-operator .
FROM cgr.dev/chainguard/static
COPY --from=builder --chown=nonroot:nonroot /volume/gitops-operator /app/
COPY files/known_hosts /home/nonroot/.ssh/known_hosts
EXPOSE 8000
ENTRYPOINT ["/app/gitops-operator"]