yagcdn/Dockerfile

60 lines
1.8 KiB
Docker
Raw Permalink Normal View History

2019-07-27 20:25:45 +02:00
FROM node:alpine as frontend
2019-07-28 21:49:23 +02:00
# install envsubst
RUN apk add -U --upgrade --no-cache gettext
2019-07-29 18:53:54 +02:00
RUN yarn global add elm uglify-js
2019-07-27 20:25:45 +02:00
2019-07-28 21:44:10 +02:00
COPY ./frontend/build.sh ./build.sh
2019-07-29 21:18:00 +02:00
COPY ./frontend/assets ./assets
2019-07-28 21:51:17 +02:00
COPY ./frontend/template.html ./template.html
2019-07-27 20:25:45 +02:00
COPY ./frontend/elm.json ./elm.json
COPY ./frontend/src ./src
2019-07-29 18:53:54 +02:00
# COPY ./frontend/tests ./tests
2019-07-27 20:25:45 +02:00
2019-07-28 21:44:10 +02:00
RUN ./build.sh
2019-07-27 20:25:45 +02:00
FROM ekidd/rust-musl-builder:stable as backend
# create new cargo project
2019-08-09 19:43:58 +02:00
RUN USER=rust cargo new --bin yagcdn
2019-08-07 22:27:37 +02:00
RUN USER=rust cargo new --lib time-cache
2019-07-27 20:25:45 +02:00
# copy build config
2019-08-09 19:43:58 +02:00
COPY --chown=rust ./backend/Cargo.lock ./yagcdn/Cargo.lock
COPY --chown=rust ./backend/Cargo.toml ./yagcdn/Cargo.toml
2019-08-07 22:24:20 +02:00
COPY --chown=rust ./time-cache/Cargo.toml ./time-cache/Cargo.toml
2019-08-07 22:28:36 +02:00
2019-08-09 19:43:58 +02:00
WORKDIR /home/rust/src/yagcdn
2019-07-27 20:25:45 +02:00
# build to cache dependencies
2019-09-16 22:42:41 +02:00
# RUN cargo build --release
2019-07-27 20:25:45 +02:00
# delete build cache to prevent caching issues later on
2019-09-16 22:42:41 +02:00
# RUN rm -r ./target/x86_64-unknown-linux-musl/release/.fingerprint/yagcdn*
# RUN rm -r ./target/x86_64-unknown-linux-musl/release/.fingerprint/time-cache-*
2019-07-27 20:25:45 +02:00
2019-08-09 12:39:04 +02:00
COPY ./backend/static ./static
COPY ./backend/src ./src
2019-08-09 14:26:51 +02:00
COPY ./time-cache/src ../time-cache/src
2019-07-27 20:25:45 +02:00
# build source code
2019-09-16 22:42:41 +02:00
RUN --mount=type=cache,target=../../usr/local/cargo/registry \
--mount=type=cache,target=target \
cargo build --release
2019-07-27 20:25:45 +02:00
# create /etc/password for rootless scratch container
FROM alpine:latest as user_builder
RUN USER=root adduser -D -u 10001 dummy
FROM scratch
# copy certificates
COPY --from=linuxkit/ca-certificates:v0.7 / /
COPY --from=user_builder /etc/passwd /etc/passwd
USER dummy
2019-08-09 19:43:58 +02:00
COPY --from=backend /home/rust/src/yagcdn/target/x86_64-unknown-linux-musl/release/yagcdn /
2019-07-28 21:55:11 +02:00
COPY --from=frontend /output/index.html /public/index.html
2019-07-28 21:56:53 +02:00
COPY --from=frontend /output/scripts /public/scripts
2019-07-29 21:16:46 +02:00
COPY --from=frontend /output/assets /public/assets
2019-07-27 20:25:45 +02:00
2019-08-09 19:43:58 +02:00
ENTRYPOINT ["/yagcdn"]