This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
62 lines (52 loc) · 1.54 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
# build & package frontend code
FROM node:16 as frontend-builder
WORKDIR ./frontend
ADD ./frontend .
RUN npm install
RUN npm run build
# build rust code
FROM rust:1.61 as server-builder
# create an empty rust project(with no source code)
# and compile dependencies in a separate layer
# this can reduce compilation time when we make changes to
# the source code but not the dependencies
RUN USER=root cargo new --bin Danmuji
WORKDIR ./Danmuji
COPY ./Cargo.toml ./Cargo.toml
RUN cargo build --release
RUN rm src/*.rs
# add source code and re-build, this time
# with source code
ADD . ./
RUN rm ./target/release/deps/Danmuji*
RUN cargo build --release
# final container image that serves
# the binaries
FROM debian:buster-slim
# configurable application root directory
ARG APP_ROOT=/usr/src/app
# application port
# alert: this should match the port exposed
# in ./src/main.rs
ARG APP_PORT=9000
# install openssl packages
RUN apt-get update \
&& apt-get install -y ca-certificates tzdata \
&& rm -rf /var/lib/apt/lists/*
EXPOSE $APP_PORT
# create a non-root user
# to run our binary
ENV APP_USER=appuser
RUN groupadd $APP_USER \
&& useradd -g $APP_USER $APP_USER \
&& mkdir -p ${APP_ROOT}
# copy rust binary
COPY --from=server-builder /Danmuji/target/release/Danmuji ${APP_ROOT}/Danmuji
# copy frontend package
COPY --from=frontend-builder /frontend/dist ${APP_ROOT}/frontend/dist
# make APP_USER own the application root directory
RUN chown -R $APP_USER:$APP_USER ${APP_ROOT}
# execution environment
USER $APP_USER
WORKDIR ${APP_ROOT}
CMD ["./Danmuji"]