-
Notifications
You must be signed in to change notification settings - Fork 1
/
dockerfile-gen.sh
executable file
·310 lines (229 loc) · 5.85 KB
/
dockerfile-gen.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
307
308
309
310
#! /usr/bin/env bash
# This will create an image that does NOT install mysql (compared to original version)
#
set -e
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
for n in main.sh apt.sh debugging.sh nodejs.sh git.sh; do
# shellcheck disable=SC1090
source "${SCRIPT_PATH}/dockerfile-lib/$n"
done
DEV_MODE=
FORCE_GIT_CLONE=
SHINOBI_BASEDIR=/home/Shinobi
# ==== command line parsing
checkArg () {
if [ -z "$2" ] || [[ "$2" == "-"* ]]; then
echo "Expected argument for option: $1. None received"
exit 1
fi
}
arguments=()
while [[ $# -gt 0 ]]
do
# split --x=y to have them separated
[[ $1 == --*=* ]] && set -- "${1%%=*}" "${1#*=}" "${@:2}"
case "$1" in
--dev)
DEV_MODE=1
shift
;;
--run-with-debug)
RUN_WITH_DEBUG=1
shift
;;
--force-git-clone)
FORCE_GIT_CLONE=1
shift
;;
--) # end argument parsing
shift
break
;;
-*) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
;;
*) # preserve positional arguments
arguments+=("$1")
shift
;;
esac
done
# ========
start_dockerfile() {
exit_run_cmd
GEN_FROM "ubuntu:22.04"
cat <<EOS
ENV \
LC_ALL=C.UTF-8 \
LANG=C.UTF-8 \
APP_UPDATE=manual \
APP_BRANCH=dev \
APP_PORT=8080
EXPOSE 8080
VOLUME ${SHINOBI_BASEDIR}/videos
VOLUME ${SHINOBI_BASEDIR}/libs/customAutoload
VOLUME /config
EOS
}
end_dockerfile() {
exit_run_cmd
cat <<'EOS'
CMD ["pm2-docker", "Docker/pm2.yml"]
EOS
echo "WORKDIR ${SHINOBI_BASEDIR}"
echo "ENTRYPOINT [\"${SHINOBI_BASEDIR}/docker-entrypoint.sh\"]"
}
run_shinobi_makedirs() {
enter_run_cmd
# Create additional directories for: Custom configuration, working directory, database directory, scripts
cat << EOS
; mkdir -p \\
/config \\
${SHINOBI_BASEDIR} \\
/customAutoLoad \\
EOS
}
SHINOBI_REQ_PACKAGES_RUNTIME=(jq mysql-client)
# 'gyp' node modules requires: 'apt.py' (python package), make
SHINOBI_REQ_PACKAGES_BUILDTIME=(python3 make git)
run_install_ffmpeg() {
if true; then
cmd_apt_min_install software-properties-common
enter_run_cmd
cat << EOS
; add-apt-repository ppa:savoury1/ffmpeg6 \\
; add-apt-repository ppa:savoury1/ffmpeg4 \\
; apt update \\
; DEBIAN_FRONTEND=noninteractive apt full-upgrade -yqq -o Dpkg::Options::=--force-unsafe-io \\
EOS
cmd_apt_min_install ffmpeg
#enter_run_cmd
#echo '; ffmpeg --version \'
#cmd_apt_install ffmpeg
else
# not sure why they need it
cmd_apt_min_install \
libfreetype6-dev \
libgnutls28-dev \
libmp3lame-dev \
libass-dev \
libogg-dev \
libtheora-dev \
libvorbis-dev \
libvpx-dev \
libwebp-dev \
libssh2-1-dev \
libopus-dev \
librtmp-dev \
libx264-dev \
libx265-dev \
yasm
enter_run_cmd
cat << EOS
; npm install ffbinaries \\
EOS
fi
}
run_install_runtime_dependencies() {
cmd_apt_min_install "${SHINOBI_REQ_PACKAGES_RUNTIME[@]}"
run_install_ffmpeg
}
run_install_build_time_dependencies() {
cmd_apt_min_install "${SHINOBI_REQ_PACKAGES_BUILDTIME[@]}"
}
run_shinobi_install_package_dependencies() {
run_install_runtime_dependencies
run_install_build_time_dependencies
return 0
cmd_apt_min_install \
build-essential \
bzip2 \
coreutils \
gnutls-bin \
nasm \
tar \
x264
# Install additional packages
# SEEME: using this ffmpeg OR the ffbinaries from npm install!?!?
cmd_apt_min_install \
ffmpeg \
git \
make \
mariadb-client \
pkg-config \
python \
wget \
tar \
sudo \
xz-utils
}
run_shinobi_code_clone() {
cmd_apt_min_install git
run_git_clone_into_existing_dir https://gitlab.com/Shinobi-Systems/Shinobi.git "$SHINOBI_BASEDIR" -b "dev"
}
run_shinobi_install_nodejs_dependencies() {
enter_run_cmd
cat << EOS
; ld=\$(pwd) \\
; cd "$SHINOBI_BASEDIR" \\
; npm i npm@latest -g \\
; npm install --unsafe-perm \\
; npm install pm2 -g \\
; cd "\$ld" \\
EOS
# ; npm audit fix --force \\
# why was this? ; npm install edit-json-file \\ ; npm install jsonfile \\
}
run_shinobi_configs_symlinks() {
enter_run_cmd
cat << EOS
; ln -s /config/conf.json "$SHINOBI_BASEDIR/conf.json" \\
; ln -s /config/super.json "$SHINOBI_BASEDIR/super.json" \\
EOS
}
copy_files() {
exit_run_cmd
cat << EOS
COPY docker-entrypoint.sh ${SHINOBI_BASEDIR}/
COPY /tools/modifyJson.js ${SHINOBI_BASEDIR}/tools
EOS
}
run_fix_files() {
enter_run_cmd
cat << EOS
; chmod -f +x ${SHINOBI_BASEDIR}/*.sh \\
; chmod 777 ${SHINOBI_BASEDIR}/plugins \\
EOS
}
run_cleanup() {
enter_run_cmd
# can't call that, nodejs needs ca-certificates
#run_apt_remove_initial_packages
run_apt_cleanups
enter_run_cmd
cat <<'EOS'
; rm -rf /root/.cache \
; rm -rf /root/.npm \
; rm -rf /root/.ffbinaries-cache \
EOS
}
# =======
start_dockerfile
export NODE_MAJOR_VERSION=16
run_shinobi_makedirs
[ -z "$DEV_MODE" ] && copy_files
run_apt_initial_minimal_installs
# repositories:
run_nodejs_add_repo
# end of adding repositories
run_apt_update
run_nodejs_install
run_shinobi_install_package_dependencies
run_shinobi_code_clone
run_shinobi_install_nodejs_dependencies
run_shinobi_configs_symlinks
[ -n "$DEV_MODE" ] && copy_files
run_fix_files
[ -z "$DEV_MODE" ] && run_cleanup
end_dockerfile