-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sh
executable file
·306 lines (245 loc) · 14.1 KB
/
build.sh
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/bin/bash
# Copyright (c) 2019 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
set -e
set -u
# conf
CHE_THEIA_BRANCH="master"
THEIA_BRANCH="master"
#need to edit conf/theia/ubi8-brew/builder-from.dockerfile file as well for now
#need to edit conf/theia-endpoint-runtime/ubi8-brew/builder-from.dockerfile file as well for now
CHE_THEIA_DEV_IMAGE_NAME="quay.io/crw/theia-dev-rhel8:next"
CHE_THEIA_IMAGE_NAME="quay.io/crw/theia-rhel8:next"
CHE_THEIA_ENDPOINT_IMAGE_NAME="quay.io/crw/theia-endpoint-rhel8:next"
CHE_THEIA_ENDPOINT_BINARY_IMAGE_NAME="quay.io/crw/theia-endpoint-binary-rhel8:next"
base_dir=$(cd "$(dirname "$0")"; pwd)
# variables
TMP_DIR=${base_dir}/tmp
BREW_DOCKERFILE_ROOT_DIR=${base_dir}/"dockerfiles"
CHE_THEIA_DIR=${TMP_DIR}/che-theia
TMP_THEIA_DEV_BUILDER_IMAGE="che-theia-dev-builder:tmp"
TMP_THEIA_BUILDER_IMAGE="che-theia-builder:tmp"
TMP_THEIA_RUNTIME_IMAGE="che-theia-runtime:tmp"
TMP_THEIA_ENDPOINT_BUILDER_IMAGE="che-theia-endpoint-builder:tmp"
TMP_THEIA_ENDPOINT_BINARY_BUILDER_IMAGE="che-theia-endpoint-binary-builder:tmp"
if [ ! -d "${TMP_DIR}" ]; then
rm -rf "${TMP_DIR}"
mkdir -p "${TMP_DIR}"
# Clone che-theia with sha-1/tag/whatever
git clone -b ${CHE_THEIA_BRANCH} --single-branch --depth 1 https://github.com/eclipse/che-theia "${TMP_DIR}"/che-theia
# init yarn in che-theia
pushd "${CHE_THEIA_DIR}" >/dev/null
yarn
popd >/dev/null
fi
mkdir -p "${BREW_DOCKERFILE_ROOT_DIR}"
DOCKERFILES_ROOT_DIR=${TMP_DIR}/che-theia/dockerfiles
handle_che_theia_dev() {
# build only ubi8 image
pushd "${DOCKERFILES_ROOT_DIR}"/theia-dev >/dev/null
bash ./build.sh --dockerfile:Dockerfile.ubi8 --skip-tests --dry-run
docker build -f .Dockerfile -t "${TMP_BUILDER_IMAGE}" .
# For use in default
docker tag "${TMP_BUILDER_IMAGE}" eclipse/che-theia-dev:next
popd >/dev/null
# Create image theia-dev:ubi8-brew
rm -rf "${DOCKERFILES_ROOT_DIR}"/theia-dev/docker/ubi8-brew
cp -r "${DOCKERFILES_ROOT_DIR}"/theia-dev/docker/ubi8 "${DOCKERFILES_ROOT_DIR}"/theia-dev/docker/ubi8-brew
# Add extra conf
cp conf/theia-dev/ubi8-brew/* "${DOCKERFILES_ROOT_DIR}"/theia-dev/docker/ubi8-brew/
# dry-run for theia-dev:ubi8-brew to only generate Dockerfile
pushd "${DOCKERFILES_ROOT_DIR}"/theia-dev >/dev/null
bash ./build.sh --dockerfile:Dockerfile.ubi8-brew --skip-tests --dry-run
popd >/dev/null
# Copy assets from ubi8 to local
pushd "${BREW_DOCKERFILE_ROOT_DIR}"/theia-dev >/dev/null
echo "Remove previous assets"
rm -rf assets-*
# copy assets
cp "${CHE_THEIA_DIR}"/dockerfiles/theia-dev/asset-* .
# Copy src
rm -rf src
cp -r "${DOCKERFILES_ROOT_DIR}"/theia-dev/src .
# Create asset with yarn cache
# /usr/local/share/.cache/yarn/v4 = yarn cache dir
# /home/theia-dev/.yarn-global = yarn
# /opt/app-root/src/.npm-global = yarn symlinks
docker run --rm --entrypoint= ${TMP_THEIA_DEV_BUILDER_IMAGE} tar -pzcf - /usr/local/share/.cache/yarn/v4 /home/theia-dev/.yarn-global /opt/app-root/src/.npm-global > asset-yarn.tgz
popd >/dev/null
# Copy generate Dockerfile
mkdir -p "${BREW_DOCKERFILE_ROOT_DIR}"/theia-dev
cp "${DOCKERFILES_ROOT_DIR}"/theia-dev/.Dockerfile "${BREW_DOCKERFILE_ROOT_DIR}"/theia-dev/Dockerfile
# build local
pushd "${BREW_DOCKERFILE_ROOT_DIR}"/theia-dev >/dev/null
docker build -t ${CHE_THEIA_DEV_IMAGE_NAME} .
popd >/dev/null
}
# now do che-theia
handle_che_theia() {
# build only ubi8 image and for target builder first, so we can extract data
pushd "${DOCKERFILES_ROOT_DIR}"/theia >/dev/null
# first generate the Dockerfile
bash ./build.sh --dockerfile:Dockerfile.ubi8 --skip-tests --dry-run --build-args:DO_REMOTE_CHECK=false,DO_CLEANUP=false --tag:next --branch:${THEIA_BRANCH} --target:builder
cp .Dockerfile .ubi8-dockerfile
# Create one image for builder
docker build -f .ubi8-dockerfile -t ${TMP_THEIA_BUILDER_IMAGE} --target builder .
# and create runtime image as well
docker build -f .ubi8-dockerfile -t ${TMP_THEIA_RUNTIME_IMAGE} .
popd >/dev/null
# Create image theia-dev:ubi8-brew
rm -rf "${DOCKERFILES_ROOT_DIR}"/theia/docker/ubi8-brew
cp -r "${DOCKERFILES_ROOT_DIR}"/theia/docker/ubi8 "${DOCKERFILES_ROOT_DIR}"/theia/docker/ubi8-brew
# Add extra conf
cp conf/theia/ubi8-brew/* "${DOCKERFILES_ROOT_DIR}"/theia/docker/ubi8-brew/
# dry-run for theia:ubi8-brew to only generate Dockerfile
pushd "${DOCKERFILES_ROOT_DIR}"/theia >/dev/null
bash ./build.sh --dockerfile:Dockerfile.ubi8-brew --skip-tests --dry-run --build-args:DO_REMOTE_CHECK=false --tag:next --branch:${THEIA_BRANCH} --target:builder
popd >/dev/null
# Copy assets from ubi8 to local
pushd "${BREW_DOCKERFILE_ROOT_DIR}"/theia >/dev/null
# copy assets
cp "${CHE_THEIA_DIR}"/dockerfiles/theia/asset-* .
# npm/yarn cache
# /usr/local/share/.cache/yarn/v4 = yarn cache dir
# /home/theia-dev/.yarn-global = yarn
# /opt/app-root/src/.npm-global = yarn symlinks
docker run --rm --entrypoint= ${TMP_THEIA_BUILDER_IMAGE} tar -pzcf - /usr/local/share/.cache/yarn/v4 /home/theia-dev/.yarn-global /opt/app-root/src/.npm-global > asset-yarn.tar.gz
# post-install dependencies
# /home/theia-dev/theia-source-code/packages/java/download = jdt ls binary
# /home/theia-dev/theia-source-code/packages/debug-nodejs/download = node debug vscode binary
# /home/theia-dev/theia-source-code/packages/java-debug/download = java debug vscode binary
# /tmp/vscode-ripgrep-cache-1.2.4 /tmp/vscode-ripgrep-cache-1.5.7 = rigrep binaries
# /home/theia-dev/.cache = include electron/node-gyp cache
docker run --rm --entrypoint= ${TMP_THEIA_BUILDER_IMAGE} tar -pzcf - /home/theia-dev/theia-source-code/packages/java/download /home/theia-dev/theia-source-code/packages/java-debug/download /home/theia-dev/theia-source-code/packages/debug-nodejs/download /tmp/vscode-ripgrep-cache-1.2.4 /tmp/vscode-ripgrep-cache-1.5.7 /home/theia-dev/.cache > asset-post-download-dependencies.tar.gz
# node-headers
docker run --rm --entrypoint= ${TMP_THEIA_BUILDER_IMAGE} sh -c 'nodeVersion=$(node --version); download_url="https://nodejs.org/download/release/${nodeVersion}/node-${nodeVersion}-headers.tar.gz" && curl ${download_url}' > asset-node-headers.tar.gz
# moxios is used with a github URL, not a npmjs dependency, need to provide the dependency
git clone https://github.com/stoplightio/moxios.git "${BREW_DOCKERFILE_ROOT_DIR}"/moxios
pushd "${BREW_DOCKERFILE_ROOT_DIR}"/moxios >/dev/null
tar zcf "${BREW_DOCKERFILE_ROOT_DIR}/theia/asset-moxios.tgz" -- *
rm -rf "${BREW_DOCKERFILE_ROOT_DIR}"/moxios
popd >/dev/null
# Add yarn.lock after compilation
docker run --rm --entrypoint= ${TMP_THEIA_BUILDER_IMAGE} sh -c 'cat /home/theia-dev/theia-source-code/yarn.lock' > asset-yarn.lock
# Theia source code
docker run --rm --entrypoint= ${TMP_THEIA_BUILDER_IMAGE} sh -c 'cat /home/theia-dev/theia-source-code.tgz' > asset-theia-source-code.tar.gz
# npm/yarn cache
# /usr/local/share/.cache/yarn/v4/ = yarn cache dir
# /opt/app-root/src/.npm-global = npm global
docker run --rm --entrypoint= ${TMP_THEIA_RUNTIME_IMAGE} tar -pzcf - /usr/local/share/.cache/yarn/v4/ /opt/app-root/src/.npm-global > asset-yarn-runtime-image.tar.gz
rm -rf src
cp -r "${DOCKERFILES_ROOT_DIR}"/theia/src .
# Copy generate Dockerfile
mkdir -p "${BREW_DOCKERFILE_ROOT_DIR}"/theia
cp "${DOCKERFILES_ROOT_DIR}"/theia/.Dockerfile "${BREW_DOCKERFILE_ROOT_DIR}"/theia/Dockerfile
# build local
pushd "${BREW_DOCKERFILE_ROOT_DIR}"/theia >/dev/null
docker build -t ${CHE_THEIA_IMAGE_NAME} .
popd >/dev/null
}
# now do che-theia-endpoint-runtime
handle_che_theia_endpoint_runtime() {
# build only ubi8 image and for target builder first, so we can extract data
pushd "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime >/dev/null
# first generate the Dockerfile
bash ./build.sh --dockerfile:Dockerfile.ubi8 --skip-tests --dry-run --build-args:DO_REMOTE_CHECK=false --tag:next --target:builder
# keep a copy of the file
cp .Dockerfile .ubi8-dockerfile
# Create one image for builder target
docker build -f .ubi8-dockerfile -t ${TMP_THEIA_ENDPOINT_BUILDER_IMAGE} --target builder .
popd >/dev/null
# Create image theia-endpoint-runtime:ubi8-brew
rm -rf "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime/docker/ubi8-brew
cp -r "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime/docker/ubi8 "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime/docker/ubi8-brew
# Add extra conf
cp conf/theia-endpoint-runtime/ubi8-brew/* "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime/docker/ubi8-brew/
# dry-run for theia-endpoint-runtime:ubi8-brew to only generate Dockerfile
pushd "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime >/dev/null
bash ./build.sh --dockerfile:Dockerfile.ubi8-brew --skip-tests --dry-run --build-args:DO_REMOTE_CHECK=false --tag:next --target:builder
popd >/dev/null
# Copy assets from ubi8 to local
pushd "${BREW_DOCKERFILE_ROOT_DIR}"/theia-endpoint-runtime >/dev/null
# npm/yarn cache
# /usr/local/share/.cache/yarn/v4 = yarn cache dir
# /home/theia-dev/.yarn-global = yarn
# /opt/app-root/src/.npm-global = yarn symlinks
docker run --rm --entrypoint= ${TMP_THEIA_ENDPOINT_BUILDER_IMAGE} tar -pzcf - /usr/local/share/.cache/yarn/v4 /home/theia-dev/.yarn-global /opt/app-root/src/.npm-global > asset-theia-endpoint-runtime-yarn.tar.gz
# node-headers
docker run --rm --entrypoint= ${TMP_THEIA_ENDPOINT_BUILDER_IMAGE} sh -c 'nodeVersion=$(node --version); download_url="https://nodejs.org/download/release/${nodeVersion}/node-${nodeVersion}-headers.tar.gz" && curl ${download_url}' > asset-node-headers.tar.gz
# Add yarn.lock after compilation
docker run --rm --entrypoint= ${TMP_THEIA_ENDPOINT_BUILDER_IMAGE} sh -c 'cat /home/workspace/yarn.lock' > asset-workspace-yarn.lock
docker run --rm --entrypoint= ${TMP_THEIA_ENDPOINT_BUILDER_IMAGE} sh -c 'cat /home/workspace/packages/theia-remote/yarn.lock' > asset-theia-remote-yarn.lock
# moxios is used with a github URL, not a npmjs dependency, need to provide the dependency
git clone https://github.com/stoplightio/moxios.git "${BREW_DOCKERFILE_ROOT_DIR}"/moxios
pushd "${BREW_DOCKERFILE_ROOT_DIR}"/moxios >/dev/null
tar zcf "${BREW_DOCKERFILE_ROOT_DIR}/theia/asset-moxios.tgz" -- *
rm -rf "${BREW_DOCKERFILE_ROOT_DIR}"/moxios
popd >/dev/null
# post-install dependencies
# /tmp/vscode-ripgrep-cache-1.2.4 /tmp/vscode-ripgrep-cache-1.5.7 = rigrep binaries
# /home/theia-dev/.cache = include electron/node-gyp cache
docker run --rm --entrypoint= ${TMP_THEIA_BUILDER_IMAGE} tar -pzcf - /tmp/vscode-ripgrep-cache-1.2.4 /tmp/vscode-ripgrep-cache-1.5.7 /home/theia-dev/.cache > asset-download-dependencies.tar.gz
# npm/yarn cache
# /usr/local/share/.cache/yarn/v4/ = yarn cache dir
# /opt/app-root/src/.npm-global = npm global
docker run --rm --entrypoint= ${TMP_THEIA_ENDPOINT_BUILDER_IMAGE} tar -pzcf - /usr/local/share/.cache/yarn/v4/ /opt/app-root/src/.npm-global > asset-yarn-runtime-image.tar.gz
rm -rf src docker-build
cp -r "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime/etc .
cp -r "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime/docker-build .
# Copy generate Dockerfile
cp "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime/.Dockerfile "${BREW_DOCKERFILE_ROOT_DIR}"/theia-endpoint-runtime/Dockerfile
# build local
docker build -t ${CHE_THEIA_ENDPOINT_IMAGE_NAME} .
popd >/dev/null
}
# now do che-theia-endpoint-runtime-binary
handle_che_theia_endpoint_runtime_binary() {
# build only ubi8 image and for target builder first, so we can extract data
pushd "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime-binary >/dev/null
# first generate the Dockerfile
bash ./build.sh --dockerfile:Dockerfile.ubi8 --skip-tests --dry-run --build-args:DO_REMOTE_CHECK=false --tag:next --target:builder
# keep a copy of the file
cp .Dockerfile .ubi8-dockerfile
# Create one image for builder target
docker build -f .ubi8-dockerfile -t ${TMP_THEIA_ENDPOINT_BINARY_BUILDER_IMAGE} --target builder .
popd >/dev/null
# Create image theia-endpoint-runtime-binary:ubi8-brew
rm -rf "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime-binary/docker/ubi8-brew
cp -r "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime-binary/docker/ubi8 "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime-binary/docker/ubi8-brew
# Add extra conf
cp conf/theia-endpoint-runtime-binary/ubi8-brew/* "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime-binary/docker/ubi8-brew/
# dry-run for theia-endpoint-runtime:ubi8-brew to only generate Dockerfile
pushd "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime-binary >/dev/null
bash ./build.sh --dockerfile:Dockerfile.ubi8-brew --skip-tests --dry-run --build-args:DO_REMOTE_CHECK=false --tag:next --target:builder
popd >/dev/null
# Copy assets from ubi8 to local
pushd "${BREW_DOCKERFILE_ROOT_DIR}"/theia-endpoint-runtime-binary >/dev/null
# npm/yarn cache
# /usr/local/share/.cache/yarn/v4 = yarn cache dir
# /usr/local/share/.config/yarn/global
# /opt/app-root/src/.npm-global = yarn symlinks
docker run --rm --entrypoint= ${TMP_THEIA_ENDPOINT_BINARY_BUILDER_IMAGE} tar -pzcf - /usr/local/share/.cache/yarn/v4 /usr/local/share/.config/yarn/global > asset-theia-endpoint-runtime-binary-yarn.tar.gz
# node
docker run --rm --entrypoint= ${TMP_THEIA_ENDPOINT_BINARY_BUILDER_IMAGE} sh -c 'nodeVersion=$(node --version); download_url="https://nodejs.org/download/release/${nodeVersion}/node-${nodeVersion}.tar.gz" && curl ${download_url}' > asset-node-src.tar.gz
# Copy generate Dockerfile
cp "${DOCKERFILES_ROOT_DIR}"/theia-endpoint-runtime-binary/.Dockerfile "${BREW_DOCKERFILE_ROOT_DIR}"/theia-endpoint-runtime-binary/Dockerfile
# build local
docker build -t ${CHE_THEIA_ENDPOINT_BINARY_IMAGE_NAME} .
popd >/dev/null
}
mkdir -p dockerfiles/theia
mkdir -p dockerfiles/theia-dev
mkdir -p dockerfiles/theia-endpoint
mkdir -p dockerfiles/theia-endpoint-runtime
mkdir -p dockerfiles/theia-endpoint-runtime-binary
handle_che_theia_dev
handle_che_theia
handle_che_theia_endpoint_runtime
handle_che_theia_endpoint_runtime_binary