Skip to content

Commit 9b94a2f

Browse files
authored
Merge pull request fcwu#128 from tostein/configureable_path
Dynamic prefix path
2 parents c850262 + 0cb3248 commit 9b94a2f

File tree

14 files changed

+327
-27
lines changed

14 files changed

+327
-27
lines changed

Dockerfile

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,111 @@
1-
Dockerfile.amd64
1+
# Built with arch: amd64 flavor: lxde image: ubuntu:18.04 localbuild: 1
2+
#
3+
################################################################################
4+
# base system
5+
################################################################################
6+
7+
FROM ubuntu:16.04 as system
8+
9+
RUN sed -i 's#http://archive.ubuntu.com/#http://tw.archive.ubuntu.com/#' /etc/apt/sources.list;
10+
11+
# built-in packages
12+
ENV DEBIAN_FRONTEND noninteractive
13+
RUN apt update \
14+
&& apt install -y --no-install-recommends software-properties-common curl apache2-utils \
15+
&& apt update \
16+
&& apt install -y --no-install-recommends --allow-unauthenticated \
17+
supervisor nginx sudo net-tools zenity xz-utils \
18+
dbus-x11 x11-utils alsa-utils \
19+
mesa-utils libgl1-mesa-dri \
20+
&& apt autoclean -y \
21+
&& apt autoremove -y \
22+
&& rm -rf /var/lib/apt/lists/*
23+
# install debs error if combine together
24+
RUN add-apt-repository -y ppa:fcwu-tw/apps \
25+
&& apt update \
26+
&& apt install -y --no-install-recommends --allow-unauthenticated \
27+
xvfb x11vnc\
28+
vim-tiny firefox chromium-browser ttf-ubuntu-font-family ttf-wqy-zenhei \
29+
&& add-apt-repository -r ppa:fcwu-tw/apps \
30+
&& apt autoclean -y \
31+
&& apt autoremove -y \
32+
&& rm -rf /var/lib/apt/lists/*
33+
34+
RUN apt update \
35+
&& apt install -y --no-install-recommends --allow-unauthenticated \
36+
lxde gtk2-engines-murrine gnome-themes-standard gtk2-engines-pixbuf gtk2-engines-murrine \
37+
&& apt autoclean -y \
38+
&& apt autoremove -y \
39+
&& rm -rf /var/lib/apt/lists/*
40+
41+
42+
# Additional packages require ~600MB
43+
# libreoffice pinta language-pack-zh-hant language-pack-gnome-zh-hant firefox-locale-zh-hant libreoffice-l10n-zh-tw
44+
45+
# tini for subreap
46+
ARG TINI_VERSION=v0.18.0
47+
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /bin/tini
48+
RUN chmod +x /bin/tini
49+
50+
# ffmpeg
51+
RUN apt update \
52+
&& apt install -y --no-install-recommends --allow-unauthenticated \
53+
ffmpeg \
54+
&& rm -rf /var/lib/apt/lists/* \
55+
&& mkdir /usr/local/ffmpeg \
56+
&& ln -s /usr/bin/ffmpeg /usr/local/ffmpeg/ffmpeg
57+
58+
# python library
59+
COPY image/usr/local/lib/web/backend/requirements.txt /tmp/
60+
RUN apt-get update \
61+
&& dpkg-query -W -f='${Package}\n' > /tmp/a.txt \
62+
&& apt-get install -y python-pip python-dev build-essential \
63+
&& pip install setuptools wheel && pip install -r /tmp/requirements.txt \
64+
&& dpkg-query -W -f='${Package}\n' > /tmp/b.txt \
65+
&& apt-get remove -y `diff --changed-group-format='%>' --unchanged-group-format='' /tmp/a.txt /tmp/b.txt | xargs` \
66+
&& apt-get autoclean -y \
67+
&& apt-get autoremove -y \
68+
&& rm -rf /var/lib/apt/lists/* \
69+
&& rm -rf /var/cache/apt/* /tmp/a.txt /tmp/b.txt
70+
71+
72+
################################################################################
73+
# builder
74+
################################################################################
75+
# FROM ubuntu:18.04 as builder
76+
77+
RUN apt-get update \
78+
&& apt-get install -y --no-install-recommends curl ca-certificates gnupg patch
79+
80+
# nodejs
81+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
82+
&& apt-get install -y nodejs
83+
84+
# yarn
85+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
86+
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
87+
&& apt-get update \
88+
&& apt-get install -y yarn
89+
90+
ARG ABC
91+
ENV PREFIX_PATH "/app"
92+
93+
COPY image /
94+
95+
# build frontend
96+
COPY web /src/web
97+
RUN /etc/install.sh
98+
99+
LABEL maintainer="Tobias Stein, fcwu.tw@gmail.com"
100+
101+
# COPY --from=builder /src/web/dist/ /usr/local/lib/web/frontend/
102+
RUN mkdir -p /usr/local/lib/web/frontend
103+
104+
RUN cp -R /src/web/dist/. /usr/local/lib/web/frontend/
105+
106+
EXPOSE 80
107+
WORKDIR /root
108+
ENV HOME=/home/ubuntu \
109+
SHELL=/bin/bash
110+
HEALTHCHECK --interval=30s --timeout=5s CMD curl --fail http://127.0.0.1:6079/api/health
111+
ENTRYPOINT ["/startup.sh"]

Dockerfile.18.04

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Built with arch: amd64 flavor: lxde image: ubuntu:18.04 localbuild: 1
2+
#
3+
################################################################################
4+
# base system
5+
################################################################################
6+
7+
FROM ubuntu:18.04 as system
8+
9+
10+
11+
RUN sed -i 's#http://archive.ubuntu.com/#http://tw.archive.ubuntu.com/#' /etc/apt/sources.list;
12+
13+
14+
# built-in packages
15+
ENV DEBIAN_FRONTEND noninteractive
16+
RUN apt update \
17+
&& apt install -y --no-install-recommends software-properties-common curl apache2-utils \
18+
&& apt update \
19+
&& apt install -y --no-install-recommends --allow-unauthenticated \
20+
supervisor nginx sudo net-tools zenity xz-utils \
21+
dbus-x11 x11-utils alsa-utils \
22+
mesa-utils libgl1-mesa-dri \
23+
&& apt autoclean -y \
24+
&& apt autoremove -y \
25+
&& rm -rf /var/lib/apt/lists/*
26+
# install debs error if combine together
27+
RUN add-apt-repository -y ppa:fcwu-tw/apps \
28+
&& apt update \
29+
&& apt install -y --no-install-recommends --allow-unauthenticated \
30+
xvfb x11vnc=0.9.16-1 \
31+
vim-tiny firefox chromium-browser ttf-ubuntu-font-family ttf-wqy-zenhei \
32+
&& add-apt-repository -r ppa:fcwu-tw/apps \
33+
&& apt autoclean -y \
34+
&& apt autoremove -y \
35+
&& rm -rf /var/lib/apt/lists/*
36+
37+
RUN apt update \
38+
&& apt install -y --no-install-recommends --allow-unauthenticated \
39+
lxde gtk2-engines-murrine gnome-themes-standard gtk2-engines-pixbuf gtk2-engines-murrine arc-theme \
40+
&& apt autoclean -y \
41+
&& apt autoremove -y \
42+
&& rm -rf /var/lib/apt/lists/*
43+
44+
45+
# Additional packages require ~600MB
46+
# libreoffice pinta language-pack-zh-hant language-pack-gnome-zh-hant firefox-locale-zh-hant libreoffice-l10n-zh-tw
47+
48+
# tini for subreap
49+
ARG TINI_VERSION=v0.18.0
50+
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /bin/tini
51+
RUN chmod +x /bin/tini
52+
53+
# ffmpeg
54+
RUN apt update \
55+
&& apt install -y --no-install-recommends --allow-unauthenticated \
56+
ffmpeg \
57+
&& rm -rf /var/lib/apt/lists/* \
58+
&& mkdir /usr/local/ffmpeg \
59+
&& ln -s /usr/bin/ffmpeg /usr/local/ffmpeg/ffmpeg
60+
61+
# python library
62+
COPY image/usr/local/lib/web/backend/requirements.txt /tmp/
63+
RUN apt-get update \
64+
&& dpkg-query -W -f='${Package}\n' > /tmp/a.txt \
65+
&& apt-get install -y python-pip python-dev build-essential \
66+
&& pip install setuptools wheel && pip install -r /tmp/requirements.txt \
67+
&& dpkg-query -W -f='${Package}\n' > /tmp/b.txt \
68+
&& apt-get remove -y `diff --changed-group-format='%>' --unchanged-group-format='' /tmp/a.txt /tmp/b.txt | xargs` \
69+
&& apt-get autoclean -y \
70+
&& apt-get autoremove -y \
71+
&& rm -rf /var/lib/apt/lists/* \
72+
&& rm -rf /var/cache/apt/* /tmp/a.txt /tmp/b.txt
73+
74+
75+
################################################################################
76+
# builder
77+
################################################################################
78+
# FROM ubuntu:18.04 as builder
79+
80+
81+
RUN sed -i 's#http://archive.ubuntu.com/#http://tw.archive.ubuntu.com/#' /etc/apt/sources.list;
82+
83+
84+
RUN apt-get update \
85+
&& apt-get install -y --no-install-recommends curl ca-certificates gnupg patch
86+
87+
# nodejs
88+
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
89+
&& apt-get install -y nodejs
90+
91+
# yarn
92+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
93+
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
94+
&& apt-get update \
95+
&& apt-get install -y yarn
96+
97+
ENV PREFIX_PATH "/app"
98+
99+
COPY image /
100+
101+
# build frontend
102+
COPY web /src/web
103+
RUN /etc/install.sh
104+
105+
LABEL maintainer="Tobias Stein, fcwu.tw@gmail.com"
106+
107+
# COPY --from=builder /src/web/dist/ /usr/local/lib/web/frontend/
108+
RUN mkdir -p /usr/local/lib/web/frontend
109+
110+
RUN cp -R /src/web/dist/. /usr/local/lib/web/frontend/
111+
112+
EXPOSE 80
113+
WORKDIR /root
114+
ENV HOME=/home/ubuntu \
115+
SHELL=/bin/bash
116+
HEALTHCHECK --interval=30s --timeout=5s CMD curl --fail http://127.0.0.1:6079/api/health
117+
ENTRYPOINT ["/startup.sh"]

image/etc/RenameURL.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os, fnmatch
2+
3+
toFind = "/app"
4+
toReplace = os.getenv("PREFIX_PATH")
5+
6+
if (toReplace is None):
7+
print("No path given by environment variable.")
8+
exit()
9+
10+
print("using path {0} ...".format(toReplace))
11+
12+
def findReplace(directory, find, replace):
13+
print("Rename {0} into {1} at {2}".format(toFind, toReplace, directory))
14+
for path, dirs, files in os.walk(os.path.abspath(directory)):
15+
for filename in files:
16+
filepath = os.path.join(path, filename)
17+
with open(filepath) as f:
18+
s = f.read()
19+
s = s.replace(find, replace)
20+
with open(filepath, "w") as f:
21+
f.write(s)
22+
23+
findReplace("/etc/nginx/sites-enabled/", toFind, toReplace)

image/etc/install.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
echo 'Building Node.js project...'
3+
cd /src/web \
4+
&& yarn \
5+
&& npm run build
6+
7+
cp -R /src/web/dist/. /usr/local/lib/web/frontend/
8+
echo 'Build finished.'

image/etc/nginx/sites-enabled/default

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@ server {
1313
root /usr/local/lib/web/frontend/;
1414
index index.html index.htm;
1515

16-
location ~ ^/api {
16+
location = /app {
17+
try_files $uri @rewrites;
18+
}
19+
20+
location @rewrites {
21+
rewrite ^(.+)$ /index.html last;
22+
}
23+
24+
location ~ ^/app/api {
1725
try_files $uri @api;
1826
}
1927

20-
location = /websockify {
28+
location = /app/websockify {
2129
proxy_http_version 1.1;
2230
proxy_set_header Upgrade $http_upgrade;
2331
proxy_set_header Connection "upgrade";

image/etc/supervisor/conf.d/supervisord.conf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ directory=/root
77
[program:nginx]
88
priority=10
99
command=nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
10+
stdout_logfile=/dev/fd/1
11+
stdout_logfile_maxbytes=0
12+
stderr_logfile=/dev/fd/1
13+
stderr_logfile_maxbytes=0
1014

1115
[program:web]
1216
priority=10
@@ -41,8 +45,6 @@ user=%USER%
4145
environment=DISPLAY=":1",HOME="%HOME%",USER="%USER%"
4246

4347

44-
45-
4648
[program:xvfb]
4749
priority=10
4850
command=/usr/local/bin/xvfb.sh
@@ -52,8 +54,10 @@ stopsignal=KILL
5254
priority=20
5355
command=x11vnc -display :1 -xkb -forever -shared -repeat
5456

57+
5558
[program:novnc]
5659
priority=25
57-
directory=/usr/local/lib/web/frontend/static/novnc
58-
command=bash /usr/local/lib/web/frontend/static/novnc/utils/launch.sh --listen 6081
60+
directory=/usr/local/lib/web/frontend%(ENV_PREFIX_PATH)s/static/novnc
61+
command=bash /usr/local/lib/web/frontend%(ENV_PREFIX_PATH)s/static/novnc/utils/launch.sh --listen 6081
5962
stopasgroup=true
63+

image/startup.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,21 @@ if [ -n "$HTTP_PASSWORD" ]; then
5959
sed -i 's|#_HTTP_PASSWORD_#||' /etc/nginx/sites-enabled/default
6060
fi
6161

62+
# dynamic prefix path renaming
63+
if [ -n "$DYNAMIC_PREFIX_PATH" ]; then
64+
PREFIX_PATH="$DYNAMIC_PREFIX_PATH"
65+
echo "DYNAMIC_PREFIX_PATH: $PREFIX_PATH"
66+
python /etc/RenameURL.py
67+
/etc/install.sh
68+
cat /etc/nginx/sites-enabled/default
69+
fi
70+
6271
# novnc websockify
63-
ln -s /usr/local/lib/web/frontend/static/websockify /usr/local/lib/web/frontend/static/novnc/utils/websockify
64-
chmod +x /usr/local/lib/web/frontend/static/websockify/run
72+
ln -s "/usr/local/lib/web/frontend$PREFIX_PATH/static/websockify" "/usr/local/lib/web/frontend$PREFIX_PATH/static/novnc/utils/websockify"
73+
chmod +x "/usr/local/lib/web/frontend$PREFIX_PATH/static/websockify/run"
6574

6675
# clearup
67-
PASSWORD=
76+
PASSWORD=+
6877
HTTP_PASSWORD=
6978

70-
exec /bin/tini -- /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
79+
exec /bin/tini -- /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf

image/usr/local/lib/web/backend/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def run_server():
114114
)
115115
logging.getLogger("werkzeug").setLevel(logging.WARNING)
116116
log = logging.getLogger('novnc2')
117+
117118
entrypoint()
118119

119120

0 commit comments

Comments
 (0)