-
Notifications
You must be signed in to change notification settings - Fork 6
/
Dockerfile
85 lines (71 loc) · 3.35 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
### wasm
# FROM rust:1.75.0-alpine AS wasm-rust-stage
FROM rust@sha256:7cfbe91942d2673d2b5e3bcfa3b0036b8009d822dc3bfeb1a90b2aaea86eca5d AS wasm-rust-stage
WORKDIR /app
ENV CI=true
ENV CARGO_INCREMENTAL=false
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
RUN apk add --no-cache musl-dev zip
RUN rustup target add wasm32-unknown-unknown
RUN cd /tmp \
&& wget https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-musl.tar.gz \
&& tar xf cargo-chef-x86_64-unknown-linux-musl.tar.gz \
&& mv cargo-chef /usr/local/bin/cargo-chef
RUN cd /tmp \
&& wget https://github.com/rustwasm/wasm-pack/releases/download/v0.12.1/wasm-pack-v0.12.1-x86_64-unknown-linux-musl.tar.gz \
&& tar xf wasm-pack-v0.12.1-x86_64-unknown-linux-musl.tar.gz \
&& mv wasm-pack-v0.12.1-x86_64-unknown-linux-musl/wasm-pack /usr/local/bin/wasm-pack
FROM wasm-rust-stage AS wasm-chef-planner-stage
COPY . .
RUN sed -i 's/# lto = true/lto = true/' Cargo.toml \
&& sed -i 's/# opt-level = "s"/opt-level = "s"/' Cargo.toml
RUN cargo chef prepare --recipe-path recipe.json
FROM wasm-rust-stage AS wasm-stage
COPY --from=wasm-chef-planner-stage /app/recipe.json recipe.json
RUN cargo chef cook --recipe-path recipe.json --target wasm32-unknown-unknown --package vault-wasm --release \
&& cd vault-wasm \
# this downloads wasm-opt but the version is pinned so it is reproducible
&& wasm-pack build --target web --out-name vault-wasm
ARG GIT_REVISION=unknown
ARG GIT_RELEASE=
ENV GIT_REVISION=${GIT_REVISION}
ENV GIT_RELEASE=${GIT_RELEASE}
COPY . .
RUN sed -i 's/# lto = true/lto = true/' Cargo.toml \
&& sed -i 's/# opt-level = "s"/opt-level = "s"/' Cargo.toml
RUN cd vault-wasm \
&& wasm-pack build --target web --out-name vault-wasm --out-dir vault-wasm-web \
&& wasm-pack build --target nodejs --out-name vault-wasm --out-dir vault-wasm-nodejs \
&& ./fix-helpers-nodejs.sh vault-wasm-nodejs \
&& cd vault-wasm-nodejs \
&& tar cvzpf ../vault-wasm-nodejs.tar.gz .
### frontend
# FROM node:20.11-alpine3.19 AS frontend-stage
FROM node@sha256:201a9b31be9fb5148ca40c9e727d5e559c659ed9521b3175ba73847026257e32 AS frontend-stage
WORKDIR /app
ARG GIT_REVISION=unknown
ARG GIT_RELEASE=
COPY vault-web/package.json vault-web/package.json
COPY vault-web/package-lock.json vault-web/package-lock.json
RUN cd vault-web && npm ci
COPY vault-web vault-web
COPY --from=wasm-stage /app/vault-wasm/vault-wasm-web vault-web/src/vault-wasm
RUN cd vault-web && node_modules/.bin/tsc
RUN cd vault-web && node_modules/.bin/eslint src
RUN cd vault-web && VITE_GIT_REVISION=${GIT_REVISION} VITE_GIT_RELEASE=${GIT_RELEASE} node_modules/.bin/vite build
RUN echo -n ${GIT_REVISION} > vault-web/dist/gitrevision.txt
RUN echo -n ${GIT_RELEASE} > vault-web/dist/gitrelease.txt
### static
# FROM busybox:1.34.1 AS static-stage
FROM busybox@sha256:d345780059f4b200c1ebfbcfb141c67212e1ad4ea7538dcff759895bfcf99e6e AS static-stage
COPY --from=frontend-stage /app/vault-web/dist/ /vault-web
RUN cd vault-web && tar cvzpf ../vault-web.tar.gz .
COPY --from=wasm-stage /app/vault-wasm/vault-wasm-nodejs.tar.gz /vault-wasm-nodejs.tar.gz
### caddy
# FROM caddy:2.6.2-alpine AS caddy-stage
FROM caddy@sha256:7992b931b7da3cf0840dd69ea74b2c67d423faf03408da8abdc31b7590a239a7 AS caddy-stage
WORKDIR /app
COPY --from=frontend-stage /app/vault-web/dist /app/dist
COPY vault-web/Caddyfile .
EXPOSE 5173
CMD ["caddy", "run"]