From 588b2fe328c09bbedae7e4f3eb4544098b5e1c3d Mon Sep 17 00:00:00 2001 From: Viktor Petersson Date: Fri, 17 Feb 2023 11:18:56 +0000 Subject: [PATCH] Refactors wifi-connect structure --- README.md | 5 +++++ balena.yml | 7 ++++--- bin/build_containers.sh | 26 +++++++++++++++++++++----- bin/install_wifi_connect.sh | 15 --------------- docker/Dockerfile.base.tmpl | 4 ++-- docker/Dockerfile.viewer.tmpl | 2 +- docker/Dockerfile.wifi-connect.tmpl | 10 +++------- 7 files changed, 36 insertions(+), 33 deletions(-) delete mode 100644 bin/install_wifi_connect.sh diff --git a/README.md b/README.md index 4b2eb646d..6a8d30ceb 100644 --- a/README.md +++ b/README.md @@ -53,9 +53,12 @@ Anthias works on all Raspberry Pi versions, including Raspberry Pi Zero, Raspber To simplify development of the server module of Anthias, we've created a Docker container. This is intended to run on your local machine with the Anthias repository mounted as a volume. +Do note that Anthias is using Docker's [buildx](https://docs.docker.com/engine/reference/commandline/buildx/) for the image builds. This is used both for cross compilation as well as for local caching. You might need to run `docker buildx create --use` first. + Assuming you're in the source code repository, simply run: ```bash + ./bin/build_containers.sh $ docker-compose \ -f docker-compose.dev.yml up ``` @@ -65,6 +68,7 @@ $ docker-compose \ Start the containers. ```bash +$ ./bin/build_containers.sh $ docker-compose \ -f docker-compose.test.yml up -d ``` @@ -72,6 +76,7 @@ $ docker-compose \ Run the unit tests. ```bash +$ ./bin/build_containers.sh $ docker-compose \ -f docker-compose.test.yml \ exec -T srly-ose-test bash ./bin/prepare_test_environment.sh -s diff --git a/balena.yml b/balena.yml index 08f5dbbb8..2393da59a 100644 --- a/balena.yml +++ b/balena.yml @@ -10,9 +10,10 @@ post-provisioning: >- With Anthias, a monitor/TV and a Raspberry Pi, you can create a remotely managed screen that can display: - - images - - video - - web pages + * Images + * Video + * Web pages + * Video feeds (RTSP) Thanks to Balena [OpenFleets](https://hub.balena.io/organizations/screenly_ose/fleets), you benefit from having automatic updates. As soon as updates are shipped, they will be deployed to your device. diff --git a/bin/build_containers.sh b/bin/build_containers.sh index 158001280..87919a2cb 100755 --- a/bin/build_containers.sh +++ b/bin/build_containers.sh @@ -11,11 +11,6 @@ export GIT_SHORT_HASH=$(git rev-parse --short HEAD) export GIT_HASH=$(git rev-parse HEAD) export BASE_IMAGE_TAG=buster export DEBIAN_VERSION=buster -export QT_VERSION=5.15.2 -export WEBVIEW_GIT_HASH=0b6d49359133246659b9ba1d8dd883e3fc5c9a91 -export WEBVIEW_BASE_URL="https://github.com/Screenly/Anthias/releases/download/WebView-v0.2.1" -export CHROME_DL_URL="https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_107.0.5304.121-1_amd64.deb" -export CHROMEDRIVER_DL_URL="https://chromedriver.storage.googleapis.com/107.0.5304.62/chromedriver_linux64.zip" DOCKER_BUILD_ARGS=("buildx" "build" "--load") echo 'Make sure you ran `docker buildx create --use` before the command' @@ -56,6 +51,27 @@ fi for container in server celery redis websocket nginx viewer wifi-connect 'test'; do echo "Building $container" + if [ "$container" == 'viewer' ]; then + export QT_VERSION=5.15.2 + export WEBVIEW_GIT_HASH=0b6d49359133246659b9ba1d8dd883e3fc5c9a91 + export WEBVIEW_BASE_URL="https://github.com/Screenly/Anthias/releases/download/WebView-v0.2.1" + export CHROME_DL_URL="https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_107.0.5304.121-1_amd64.deb" + export CHROMEDRIVER_DL_URL="https://chromedriver.storage.googleapis.com/107.0.5304.62/chromedriver_linux64.zip" + + elif [ "$container" == 'wifi-connect' ]; then + # Logic for determining the correct architecture for the wifi-connect container + if [ "$TARGET_PLATFORM" = 'linux/arm/v6' ]; then + architecture=rpi + else + architecture=armv7hf + fi + + wc_download_url='https://api.github.com/repos/balena-os/wifi-connect/releases/45509064' + jq_filter=".assets[] | select (.name|test(\"linux-$architecture\")) | .browser_download_url" + archive_url=$(curl -sL "$wc_download_url" | jq -r "$jq_filter") + export ARCHIVE_URL="$archive_url" + fi + # For all but redis and nginx, and viewer append the base layer if [ ! "$container" == 'redis' ] || [ ! "$container" == 'nginx' ] || [ ! "$container" == 'viewer' ]; then cat "docker/Dockerfile.base.tmpl" | envsubst > "docker/Dockerfile.$container" diff --git a/bin/install_wifi_connect.sh b/bin/install_wifi_connect.sh deleted file mode 100644 index c020916f6..000000000 --- a/bin/install_wifi_connect.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -if [[ "$TARGET_PLATFORM" = 'linux/arm/v6' ]]; then - architecture='rpi' -else - architecture='armv7hf' -fi - -wc_download_url='https://api.github.com/repos/balena-os/wifi-connect/releases/45509064' -jq_filter=".assets[] | select (.name|test(\"linux-$architecture\")) | .browser_download_url" -archive_url=$(curl -sL $wc_download_url | jq -r "$jq_filter") -archive_file=$(basename $archive_url) - -wget $archive_url -tar -xvz -C /usr/src/app -f $archive_file diff --git a/docker/Dockerfile.base.tmpl b/docker/Dockerfile.base.tmpl index e15d2f0ad..9314f1319 100644 --- a/docker/Dockerfile.base.tmpl +++ b/docker/Dockerfile.base.tmpl @@ -14,13 +14,13 @@ RUN --mount=type=cache,target=/var/cache/apt \ libcec-dev \ libffi-dev \ libraspberrypi0 \ + libraspberrypi0 \ libssl-dev \ libzmq3-dev \ lsb-release \ - libraspberrypi0 \ - omxplayer \ mplayer \ net-tools \ + omxplayer \ procps \ psmisc \ python-dev \ diff --git a/docker/Dockerfile.viewer.tmpl b/docker/Dockerfile.viewer.tmpl index 4ce9086ce..3df0e1695 100644 --- a/docker/Dockerfile.viewer.tmpl +++ b/docker/Dockerfile.viewer.tmpl @@ -1,4 +1,4 @@ -# syntax=docker/dockerfile:1.3 +# syntax=docker/dockerfile:1.4 FROM ${BASE_IMAGE}:${BASE_IMAGE_TAG} # This list needs to be trimmed back later diff --git a/docker/Dockerfile.wifi-connect.tmpl b/docker/Dockerfile.wifi-connect.tmpl index def746c08..e1489b932 100644 --- a/docker/Dockerfile.wifi-connect.tmpl +++ b/docker/Dockerfile.wifi-connect.tmpl @@ -1,17 +1,13 @@ RUN --mount=type=cache,target=/var/cache/apt \ - apt-get update && \ apt-get -y install --no-install-recommends \ dnsmasq \ - jq \ - wget \ wireless-tools WORKDIR /usr/src/app -ARG TARGET_PLATFORM - -COPY ./bin/install_wifi_connect.sh . -RUN bash ./install_wifi_connect.sh +RUN curl -sL -o /tmp/wifi_connect.tgz "$ARCHIVE_URL" && \ + tar xfz /tmp/wifi_connect.tgz -C /usr/src/app && \ + rm /tmp/wifi_connect.tgz COPY requirements/requirements.wifi-connect.txt /tmp/requirements.txt RUN --mount=type=cache,target=/root/.cache/pip \