-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
70 lines (56 loc) · 2.24 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
63
64
65
66
67
68
69
70
FROM --platform=$TARGETPLATFORM messense/rust-musl-cross:x86_64-musl AS base-amd64
ARG TARGET="x86_64-unknown-linux-musl"
FROM --platform=$TARGETPLATFORM alpine AS alpine-amd64
ARG TARGET="x86_64-unknown-linux-musl"
FROM --platform=$TARGETPLATFORM messense/rust-musl-cross:aarch64-musl AS base-arm64
ARG TARGET="aarch64-unknown-linux-musl"
FROM --platform=$TARGETPLATFORM alpine AS alpine-arm64
ARG TARGET="aarch64-unknown-linux-musl"
# ======================== SETUP RUST ========================
FROM base-$TARGETARCH AS base
WORKDIR /eve
RUN rustup update nightly && \
rustup target add --toolchain nightly $TARGET && \
rustup default nightly
# ======================== BUILD DEPS ========================
FROM base AS build-deps
COPY Cargo.lock .
COPY Cargo.toml .
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
RUN rm -r ./src
# ======================== BUILD PROJECT ========================
FROM build-deps AS build
COPY src src
RUN touch src/main.rs
RUN cargo build --release && \
musl-strip ./target/$TARGET/release/eve
# ======================== GET JAVA ========================
FROM alpine-$TARGETARCH as java
ARG TARGETARCH
ARG JAVA_URL_amd64
ARG JAVA_URL_arm64
RUN if [ "$TARGETARCH" = "amd64" ]; then \
JAVA_URL=$JAVA_URL_amd64; \
elif [ "$TARGETARCH" = "arm64" ]; then \
JAVA_URL=$JAVA_URL_arm64; \
fi && \
cd ~/ && wget --no-check-certificate -O java_jdk.tar.gz -c $JAVA_URL
RUN mkdir /usr/lib/jvm && \
tar -xvzf ~/java_jdk.tar.gz -C /usr/lib/jvm
# ======================== FINAL ========================
FROM alpine-$TARGETARCH
ENV TZ=Europe/Zurich
ARG JAVA_JDK
RUN apk add --no-cache dpkg
COPY --from=java /usr/lib/jvm/ /usr/lib/jvm/
RUN echo "PATH=\"/usr/lib/jvm/$JAVA_JDK/bin\"" > /etc/environment
RUN echo "JAVA_HOME=\"/usr/lib/jvm/$JAVA_JDK\"" >> /etc/environment
RUN update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/$JAVA_JDK/bin/java" 0
RUN update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/$JAVA_JDK/bin/javac" 0
RUN update-alternatives --set java /usr/lib/jvm/$JAVA_JDK/bin/java
RUN update-alternatives --set javac /usr/lib/jvm/$JAVA_JDK/bin/javac
USER 405
WORKDIR /eve
COPY --from=build /eve/target/$TARGET/release/eve ./
CMD ["./eve"]