Skip to content

Commit 243813f

Browse files
committed
feat: add Ubuntu desktop environment (test)
1 parent 8496ffb commit 243813f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1685
-0
lines changed

ubuntu/Dockerfile.18.04.xfce.amd64

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
FROM ubuntu:18.04 as system
2+
3+
RUN sed -i 's#http://archive.ubuntu.com/ubuntu/#mirror://mirrors.ubuntu.com/mirrors.txt#' /etc/apt/sources.list;
4+
5+
# built-in packages
6+
ENV DEBIAN_FRONTEND noninteractive
7+
RUN apt update \
8+
&& apt install -y --no-install-recommends software-properties-common curl apache2-utils \
9+
&& apt update \
10+
&& apt install -y --no-install-recommends --allow-unauthenticated \
11+
supervisor nginx sudo net-tools zenity xz-utils \
12+
dbus-x11 x11-utils alsa-utils \
13+
mesa-utils libgl1-mesa-dri \
14+
&& apt autoclean -y \
15+
&& apt autoremove -y \
16+
&& rm -rf /var/lib/apt/lists/*
17+
# install debs error if combine together
18+
RUN apt update \
19+
&& apt install -y --no-install-recommends --allow-unauthenticated \
20+
xvfb x11vnc \
21+
vim-tiny firefox xfce4-terminal ttf-ubuntu-font-family \
22+
&& apt autoclean -y \
23+
&& apt autoremove -y \
24+
&& rm -rf /var/lib/apt/lists/*
25+
26+
RUN apt update \
27+
&& apt install -y --no-install-recommends --allow-unauthenticated \
28+
xubuntu-desktop \
29+
&& apt autoclean -y \
30+
&& apt autoremove -y \
31+
&& rm -rf /var/lib/apt/lists/*
32+
33+
# python library (for backend)
34+
COPY rootfs/usr/local/lib/web/backend/requirements.txt /tmp/
35+
RUN apt-get update \
36+
&& dpkg-query -W -f='${Package}\n' > /tmp/a.txt \
37+
&& apt-get install -y python-pip python-dev build-essential \
38+
&& pip install setuptools wheel && pip install -r /tmp/requirements.txt \
39+
&& dpkg-query -W -f='${Package}\n' > /tmp/b.txt \
40+
&& apt-get remove -y `diff --changed-group-format='%>' --unchanged-group-format='' /tmp/a.txt /tmp/b.txt | xargs` \
41+
&& apt-get autoclean -y \
42+
&& apt-get autoremove -y \
43+
&& rm -rf /var/lib/apt/lists/* \
44+
&& rm -rf /var/cache/apt/* /tmp/a.txt /tmp/b.txt
45+
46+
######## Frontend builder
47+
FROM ubuntu:18.04 as builder
48+
49+
RUN sed -i 's#http://archive.ubuntu.com/ubuntu/#mirror://mirrors.ubuntu.com/mirrors.txt#' /etc/apt/sources.list;
50+
51+
52+
RUN apt-get update \
53+
&& apt-get install -y --no-install-recommends curl ca-certificates gnupg patch
54+
55+
# nodejs
56+
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - \
57+
&& apt-get install -y nodejs
58+
59+
# yarn
60+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
61+
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
62+
&& apt-get update \
63+
&& apt-get install -y yarn
64+
65+
# build frontend
66+
COPY web /src/web
67+
RUN cd /src/web \
68+
&& yarn \
69+
&& yarn build
70+
71+
####### Build final image with frontend
72+
FROM system
73+
LABEL maintainer="[email protected]"
74+
75+
COPY --from=builder /src/web/dist/ /usr/local/lib/web/frontend/
76+
COPY rootfs /
77+
RUN ln -sf /usr/local/lib/web/frontend/static/websockify /usr/local/lib/web/frontend/static/novnc/utils/websockify && \
78+
chmod +x /usr/local/lib/web/frontend/static/websockify/run
79+
80+
RUN ln -sf /usr/local/lib/web/frontend/static/vnc.html /usr/local/lib/web/frontend/static/index.html
81+
RUN ln -sf /usr/local/lib/web/frontend/static/novnc/vnc.html /usr/local/lib/web/frontend/static/novnc/index.html
82+
83+
EXPOSE 80
84+
WORKDIR /home/work
85+
86+
ENV HOME=/home/work \
87+
SHELL=/bin/bash
88+
HEALTHCHECK --interval=30s --timeout=5s CMD curl --fail http://127.0.0.1:6079/api/health
89+
90+
91+
#RUN /setup.sh
92+
93+
#ENTRYPOINT ["/startup.sh"]
94+
95+
# Backend.AI specifics
96+
LABEL ai.backend.kernelspec="1" \
97+
ai.backend.envs.corecount="OPENBLAS_NUM_THREADS,OMP_NUM_THREADS,NPROC" \
98+
ai.backend.features="batch query uid-match user-input" \
99+
ai.backend.resource.min.cpu="1" \
100+
ai.backend.resource.min.mem="1g" \
101+
ai.backend.base-distro="ubuntu18.04" \
102+
ai.backend.runtime-type="python" \
103+
ai.backend.runtime-path="/usr/bin/python3" \
104+
ai.backend.service-ports="xfce:http:80,vnc:http:5900"
105+
106+
COPY ./service-defs /etc/backend.ai/service-defs
107+
COPY policy.yml /etc/backend.ai/jail/policy.yml
108+
COPY bootstrap.sh /opt/container/bootstrap.sh
109+
WORKDIR /home/work

ubuntu/bootstrap.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
3+
if [ -n "$VNC_PASSWORD" ]; then
4+
echo -n "$VNC_PASSWORD" > /.password1
5+
x11vnc -storepasswd $(cat /.password1) /.password2
6+
chmod 400 /.password*
7+
sed -i 's/^command=x11vnc.*/& -rfbauth \/.password2/' /etc/supervisor/conf.d/supervisord.conf
8+
export VNC_PASSWORD=
9+
fi
10+
11+
if [ -n "$X11VNC_ARGS" ]; then
12+
sed -i "s/^command=x11vnc.*/& ${X11VNC_ARGS}/" /etc/supervisor/conf.d/supervisord.conf
13+
fi
14+
15+
if [ -n "$OPENBOX_ARGS" ]; then
16+
sed -i "s#^command=/usr/bin/openbox.*#& ${OPENBOX_ARGS}#" /etc/supervisor/conf.d/supervisord.conf
17+
fi
18+
19+
if [ -n "$RESOLUTION" ]; then
20+
sed -i "s/1024x768/$RESOLUTION/" /usr/local/bin/xvfb.sh
21+
fi
22+
23+
#USER=${USER:-root}
24+
USER=work
25+
HOME=/home/work
26+
cp -r /root/{.gtkrc-2.0,.asoundrc} ${HOME}
27+
#[ -d "/dev/snd" ] && chgrp -R adm /dev/snd
28+
sed -i -e "s|%USER%|$USER|" -e "s|%HOME%|$HOME|" /etc/supervisor/conf.d/supervisord.conf
29+
30+
# home folder
31+
if [ ! -x "$HOME/.config/pcmanfm/LXDE/" ]; then
32+
mkdir -p $HOME/.config/pcmanfm/LXDE/
33+
ln -sf /usr/local/share/doro-lxde-wallpapers/desktop-items-0.conf $HOME/.config/pcmanfm/LXDE/
34+
chown -R $USER:$USER $HOME
35+
fi
36+
37+
# nginx workers
38+
sed -i 's|worker_processes .*|worker_processes 1;|' /etc/nginx/nginx.conf
39+
40+
echo ">> Starting background VNC server"
41+
printf "backendai\nbackendai\n\n" | /opt/kernel/su-exec $LOCAL_USER_ID:$LOCAL_GROUP_ID vncpasswd >/dev/null 2>&1
42+
43+
mkdir -p /home/work/.vnc
44+
cat >/home/work/.vnc/xstartup <<EOF
45+
#!/bin/sh
46+
xhost +
47+
# SESSION_MANAGER is inherited from the environment and some window
48+
# managers require that it be cleared.
49+
# http://osdir.com/ml/gnome.ximian.snapshots/2002-09/msg00034.html
50+
# For example, Xfce4 version 4.6.1 and Deb5-64 require the unsetenv.
51+
# Goolging indicates that others also require the unsetenv.
52+
unsetenv SESSION_MANAGER
53+
# Startup scripts, e.g. /etc/xdg/xfce4/xinitrc require
54+
# http://en.wikipedia.org/wiki/D-Bus to run correctly.
55+
unsetenv DBUS_SESSION_BUS_ADDRESS
56+
# Set VNCSESSION to tell /etc/xdg/xfce4/xinitrc to not run xscreensaver
57+
# http://vstone.eu/2009/04/disabling-xscreensaver-when-using-xfce-vnc/
58+
setenv VNCSESSION yes
59+
startxfce4 &
60+
# Make sure that copy / paste are correctly forwarded to the VNC viewer
61+
vncconfig -nowin &
62+
EOF
63+
chmod +x /home/work/.vnc/xstartup
64+
65+
cat >/home/work/.xscreensaver <<EOF
66+
mode: off
67+
EOF
68+
69+
chown -R $LOCAL_USER_ID:$LOCAL_GROUP_ID /home/work
70+
#/opt/kernel/su-exec $LOCAL_USER_ID:$LOCAL_GROUP_ID /usr/bin/vncserver -geometry 1600x1200
71+
72+
#echo ">> VNC server is started."
73+
74+
supervisord -c /etc/supervisor/supervisord.conf
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
server {
2+
listen 80 default_server;
3+
4+
root /usr/local/lib/web/frontend;
5+
index index.html index.htm;
6+
7+
location ~ /api/ {
8+
try_files $uri @api;
9+
}
10+
11+
location ~ /resize$ {
12+
try_files $uri @api;
13+
}
14+
15+
location ~ /websockify$ {
16+
proxy_http_version 1.1;
17+
proxy_set_header Upgrade $http_upgrade;
18+
proxy_set_header Connection "upgrade";
19+
proxy_buffering off;
20+
proxy_connect_timeout 7d;
21+
proxy_send_timeout 7d;
22+
proxy_read_timeout 7d;
23+
proxy_pass http://127.0.0.1:6081;
24+
}
25+
26+
location @api {
27+
proxy_set_header X-Real-IP $remote_addr;
28+
proxy_set_header X-Forwarded-For $remote_addr;
29+
proxy_set_header Host $host;
30+
proxy_pass http://127.0.0.1:6079;
31+
max_ranges 0;
32+
}
33+
34+
#location / {
35+
# proxy_pass http://127.0.0.1:6081;
36+
#}
37+
}
38+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[supervisord]
2+
redirect_stderr=true
3+
stopsignal=QUIT
4+
autorestart=true
5+
directory=/root
6+
7+
[program:nginx]
8+
priority=10
9+
command=nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
10+
11+
[program:web]
12+
priority=10
13+
directory=/usr/local/lib/web/backend
14+
command=/usr/local/lib/web/backend/run.py
15+
#stdout_logfile=/dev/fd/1
16+
#stdout_logfile_maxbytes=0
17+
#stderr_logfile=/dev/fd/1
18+
#stderr_logfile_maxbytes=0
19+
20+
[group:x]
21+
programs=xvfb,lxpanel,x11vnc,novnc
22+
23+
[program:lxpanel]
24+
priority=15
25+
directory=%HOME%
26+
command=/usr/bin/startxfce4
27+
user=%USER%
28+
environment=DISPLAY=":1",HOME="%HOME%",USER="%USER%"
29+
30+
[program:xvfb]
31+
priority=10
32+
command=/usr/local/bin/xvfb.sh
33+
stopsignal=KILL
34+
35+
[program:x11vnc]
36+
priority=20
37+
command=x11vnc -display :1 -xkb -forever -shared -repeat -ncache 10
38+
39+
[program:novnc]
40+
priority=25
41+
directory=/usr/local/lib/web/frontend/static/novnc
42+
command=bash /usr/local/lib/web/frontend/static/novnc/utils/launch.sh --listen 6081
43+
stopasgroup=true

ubuntu/rootfs/root/.asoundrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pcm.loop {
2+
type plug
3+
slave.pcm "hw:Loopback,2,0"
4+
}

ubuntu/rootfs/root/.gtkrc-2.0

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# DO NOT EDIT! This file will be overwritten by LXAppearance.
2+
# Any customization should be done in ~/.gtkrc-2.0.mine instead.
3+
include "/usr/share/themes/Arc/gtk-2.0/gtkrc"
4+
5+
gtk-theme-name="Arc"
6+
gtk-icon-theme-name="nuoveXT2"
7+
gtk-font-name="Sans 10"
8+
gtk-cursor-theme-name="DMZ-White"
9+
gtk-cursor-theme-size=18
10+
gtk-toolbar-style=GTK_TOOLBAR_BOTH_HORIZ
11+
gtk-toolbar-icon-size=GTK_ICON_SIZE_LARGE_TOOLBAR
12+
gtk-button-images=1
13+
gtk-menu-images=1
14+
gtk-enable-event-sounds=1
15+
gtk-enable-input-feedback-sounds=1
16+
gtk-xft-antialias=1
17+
gtk-xft-hinting=1
18+
gtk-xft-hintstyle="hintslight"
19+
gtk-xft-rgba="rgb"
20+
include "/root/.gtkrc-2.0.mine"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
if [ -z "$ALSADEV" ]; then
4+
zenity --error --text "To support audio, please read README.md and run container with --device /dev/snd -e ALSADEV=..."
5+
exit 1
6+
fi
7+
8+
exec /usr/bin/chromium-browser --no-sandbox --alsa-output-device="$ALSADEV" "$@"

ubuntu/rootfs/usr/local/bin/xvfb.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
exec /usr/bin/Xvfb :1 -screen 0 1024x768x24

0 commit comments

Comments
 (0)