-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDockerfile
46 lines (38 loc) · 1.48 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
# FROM ekidd/rust-musl-builder:stable as builder
FROM clux/muslrust:stable as builder
# create new cargo project
RUN cargo init --lib
# RUN USER=rust cargo init --lib
RUN echo 'fn main() { println!("Hello, world!"); }' >> src/main.rs
# copy build config
# COPY --chown=rust ./Cargo.lock ./Cargo.lock
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
# HACK: remove build-dependencies so we have at least some caching
RUN head -n $(($(grep -n "\[build-dependencies\]" Cargo.toml | cut -f1 -d:) - 1)) Cargo.toml | sed '/src\/build.rs/d' > \
Cargo.toml2 && rm Cargo.toml && mv Cargo.toml2 Cargo.toml
# build to cache dependencies
RUN cargo build --release
# delete build cache to prevent caching issues later on
RUN rm -r ./target/x86_64-unknown-linux-musl/release/.fingerprint/hoc-*
# copy original Cargo.toml (HACK)
COPY ./Cargo.toml ./Cargo.toml
# we need our git folder so we can determine the commitref of HEAD
COPY ./.git ./.git
# copy source code
COPY ./static ./static
COPY ./templates ./templates
COPY ./src ./src
# build source code
RUN cargo build --release
FROM alpine:latest
RUN apk --no-cache add --update git
RUN adduser -D hoc
WORKDIR /home/hoc
USER hoc
# once we don't need a git binary anymore, this should be enough
# FROM scratch
# COPY --from=linuxkit/ca-certificates:v0.7 / /
# COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/hoc .
COPY --from=builder /volume/target/x86_64-unknown-linux-musl/release/hoc .
ENTRYPOINT ["/home/hoc/hoc"]