-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
145 lines (124 loc) · 4.83 KB
/
Dockerfile
File metadata and controls
145 lines (124 loc) · 4.83 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# =============================
# Base Node image
# =============================
FROM node:24.11.1-alpine3.22 AS base
WORKDIR /app
ENV NODE_ENV=production
# =============================
# Package preparation (stripping version for caching)
# =============================
FROM base AS package-strip
RUN apk add --no-cache jq moreutils
ADD package.json package-lock.json ./
# remove version from manifest for better caching when building a release
RUN jq '.version="build"' package.json | sponge package.json
RUN jq '.version="build"' package-lock.json | sponge package-lock.json
# =============================
# Tippecanoe builder
# =============================
FROM base AS tippecanoe-builder
WORKDIR /tmp/
RUN apk add --no-cache curl cmake make g++
RUN apk add git zlib-dev sqlite-dev bash
RUN git clone https://github.com/mapbox/tippecanoe.git
WORKDIR /tmp/tippecanoe
RUN git checkout 1.36.0
RUN make -j
RUN make install
RUN test -f /usr/local/bin/tippecanoe
# =============================
# Full dependencies installation (for types and building)
# =============================
FROM base AS installer
RUN apk add --no-cache git jq moreutils
RUN npm i -g clean-modules@3.0.4
COPY --from=package-strip /app/package.json package.json
COPY --from=package-strip /app/package-lock.json package-lock.json
COPY ui/package.json ui/package.json
COPY api/package.json api/package.json
COPY worker/package.json worker/package.json
# full deps install used for types and ui building
# also used to fill the npm cache for faster install api and worker deps
RUN npm ci --omit=dev --omit=optional --no-audit --no-fund
# =============================
# Build Types for API and Worker
# =============================
FROM installer AS types
COPY api/types api/types
COPY api/doc api/doc
COPY api/config api/config
COPY worker/config worker/config
RUN npm run build-types
# =============================
# Build UI with Vite
# =============================
FROM installer AS ui
RUN npm i --no-save @rollup/rollup-linux-x64-musl
COPY --from=types /app/api/config api/config
COPY --from=types /app/api/types api/types
ADD /api/src/config.ts api/src/config.ts
COPY shared shared
ADD /ui ui
RUN npm -w ui run build
# =============================
# Install production dependencies for Worker
# =============================
FROM installer AS worker-installer
RUN npm ci -w worker --prefer-offline --omit=dev --omit=optional --no-audit --no-fund && \
npx clean-modules --yes
RUN mkdir -p /app/worker/node_modules
RUN mkdir -p /app/shared/node_modules
# =============================
# Final Worker Image
# =============================
FROM base AS worker
# install gdal for ogr2ogr
RUN apk add --no-cache gmp gdal-tools
RUN test -f /usr/bin/ogr2ogr
RUN ln -s /usr/lib/libproj.so.25 /usr/lib/libproj.so
RUN test -f /usr/lib/libproj.so
COPY --from=tippecanoe-builder /usr/local/bin/tippecanoe /usr/local/bin/tippecanoe
COPY --from=worker-installer /app/node_modules node_modules
COPY worker worker
COPY shared shared
COPY upgrade upgrade
COPY --from=types /app/worker/config worker/config
COPY --from=types /app/api/types api/types
COPY --from=worker-installer /app/worker/node_modules worker/node_modules
COPY --from=worker-installer /app/shared/node_modules shared/node_modules
COPY package.json README.md LICENSE BUILD.json* ./
EXPOSE 9090
# USER node # This would be great to use, but not possible as the volumes are mounted as root
WORKDIR /app/worker
CMD ["node", "--disable-warning=ExperimentalWarning", "--optimize-for-size", "index.ts"]
# =============================
# Install production dependencies for API
# =============================
FROM installer AS api-installer
# remove other workspaces and reinstall, otherwise we can have some peer dependencies from other workspaces
RUN npm ci -w api --prefer-offline --omit=dev --omit=optional --no-audit --no-fund && \
npx clean-modules --yes
RUN mkdir -p /app/api/node_modules
RUN mkdir -p /app/shared/node_modules
# =============================
# Final API Image
# =============================
FROM base AS main
RUN apk add --no-cache python3 make g++
COPY --from=api-installer /app/node_modules node_modules
COPY api api
COPY shared shared
COPY --from=types /app/api/types api/types
COPY --from=types /app/api/doc api/doc
COPY --from=types /app/api/config api/config
COPY --from=api-installer /app/api/node_modules api/node_modules
COPY --from=api-installer /app/shared/node_modules shared/node_modules
COPY --from=ui /app/ui/dist ui/dist
COPY package.json README.md LICENSE BUILD.json* ./
# artificially create a dependency to "worker" target for better caching in github ci
COPY --from=worker /app/package.json package.json
EXPOSE 8080
EXPOSE 9090
# USER node # This would be great to use, but not possible as the volumes are mounted as root
WORKDIR /app/api
CMD ["node", "--max-http-header-size", "65536", "--disable-warning=ExperimentalWarning", "index.ts"]