mirror of
https://github.com/fcwu/docker-ubuntu-vnc-desktop
synced 2025-12-06 08:22:31 +01:00
Add ENV variable PREFIX_PATH to backend and web project
This commit is contained in:
parent
f26fe29012
commit
175d7a8517
10 changed files with 49 additions and 25 deletions
|
|
@ -94,7 +94,7 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get install -y yarn
|
&& apt-get install -y yarn
|
||||||
|
|
||||||
ENV PREFIX_PATH = "APP"
|
ENV PREFIX_PATH "/app"
|
||||||
|
|
||||||
# build frontend
|
# build frontend
|
||||||
COPY web /src/web
|
COPY web /src/web
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,19 @@ server {
|
||||||
root /usr/local/lib/web/frontend/;
|
root /usr/local/lib/web/frontend/;
|
||||||
index index.html index.htm;
|
index index.html index.htm;
|
||||||
|
|
||||||
location ~ ^/APP/api {
|
location = /app {
|
||||||
|
try_files $uri @rewrites;
|
||||||
|
}
|
||||||
|
|
||||||
|
location @rewrites {
|
||||||
|
rewrite ^(.+)$ /index.html last;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ ^/app/api {
|
||||||
try_files $uri @api;
|
try_files $uri @api;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = /APP/websockify {
|
location = /app/websockify {
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@ directory=/root
|
||||||
[program:nginx]
|
[program:nginx]
|
||||||
priority=10
|
priority=10
|
||||||
command=nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
|
command=nginx -c /etc/nginx/nginx.conf -g 'daemon off;'
|
||||||
|
stdout_logfile=/dev/fd/1
|
||||||
|
stdout_logfile_maxbytes=0
|
||||||
|
stderr_logfile=/dev/fd/1
|
||||||
|
stderr_logfile_maxbytes=0
|
||||||
|
|
||||||
[program:web]
|
[program:web]
|
||||||
priority=10
|
priority=10
|
||||||
|
|
@ -41,8 +45,6 @@ user=%USER%
|
||||||
environment=DISPLAY=":1",HOME="%HOME%",USER="%USER%"
|
environment=DISPLAY=":1",HOME="%HOME%",USER="%USER%"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[program:xvfb]
|
[program:xvfb]
|
||||||
priority=10
|
priority=10
|
||||||
command=/usr/local/bin/xvfb.sh
|
command=/usr/local/bin/xvfb.sh
|
||||||
|
|
@ -52,8 +54,10 @@ stopsignal=KILL
|
||||||
priority=20
|
priority=20
|
||||||
command=x11vnc -display :1 -xkb -forever -shared -repeat
|
command=x11vnc -display :1 -xkb -forever -shared -repeat
|
||||||
|
|
||||||
|
|
||||||
[program:novnc]
|
[program:novnc]
|
||||||
priority=25
|
priority=25
|
||||||
directory=/usr/local/lib/web/frontend/static/novnc
|
directory=/usr/local/lib/web/frontend%(ENV_PREFIX_PATH)s/static/novnc
|
||||||
command=bash /usr/local/lib/web/frontend/static/novnc/utils/launch.sh --listen 6081
|
command=bash /usr/local/lib/web/frontend%(ENV_PREFIX_PATH)s/static/novnc/utils/launch.sh --listen 6081
|
||||||
stopasgroup=true
|
stopasgroup=true
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@ if [ -n "$HTTP_PASSWORD" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# novnc websockify
|
# novnc websockify
|
||||||
ln -s /usr/local/lib/web/frontend/static/websockify /usr/local/lib/web/frontend/static/novnc/utils/websockify
|
ln -s "/usr/local/lib/web/frontend$PREFIX_PATH/static/websockify" "/usr/local/lib/web/frontend$PREFIX_PATH/static/novnc/utils/websockify"
|
||||||
chmod +x /usr/local/lib/web/frontend/static/websockify/run
|
chmod +x "/usr/local/lib/web/frontend$PREFIX_PATH/static/websockify/run"
|
||||||
|
|
||||||
# clearup
|
# clearup
|
||||||
PASSWORD=
|
PASSWORD=
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,14 @@ from __future__ import (
|
||||||
absolute_import, division, print_function, with_statement
|
absolute_import, division, print_function, with_statement
|
||||||
)
|
)
|
||||||
import re
|
import re
|
||||||
from os import environ
|
import os
|
||||||
from flask import (
|
from flask import (
|
||||||
Flask,
|
Flask,
|
||||||
request,
|
request,
|
||||||
Response,
|
Response,
|
||||||
jsonify,
|
jsonify,
|
||||||
abort,
|
abort,
|
||||||
|
url_for,
|
||||||
)
|
)
|
||||||
from gevent import subprocess as gsp, spawn, sleep
|
from gevent import subprocess as gsp, spawn, sleep
|
||||||
from geventwebsocket.exceptions import WebSocketError
|
from geventwebsocket.exceptions import WebSocketError
|
||||||
|
|
@ -21,12 +22,14 @@ from .log import log
|
||||||
# Flask app
|
# Flask app
|
||||||
app = Flask('novnc2')
|
app = Flask('novnc2')
|
||||||
app.config.from_object('config.Default')
|
app.config.from_object('config.Default')
|
||||||
app.config.from_object(environ.get('CONFIG') or 'config.Development')
|
app.config.from_object(os.environ.get('CONFIG') or 'config.Development')
|
||||||
|
|
||||||
|
PREFIX = os.getenv("PREFIX_PATH")
|
||||||
|
|
||||||
@app.route('/api/state')
|
@app.route(PREFIX+'/api/state')
|
||||||
@httperror
|
@httperror
|
||||||
def apistate():
|
def apistate():
|
||||||
|
print(url_for("apistate"))
|
||||||
state.wait(int(request.args.get('id', -1)), 30)
|
state.wait(int(request.args.get('id', -1)), 30)
|
||||||
state.switch_video(request.args.get('video', 'false') == 'true')
|
state.switch_video(request.args.get('video', 'false') == 'true')
|
||||||
mystate = state.to_dict()
|
mystate = state.to_dict()
|
||||||
|
|
@ -36,14 +39,15 @@ def apistate():
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/health')
|
@app.route(PREFIX+'/api/health')
|
||||||
def apihealth():
|
def apihealth():
|
||||||
|
print(url_for("apihealth"))
|
||||||
if state.health:
|
if state.health:
|
||||||
return 'success'
|
return 'success'
|
||||||
abort(503, 'unhealthy')
|
abort(503, 'unhealthy')
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/reset')
|
@app.route(PREFIX+'/api/reset')
|
||||||
def reset():
|
def reset():
|
||||||
if 'w' in request.args and 'h' in request.args:
|
if 'w' in request.args and 'h' in request.args:
|
||||||
args = {
|
args = {
|
||||||
|
|
@ -68,7 +72,7 @@ def reset():
|
||||||
return jsonify({'code': 200})
|
return jsonify({'code': 200})
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/live.flv')
|
@app.route(PREFIX+'/api/live.flv')
|
||||||
@httperror
|
@httperror
|
||||||
def liveflv():
|
def liveflv():
|
||||||
def generate():
|
def generate():
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,6 @@ const merge = require('webpack-merge')
|
||||||
const prodEnv = require('./prod.env')
|
const prodEnv = require('./prod.env')
|
||||||
|
|
||||||
module.exports = merge(prodEnv, {
|
module.exports = merge(prodEnv, {
|
||||||
NODE_ENV: '"development"'
|
NODE_ENV: '"development"',
|
||||||
|
PREFIX_PATH: '"/app"'
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const BACKEND = process.env.BACKEND || 'http://127.0.0.1:6080'
|
const BACKEND = process.env.BACKEND || 'http://127.0.0.1:6080'
|
||||||
|
|
||||||
const PREFIX_PATH = process.env.PREFIX_PATH
|
const PREFIX_PATH = process.env.PREFIX_PATH || '/app'
|
||||||
|
|
||||||
|
console.log(`within /config/index.js: ${process.env.PREFIX_PATH}`)
|
||||||
|
|
||||||
const api_key = `${PREFIX_PATH}/api`
|
const api_key = `${PREFIX_PATH}/api`
|
||||||
const websockify_key = `${PREFIX_PATH}/websockfiy`
|
const websockify_key = `${PREFIX_PATH}/websockfiy`
|
||||||
|
|
@ -67,7 +69,7 @@ module.exports = {
|
||||||
|
|
||||||
// Paths
|
// Paths
|
||||||
assetsRoot: path.resolve(__dirname, '../dist'),
|
assetsRoot: path.resolve(__dirname, '../dist'),
|
||||||
assetsSubDirectory: 'static',
|
assetsSubDirectory: PREFIX_PATH.substr(1)+'/static',
|
||||||
assetsPublicPath: '/',
|
assetsPublicPath: '/',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
module.exports = {
|
module.exports = {
|
||||||
NODE_ENV: '"production"'
|
NODE_ENV: '"production"',
|
||||||
|
PREFIX_PATH: '"/app"'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ export default {
|
||||||
'h': h
|
'h': h
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const response = await this.$http.get(process.env.PREFIX_PATH + '/api/state', {params: params})
|
const response = await this.$http.get(`${process.env.PREFIX_PATH}` + '/api/state', {params: params})
|
||||||
const body = response.data
|
const body = response.data
|
||||||
if (body.code !== 200) {
|
if (body.code !== 200) {
|
||||||
this.stateErrorCount += 1
|
this.stateErrorCount += 1
|
||||||
|
|
@ -71,7 +71,7 @@ export default {
|
||||||
|
|
||||||
// adaptive resolution
|
// adaptive resolution
|
||||||
if (!body.data.config.fixedResolution && body.data.config.sizeChangedCount === 0) {
|
if (!body.data.config.fixedResolution && body.data.config.sizeChangedCount === 0) {
|
||||||
const response = await this.$http.get(process.env.PREFIX_PATH + '/api/reset', {params: params})
|
const response = await this.$http.get(`${process.env.PREFIX_PATH}` + '/api/reset', {params: params})
|
||||||
const body = response.data
|
const body = response.data
|
||||||
if (body.code !== 200) {
|
if (body.code !== 200) {
|
||||||
this.stateErrorCount += 1
|
this.stateErrorCount += 1
|
||||||
|
|
@ -136,7 +136,9 @@ export default {
|
||||||
// console.trace()
|
// console.trace()
|
||||||
console.log(`connecting...`)
|
console.log(`connecting...`)
|
||||||
this.errorMessage = ''
|
this.errorMessage = ''
|
||||||
let websockifyPath = process.env.PREFIX_PATH + '/websockify'
|
let prefixName = `${process.env.PREFIX_PATH}`.substr(1)
|
||||||
|
console.log(prefixName)
|
||||||
|
let websockifyPath = prefixName + '/websockify'
|
||||||
if (force || this.vncState === 'stopped') {
|
if (force || this.vncState === 'stopped') {
|
||||||
this.vncState = 'connecting'
|
this.vncState = 'connecting'
|
||||||
let hostname = window.location.hostname
|
let hostname = window.location.hostname
|
||||||
|
|
@ -144,7 +146,7 @@ export default {
|
||||||
if (!port) {
|
if (!port) {
|
||||||
port = window.location.protocol[4] === 's' ? 443 : 80
|
port = window.location.protocol[4] === 's' ? 443 : 80
|
||||||
}
|
}
|
||||||
let url = 'static/vnc.html?'
|
let url = prefixName + '/static/vnc.html?'
|
||||||
url += 'autoconnect=1&'
|
url += 'autoconnect=1&'
|
||||||
url += `host=${hostname}&port=${port}&`
|
url += `host=${hostname}&port=${port}&`
|
||||||
url += `path=${websockifyPath}&title=novnc2&`
|
url += `path=${websockifyPath}&title=novnc2&`
|
||||||
|
|
@ -155,7 +157,7 @@ export default {
|
||||||
if (force || this.videoState === 'stopped') {
|
if (force || this.videoState === 'stopped') {
|
||||||
const w = this.$refs.vncFrame.clientWidth
|
const w = this.$refs.vncFrame.clientWidth
|
||||||
const h = this.$refs.vncFrame.clientHeight
|
const h = this.$refs.vncFrame.clientHeight
|
||||||
let url = `static/video.html?width=${w}&height=${h}&base=${window.location.host}`
|
let url = prefixName + `/static/video.html?width=${w}&height=${h}&base=${window.location.host}`
|
||||||
this.$refs.videoFrame.setAttribute('src', url)
|
this.$refs.videoFrame.setAttribute('src', url)
|
||||||
this.videoState = 'connecting'
|
this.videoState = 'connecting'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,11 @@ import Vnc from '@/components/Vnc'
|
||||||
|
|
||||||
Vue.use(Router)
|
Vue.use(Router)
|
||||||
|
|
||||||
|
console.log(`within (router) /src/index.js: ${process.env.PREFIX_PATH}`)
|
||||||
|
|
||||||
export default new Router({
|
export default new Router({
|
||||||
mode: 'history',
|
mode: 'history',
|
||||||
base: process.env.PREFIX_PATH,
|
base: `${process.env.PREFIX_PATH}`,
|
||||||
routes: [
|
routes: [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue