Alpine images

This commit is contained in:
Myve 2024-07-18 21:34:48 +00:00
commit c8bf7daf02
16 changed files with 392 additions and 0 deletions

43
base/Dockerfile Normal file
View file

@ -0,0 +1,43 @@
# syntax = docker/dockerfile:1.2
FROM alpine:edge
USER root
# Build ARG for additional pacman packages to install (eg, openssh)
ARG addpkg
# Copy app folder
COPY app /app
# Install noVNC
RUN printf '%s\n' 'https://dl-cdn.alpinelinux.org/alpine/edge/main/' \
'https://dl-cdn.alpinelinux.org/alpine/edge/community/' \
'https://dl-cdn.alpinelinux.org/alpine/edge/testing/' >/etc/apk/repositories \
&& apk update \
&& apk upgrade \
&& apk add --no-cache ${addpkg} \
doas \
bash bash-completion \
novnc websockify \
nginx \
&& adduser -s /bin/bash -D user \
&& printf '%s' 'permit nopass user as root cmd /usr/sbin/nginx' >/etc/doas.conf \
&& passwd -l root >/dev/null 2>&1 \
&& sed '/^http {/a\ \
include /app/nginx/\*.conf;\n\ \
types_hash_max_size 4096;\n\ \
server_names_hash_bucket_size 128;\n' -i /etc/nginx/nginx.conf \
&& chown -R user /app /usr/share/novnc/
# Default environment
USER user
WORKDIR /home/user
ENV HOME=/home/user
ENV DISPLAY=:0
ENV SHELL=/bin/bash
ENV PS1="[\u@\h \W \$?]\$ "
# Expose nginx port for VNC webui
EXPOSE 6900
# Docker entrypoint
ENTRYPOINT ["/app/entrypoint"]

24
base/app/entrypoint Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Export all variables
set -a
# Abort if an error is encountered
set -e
# SSH config
if [ -f ~/.ssh/id_ed25519 ]
then
chmod 0600 ~/.ssh/id_ed25519
fi
# Run all scripts in init folder
for file in /app/init.d/*.sh
do
/bin/bash -c ${file} >>/app/logs/$(echo ${file} | sed 's|/app/init.d/||;s|\.sh$||').log
done
# Read cli parameters
exec "${@}" &
# Monitor log
tail -f /app/logs/*.log

9
base/app/init.d/01-init.sh Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Create base directories
for dir in vnc config ssh
do
[ -d ~/.${dir} ] || mkdir -p ~/.${dir}
done
## OPTIONAL: More commands may be added below

46
base/app/init.d/10-nginx.sh Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env bash
# Reformat path
if [[ ${MYVNC_PROXYPATH} == "/" ]]
then
unset _MYVNC_PROXYPATH
elif [ ${MYVNC_PROXYPATH} ]
then
_MYVNC_PROXYPATH=$(echo ${MYVNC_PROXYPATH} | sed "s|^/*||g;s|/*$||g;s|/*/|/|g;s|^|/|")
fi
# Add novnc virtual proxy conf
cat >/app/nginx/novnc.conf <<- novnc
upstream vnc_proxy {
server 127.0.0.1:6080;
}
server {
listen 6900;
location ${_MYVNC_PROXYPATH}/websockify {
proxy_http_version 1.1;
proxy_pass http://vnc_proxy/;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
# VNC connection timeout
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
# Disable cache
proxy_buffering off;
}
location ${_MYVNC_PROXYPATH}/ {
index vnc.html;
alias /usr/share/novnc/;
try_files \$uri \$uri/ /vnc.html;
# In the location block related to noVNC
add_header Cache-Control no-cache;
}
}
novnc
# Start nginx
doas /usr/sbin/nginx -g "daemon off;" &

35
base/app/init.d/10-novnc.sh Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Turn vnc sharing on/off
if [[ ${MYVNC_VNCSHARING} == "true" ]] || [[ ${MYVNC_VNCSHARING} == "1" ]]
then
_MYVNC_VNCSHARING=true
else
_MYVNC_VNCSHARING=false
fi
# Always default to remote scaling
sed -i "/UI.initSetting\|resize/ s/resize', '.*');/resize', 'scale');/" /usr/share/novnc/app/ui.js
# Always default to autoconnect=true
sed -i "/let autoconnect/ s/autoconnect', .*);/autoconnect', true);/" /usr/share/novnc/app/ui.js
# Change vnc shared view settings (defaults to false/off)
sed -i "/UI.initSetting\|shared/ s/shared', .*);/shared', ${_MYVNC_VNCSHARING});/" /usr/share/novnc/app/ui.js
# NoVNC custom title
sed -i "/<title>noVNC<\/title>/ s/noVNC/${MYVNC_CUSTOM_TITLE:-noVNC}/g" /usr/share/novnc/*.html
# Apply subpath to websocket
if [[ ${MYVNC_PROXYPATH} == "/" ]]
then
unset _MYVNC_PROXYPATH
elif [ ${MYVNC_PROXYPATH} ]
then
_MYVNC_PROXYPATH=$(echo ${MYVNC_PROXYPATH} | sed "s|^/*||g;s|/*$||g;s|/*/|/|g")
sed -i "/UI.initSetting/ s|websockify|${_MYVNC_PROXYPATH}/&|" /usr/share/novnc/app/ui.js
fi
# Start NoVNC
novnc_server \
--vnc ${MYVNC_VNCSERVER_HOST:-localhost}:${MYVNC_VNCSERVER_PORT:-5900} \
--file-only &

8
base/build Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env bash
# Docker build
# Optional buildtag, addpkg
# addpkg=openssh \
DOCKER_BUILDKIT=1 \
docker build ./. \
--build-arg pkg=${addpkg:-""} \
--tag ${buildtag:-alpine/base}