-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
88 lines (67 loc) · 2.19 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# build frontend
FROM node:8 as frontend
RUN mkdir /web
WORKDIR /web
# install deps
COPY ./web/package.json ./package.json
COPY ./web/yarn.lock ./yarn.lock
RUN yarn install
# build app
COPY ./web/src ./src
COPY ./web/public ./public
RUN yarn build
# prepare a directory of assets that will be exported into the server build
# these are generated by yarn build
RUN mkdir -p ./export_assets/static/js
RUN mkdir -p ./export_assets/static/css
RUN mkdir -p ./export_assets/static/media
RUN cp ./build/static/js/main.*.js ./export_assets/static/js/main.js
RUN cp ./build/static/css/main.*.css ./export_assets/static/css/main.css
# uncomment if there's media/icons
#RUN cp ./build/static/media/* ./export_assets/static/media
RUN cp ./public/manifest.json ./export_assets/static/manifest.json
# these are human generated
COPY ./assets/favicon.ico ./export_assets/favicon.ico
COPY ./assets/main.html ./export_assets/main.html
COPY ./assets/robots.txt ./export_assets/robots.txt
# save the git hash of this build
COPY ./.git ./.git
RUN git rev-parse HEAD > ./export_assets/__web_commit.txt
RUN rm -rf ./.git
# build the backend
FROM rust:1.58.1-bullseye as backend
# create a new empty shell
RUN USER=root cargo new --bin transfer
WORKDIR /transfer
# copy over your manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
COPY ./Migrant.toml ./Migrant.toml
# this build step will cache your dependencies
RUN cargo build --release
RUN rm src/*.rs
# copy all source files
COPY ./src ./src
# build for release
RUN rm ./target/release/deps/transfer*
RUN cargo build --release
# save git hash of this build
COPY ./.git ./.git
RUN git rev-parse HEAD > ./__server_commit.txt
RUN rm -rf ./.git
FROM debian:bullseye-slim
RUN mkdir /transfer
WORKDIR /transfer
# copy all static files
COPY ./Migrant.toml ./Migrant.toml
COPY ./migrations ./migrations
# copy frontend assets
COPY --from=frontend /web/export_assets ./assets
# pull in configs
COPY ./config.ron ./config.ron
RUN mkdir ./bin
COPY --from=backend /transfer/target/release/transfer ./bin/transfer
COPY --from=backend /transfer/__server_commit.txt ./commit_hash.txt
RUN rm -rf ./target
# set the startup command to run your binary
CMD ["./bin/transfer", "serve"]