Skip to content

Commit 12b6fe9

Browse files
committed
feat: support video mode
1 parent 44c1f26 commit 12b6fe9

File tree

267 files changed

+9303
-37472
lines changed

Some content is hidden

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

267 files changed

+9303
-37472
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web/node_modules

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
tags
3+
cscope*

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "web/static/novnc"]
2+
path = web/static/novnc
3+
url = https://github.com/novnc/noVNC
4+
[submodule "web/static/websockify"]
5+
path = web/static/websockify
6+
url = https://github.com/novnc/websockify

DEVELOPMENT.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Run in local
2+
```
3+
make build
4+
make run
5+
```
6+
7+
## develop backend
8+
```
9+
make shell
10+
supervisorctl stop web
11+
cd /src/image/usr/local/lib/web/backend
12+
./run.py --debug
13+
```
14+
15+
## develop frontend
16+
```
17+
cd web
18+
yarn add
19+
BACKEND=http://127.0.0.1:6080 npm run dev
20+
```

Dockerfile

+66-19
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
FROM ubuntu:16.04
2-
LABEL maintainer="fcwu.tw@gmail.com"
1+
################################################################################
2+
# base system
3+
################################################################################
4+
FROM ubuntu:16.04 as system
35

4-
RUN sed -i 's#http://archive.ubuntu.com/#http://tw.archive.ubuntu.com/#' /etc/apt/sources.list
6+
ARG localbuild
7+
RUN if [ "x$localbuild" != "x" ]; then sed -i 's#http://archive.ubuntu.com/#http://qnap.dorowu.com/#' /etc/apt/sources.list; fi
58

69
# built-in packages
710
RUN apt-get update \
811
&& apt-get install -y --no-install-recommends software-properties-common curl apache2-utils \
912
&& add-apt-repository ppa:fcwu-tw/apps \
1013
&& apt-get update \
1114
&& apt-get install -y --no-install-recommends --allow-unauthenticated \
12-
supervisor \
13-
sudo vim-tiny \
14-
net-tools \
15-
lxde x11vnc xvfb \
16-
gtk2-engines-murrine ttf-ubuntu-font-family \
17-
libreoffice firefox \
18-
fonts-wqy-microhei \
19-
language-pack-zh-hant language-pack-gnome-zh-hant firefox-locale-zh-hant libreoffice-l10n-zh-tw \
20-
nginx \
21-
python-pip python-dev build-essential \
15+
supervisor nginx sudo vim-tiny net-tools zenity xz-utils \
16+
dbus-x11 x11-utils alsa-utils \
2217
mesa-utils libgl1-mesa-dri \
23-
gnome-themes-standard gtk2-engines-pixbuf gtk2-engines-murrine pinta arc-theme \
24-
dbus-x11 x11-utils \
18+
lxde x11vnc xvfb \
19+
gtk2-engines-murrine gnome-themes-standard gtk2-engines-pixbuf gtk2-engines-murrine arc-theme \
20+
firefox chromium-browser \
21+
ttf-ubuntu-font-family ttf-wqy-zenhei \
22+
&& add-apt-repository -r ppa:fcwu-tw/apps \
2523
&& apt-get autoclean \
2624
&& apt-get autoremove \
2725
&& rm -rf /var/lib/apt/lists/*
28-
26+
# Additional packages require ~600MB
27+
# libreoffice pinta language-pack-zh-hant language-pack-gnome-zh-hant firefox-locale-zh-hant libreoffice-l10n-zh-tw
2928

3029
# tini for subreap
3130
ARG TINI_VERSION=v0.9.0
@@ -36,9 +35,57 @@ RUN chmod +x /bin/tini
3635
RUN mkdir -p /usr/local/ffmpeg \
3736
&& curl -sSL https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-64bit-static.tar.xz | tar xJvf - -C /usr/local/ffmpeg/ --strip 1
3837

39-
ADD image/usr/local/lib/web/backend/requirements.txt /tmp/
40-
RUN pip install setuptools wheel && pip install -r /tmp/requirements.txt
41-
ADD image /
38+
# python library
39+
COPY image/usr/local/lib/web/backend/requirements.txt /tmp/
40+
RUN apt-get update \
41+
&& dpkg-query -W -f='${Package}\n' > /tmp/a.txt \
42+
&& apt-get install -y python-pip python-dev build-essential \
43+
&& pip install setuptools wheel && pip install -r /tmp/requirements.txt \
44+
&& dpkg-query -W -f='${Package}\n' > /tmp/b.txt \
45+
&& apt-get remove -y `diff --changed-group-format='%>' --unchanged-group-format='' /tmp/a.txt /tmp/b.txt | xargs` \
46+
&& apt-get autoclean -y \
47+
&& apt-get autoremove -y \
48+
&& rm -rf /var/lib/apt/lists/* \
49+
&& rm -rf /var/cache/apt/* /tmp/a.txt /tmp/b.txt
50+
51+
52+
################################################################################
53+
# builder
54+
################################################################################
55+
FROM ubuntu:16.04 as builder
56+
57+
ARG localbuild
58+
RUN if [ "x$localbuild" != "x" ]; then sed -i 's#http://archive.ubuntu.com/#http://qnap.dorowu.com/#' /etc/apt/sources.list; fi
59+
60+
RUN apt-get update \
61+
&& apt-get install -y --no-install-recommends curl ca-certificates
62+
63+
# nodejs
64+
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash - \
65+
&& apt-get install -y nodejs
66+
67+
# yarn
68+
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
69+
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
70+
&& apt-get update \
71+
&& apt-get install -y yarn
72+
73+
# build frontend
74+
COPY web /src/web
75+
RUN cd /src/web \
76+
&& yarn \
77+
&& npm run build
78+
79+
80+
################################################################################
81+
# merge
82+
################################################################################
83+
FROM scratch
84+
LABEL maintainer="fcwu.tw@gmail.com"
85+
86+
COPY --from=system / /
87+
COPY --from=builder /src/web/dist/ /usr/local/lib/web/frontend/
88+
COPY image /
4289

4390
EXPOSE 80
4491
WORKDIR /root

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ REPO ?= dorowu/ubuntu-desktop-lxde-vnc
44
TAG ?= latest
55

66
build:
7-
docker build -t $(REPO):$(TAG) .
7+
docker build -t $(REPO):$(TAG) --build-arg localbuild=1 .
88

99
run:
1010
docker run --rm \
@@ -13,8 +13,8 @@ run:
1313
-e USER=doro -e PASSWORD=mypassword \
1414
-e ALSADEV=hw:2,0 \
1515
-e SSL_PORT=443 \
16-
-e HTTP_PASSWORD=mypassword \
1716
-v ${PWD}/ssl:/etc/nginx/ssl \
17+
--device /dev/snd \
1818
--name ubuntu-desktop-lxde-test \
1919
$(REPO):$(TAG)
2020

README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ The Resolution of virtual desktop adapts browser window size when first connecti
7272
docker run -p 6080:80 -e RESOLUTION=1920x1080 dorowu/ubuntu-desktop-lxde-vnc
7373
```
7474

75-
7675
Default Desktop User
7776
--------------------
7877

@@ -82,6 +81,30 @@ The default user is `root`. You may change the user and password respectively by
8281
docker run -p 6080:80 -e USER=doro -e PASSWORD=password dorowu/ubuntu-desktop-lxde-vnc
8382
```
8483

84+
Sound (Preview version and Linux only)
85+
-------------------
86+
87+
It only works in Linux.
88+
89+
First of all, insert kernel module `snd-aloop` and specify `2` as the index of sound loop device
90+
91+
```
92+
sudo modprobe snd-aloop index=2
93+
```
94+
95+
Start the container
96+
97+
```
98+
docker run -it --rm -p 6080:80 --device /dev/snd -e ALSADEV=hw:2,0 dorowu/ubuntu-desktop-lxde-vnc
99+
```
100+
101+
where `--device /dev/snd -e ALSADEV=hw:2,0` means to grant sound device to container and set basic ASLA config to use card 2.
102+
103+
Launch a browser with URL http://127.0.0.1:6080/#/?video, where `video` means to start with video mode. Now you can start Chromium in start menu (Internet -> Chromium Web Browser Sound) and try to play some video.
104+
105+
[![demo](http://img.youtube.com/vi/Kv9FGClP1-k/0.jpg)](http://www.youtube.com/watch?v=Kv9FGClP1-k)
106+
107+
85108
Troubleshooting and FAQ
86109
==================
87110

image/etc/nginx/sites-enabled/default

+8-20
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,21 @@ server {
1010
#_HTTP_PASSWORD_#auth_basic "Private Property";
1111
#_HTTP_PASSWORD_#auth_basic_user_file /etc/nginx/.htpasswd;
1212

13-
root /usr/share/nginx/html;
13+
root /usr/local/lib/web/frontend/;
1414
index index.html index.htm;
1515

16-
location / {
17-
try_files $uri @proxy;
18-
}
19-
20-
location = / {
21-
try_files $uri @proxy2;
22-
}
23-
2416
location ~ ^/api {
25-
try_files $uri @proxy2;
17+
try_files $uri @api;
2618
}
2719

28-
location = /redirect.html {
29-
try_files $uri @proxy2;
20+
location = /websockify {
21+
proxy_http_version 1.1;
22+
proxy_set_header Upgrade $http_upgrade;
23+
proxy_set_header Connection "upgrade";
24+
proxy_pass http://127.0.0.1:6081;
3025
}
3126

32-
location @proxy2 {
27+
location @api {
3328
proxy_set_header X-Real-IP $remote_addr;
3429
proxy_set_header X-Forwarded-For $remote_addr;
3530
proxy_set_header Host $host;
@@ -44,11 +39,4 @@ server {
4439
proxy_pass http://127.0.0.1:6081;
4540
max_ranges 0;
4641
}
47-
48-
location = /websockify {
49-
proxy_http_version 1.1;
50-
proxy_set_header Upgrade $http_upgrade;
51-
proxy_set_header Connection "upgrade";
52-
proxy_pass http://127.0.0.1:6081;
53-
}
5442
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ directory=/usr/local/lib/web/backend
1414
command=/usr/local/lib/web/backend/run.py
1515
stdout_logfile=/dev/fd/1
1616
stdout_logfile_maxbytes=0
17+
stderr_logfile=/dev/fd/1
18+
stderr_logfile_maxbytes=0
1719

1820
[group:x]
1921
programs=xvfb,wm,lxpanel,pcmanfm,x11vnc,novnc
@@ -48,6 +50,6 @@ command=x11vnc -display :1 -xkb -forever -shared -repeat
4850

4951
[program:novnc]
5052
priority=25
51-
directory=/usr/local/lib/novnc/
52-
command=/usr/local/lib/novnc/utils/launch.sh --listen 6081
53+
directory=/usr/local/lib/web/frontend/static/novnc
54+
command=bash /usr/local/lib/web/frontend/static/novnc/utils/launch.sh --listen 6081
5355
stopasgroup=true

image/root/.asoundrc

+4
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+
}

image/startup.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ if [ "$USER" != "root" ]; then
2323
fi
2424
HOME=/home/$USER
2525
echo "$USER:$PASSWORD" | chpasswd
26-
cp -r /root/.* ${HOME}
26+
cp -r /root/{.gtkrc-2.0,.asoundrc} ${HOME}
27+
[ -d "/dev/snd" ] && chgrp -R adm /dev/snd
2728
fi
2829
sed -i "s|%USER%|$USER|" /etc/supervisor/conf.d/supervisord.conf
2930
sed -i "s|%HOME%|$HOME|" /etc/supervisor/conf.d/supervisord.conf
@@ -50,6 +51,10 @@ if [ -n "$HTTP_PASSWORD" ]; then
5051
sed -i 's|#_HTTP_PASSWORD_#||' /etc/nginx/sites-enabled/default
5152
fi
5253

54+
# novnc websockify
55+
ln -s /usr/local/lib/web/frontend/static/websockify /usr/local/lib/web/frontend/static/novnc/utils/websockify
56+
chmod +x /usr/local/lib/web/frontend/static/websockify/run
57+
5358
# clearup
5459
PASSWORD=
5560
HTTP_PASSWORD=
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" "$@"

image/usr/local/lib/novnc/.gitlastcommit

-1
This file was deleted.

image/usr/local/lib/novnc/.npmignore

-20
This file was deleted.

image/usr/local/lib/novnc/.travis.yml

-20
This file was deleted.

image/usr/local/lib/novnc/CONTRIBUTING.md

-54
This file was deleted.

0 commit comments

Comments
 (0)