Skip to content

Commit

Permalink
Add support for x86 devices (#2048)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomiguelino authored Sep 19, 2024
1 parent 5e55668 commit 37f4d74
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 73 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
needs: run-tests
strategy:
matrix:
board: ['pi1', 'pi2', 'pi3', 'pi4']
board: ['pi1', 'pi2', 'pi3', 'pi4', 'x86']
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -61,6 +61,7 @@ jobs:
run: |
export BUILD_TARGET=${{ matrix.board }}
export PUSH=1
export SKIP_TEST=1
./bin/build_containers.sh
balena:
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ We've tested Anthias and is known to work on the following Raspberry Pi models:
* Raspberry Pi 3 Model B+ - 32-bit and 64-bit Bullseye, 64-bit Bookworm
* Raspberry Pi 3 Model B - 64-bit Bookworm and Bullseye
* Raspberry Pi 2 Model B - 32-bit Bookworm and Bullseye
* x86 Devices - 64-bit Bullseye
* These devices can be something similar to a NUC.


We're still fixing the installer so that it'll work with Raspberry Pi Zero and Raspberry Pi 1.
Expand Down Expand Up @@ -69,6 +71,13 @@ The image file looks something like `<yyyy>-<mm>-<dd>-raspberry<version>.zip`. T

If you'd like more control over your digital signage instance, try installing it on Raspberry Pi OS Lite.

Before you start, make sure that you have `curl` installed. If not, you can install it by running:

```bash
$ sudo apt update
$ sudo apt install -y curl
```

The tl;dr for on [Raspberry Pi OS](https://www.raspberrypi.com/software/) is:

```
Expand Down
5 changes: 4 additions & 1 deletion ansible/roles/network/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@
register: nm_pkla_path

- name: Copy org.freedesktop.NetworkManager.pkla to 50-local.d
ansible.builtin.command: cp -f /var/lib/polkit-1/localauthority/10-vendor.d/org.freedesktop.NetworkManager.pkla /etc/polkit-1/localauthority/50-local.d
ansible.builtin.shell: |
mkdir -p /etc/polkit-1/localauthority/50-local.d
cp -f /var/lib/polkit-1/localauthority/10-vendor.d/org.freedesktop.NetworkManager.pkla \
/etc/polkit-1/localauthority/50-local.d
when: manage_network|bool
changed_when: not nm_pkla_path.stat.exists

Expand Down
66 changes: 56 additions & 10 deletions ansible/roles/system/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
- name: Notice for cmdline.txt.orig file
ansible.builtin.debug:
msg: "Use cmdline.txt.orig for boot parameters (don't remove this file)"
tags:
- touches-boot-partition
- raspberry-pi

- name: Copy cmdline.txt.orig to cmdline.txt
ansible.builtin.copy:
Expand Down Expand Up @@ -206,15 +209,25 @@
update_cache: true
when: not cdefs_exist

- name: Install Anthias dependencies
- name: Install Anthias dependencies (all platforms)
ansible.builtin.apt:
name:
- rpi-update
- bc
- python3
- python3-redis
state: present

- name: Install Anthias dependencies (Raspberry Pi)
ansible.builtin.apt:
name:
- rpi-update
state: present
when: |
ansible_architecture == "aarch64" or
ansible_architecture == "armv7l" or
ansible_architecture == "armv6l"
- name: Remove deprecated apt dependencies
ansible.builtin.apt:
name:
Expand Down Expand Up @@ -244,21 +257,35 @@
- docker-compose
state: absent

- name: Add docker apt key
- name: Add Docker apt key (x86)
ansible.builtin.apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
when: ansible_architecture == "x86_64"

- name: Add Docker apt key (Raspberry Pi)
ansible.builtin.apt_key:
url: https://download.docker.com/linux/raspbian/gpg
state: present
when: |
ansible_architecture == "aarch64" or
ansible_architecture == "armv7l" or
ansible_architecture == "armv6l"
- name: Get raspbian name
- name: Get Debian name
ansible.builtin.command: lsb_release -cs
register: raspbian_name
register: debian_name
changed_when: false

- name: Set architecture
ansible.builtin.set_fact:
architecture: "{{ 'amd64' if ansible_architecture == 'x86_64' else 'armhf' }}"

- name: Add Docker repo
ansible.builtin.lineinfile:
path: /etc/apt/sources.list.d/docker.list
create: true
line: "deb [arch=armhf] https://download.docker.com/linux/debian {{ raspbian_name.stdout }} stable"
line: "deb [arch={{ architecture }}] https://download.docker.com/linux/debian {{ debian_name.stdout }} stable"
state: present
owner: root
group: root
Expand All @@ -267,13 +294,28 @@
- name: Install Docker
ansible.builtin.apt:
name:
- docker-ce:armhf
- docker-ce-cli:armhf
- docker-compose-plugin:armhf
- docker-ce:{{ architecture }}
- docker-ce-cli:{{ architecture }}
- docker-compose-plugin:{{ architecture }}
update_cache: true
install_recommends: false

- name: Add user to docker group
- name: Add user to Docker group (all platforms)
ansible.builtin.user:
name: "{{ lookup('env', 'USER') }}"
group: "{{ lookup('env', 'USER') }}"
groups:
- docker
- adm
- sudo
- video
- plugdev
- users
- input
- netdev
- dialout

- name: Add user to Docker group (Raspberry Pi)
ansible.builtin.user:
name: "{{ lookup('env', 'USER') }}"
group: "{{ lookup('env', 'USER') }}"
Expand All @@ -288,6 +330,10 @@
- netdev
- gpio
- dialout
when: |
ansible_architecture == "aarch64" or
ansible_architecture == "armv7l" or
ansible_architecture == "armv6l"
- name: Perform system upgrade
ansible.builtin.apt:
Expand Down
44 changes: 27 additions & 17 deletions bin/build_containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ declare -a SERVICES=(
'test'
)

BUILD_TARGET=${BUILD_TARGET:-x86}

DOCKER_BUILD_ARGS=("buildx" "build" "--load")
echo 'Make sure you ran `docker buildx create --use` before the command'

Expand All @@ -31,9 +33,9 @@ if [ -n "${CLEAN_BUILD+x}" ]; then
fi

# Detect what platform
if [ ! -f /proc/device-tree/model ] && [ -z "${BUILD_TARGET+x}" ]; then
export BOARD="x86"
if [ ! -f /proc/device-tree/model ] && [ "$BUILD_TARGET" == 'x86' ]; then
export BASE_IMAGE=debian
export BOARD="x86"
export TARGET_PLATFORM=linux/amd64
elif grep -qF "Raspberry Pi 4" /proc/device-tree/model || [ "${BUILD_TARGET}" == 'pi4' ]; then
export BASE_IMAGE=balenalib/raspberrypi3-debian
Expand Down Expand Up @@ -73,23 +75,27 @@ for container in ${SERVICES[@]}; do
fi

if [ "$container" == 'viewer' ]; then
export QT_VERSION=5.15.14
export WEBVIEW_GIT_HASH=4bd295c4a1197a226d537938e947773f4911ca24
export WEBVIEW_BASE_URL="https://github.com/Screenly/Anthias/releases/download/WebView-v0.3.1"
export WEBVIEW_GIT_HASH=5e556681738a1fa918dc9f0bf5879ace2e603e12
export WEBVIEW_BASE_URL="https://github.com/Screenly/Anthias/releases/download/WebView-v0.3.3"

if [ "$BOARD" == 'x86' ]; then
export QT_MAJOR_VERSION=6
export QT_VERSION=6.6.3
else
export QT_MAJOR_VERSION=5
export QT_VERSION=5.15.14
fi
elif [ "$container" == 'test' ]; then
export CHROME_DL_URL="https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.86/linux64/chrome-linux64.zip"
export CHROMEDRIVER_DL_URL="https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.86/linux64/chromedriver-linux64.zip"
elif [ "$container" == 'wifi-connect' ]; then
# We don't support wifi-connect on x86 yet.
if [ "$BOARD" == 'x86' ]; then
continue
fi

# Logic for determining the correct architecture for the wifi-connect container
if [ "$TARGET_PLATFORM" = 'linux/arm/v6' ]; then
architecture=rpi
else
elif [ "$TARGET_PLATFORM" = 'linux/arm/v7' ] || [ "$TARGET_PLATFORM" = 'linux/arm/v8' ]; then
architecture=armv7hf
elif [ "$TARGET_PLATFORM" = 'linux/amd64' ]; then
architecture=amd64
fi

wc_download_url='https://api.github.com/repos/balena-os/wifi-connect/releases/93025295'
Expand All @@ -114,13 +120,17 @@ for container in ${SERVICES[@]}; do
SED_ARGS=(-i)
fi

sed "${SED_ARGS[@]}" -e '/libraspberrypi0/d' $(find docker/ -maxdepth 1 -not -name "*.tmpl" -type f)
PACKAGES_TO_REMOVE=(
"libraspberrypi0"
"libgst-dev"
"libsqlite0-dev"
"libsrtp0-dev"
"libssl1.1"
)

# Don't build the viewer container if we're on x86
if [ "$container" == 'viewer' ]; then
echo "Skipping viewer container for x86 builds..."
continue
fi
for package in "${PACKAGES_TO_REMOVE[@]}"; do
sed "${SED_ARGS[@]}" -e "/$package/d" $(find docker/ -maxdepth 1 -not -name "*.tmpl" -type f)
done
else
if [ "$BOARD" == "pi1" ] && [ "$container" == "viewer" ]; then
# Remove the libssl1.1 from Dockerfile.viewer
Expand Down
23 changes: 17 additions & 6 deletions bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ GITHUB_RELEASES_URL="https://github.com/Screenly/Anthias/releases"
GITHUB_RAW_URL="https://raw.githubusercontent.com/Screenly/Anthias"
DOCKER_TAG="latest"
UPGRADE_SCRIPT_PATH="${ANTHIAS_REPO_DIR}/bin/upgrade_containers.sh"
ARCHITECTURE=$(uname -m)

INTRO_MESSAGE=(
"Anthias requires a dedicated Raspberry Pi and an SD card."
Expand Down Expand Up @@ -66,6 +67,8 @@ function install_prerequisites() {
return
fi

sudo apt -y update && sudo apt -y install gnupg

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://repo.charm.sh/apt/gpg.key | \
sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
Expand Down Expand Up @@ -123,15 +126,15 @@ function initialize_locales() {
function install_packages() {
display_section "Install Packages via APT"

RASPBERRY_PI_OS_VERSION=$(lsb_release -rs)
APT_INSTALL_ARGS=(
local DISTRO_VERSION=$(lsb_release -rs)
local APT_INSTALL_ARGS=(
"git"
"libffi-dev"
"libssl-dev"
"whois"
)

if [ "$RASPBERRY_PI_OS_VERSION" -ge 12 ]; then
if [ "$DISTRO_VERSION" -ge 12 ]; then
APT_INSTALL_ARGS+=(
"python3-dev"
"python3-full"
Expand All @@ -149,8 +152,11 @@ function install_packages() {
APT_INSTALL_ARGS+=("network-manager")
fi

sudo sed -i 's/apt.screenlyapp.com/archive.raspbian.org/g' \
/etc/apt/sources.list
if [ "$ARCHITECTURE" != "x86_64" ]; then
sudo sed -i 's/apt.screenlyapp.com/archive.raspbian.org/g' \
/etc/apt/sources.list
fi

sudo apt update -y
sudo apt-get install -y "${APT_INSTALL_ARGS[@]}"
}
Expand Down Expand Up @@ -185,9 +191,13 @@ function run_ansible_playbook() {

sudo -u ${USER} ${SUDO_ARGS[@]} ansible localhost \
-m git \
-a "repo=$REPOSITORY dest=${ANTHIAS_REPO_DIR} version=${BRANCH} force=no"
-a "repo=$REPOSITORY dest=${ANTHIAS_REPO_DIR} version=${BRANCH} force=yes"
cd ${ANTHIAS_REPO_DIR}/ansible

if [ "$ARCHITECTURE" == "x86_64" ]; then
ANSIBLE_PLAYBOOK_ARGS+=("--skip-tags" "raspberry-pi")
fi

sudo -E -u ${USER} ${SUDO_ARGS[@]} \
ansible-playbook site.yml "${ANSIBLE_PLAYBOOK_ARGS[@]}"
}
Expand Down Expand Up @@ -374,6 +384,7 @@ function main() {
install_packages
install_ansible
run_ansible_playbook

upgrade_docker_containers
cleanup
modify_permissions
Expand Down
9 changes: 8 additions & 1 deletion bin/upgrade_containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ if [ -z "$DOCKER_TAG" ]; then
fi

# Detect Raspberry Pi version
if grep -qF "Raspberry Pi 4" /proc/device-tree/model; then
if [ ! -f /proc/device-tree/model ] && [ "$(uname -m)" = "x86_64" ]; then
export DEVICE_TYPE="x86"
elif grep -qF "Raspberry Pi 4" /proc/device-tree/model; then
export DEVICE_TYPE="pi4"
elif grep -qF "Raspberry Pi 3" /proc/device-tree/model; then
export DEVICE_TYPE="pi3"
Expand All @@ -47,6 +49,11 @@ cat /home/${USER}/screenly/docker-compose.yml.tmpl \
| envsubst \
> /home/${USER}/screenly/docker-compose.yml

if [ "$DEVICE_TYPE" = "x86" ]; then
sed -i '/devices:/ {N; /\n.*\/dev\/vchiq:\/dev\/vchiq/d}' \
/home/${USER}/screenly/docker-compose.yml
fi

sudo -E docker compose \
-f /home/${USER}/screenly/docker-compose.yml \
pull
Expand Down
1 change: 1 addition & 0 deletions docker/Dockerfile.base.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RUN --mount=type=cache,target=/var/cache/apt \
python3-setuptools \
python3-simplejson \
python-is-python3 \
sudo \
sqlite3

# Works around issue with `curl`
Expand Down
Loading

0 comments on commit 37f4d74

Please sign in to comment.