Skip to content

Commit

Permalink
feat: support video mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dorowu-qnap committed Mar 27, 2018
1 parent 44c1f26 commit 12b6fe9
Show file tree
Hide file tree
Showing 267 changed files with 9,303 additions and 37,472 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web/node_modules
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
tags
cscope*
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "web/static/novnc"]
path = web/static/novnc
url = https://github.com/novnc/noVNC
[submodule "web/static/websockify"]
path = web/static/websockify
url = https://github.com/novnc/websockify
20 changes: 20 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Run in local
```
make build
make run
```

## develop backend
```
make shell
supervisorctl stop web
cd /src/image/usr/local/lib/web/backend
./run.py --debug
```

## develop frontend
```
cd web
yarn add
BACKEND=http://127.0.0.1:6080 npm run dev
```
85 changes: 66 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
FROM ubuntu:16.04
LABEL maintainer="[email protected]"
################################################################################
# base system
################################################################################
FROM ubuntu:16.04 as system

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

# built-in packages
RUN apt-get update \
&& apt-get install -y --no-install-recommends software-properties-common curl apache2-utils \
&& add-apt-repository ppa:fcwu-tw/apps \
&& apt-get update \
&& apt-get install -y --no-install-recommends --allow-unauthenticated \
supervisor \
sudo vim-tiny \
net-tools \
lxde x11vnc xvfb \
gtk2-engines-murrine ttf-ubuntu-font-family \
libreoffice firefox \
fonts-wqy-microhei \
language-pack-zh-hant language-pack-gnome-zh-hant firefox-locale-zh-hant libreoffice-l10n-zh-tw \
nginx \
python-pip python-dev build-essential \
supervisor nginx sudo vim-tiny net-tools zenity xz-utils \
dbus-x11 x11-utils alsa-utils \
mesa-utils libgl1-mesa-dri \
gnome-themes-standard gtk2-engines-pixbuf gtk2-engines-murrine pinta arc-theme \
dbus-x11 x11-utils \
lxde x11vnc xvfb \
gtk2-engines-murrine gnome-themes-standard gtk2-engines-pixbuf gtk2-engines-murrine arc-theme \
firefox chromium-browser \
ttf-ubuntu-font-family ttf-wqy-zenhei \
&& add-apt-repository -r ppa:fcwu-tw/apps \
&& apt-get autoclean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/*

# Additional packages require ~600MB
# libreoffice pinta language-pack-zh-hant language-pack-gnome-zh-hant firefox-locale-zh-hant libreoffice-l10n-zh-tw

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

ADD image/usr/local/lib/web/backend/requirements.txt /tmp/
RUN pip install setuptools wheel && pip install -r /tmp/requirements.txt
ADD image /
# python library
COPY image/usr/local/lib/web/backend/requirements.txt /tmp/
RUN apt-get update \
&& dpkg-query -W -f='${Package}\n' > /tmp/a.txt \
&& apt-get install -y python-pip python-dev build-essential \
&& pip install setuptools wheel && pip install -r /tmp/requirements.txt \
&& dpkg-query -W -f='${Package}\n' > /tmp/b.txt \
&& apt-get remove -y `diff --changed-group-format='%>' --unchanged-group-format='' /tmp/a.txt /tmp/b.txt | xargs` \
&& apt-get autoclean -y \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /var/cache/apt/* /tmp/a.txt /tmp/b.txt


################################################################################
# builder
################################################################################
FROM ubuntu:16.04 as builder

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

RUN apt-get update \
&& apt-get install -y --no-install-recommends curl ca-certificates

# nodejs
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash - \
&& apt-get install -y nodejs

# yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-get update \
&& apt-get install -y yarn

# build frontend
COPY web /src/web
RUN cd /src/web \
&& yarn \
&& npm run build


################################################################################
# merge
################################################################################
FROM scratch
LABEL maintainer="[email protected]"

COPY --from=system / /
COPY --from=builder /src/web/dist/ /usr/local/lib/web/frontend/
COPY image /

EXPOSE 80
WORKDIR /root
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ REPO ?= dorowu/ubuntu-desktop-lxde-vnc
TAG ?= latest

build:
docker build -t $(REPO):$(TAG) .
docker build -t $(REPO):$(TAG) --build-arg localbuild=1 .

run:
docker run --rm \
Expand All @@ -13,8 +13,8 @@ run:
-e USER=doro -e PASSWORD=mypassword \
-e ALSADEV=hw:2,0 \
-e SSL_PORT=443 \
-e HTTP_PASSWORD=mypassword \
-v ${PWD}/ssl:/etc/nginx/ssl \
--device /dev/snd \
--name ubuntu-desktop-lxde-test \
$(REPO):$(TAG)

Expand Down
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ The Resolution of virtual desktop adapts browser window size when first connecti
docker run -p 6080:80 -e RESOLUTION=1920x1080 dorowu/ubuntu-desktop-lxde-vnc
```


Default Desktop User
--------------------

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

Sound (Preview version and Linux only)
-------------------

It only works in Linux.

First of all, insert kernel module `snd-aloop` and specify `2` as the index of sound loop device

```
sudo modprobe snd-aloop index=2
```

Start the container

```
docker run -it --rm -p 6080:80 --device /dev/snd -e ALSADEV=hw:2,0 dorowu/ubuntu-desktop-lxde-vnc
```

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.

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.

[![demo](http://img.youtube.com/vi/Kv9FGClP1-k/0.jpg)](http://www.youtube.com/watch?v=Kv9FGClP1-k)


Troubleshooting and FAQ
==================

Expand Down
28 changes: 8 additions & 20 deletions image/etc/nginx/sites-enabled/default
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,21 @@ server {
#_HTTP_PASSWORD_#auth_basic "Private Property";
#_HTTP_PASSWORD_#auth_basic_user_file /etc/nginx/.htpasswd;

root /usr/share/nginx/html;
root /usr/local/lib/web/frontend/;
index index.html index.htm;

location / {
try_files $uri @proxy;
}

location = / {
try_files $uri @proxy2;
}

location ~ ^/api {
try_files $uri @proxy2;
try_files $uri @api;
}

location = /redirect.html {
try_files $uri @proxy2;
location = /websockify {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:6081;
}

location @proxy2 {
location @api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
Expand All @@ -44,11 +39,4 @@ server {
proxy_pass http://127.0.0.1:6081;
max_ranges 0;
}

location = /websockify {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:6081;
}
}
6 changes: 4 additions & 2 deletions image/etc/supervisor/conf.d/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ directory=/usr/local/lib/web/backend
command=/usr/local/lib/web/backend/run.py
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/1
stderr_logfile_maxbytes=0

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

[program:novnc]
priority=25
directory=/usr/local/lib/novnc/
command=/usr/local/lib/novnc/utils/launch.sh --listen 6081
directory=/usr/local/lib/web/frontend/static/novnc
command=bash /usr/local/lib/web/frontend/static/novnc/utils/launch.sh --listen 6081
stopasgroup=true
4 changes: 4 additions & 0 deletions image/root/.asoundrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pcm.loop {
type plug
slave.pcm "hw:Loopback,2,0"
}
7 changes: 6 additions & 1 deletion image/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ if [ "$USER" != "root" ]; then
fi
HOME=/home/$USER
echo "$USER:$PASSWORD" | chpasswd
cp -r /root/.* ${HOME}
cp -r /root/{.gtkrc-2.0,.asoundrc} ${HOME}
[ -d "/dev/snd" ] && chgrp -R adm /dev/snd
fi
sed -i "s|%USER%|$USER|" /etc/supervisor/conf.d/supervisord.conf
sed -i "s|%HOME%|$HOME|" /etc/supervisor/conf.d/supervisord.conf
Expand All @@ -50,6 +51,10 @@ if [ -n "$HTTP_PASSWORD" ]; then
sed -i 's|#_HTTP_PASSWORD_#||' /etc/nginx/sites-enabled/default
fi

# novnc websockify
ln -s /usr/local/lib/web/frontend/static/websockify /usr/local/lib/web/frontend/static/novnc/utils/websockify
chmod +x /usr/local/lib/web/frontend/static/websockify/run

# clearup
PASSWORD=
HTTP_PASSWORD=
Expand Down
8 changes: 8 additions & 0 deletions image/usr/local/bin/chromium-browser-sound.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

if [ -z "$ALSADEV" ]; then
zenity --error --text "To support audio, please read README.md and run container with --device /dev/snd -e ALSADEV=..."
exit 1
fi

exec /usr/bin/chromium-browser --no-sandbox --alsa-output-device="$ALSADEV" "$@"
1 change: 0 additions & 1 deletion image/usr/local/lib/novnc/.gitlastcommit

This file was deleted.

20 changes: 0 additions & 20 deletions image/usr/local/lib/novnc/.npmignore

This file was deleted.

20 changes: 0 additions & 20 deletions image/usr/local/lib/novnc/.travis.yml

This file was deleted.

54 changes: 0 additions & 54 deletions image/usr/local/lib/novnc/CONTRIBUTING.md

This file was deleted.

Loading

0 comments on commit 12b6fe9

Please sign in to comment.