Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Add Xserver and Pulseaudio (#96)
Browse files Browse the repository at this point in the history
* Add Xserver and Pulseaudio

* Add temp folder

* Add warp-client to ´temp´ folder

* Add warp binary

* Add xserver and pulseaudio

* Fix xserver installation

* add sysbox installation script

* Added dbus xvfb and pulseaudio services

* Fix symlinking

* Fix dbus, xserver and pulseudio startup errors

* Run as user

* Fix build errors for user 'admin'

* test ffmpeg

* Add ffmpeg v6 manually

* Fix ffmpeg version

* Fix ffmpeg

* Fix pulseaudio

* Fix default.pa

* Add non-root user

* Add user-group docker

* Start everything in its own service

* fix xvfb.service

* Fix ffmpeg.sh not running, stuck on Xserver socket

* Fix No.2 for ffmpeg

* Add `ExecStartPre`, might work

* debug

* debug 2

* debug 3

* debug 3

* ffmpeg fix

* Added a fix to sudo

* debug 5

* Remove the dbus service

* Add a FIXME for future me
  • Loading branch information
wanjohiryan committed Sep 27, 2023
1 parent d1e54ab commit ac49d09
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHECKLIST-B4-RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- [x] Xserver, pulseaudio and ffmpeg in base container
- [ ] Add warp client and hook it up to ffmpeg
- [ ] Steam container as a sidecar
- [ ] Input inside base container
- [ ] Launch a test run on AWS:
- [x] Test ffmpeg, xserver and pulseaudio
- [ ] Test warp
133 changes: 115 additions & 18 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#
# This will run systemd, sshd and docker;
#https://github.com/nestybox/dockerfiles/blob/master/ubuntu-jammy-systemd/Dockerfile
FROM ghcr.io/wanjohiryan/ffmpeg/v6:nightly
#FROM ghcr.io/wanjohiryan/ffmpeg/v6:nightly
FROM ubuntu:jammy
#
# Systemd installation
#
RUN apt-get update; \
RUN apt-get update -y; \
apt-get install -y --no-install-recommends \
systemd \
systemd-sysv \
Expand Down Expand Up @@ -39,10 +40,67 @@ RUN apt-get update; \
/usr/share/man/* \
/usr/share/local/*

#
# Install locales to prevent X11 errors
#
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV TZ UTC

ARG USERNAME=admin
ARG USER_UID=1000
ARG USER_GID=${USER_UID}

#
#Add dependencies
#
RUN apt-get update -y; \
apt-get upgrade -y; \
apt-get install -y --no-install-recommends \
wget \
vim \
software-properties-common \
gpg-agent \
dbus-user-session \
dbus-x11 \
libdbus-c++-1-0v5\
#
#Xvfb
xvfb \
#
#Pulseaudio
pulseaudio; \
#
# Housekeeping
#
apt-get clean -y; \
rm -rf \
/var/cache/debconf/* \
/var/lib/apt/lists/* \
/var/log/* \
/tmp/* \
/var/tmp/* \
/usr/share/doc/* \
/usr/share/man/* \
/usr/share/local/*

#
#Install ffmpeg v6 this has never been reliable for me. Do imma get swap this for a better alternative later on
#
RUN apt-get update -y; \
apt-get upgrade -y; \
add-apt-repository ppa:savoury1/ffmpeg4 \
add-apt-repository ppa:savoury1/ffmpeg6 \
apt-get update -y; \
apt-get upgrade -y && apt-get dist-upgrade -y; \
apt-get install ffmpeg -y; \
#
# Log out the ffmpeg version
ffmpeg -version


#
#Create a non-root user `admin`
#
Expand All @@ -53,13 +111,15 @@ RUN apt-get update; \
groupadd --gid ${USER_GID} ${USERNAME}; \
useradd --uid ${USER_UID} --gid ${USERNAME} --shell /bin/bash --create-home ${USERNAME};\
usermod -a -G adm,audio,input,pulse-access,sudo,tape,tty,video,ffmpeg ${USERNAME} ;\
#
#Remove sudo password
echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers; \
#
#make directories for arc3dia
#
mkdir -p /certs /media;\
chmod 1777 /certs /media; \
chown ${USERNAME} /certs /media; \
mkdir -p /certs /scripts /media;\
chmod 1777 /certs /scripts /media; \
chown ${USERNAME} /certs /media /scripts; \
chown -R $USERNAME:$USERNAME /home/${USERNAME} ;\
ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" > /etc/timezone

Expand All @@ -76,40 +136,77 @@ RUN systemctl mask systemd-udevd.service \
#
# Install Docker
#
RUN apt-get update && apt-get install -y curl; \
RUN apt-get update -y && apt-get install -y curl; \
rm -rf /var/lib/apt/lists/*; \
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh; \
#
# Add user "admin" to the Docker group
#
usermod -a -G docker admin
groupadd docker; \
usermod -a -G docker $USERNAME; \
newgrp docker

ADD https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker /etc/bash_completion.d/docker.sh

#
# Install Sshd
# Install sshd
#
RUN apt-get update && apt-get install --no-install-recommends -y openssh-server \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir /home/admin/.ssh \
&& chown admin:admin /home/admin/.ssh
RUN apt-get update && apt-get install --no-install-recommends -y openssh-server; \
rm -rf /var/lib/apt/lists/* ;\
mkdir /home/${USERNAME}/.ssh; \
chown $USERNAME:$USERNAME /home/${USERNAME}/.ssh

#
# Make use of stopsignal (instead of sigterm) to stop systemd containers.
#
STOPSIGNAL SIGRTMIN+3

#
#Copy the systemd.service file for starting the server
#Copy Warp [CLIENT] linux binary and the start script into the container
#
#TODO:
# COPY docker/base/server.service /lib/systemd/system/
# RUN ln -sf /lib/systemd/system/server.service \
# /etc/systemd/system/multi-user.target.wants/server.service
COPY temp/warp /usr/bin/
COPY docker/base/ffmpeg.sh /scripts/
RUN chmod +x /scripts/ffmpeg.sh /usr/bin/warp

#
#Copy the systemd.service file for starting the server
#
COPY docker/base/*.service /lib/systemd/system/
RUN ln -sf /lib/systemd/system/warp.service \
/etc/systemd/system/multi-user.target.wants/warp.service
# RUN ln -sf /lib/systemd/system/dbus.service \
# /etc/systemd/system/multi-user.target.wants/dbus-server.service
RUN ln -sf /lib/systemd/system/pulseaudio.service \
/etc/systemd/system/multi-user.target.wants/pulseaudio.service
RUN ln -sf /lib/systemd/system/xserver.service \
/etc/systemd/system/multi-user.target.wants/xserver.service
#
# For ssh, and http3 connections respectively
# Warp runs on port 4443
#
EXPOSE 22 443/udp 443 80

#RUN ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" | sudo tee /etc/timezone

# FIXME: Remove this
#After a lot of thought, i commented out this as running the warp relay server on a local machine might not be the ideal way to do this.
#Ideally we should have the client run locally, transmit the audio and video to a remote warp relay server that will transmit the content to all available clients.

# EXPOSE 22 4443/udp 4443 80

#the volume that houses the key and cert files as `/certs/key.pem` and `/certs/cert.pem`
VOLUME [ "/certs" ]

ENV DISPLAY :0
ENV DPI 96
ENV CDEPTH 24
ENV USER ${USERNAME}
ENV SHELL /bin/bash

ENV WARP_SERVER_URL "${WARP_SERVER_URL:-"https://localhost"}"
ENV WARP_SERVER_PORT "${WARP_SERVER_PORT:-4443}"

#Full server url
ENV WARP_SERVER_FULL_URL="${WARP_SERVER_URL}:${WARP_SERVER_PORT}"

#
# Set systemd as entrypoint.
Expand Down
14 changes: 14 additions & 0 deletions docker/base/dbus-server.service.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Dbus server
StartLimitIntervalSec=0

[Service]
ExecStart=/etc/init.d/dbus start
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=dbus-server

[Install]
WantedBy=multi-user.target
46 changes: 46 additions & 0 deletions docker/base/ffmpeg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

#
#FIXME: Remove this file (it is here for refence) then fix this ffmpeg error ``Sep 27 05:27:13 2f07ec1815e1 arc3dia-server[1140]: [mp4 @ 0x56057dc86140] Application provided duration: -1 / timestamp: 2744278 is out of range for mov/mp4 format``
# i think it is the ``streaming 1`` option.
#

CMD=(
ffmpeg
-hide_banner
-loglevel error
#screen image size
-s 1920x1080
#video fps
-r 30
#grab x11 display
-f x11grab
-i ${DISPLAY}
#capture pulse audio
-f pulse
-re
-i default
-c:v libx264
-preset veryfast
-tune zerolatency
-profile main
-pix_fmt yuv420p #let us use 4:2:0 for now
#FIXME: add full color 4:4:4
-c:a aac
-b:a 128k
-ar 44100
-ac 2
-map v:0 -s:v:0 1280x720 -b:v:0 3M
#FIXME: add this later
#-map v:0 -s:v:1 854x480 -b:v:1 1.1M
#-map v:0 -s:v:2 640x360 -b:v:2 365k
-map 1:a
-streaming 1
-movflags empty_moov+frag_every_frame+separate_moof+omit_tfhd_offset

./playlist.mpd
#Then send this to our remote/local warp-relay server
#- | RUST_LOG=warp=info /usr/bin/warp -i - -u $WARP_SERVER_FULL_URL
)

exec "${CMD[@]}"
16 changes: 16 additions & 0 deletions docker/base/pulseaudio.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Pulseaudio server
After=xserver.service
StartLimitIntervalSec=0

[Service]
ExecStart=/usr/bin/pulseaudio --disallow-exit --disallow-module-loading --exit-idle-time=-1
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=pulse-server
User=admin

[Install]
WantedBy=multi-user.target
4 changes: 2 additions & 2 deletions docker/base/warp.service
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[Unit]
Description=Arc3dia server
After=docker.service
After=pulseaudio.service
StartLimitIntervalSec=0

[Service]
ExecStart=/usr/bin/warp -dash /media/playlist.mpd -cert /certs/cert.pem -key /certs/key.pem
ExecStart=/usr/bin/ffmpeg -hide_banner -loglevel error -s 1920x1080 -r 30 -f x11grab -i :0 -f pulse -re -i default -f mp4 -streaming 1 -movflags empty_moov+frag_every_frame+separate_moof+omit_tfhd_offset /media/arc3dia.mp4
Restart=always
RestartSec=10
StandardOutput=syslog
Expand Down
14 changes: 14 additions & 0 deletions docker/base/xserver.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=X server
StartLimitIntervalSec=0

[Service]
ExecStart=/usr/bin/Xvfb :0 -screen 0 8192x4096x24 -dpi 96
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=x-server

[Install]
WantedBy=multi-user.target
48 changes: 48 additions & 0 deletions sysbox-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

#Make the amd gpu available inside the container
#chmod -R 777 /dev/dri

#
#This script is for anyone who has trouble installing sybox on their system
#

#This works with AWS-linux
sudo yum install jq git -y

#Install docker
sudo amazon-linux-extras install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user

#make docker autostart
sudo chkconfig docker on

#reboot if necessary
sudo reboot

#clone the sybox repo
git clone --recursive https://github.com/nestybox/sysbox.git

#run make
cd sysbox && sudo make sysbox-static

#then install the built packages
sudo make install

#start the sysbox systemd service
sudo ./scr/sysbox

#configure docker to use sysbox as a runtime !jq must be installed for this to work
sudo ./scr/docker-cfg --sysbox-runtime=enable

sudo cat /etc/docker/daemon.json

# if everything was correcctly installed you should see, otherwise this will be empty
#{
# "runtimes": {
# "sysbox-runc": {
# "path": "/usr/bin/sysbox-runc"
# }
# }
#}
3 changes: 3 additions & 0 deletions temp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a temporary folder for Warp ubuntu binary...

It will stay here until [warp](https://github.com/wanjohiryan/warp) gets a release... probably v1 release
Binary file added temp/warp
Binary file not shown.

0 comments on commit ac49d09

Please sign in to comment.