-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
237 lines (227 loc) · 12.5 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
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
ARG DEBIANVERSION="bookworm-slim"
ARG GUNBOTVERSION="latest"
ARG GITHUBOWNER="GuntharDeNiro"
ARG GITHUBREPO="BTCT"
ARG GITHUBOWNERBETA="computeronix"
ARG GITHUBREPOBETA="BTCT-Beta"
ARG GUNBOTBETAVERSION="latest"
ARG GBINSTALLLOC="/opt/gunbot"
ARG GBMOUNT="/mnt/gunbot"
ARG GBACTIVATEBETA
ARG GBBETA="gunthy-linux.zip"
ARG GBPORT=5000
ARG MAINTAINER="computeronix"
ARG WEBSITE="https://hub.docker.com/r/computeronix/gunbot"
ARG DESCRIPTION="(Unofficial) Gunbot Docker Container - ${GUNBOTVERSION}"
#SCRATCH WORKSPACE FOR BUILDING IMAGE
FROM --platform="linux/amd64" debian:${DEBIANVERSION} AS gunbot-builder
ARG GUNBOTVERSION
ARG GITHUBOWNER
ARG GITHUBREPO
ARG GBINSTALLLOC
ARG GITHUBOWNERBETA
ARG GITHUBREPOBETA
ARG GUNBOTBETAVERSION
ARG GBACTIVATEBETA
ARG GBBETA
ARG GBMOUNT
ARG GBPORT
WORKDIR /tmp
#BUILDING IMAGE
#update mirrors and install packages
RUN apt-get update && apt-get install -y wget jq unzip \
#remove mirrors
&& rm -rf /var/lib/apt/lists/* \
#pull ${GUNBOTVERSION} from official GitHub and extract linux client
&& wget -q -nv -O gunbot.zip $(wget -q -nv -O- https://api.github.com/repos/${GITHUBOWNER}/${GITHUBREPO}/releases/${GUNBOTVERSION} 2>/dev/null | jq -r '.assets[] | select(.browser_download_url | contains("linux")) | .browser_download_url') \
&& unzip -d . gunbot.zip \
&& mv gunthy_linux gunbot \
#check for gunbot beta activation
&& if [ "$GBACTIVATEBETA" = 1 ]; then \
wget -q -nv -O gunbot-beta.zip $(wget -q -nv -O- https://api.github.com/repos/${GITHUBOWNERBETA}/${GITHUBREPOBETA}/releases/${GUNBOTBETAVERSION} 2>/dev/null | jq -r '.assets[] | select(.browser_download_url | contains("linux")) | .browser_download_url') ; \
unzip -d . gunbot-beta.zip ; \
mv -f gunthy-linux gunbot ; \
fi \
#create self-signed ssl configuratuon
&& printf "[req]\n" > gunbot/ssl.config \
&& printf "distinguished_name = req_distinguished_name\n" >> gunbot/ssl.config \
&& printf "prompt = no\n" >> gunbot/ssl.config \
&& printf "[req_distinguished_name]\n" >> gunbot/ssl.config \
&& printf "commonName = localhost\n" >> gunbot/ssl.config \
&& printf "[ v3_req ]\n" >> gunbot/ssl.config \
&& printf "basicConstraints = CA:FALSE\n" >> gunbot/ssl.config \
&& printf "subjectKeyIdentifier = hash\n" >> gunbot/ssl.config \
&& printf "authorityKeyIdentifier = keyid:always, issuer:always\n" >> gunbot/ssl.config \
&& printf "keyUsage = nonRepudiation, digitalSignature, keyEncipherment, keyAgreement\n" >> gunbot/ssl.config \
&& printf "extendedKeyUsage = serverAuth\n" >> gunbot/ssl.config \
&& printf "subjectAltName = DNS:localhost\n" >> gunbot/ssl.config \
#create startup.sh bash script
&& printf "#!/bin/bash\n" > gunbot/startup.sh \
#check for Gunbot Beta (${GBBETA}) directory
&& printf "if [ -f ${GBMOUNT}/${GBBETA} ]; then \n" >> gunbot/startup.sh \
&& printf " unzip -d ${GBMOUNT} ${GBMOUNT}/${GBBETA}\n" >> gunbot/startup.sh \
&& printf " mv ${GBMOUNT}/gunthy-linux ${GBINSTALLLOC}\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#check for ssl.config
&& printf "if [ -f ${GBMOUNT}/ssl.config ]; then \n" >> gunbot/startup.sh \
&& printf " ln -sf ${GBMOUNT}/ssl.config ${GBINSTALLLOC}/ssl.config\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#check for localhost.crt AND localhost.key
&& printf "if [ ! -f ${GBMOUNT}/localhost.crt ] && [ ! -f ${GBMOUNT}/localhost.key ]; then \n" >> gunbot/startup.sh \
&& printf " openssl req -config ${GBINSTALLLOC}/ssl.config -newkey rsa:2048 -nodes -keyout ${GBINSTALLLOC}/localhost.key -x509 -days 365 -out ${GBINSTALLLOC}/localhost.crt -extensions v3_req 2>/dev/null \n" >> gunbot/startup.sh \
&& printf "else\n" >> gunbot/startup.sh \
&& printf " ln -sf ${GBMOUNT}/localhost.crt ${GBINSTALLLOC}/localhost.crt\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#triple check json directory is linked
&& printf "if [ -L ${GBINSTALLLOC}/json ] ; then\n" >> gunbot/startup.sh \
&& printf " if [ -d ${GBMOUNT}/json ] ; then\n" >> gunbot/startup.sh \
&& printf " echo Good link >/dev/null \n" >> gunbot/startup.sh \
&& printf " else\n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/json\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf "else\n" >> gunbot/startup.sh \
&& printf " if [ ! -d ${GBMOUNT}/json ]; then \n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/json\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf " ln -sf ${GBMOUNT}/json ${GBINSTALLLOC}/json\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#triple check logs directory is linked
&& printf "if [ -L ${GBINSTALLLOC}/logs ] ; then\n" >> gunbot/startup.sh \
&& printf " if [ -d ${GBMOUNT}/logs ] ; then\n" >> gunbot/startup.sh \
&& printf " echo Good link >/dev/null \n" >> gunbot/startup.sh \
&& printf " else\n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/logs\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf "else\n" >> gunbot/startup.sh \
&& printf " if [ ! -d ${GBMOUNT}/logs ]; then \n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/logs\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf " ln -sf ${GBMOUNT}/logs ${GBINSTALLLOC}/logs\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#triple check backups directory is linked
&& printf "if [ -L ${GBINSTALLLOC}/backups ] ; then\n" >> gunbot/startup.sh \
&& printf " if [ -d ${GBMOUNT}/backups ] ; then\n" >> gunbot/startup.sh \
&& printf " echo Good link >/dev/null \n" >> gunbot/startup.sh \
&& printf " else\n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/backups\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf "else\n" >> gunbot/startup.sh \
&& printf " if [ ! -d ${GBMOUNT}/backups ]; then \n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/backups\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf " ln -sf ${GBMOUNT}/backups ${GBINSTALLLOC}/backups\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#triple check customStrategies directory is linked
&& printf "if [ -L ${GBINSTALLLOC}/customStrategies ] ; then\n" >> gunbot/startup.sh \
&& printf " if [ -d ${GBMOUNT}/customStrategies ] ; then\n" >> gunbot/startup.sh \
&& printf " echo Good link >/dev/null \n" >> gunbot/startup.sh \
&& printf " else\n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/customStrategies\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf "else\n" >> gunbot/startup.sh \
&& printf " if [ ! -d ${GBMOUNT}/customStrategies ]; then \n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/customStrategies\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf " ln -sf ${GBMOUNT}/customStrategies ${GBINSTALLLOC}/customStrategies\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#triple check user_modules directory is linked and not empty
&& printf "if [ -L ${GBINSTALLLOC}/user_modules ] ; then\n" >> gunbot/startup.sh \
&& printf " if [ -d ${GBMOUNT}/user_modules ] ; then\n" >> gunbot/startup.sh \
&& printf " echo Good link >/dev/null \n" >> gunbot/startup.sh \
&& printf " else\n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/user_modules\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf "else\n" >> gunbot/startup.sh \
&& printf " if [ ! -d ${GBMOUNT}/user_modules ]; then \n" >> gunbot/startup.sh \
&& printf " mkdir ${GBMOUNT}/user_modules\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf " if [ ! -z \"\$(ls -A ${GBINSTALLLOC}/user_modules 2>/dev/null)\" ]; then \n" >> gunbot/startup.sh \
&& printf " echo Not empty >/dev/null \n" >> gunbot/startup.sh \
&& printf " else\n" >> gunbot/startup.sh \
&& printf " ln -sf ${GBMOUNT}/user_modules ${GBINSTALLLOC}/user_modules\n" >> gunbot/startup.sh \
&& printf " fi\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#check for config.js file
&& printf "if [ ! -f ${GBMOUNT}/config.js ]; then \n" >> gunbot/startup.sh \
&& printf " cp ${GBINSTALLLOC}/config.js ${GBMOUNT}/config.js\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
&& printf "ln -sf ${GBMOUNT}/config.js ${GBINSTALLLOC}/config.js\n" >> gunbot/startup.sh \
#check for UTAconfig.json file
&& printf "if [ ! -f ${GBMOUNT}/UTAconfig.json ]; then \n" >> gunbot/startup.sh \
&& printf " cp ${GBINSTALLLOC}/UTAconfig.json ${GBMOUNT}/UTAconfig.json\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
&& printf "ln -sf ${GBMOUNT}/UTAconfig.json ${GBINSTALLLOC}/UTAconfig.json\n" >> gunbot/startup.sh \
#check for autoconfig.json file
&& printf "if [ ! -f ${GBMOUNT}/autoconfig.json ]; then \n" >> gunbot/startup.sh \
&& printf " cp ${GBINSTALLLOC}/autoconfig.json ${GBMOUNT}/autoconfig.json\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
&& printf "ln -sf ${GBMOUNT}/autoconfig.json ${GBINSTALLLOC}/autoconfig.json\n" >> gunbot/startup.sh \
#check for gunbotgui.db file
&& printf "if [ ! -f ${GBMOUNT}/gunbotgui.db ]; then \n" >> gunbot/startup.sh \
&& printf " touch ${GBINSTALLLOC}/gunbotgui.db\n" >> gunbot/startup.sh \
&& printf " cp ${GBINSTALLLOC}/gunbotgui.db ${GBMOUNT}/gunbotgui.db\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
&& printf "ln -sf ${GBMOUNT}/gunbotgui.db ${GBINSTALLLOC}/gunbotgui.db\n" >> gunbot/startup.sh \
#check for new_gui.sqlite file
&& printf "if [ ! -f ${GBMOUNT}/new_gui.sqlite ]; then \n" >> gunbot/startup.sh \
&& printf " touch ${GBINSTALLLOC}/new_gui.sqlite\n" >> gunbot/startup.sh \
&& printf " cp ${GBINSTALLLOC}/new_gui.sqlite ${GBMOUNT}/new_gui.sqlite\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
&& printf "ln -sf ${GBMOUNT}/new_gui.sqlite ${GBINSTALLLOC}/new_gui.sqlite\n" >> gunbot/startup.sh \
#setup config.js
&& printf "if [ ! -s ${GBMOUNT}/config.js ]; then \n" >> gunbot/startup.sh \
&& printf " cp ${GBINSTALLLOC}/config-js-example.txt ${GBMOUNT}/config.js\n" >> gunbot/startup.sh \
&& printf "fi\n" >> gunbot/startup.sh \
#inject config -> enable https
&& printf "jq '.GUI.https = true' ${GBINSTALLLOC}/config.js > /tmp/config2.js\n" >> gunbot/startup.sh \
#inject config -> setup json output -> ${GBINSTALLLOC}/json
&& printf "jq '.bot.json_output = \"${GBINSTALLLOC}/json\"' /tmp/config2.js > /tmp/config3.js\n" >> gunbot/startup.sh \
#inject config -> force port 5000
&& printf "jq '.GUI.port = ${GBPORT}' /tmp/config3.js > /tmp/config4.js\n" >> gunbot/startup.sh \
#inject config -> setup localhost.key
&& printf "jq '.GUI.key = \"localhost.key\"' /tmp/config4.js > /tmp/config5.js\n" >> gunbot/startup.sh \
#inject config -> setup localhost.crt
&& printf "jq '.GUI.cert = \"localhost.crt\"' /tmp/config5.js > ${GBINSTALLLOC}/config.js\n" >> gunbot/startup.sh \
#run chronyd (note will not work without proper permissions and will error, but will continue forward)
&& printf "chronyd -d || : &\n" >> gunbot/startup.sh \
#create custom.sh bash script
&& printf "#!/bin/bash\n" > gunbot/custom.sh \
#inject custom.sh script into startup.sh
&& printf "${GBINSTALLLOC}/custom.sh\n" >> gunbot/startup.sh \
#create runner.sh bash script
&& printf "#!/bin/bash\n" > gunbot/runner.sh \
#run gunbot
&& printf "${GBINSTALLLOC}/gunthy-linux\n" >> gunbot/runner.sh \
#inject runner.sh script and have it run next
&& printf "${GBINSTALLLOC}/runner.sh\n" >> gunbot/startup.sh
#BUILD THE RUN IMAGE
FROM --platform="linux/amd64" debian:${DEBIANVERSION}
ARG MAINTAINER
ARG WEBSITE
ARG DESCRIPTION
ARG GBINSTALLLOC
ARG GBBETA
ARG GBPORT
ARG GBMOUNT
ENV GUNBOTLOCATION=${GBINSTALLLOC}
LABEL \
maintainer="${MAINTAINER}" \
website="${WEBSITE}" \
description="${DESCRIPTION}"
COPY --from=gunbot-builder /tmp/gunbot ${GBINSTALLLOC}
WORKDIR ${GBINSTALLLOC}
RUN apt-get update && apt-get install -y chrony jq unzip openssl fontconfig \
&& apt-get upgrade -y \
&& apt-get autoremove -y \
&& apt-get autoclean -y \
&& rm -rf /var/lib/apt/lists/* \
#&& useradd -u 1000 gunbotuser \
#&& chown -R 1000:1000 "${GBINSTALLLOC}" \
&& mkdir "${GBMOUNT}" \
#&& chown -R 1000:1000 "${GBMOUNT}" \
&& chmod +x "${GBINSTALLLOC}/startup.sh" \
&& chmod +x "${GBINSTALLLOC}/custom.sh" \
&& chmod +x "${GBINSTALLLOC}/runner.sh"
#USER gunbotuser
EXPOSE ${GBPORT}
CMD ["bash","-c","${GUNBOTLOCATION}/startup.sh"]