Skip to content

Commit

Permalink
github-ci: Package the app as a container image
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Castello <[email protected]>
  • Loading branch information
microhobby committed Apr 23, 2024
1 parent db67acd commit 562c72f
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 116 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
run: |
xvfb-run pwsh -f ./.vscode/tasks.ps1 run build-debug-local
- name: Build Release
- name: Build Container
shell: pwsh
run: |
xvfb-run pwsh -f ./.vscode/tasks.ps1 run publish-release-amd64
pwsh -f ./.vscode/tasks.ps1 run build-container-torizon-release-amd64
- name: Release
shell: pwsh
Expand All @@ -52,5 +52,5 @@ jobs:
--target main $_tag `
-t "Torizon Emulator Manager $_tag" `
-n "Torizon Emulator Manager $_tag" `
"Torizon-Emulator-Manager-$_tag.zip" `
install.sh
install.sh `
docker-compose.yml
12 changes: 10 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
"torizon_debug_port2": "",
"torizon_debug_port3": "",
"torizon_gpu": "",
"torizon_arch": "",
"torizon_arch": "amd64",
"wait_sync": "1",
"torizon_run_as": "torizon",
"torizon_app_root": "/home/torizon/app",
"tcb.packageName": "torizonEmulatorManager",
"tcb.version": "3.8.1",
"torizon.gpuPrefixRC": true,
"dotnet.preferCSharpExtension": false,
"omnisharp.useModernNet": true,
"dotnet.server.useOmnisharp": true
"dotnet.server.useOmnisharp": false,
"docker_registry": "commontorizon",
"docker_login": "matheuscastello",
"docker_password": "secret",
"docker_tag": "amd64-v1",
"tcb.clientId": "",
"tcb.clientSecret": "secret",
"tcb.fleetName": ""
}
59 changes: 43 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ARG IMAGE_ARCH=
# Base container version
##
ARG SDK_BASE_VERSION=4-8.0-rc
ARG BASE_VERSION=4-rc
ARG BASE_VERSION=next

##
# Directory of the application inside container
Expand All @@ -30,17 +30,38 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS Build
ARG IMAGE_ARCH
ARG APP_ROOT

ENV RUST_BACKTRACE=1

# this is needed for the build to work witht he libslint

# FIXME: for now we need to use the xvfb-run to avoid the backend to crash
# this is a workaround and should be fixed in the future,
# I think that for interpret the .slint should not be needed to have
# a display server running. But we work with what we have.
RUN apt-get -q -y update && \
apt-get -q -y install \
libfontconfig1
libfontconfig1 \
mesa-utils \
x11-xserver-utils \
libxkbcommon-x11-0 \
libfontconfig1 \
libfreetype6 \
libgbm1 \
libinput10 \
libxkbcommon0 \
xkb-data \
xvfb

COPY . ${APP_ROOT}
WORKDIR ${APP_ROOT}
COPY . /build
WORKDIR /build

# build
RUN dotnet restore && \
dotnet publish -c Release -r linux-${IMAGE_ARCH}
xvfb-run dotnet publish -c Release -r linux-${IMAGE_ARCH} && \
# we need to move the output to the correct folder
if [ "${IMAGE_ARCH}" = "amd64" ]; then \
mv /build/bin/Release/net8.0/linux-x64 /build/bin/Release/net8.0/linux-amd64 ; \
fi

# BUILD ------------------------------------------------------------------------


Expand Down Expand Up @@ -71,15 +92,17 @@ RUN apt-get -q -y update && \
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive \
apt-get install \
libicu72 zlib1g unzip \
libfontconfig1 \
mesa-utils \
x11-xserver-utils \
libxkbcommon-x11-0 \
libfontconfig1 \
libfreetype6 \
libgbm1 \
libinput10 \
libxkbcommon0 \
fonts-noto-core \
fonts-noto-cjk \
fonts-noto-cjk-extra \
fonts-noto-color-emoji \
fonts-noto-ui-core \
fonts-noto-ui-extra \
libicu72 \
xkb-data \
&& rm -rf /var/lib/apt/lists/*

RUN apt-get -y update && apt-get install -y --no-install-recommends \
Expand All @@ -89,21 +112,25 @@ RUN apt-get -y update && apt-get install -y --no-install-recommends \
# DO NOT REMOVE THIS LABEL: this is used for VS Code automation
&& apt-get clean && apt-get autoremove && rm -rf /var/lib/apt/lists/*

# use docker tools
COPY --from=docker:dind /usr/local/bin/docker /usr/local/bin/
COPY --from=docker:dind /usr/local/libexec/docker/cli-plugins /usr/local/lib/docker/cli-plugins

# Default to the Skia backend for best performance
ENV SLINT_BACKEND=winit-skia
# Default to Slint running in fullscreen
ENV SLINT_FULLSCREEN=1
# Default style to fluent
ENV SLINT_STYLE=fluent

# Copy the application compiled in the build step to the $APP_ROOT directory
# path inside the container, where $APP_ROOT is the torizon_app_root
# configuration defined in settings.json
COPY --from=Build ${APP_ROOT}/bin/Release/net8.0/linux-${IMAGE_ARCH}/publish ${APP_ROOT}
COPY --from=Build /build/bin/Release/net8.0/linux-${IMAGE_ARCH}/publish ${APP_ROOT}

# "cd" (enter) into the APP_ROOT directory
WORKDIR ${APP_ROOT}

USER root

# Command executed in runtime when the container starts
CMD ["./torizonEmulatorManager"]

Expand Down
110 changes: 33 additions & 77 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,43 @@
version: "3.9"
services:
torizon-emulator-manager-debug:
torizon-emulator-manager:
build:
context: .
dockerfile: Dockerfile.debug
image: ${LOCAL_REGISTRY}:5002/torizon-emulator-manager-debug:${TAG}
ports:
- 2222:2222
dockerfile: Dockerfile
image: commontorizon/torizon-emulator-manager:amd64-v1
devices:
- /dev/kvm
environment:
- XDG_DATA_DIRS=${XDG_DATA_DIRS}
- XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}
- WAYLAND_DISPLAY=
- DISPLAY=${DISPLAY}
volumes:
- type: bind
source: /tmp
target: /tmp
- type: bind
source: /dev
target: /dev
device_cgroup_rules:
# ... for tty0
- "c 4:0 rmw"
# ... for tty7
- "c 4:7 rmw"
# ... for /dev/input devices
- "c 13:* rmw"
- "c 199:* rmw"
# ... for /dev/dri devices
- "c 226:* rmw"
depends_on: [
weston
]
- /tmp/.X11-unix:/tmp/.X11-unix
- /var/run/docker.sock:/var/run/docker.sock
- /run:/run
- /var:/var
pid: host
network_mode: host
privileged: true

torizon-emulator-manager:
torizon-emulator-manager-wsl:
build:
context: .
dockerfile: Dockerfile
image: ${DOCKER_LOGIN}/torizon-emulator-manager:${TAG}
volumes:
- type: bind
source: /tmp
target: /tmp
- type: bind
source: /dev
target: /dev
device_cgroup_rules:
# ... for tty0
- "c 4:0 rmw"
# ... for tty7
- "c 4:7 rmw"
# ... for /dev/input devices
- "c 13:* rmw"
- "c 199:* rmw"
# ... for /dev/dri devices
- "c 226:* rmw"
depends_on: [
weston
]

weston:
image: commontorizon/weston${GPU}:4-rc
image: commontorizon/torizon-emulator-manager:amd64-v1
devices:
- /dev/kvm
environment:
- ACCEPT_FSL_EULA=1
# Required to get udev events from host udevd via netlink
network_mode: host
- XDG_DATA_DIRS=${XDG_DATA_DIRS}
- XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}
- WAYLAND_DISPLAY=
- DISPLAY=${DISPLAY}
volumes:
- type: bind
source: /tmp
target: /tmp
- type: bind
source: /dev
target: /dev
- type: bind
source: /run/udev
target: /run/udev
cap_add:
- CAP_SYS_TTY_CONFIG
# Add device access rights through cgroup...
device_cgroup_rules:
# ... for tty0
- "c 4:0 rmw"
# ... for tty1
- "c 4:1 rmw"
# ... for tty7
- "c 4:7 rmw"
# ... for /dev/input devices
- "c 13:* rmw"
- "c 199:* rmw"
# ... for /dev/dri devices
- "c 226:* rmw"
- /tmp/.X11-unix:/tmp/.X11-unix
- /var/run/docker.sock:/var/run/docker.sock
- /mnt/wsl/docker.sock:/var/run/docker.sock
- /run:/run
- /var:/var
pid: host
network_mode: host
privileged: true
29 changes: 12 additions & 17 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@

VERSION="0.0.8"

echo "Installing Torizon Emulator Manager ..."
echo "📦 Installing Torizon Emulator Manager ..."

sudo apt-get install \
libicu72 zlib1g unzip \
libfontconfig1 \
mesa-utils \
x11-xserver-utils \
libxkbcommon-x11-0 \
libfontconfig1 \
libfreetype6 \
libgbm1 \
libinput10 \
libxkbcommon0 \
xkb-data
wget https://github.com/commontorizon/torizonEmulatorManager/releases/download/$VERSION/torizon-emulator-manager
wget https://github.com/commontorizon/torizonEmulatorManager/releases/download/$VERSION/docker-compose.yml
wget wget https://github.com/commontorizon/torizonEmulatorManager/releases/download/$VERSION/docker-compose.wsl.yml

wget https://github.com/commontorizon/torizonEmulatorManager/releases/download/$VERSION/Torizon-Emulator-Manager-$VERSION.zip
sudo mkdir -p /opt/torizon-emulator-manager
sudo unzip -o Torizon-Emulator-Manager-$VERSION.zip -d /opt/torizon-emulator-manager
sudo ln -sf /opt/torizon-emulator-manager/bin/Release/net8.0/linux-x64/publish/torizonEmulatorManager /usr/bin/torizon-emulator-manager
rm Torizon-Emulator-Manager-$VERSION.zip
sudo mv torizon-emulator-manager /opt/torizon-emulator-manager
sudo mv docker-compose.yml /opt/torizon-emulator-manager
sudo chmod +x /opt/torizon-emulator-manager/torizon-emulator-manager
sudo ln -sf /opt/torizon-emulator-manager/torizon-emulator-manager /usr/bin/torizon-emulator-manager

echo "🛜 Downloading the image ..."
docker compose -f /opt/torizon-emulator-manager/docker-compose.yml pull

echo "🎉 Torizon Emulator Manager installed successfully!"
echo "Now run torizon-emulator-manager command to start the application."
17 changes: 17 additions & 0 deletions torizon-emulator-manager
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

if ! command -v docker &> /dev/null; then
echo "❌ Docker is not installed."
echo "Please install Docker before running this script."
exit 1
fi

if [ -z "$WSL_DISTRO_NAME" ]; then
docker compose \
-f /opt/torizon-emulator-manager/docker-compose.yml \
run --rm torizon-emulator-manager
else
docker compose \
-f /opt/torizon-emulator-manager/docker-compose.wsl.yml \
run --rm torizon-emulator-manager-wsl
fi

0 comments on commit 562c72f

Please sign in to comment.