-
Notifications
You must be signed in to change notification settings - Fork 770
/
cashtab.Dockerfile
115 lines (91 loc) · 3.1 KB
/
cashtab.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Multi-stage
# 1) rust image for ecash-lib
# 2) Node image for building frontend assets
# 3) nginx stage to serve frontend assets
# Stage 1 - rust machine for building ecash-lib-wasm
FROM rust:1.76.0 AS wasmbuilder
RUN apt-get update \
&& apt-get install clang binaryen -y \
&& rustup target add wasm32-unknown-unknown \
&& cargo install -f [email protected]
# Copy Cargo.toml
WORKDIR /app/
COPY Cargo.toml .
# Copy chronik to same directory structure as monorepo
# This needs to be in place to run ./build-wasm
WORKDIR /app/chronik/
COPY chronik/ .
# explorer must be in place to to run ./build-wasm as it is a workspace member
WORKDIR /app/web/explorer
COPY web/explorer/ .
# bitcoinsuite-chronik-client must be in place to to run ./build-wasm as it is a workspace member
WORKDIR /app/modules/bitcoinsuite-chronik-client
COPY modules/bitcoinsuite-chronik-client/ .
# Copy secp256k1 to same directory structure as monorepo
WORKDIR /app/src/secp256k1
COPY src/secp256k1/ .
# Copy ecash-secp256k1, ecash-lib and ecash-lib-wasm files to same directory structure as monorepo
WORKDIR /app/modules/ecash-secp256k1
COPY modules/ecash-secp256k1 .
WORKDIR /app/modules/ecash-lib
COPY modules/ecash-lib .
WORKDIR /app/modules/ecash-lib-wasm
COPY modules/ecash-lib-wasm .
# Build web assembly for ecash-lib
RUN CC=clang ./build-wasm.sh
# Stage 2
FROM node:20-bookworm-slim AS builder
# Copy static assets from wasmbuilder stage (ecash-lib-wasm and ecash-lib, with wasm built in place)
WORKDIR /app/modules
COPY --from=wasmbuilder /app/modules .
# Build all local Cashtab dependencies
# ecashaddrjs
WORKDIR /app/modules/ecashaddrjs
COPY modules/ecashaddrjs/ .
RUN npm ci
RUN npm run build
# chronik-client
WORKDIR /app/modules/chronik-client
COPY modules/chronik-client/ .
RUN npm ci
RUN npm run build
# b58-ts (required for ecash-lib)
WORKDIR /app/modules/b58-ts
COPY modules/b58-ts .
RUN npm ci
# ecash-lib
WORKDIR /app/modules/ecash-lib
RUN npm ci
RUN npm run build
# ecash-agora
WORKDIR /app/modules/ecash-agora
COPY modules/ecash-agora/ .
RUN npm ci
RUN npm run build
# ecash-script
WORKDIR /app/modules/ecash-script
COPY modules/ecash-script/ .
RUN npm ci
# Now that local dependencies are ready, build cashtab
WORKDIR /app/cashtab
# Copy only the package files and install necessary dependencies.
# This reduces cache busting when source files are changed.
COPY cashtab/package.json .
COPY cashtab/package-lock.json .
# Docker should not rebuild deps just because package.json version bump
# So, always keep package.json and package-lock.json at 1.0.0 in the docker image
# Note: it will be overwritten before npm run build by the latest package.json
RUN npm version --allow-same-version 1.0.0
RUN npm ci
# Copy the rest of the project files and build
COPY cashtab/ .
RUN npm run build
# Stage 3
FROM nginx
ARG NGINX_CONF=nginx.conf
COPY cashtab/$NGINX_CONF /etc/nginx/conf.d/default.conf
# Set working directory to nginx asset directory
# Copy static assets from builder stage
COPY --from=builder /app/cashtab/build /usr/share/nginx/html/
# Containers run nginx with global directives and daemon off
ENTRYPOINT ["nginx", "-g", "daemon off;"]