-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
88 lines (72 loc) · 2.27 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
# Copyright (c) 2024 Ho Kim (ho.kim@ulagbulag.io). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.
# Configure environment variables
ARG PACKAGE="cassette"
ARG DEBIAN_VERSION="bookworm"
ARG NGINX_IMAGE="docker.io/library/nginx"
ARG NGINX_VERSION="stable"
ARG NODE_IMAGE="docker.io/library/node"
ARG NODE_VERSION="22"
ARG RUST_IMAGE="docker.io/library/rust"
ARG RUST_VERSION="1"
ARG _OS_VERSION="${DEBIAN_VERSION}"
# Be ready for serving
FROM "${NGINX_IMAGE}:${NGINX_VERSION}-${_OS_VERSION}-otel" AS server
# Server Configuration
EXPOSE 6080/tcp
WORKDIR /usr/local/bin
# Copy static files
ARG PACKAGE
ADD ./LICENSE /usr/share/licenses/${PACKAGE}/LICENSE
ADD ./robots.txt /usr/share/nginx/html/
# ADD ./favicon.ico /usr/share/nginx/html/favicon.ico
ADD ./nginx.conf /etc/nginx/conf.d/default.conf
ADD ./assets/ /usr/share/nginx/html/assets/
# Be ready for building npm
FROM "${NODE_IMAGE}:${NODE_VERSION}-${_OS_VERSION}" AS node_builder
# Load package metadata files
ADD ./package.json /src/
ADD ./package-lock.json /src/
WORKDIR /src
# Install node dependencies
RUN npm clean-install
# Be ready for building
FROM "${RUST_IMAGE}:${RUST_VERSION}-${_OS_VERSION}" AS builder
# Install dependencies
RUN true \
# Enable wasm32 target
&& rustup target add wasm32-unknown-unknown \
# Build
&& cargo install --root /usr/local \
trunk \
wasm-bindgen-cli
# Load node dependencies
COPY --from=node_builder /src/node_modules/ /src/node_modules/
# Load source files
ADD ./LICENSE /src/LICENSE
ADD ./assets/images/icons /src/assets/images/icons
ADD ./Cargo.toml /src/
ADD ./crates /src/crates
# Load static files
ADD ./index.html /src/
ADD ./static /src/static
ADD ./Trunk.toml /src/
WORKDIR /src
# Build it!
RUN \
# Cache build outputs
--mount=type=cache,target=/src/target \
--mount=type=cache,target=/usr/local/cargo/registry \
# Create an output directory
mkdir /out \
# Create an empty placeholder directories
mkdir ./examples \
# Disable terminal hooks
&& sed -i '/\[\[hooks\]\]/,$d' 'Trunk.toml' \
# Build
&& trunk build --dist '/out' --release \
--no-default-features --features 'full'
# Copy executable files
FROM server
COPY --from=builder /out /usr/share/nginx/html