forked from dappnode/DNP_DAPPMANAGER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
200 lines (167 loc) · 6.58 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
ARG NODE_VERSION=20.3.0
############
# GIT-DATA #
############
FROM --platform=${BUILDPLATFORM:-amd64} node:${NODE_VERSION}-alpine as git-data
WORKDIR /usr/src/app
RUN apk add --no-cache git
COPY .git .git
COPY dappnode_package.json .
COPY docker/getGitData.js .
RUN node getGitData /usr/src/app/.git-data.json
##################
# BUILD-BINARIES #
##################
FROM --platform=${BUILDPLATFORM:-amd64} node:${NODE_VERSION}-alpine as build-binaries
RUN apk add --no-cache bind-tools docker curl
RUN curl -L https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-$(uname -m) > /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/docker-compose
# Common base so it's cached
# --platform=$BUILDPLATFORM is used build javascript source with host arch
# Otherwise webpack builds on emulated archs can be extremely slow (+1h)
#############
# BUILD-SRC #
#############
FROM --platform=${BUILDPLATFORM:-amd64} node:${NODE_VERSION}-alpine as build-src
WORKDIR /app
RUN apk add --no-cache python3 build-base
# Copy and install deps first to cache
COPY package.json yarn.lock lerna.json tsconfig.json ./
RUN yarn --frozen-lockfile --non-interactive --ignore-scripts --ignore-optional
COPY packages/admin-ui/package.json \
packages/admin-ui/
COPY packages/dappmanager/package.json \
packages/dappmanager/
COPY packages/common/package.json \
packages/common/
COPY packages/params/package.json \
packages/params/
COPY packages/utils/package.json \
packages/utils/
COPY packages/eventBus/package.json \
packages/eventBus/
COPY packages/logger/package.json \
packages/logger/
COPY packages/dockerCompose/package.json \
packages/dockerCompose/
COPY packages/dockerApi/package.json \
packages/dockerApi/
COPY packages/hostScripts/package.json \
packages/hostScripts/
RUN yarn --frozen-lockfile --non-interactive --ignore-optional
# Build order must be as follows:
# params > common > utils > eventBus > dockerCompose > logger > hostscripts > dockerApi > dappmanager > admin-ui
# Build params
WORKDIR /app/packages/params/
COPY packages/params/ .
RUN yarn build
# Results in dist/*
# Build common
WORKDIR /app/packages/common/
COPY packages/common/ .
RUN yarn build
# Results in dist/*
# Build utils
WORKDIR /app/packages/utils/
COPY packages/utils/ .
RUN yarn build
# Results in dist/*
# Build eventBus
WORKDIR /app/packages/eventBus/
COPY packages/eventBus/ .
RUN yarn build
# Results in dist/*
# Build dockerCompose
WORKDIR /app/packages/dockerCompose/
COPY packages/dockerCompose/ .
RUN yarn build
# Results in dist/*
# Build logger
WORKDIR /app/packages/logger/
COPY packages/logger/ .
RUN yarn build
# Results in dist/*
# Build hostScripts
WORKDIR /app/packages/hostScripts/
COPY packages/hostScripts/ .
RUN yarn build
# Results in dist/*
# Build dockerApi
WORKDIR /app/packages/dockerApi/
COPY packages/dockerApi/ .
RUN yarn build
# Results in dist/*
# Build dappmanager
WORKDIR /app/packages/dappmanager/
COPY packages/dappmanager/ .
RUN yarn build
# Results in dist/*
# Build admin-ui
WORKDIR /app/packages/admin-ui/
COPY packages/admin-ui/ .
ENV REACT_APP_API_URL /
RUN yarn build
# Results in build/*
##############
# BUILD-DEPS #
##############
FROM --platform=${BUILDPLATFORM:-amd64} node:${NODE_VERSION}-alpine as build-deps
WORKDIR /usr/src/app
RUN apk add --no-cache python3
COPY --from=build-src /app .
RUN yarn install --non-interactive --frozen-lockfile --production --force --ignore-optional
##############
# PRODUCTION #
##############
FROM node:${NODE_VERSION}-alpine
ENV COMPOSE_HTTP_TIMEOUT=300 \
DOCKER_CLIENT_TIMEOUT=300 \
DOCKER_HOST=unix:///var/run/docker.sock \
UI_FILES_PATH=/usr/src/app/packages/admin-ui/build \
GIT_DATA_PATH=.git-data.json
WORKDIR /usr/src/app
# TODO: consider moving all these binaries to the build-binaries stage
RUN apk add --no-cache bind-dev xz libltdl miniupnpc zip unzip dbus bind avahi-tools
# Copy docker
COPY docker/rndc.conf /etc/bind/
COPY docker/update_local_dyndns.sh /usr/local/bin/update_local_dyndns
# Copy git data
COPY --from=git-data /usr/src/app/.git-data.json $GIT_DATA_PATH
# Copy binaries
COPY --from=build-binaries /usr/bin/nsupdate /usr/bin/nsupdate
COPY --from=build-binaries /usr/bin/docker /usr/bin/docker
COPY --from=build-binaries /usr/local/bin/docker-compose /usr/local/bin/docker-compose
# Copy scripts and services
COPY packages/hostScripts/hostScripts /usr/src/app/hostScripts
# Copy root app
COPY --from=build-deps /usr/src/app/node_modules ./node_modules
COPY --from=build-deps /usr/src/app/package.json ./package.json
# Copy common
COPY --from=build-deps /usr/src/app/packages/common/dist ./packages/common/dist
COPY --from=build-deps /usr/src/app/packages/common/node_modules ./packages/common/node_modules
COPY --from=build-deps /usr/src/app/packages/common/package.json ./packages/common/package.json
# Copy params
COPY --from=build-deps /usr/src/app/packages/params/dist ./packages/params/dist
COPY --from=build-deps /usr/src/app/packages/params/node_modules ./packages/params/node_modules
COPY --from=build-deps /usr/src/app/packages/params/package.json ./packages/params/package.json
# Copy utils
COPY --from=build-deps /usr/src/app/packages/utils/dist ./packages/utils/dist
COPY --from=build-deps /usr/src/app/packages/utils/node_modules ./packages/utils/node_modules
COPY --from=build-deps /usr/src/app/packages/utils/package.json ./packages/utils/package.json
# Copy logger
COPY --from=build-deps /usr/src/app/packages/logger/dist ./packages/logger/dist
COPY --from=build-deps /usr/src/app/packages/logger/node_modules ./packages/logger/node_modules
COPY --from=build-deps /usr/src/app/packages/logger/package.json ./packages/logger/package.json
# Copy eventBus
COPY --from=build-deps /usr/src/app/packages/eventBus/dist ./packages/eventBus/dist
COPY --from=build-deps /usr/src/app/packages/eventBus/node_modules ./packages/eventBus/node_modules
COPY --from=build-deps /usr/src/app/packages/eventBus/package.json ./packages/eventBus/package.json
# Copy admin-ui
COPY --from=build-deps /usr/src/app/packages/admin-ui/build ./packages/admin-ui/build
COPY --from=build-deps /usr/src/app/packages/admin-ui/node_modules ./packages/admin-ui/node_modules
COPY --from=build-deps /usr/src/app/packages/admin-ui/package.json ./packages/admin-ui/package.json
# Copy dappmanager
COPY --from=build-deps /usr/src/app/packages/dappmanager/dist /usr/src/app/packages/dappmanager/dist
COPY --from=build-deps /usr/src/app/packages/dappmanager/node_modules /usr/src/app/packages/dappmanager/node_modules
COPY --from=build-deps /usr/src/app/packages/dappmanager/package.json /usr/src/app/packages/dappmanager/package.json
CMD [ "node", "packages/dappmanager/dist/index" ]