2019-04-16 16:57:24 +02:00
|
|
|
FROM ekidd/rust-musl-builder:stable as builder
|
|
|
|
|
|
|
|
# create new cargo project
|
2021-06-29 19:14:51 +02:00
|
|
|
RUN USER=rust cargo init --lib
|
2019-04-16 16:57:24 +02:00
|
|
|
# copy build config
|
2019-04-23 22:09:37 +02:00
|
|
|
COPY --chown=rust ./Cargo.lock ./Cargo.lock
|
2019-04-16 16:57:24 +02:00
|
|
|
COPY ./Cargo.toml ./Cargo.toml
|
2019-04-23 22:09:37 +02:00
|
|
|
# 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 '/build.rs/d' > \
|
|
|
|
Cargo.toml2 && rm Cargo.toml && mv Cargo.toml2 Cargo.toml
|
2019-04-16 16:57:24 +02:00
|
|
|
# build to cache dependencies
|
|
|
|
RUN cargo build --release
|
2019-04-16 18:02:01 +02:00
|
|
|
# delete build cache to prevent caching issues later on
|
2019-04-16 16:57:24 +02:00
|
|
|
RUN rm -r ./target/x86_64-unknown-linux-musl/release/.fingerprint/hoc-*
|
|
|
|
|
2019-04-23 22:09:37 +02:00
|
|
|
# copy original Cargo.toml (HACK)
|
|
|
|
COPY ./Cargo.toml ./Cargo.toml
|
|
|
|
# we need our git folder so we can determine the commitref of HEAD
|
2019-04-23 18:21:42 +02:00
|
|
|
COPY ./.git ./.git
|
2019-04-23 22:09:37 +02:00
|
|
|
# copy source code
|
2019-04-16 20:56:24 +02:00
|
|
|
COPY ./static ./static
|
2019-04-23 18:21:42 +02:00
|
|
|
COPY ./templates ./templates
|
2019-04-23 19:44:08 +02:00
|
|
|
COPY ./build.rs ./build.rs
|
2019-04-16 16:57:24 +02:00
|
|
|
COPY ./src ./src
|
|
|
|
# build source code
|
|
|
|
RUN cargo build --release
|
|
|
|
|
|
|
|
FROM alpine:latest
|
|
|
|
|
2019-04-16 17:52:16 +02:00
|
|
|
RUN apk --no-cache add --update git
|
2019-04-24 00:26:23 +02:00
|
|
|
|
2019-05-28 21:56:44 +02:00
|
|
|
RUN adduser -D hoc
|
2019-05-28 21:46:47 +02:00
|
|
|
WORKDIR /home/hoc
|
2019-05-28 21:59:18 +02:00
|
|
|
USER hoc
|
2019-05-28 21:46:47 +02:00
|
|
|
|
2019-04-24 00:26:23 +02:00
|
|
|
# once we don't need a git binary anymore, this should be enough
|
|
|
|
# FROM scratch
|
|
|
|
# COPY --from=linuxkit/ca-certificates:v0.7 / /
|
|
|
|
|
2019-05-28 21:46:47 +02:00
|
|
|
COPY --from=builder /home/rust/src/target/x86_64-unknown-linux-musl/release/hoc .
|
2019-04-16 18:02:01 +02:00
|
|
|
|
2019-05-28 21:46:47 +02:00
|
|
|
ENTRYPOINT ["/home/hoc/hoc"]
|