Skip to content

Commit

Permalink
Merge pull request #46 from balenablocks/V2
Browse files Browse the repository at this point in the history
V2
  • Loading branch information
phil-d-wilson authored Apr 6, 2021
2 parents 4676a02 + 5120608 commit 2cda06b
Show file tree
Hide file tree
Showing 15 changed files with 747 additions and 307 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sha256bca9ad158da383a9af76908776cf6cd8b06359a8a1529c4862fd17fd3f2fc7b3
Dockerfile.raspberrypi3
Dockerfile.raspberrypi4-64

51 changes: 51 additions & 0 deletions Dockerfile.raspberrypi
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
ARG NODEJS_VERSION="12"

FROM balenalib/%%BALENA_MACHINE_NAME%%-node:${NODEJS_VERSION}-run
# install required packages
RUN install_packages \
chromium-browser \
rpi-chromium-mods \
libgles2-mesa \
lsb-release \
mesa-vdpau-drivers \
wget \
x11-xserver-utils \
xserver-xorg-input-evdev \
xserver-xorg-legacy \
xserver-xorg-video-fbdev \
xserver-xorg xinit \
xterm

WORKDIR /usr/src/app

# install node dependencies
COPY ./package.json /usr/src/app/package.json
RUN JOBS=MAX npm install --unsafe-perm --production && npm cache clean --force

COPY ./src /usr/src/app/

RUN mkdir -p /etc/chromium/policies
RUN mkdir /etc/chromium/policies/managed
COPY ./policy.json /etc/chromium/policies/managed/my_policy.json

RUN chmod +x ./*.sh

ENV UDEV=1

# Add chromium user
RUN useradd chromium -m -s /bin/bash -G root || true && \
groupadd -r -f chromium && id -u chromium || true \
&& chown -R chromium:chromium /home/chromium || true

COPY ./public-html /home/chromium

# udev rule to set specific permissions
RUN echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules
RUN usermod -a -G audio,video,tty chromium

# # Set up the audio block. This won't have any effect if the audio block is not being used.
RUN curl -skL https://raw.githubusercontent.com/balenablocks/audio/master/scripts/alsa-bridge/debian-setup.sh| sh
ENV PULSE_SERVER=tcp:audio:4317

# Start app
CMD ["bash", "/usr/src/app/start.sh"]
52 changes: 52 additions & 0 deletions Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
ARG NODEJS_VERSION="12"

FROM balenalib/%%BALENA_MACHINE_NAME%%-node:${NODEJS_VERSION}-run
# install required packages
RUN install_packages \
chromium \
libgles2-mesa \
lsb-release \
mesa-vdpau-drivers \
wget \
x11-xserver-utils \
xserver-xorg-input-evdev \
xserver-xorg-legacy \
xserver-xorg-video-fbdev \
xserver-xorg xinit \
xterm

WORKDIR /usr/src/app

# install node dependencies
COPY ./package.json /usr/src/app/package.json
RUN JOBS=MAX npm install --unsafe-perm --production && npm cache clean --force

COPY ./src /usr/src/app/

RUN chmod +x ./*.sh

ENV UDEV=1

RUN mkdir -p /etc/chromium/policies
RUN mkdir -p /etc/chromium/policies/recommended
COPY ./policy.json /etc/chromium/policies/recommended/my_policy.json

# Add chromium user
RUN useradd chromium -m -s /bin/bash -G root || true && \
groupadd -r -f chromium && id -u chromium || true \
&& chown -R chromium:chromium /home/chromium || true

COPY ./public-html /home/chromium

# udev rule to set specific permissions
RUN echo 'SUBSYSTEM=="vchiq",GROUP="video",MODE="0660"' > /etc/udev/rules.d/10-vchiq-permissions.rules
RUN usermod -a -G audio,video,tty chromium

RUN ln -s /usr/bin/chromium /usr/bin/chromium-browser || true

# Set up the audio block. This won't have any effect if the audio block is not being used.
RUN curl -skL https://raw.githubusercontent.com/balenablocks/audio/master/scripts/alsa-bridge/debian-setup.sh| sh
ENV PULSE_SERVER=tcp:audio:4317

# Start app
CMD ["bash", "/usr/src/app/start.sh"]
55 changes: 31 additions & 24 deletions build-images.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,57 @@
#!/bin/bash
set -e

function build_and_push_image () {
BLOCK_NAME="browser"

function build_image () {
local DOCKER_REPO=$1
local BALENA_MACHINE_NAME=$2
local DOCKER_ARCH=$3
local DOCKERFILE_DIR=./generic

echo "Building for machine name $BALENA_MACHINE_NAME, platform $DOCKER_ARCH, pushing to $DOCKER_REPO/$BLOCK_NAME"

# The RPIs all use the same dockerfile for now
if [[ $BALENA_MACHINE_NAME = raspberry* ]]; then
DOCKERFILE_DIR=./rpi
sed "s/%%BALENA_MACHINE_NAME%%/$BALENA_MACHINE_NAME/g" ./Dockerfile.raspberrypi > ./Dockerfile.$BALENA_MACHINE_NAME
else
sed "s/%%BALENA_MACHINE_NAME%%/$BALENA_MACHINE_NAME/g" ./Dockerfile.template > ./Dockerfile.$BALENA_MACHINE_NAME
fi

docker buildx build -t $DOCKER_REPO/$BLOCK_NAME:$BALENA_MACHINE_NAME --push --platform $DOCKER_ARCH --file Dockerfile.$BALENA_MACHINE_NAME .

echo "Building for machine name $BALENA_MACHINE_NAME, platform $DOCKER_ARCH using dockerfile from $DOCKERFILE_DIR, pushing to $DOCKER_REPO/browser"

sed "s/%%BALENA_MACHINE_NAME%%/$BALENA_MACHINE_NAME/g" $DOCKERFILE_DIR/Dockerfile.template > ./Dockerfile.$BALENA_MACHINE_NAME
docker buildx build -t $DOCKER_REPO/browser:$BALENA_MACHINE_NAME --platform $DOCKER_ARCH --file Dockerfile.$BALENA_MACHINE_NAME .

echo "Publishing..."
docker push $DOCKER_REPO/browser:$BALENA_MACHINE_NAME

echo "Cleaning up..."
echo "Cleaning up temporary dockerfiles..."
rm Dockerfile.$BALENA_MACHINE_NAME
}

function retag_and_push_image () {
function retag_image () {
local DOCKER_REPO=$1
local BUILT_TAG=$2
local NEW_TAG=$3

echo "Taging $DOCKER_REPO/browser:$BUILT_TAG as $DOCKER_REPO/browser:$NEW_TAG"
docker tag $DOCKER_REPO/browser:$BUILT_TAG $DOCKER_REPO/browser:$NEW_TAG
echo "Taging $DOCKER_REPO/$BLOCK_NAME:$BUILT_TAG as $DOCKER_REPO/$BLOCK_NAME:$NEW_TAG"
docker tag $DOCKER_REPO/$BLOCK_NAME:$BUILT_TAG $DOCKER_REPO/$BLOCK_NAME:$NEW_TAG

echo "Publishing..."
docker push $DOCKER_REPO/browser:$NEW_TAG
# echo "Publishing..."
docker push $DOCKER_REPO/$BLOCK_NAME:$NEW_TAG
}

function create_and_push_manifest() {
local DOCKER_REPO=$1
docker manifest rm $DOCKER_REPO/$BLOCK_NAME:latest || true
docker manifest create $DOCKER_REPO/$BLOCK_NAME:latest --amend $DOCKER_REPO/$BLOCK_NAME:raspberrypi3 --amend $DOCKER_REPO/$BLOCK_NAME:raspberrypi4-64 --amend $DOCKER_REPO/$BLOCK_NAME:genericx86-64-ext
docker manifest annotate --arch arm64 $DOCKER_REPO/$BLOCK_NAME:latest $DOCKER_REPO/$BLOCK_NAME:raspberrypi4-64
docker manifest annotate --variant v8 $DOCKER_REPO/$BLOCK_NAME:latest $DOCKER_REPO/$BLOCK_NAME:raspberrypi4-64
docker manifest push $DOCKER_REPO/$BLOCK_NAME:latest
}

# YOu can pass in a repo (such as a test docker repo) or accept the default
DOCKER_REPO=${1:-balenablocks}

#RPI4 is built as ARMv7 because the base Raspian image is 32-bit
build_and_push_image $DOCKER_REPO "raspberrypi3" "linux/arm/v7"

#only need to build once per arch, and retag & push for clones
retag_and_push_image $DOCKER_REPO "raspberrypi3" "raspberrypi4-64"
retag_and_push_image $DOCKER_REPO "raspberrypi3" "raspberrypi3-64"
retag_and_push_image $DOCKER_REPO "raspberrypi3" "fincm3"
build_image $DOCKER_REPO "raspberrypi3" "linux/arm/v7"
#RPI4 is built as ARMv7 because there are currently (jan 2021) no 64-bit chromium sources from RPI
retag_image $DOCKER_REPO "raspberrypi3" "raspberrypi4-64"

build_image $DOCKER_REPO "genericx86-64-ext" "linux/amd64"

build_and_push_image $DOCKER_REPO "genericx86-64-ext" "linux/amd64"
create_and_push_manifest $DOCKER_REPO
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ volumes:
services:

browser:
image: balenablocks/browser:raspberrypi3
image: balenablocks/browser
privileged: true # required for UDEV to find plugged in peripherals such as a USB mouse
network_mode: host
volumes:
Expand Down
42 changes: 0 additions & 42 deletions generic/Dockerfile.template

This file was deleted.

38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "browserV2",
"version": "0.0.1",
"description": "balenaBlock that provides a chromium browser wrapped in some balena genius",
"main": "index.js",
"scripts": {

},
"repository": {
"type": "git",
"url": "git+https://github.com/balenablocks/browser.git"
},
"keywords": [
"balena",
"browser",
"chromium"
],
"author": "Phil Wilson <phil@balena.io>",
"license": "Apache-2.0",
"jshintConfig": {
"esversion": 8
},
"bugs": {
"url": "https://github.com/balenablocks/browser/issues"
},
"homepage": "https://github.com/balenablocks/browser#readme",
"dependencies": {
"chrome-launcher": "^0.13.4",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"dateformat": "^3.0.3",
"debug": "^4.1.1",
"express": "^4.17.1",
"bent": "7.3.10",
"set-interval-async": "^1.0.34"
}
}

7 changes: 7 additions & 0 deletions policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"HomepageLocation": "www.balea.io",
"ExtensionInstallForcelist": [
"aleakchihdccplidncghkekgioiakgal",
"cfhdojbkjhnklbpkdaibdccddilifddb"
]
}
7 changes: 4 additions & 3 deletions public-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<header class="my-auto bg-primary text-white">
<div class="container text-center ">
<h1>balenalabs-browser</h1>
<p class="lead">A primitive block for browsing HTML</p>
<p class="lead">A balena block for browsing HTML</p>
</div>
</header>

Expand All @@ -44,8 +44,9 @@ <h1>balenalabs-browser</h1>
<h2>Choosing what to display</h2>
<p class="lead">You have a few options for choosing what to display here:</p>
<ul>
<li>You can create a service on this device serving HTTP over port 80, and it'll display here automatically! **</li>
<li>You can create a service on this device serving HTTP over port 80 or 8080, or HTTPS over 443, and it'll display here automatically! **</li>
<li>You can set a Device Variable called <code>LAUNCH_URL</code></li>
<li>You can use the API on port 5011 to set the URL (see project readme for details)</li>
</ul>
<blockquote>** The balenalabs-browser service will need <code>network_mode: host</code> set.</blockquote>
</div>
Expand All @@ -56,7 +57,7 @@ <h2>Choosing what to display</h2>
<footer class="py-5 bg-dark">
<div class="container">
<p class="m-0 text-center text-white">
Copyright 2020 Balena |
Copyright 2021 Balena |
All Rights Reserved</p>
</div>
<!-- /.container -->
Expand Down
Loading

0 comments on commit 2cda06b

Please sign in to comment.