-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
60 lines (46 loc) · 2.15 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
# STAGE: Build
FROM rust:1-alpine3.18 as builder
WORKDIR /build
# Install alpine deps
RUN apk add --no-cache build-base
# Install cargo-strip (with layer caching)
RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install cargo-strip
# Copy source files
COPY ./ ./
# Download dependencies and compile (with layer caching)
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/build/target \
cargo build --release && \
cargo strip && \
mv /build/target/release/nforwardauth /build
# STAGE: Minify
FROM node:19.8.1 as minifier
WORKDIR /build
# Install CSS minifier (lightningcss), JS minifier (uglify-js), and HTML minifier (html-minifier)
RUN npm install -g [email protected] \
&& npm install -g [email protected] \
&& npm install -g [email protected]
# Copy assets folder
COPY ./assets ./assets
# Minify CSS
RUN npx lightningcss --minify --bundle --targets '>= 0.25%' ./assets/css/style.css -o ./style.css
# Minify JS
RUN npx uglifyjs --compress --mangle -o ./script.js -- ./assets/js/script.js \
&& npx uglifyjs --compress --mangle -o ./logout.js -- ./assets/js/logout.js
# Minify HTML
RUN npx html-minifier --collapse-whitespace --remove-comments --remove-original-tags --remove-rundundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype -o ./index.html ./assets/html/index.html \
&& npx html-minifier --collapse-whitespace --remove-comments --remove-original-tags --remove-rundundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype -o ./logout.html ./assets/html/logout.html
# STAGE: Release
FROM alpine:3.17
# Copy binary from build stage
COPY --from=builder /build/nforwardauth /nforwardauth
# Copy files and assets to serve (overwritable via docker volume mount)
COPY ./public /public
COPY --from=minifier /build/style.css /public/style.css
COPY --from=minifier /build/script.js /public/script.js
COPY --from=minifier /build/logout.js /public/logout.js
COPY --from=minifier /build/index.html /public/index.html
COPY --from=minifier /build/logout.html /public/logout.html
# Set entrypoint for image
ENTRYPOINT ["/nforwardauth"]