Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
# see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/
FROM python:3.13-slim-bookworm

# Set our working directory
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
dnsmasq \
wireless-tools

# use latest version. If specific version is required, it should be provided as vX.Y.Z, e.g v4.11.37
ARG VERSION="latest"

# create /usr/src/app/ui directory where we will extract pre-built UI
WORKDIR /usr/src/app/ui

WORKDIR /usr/src/app

RUN \
export BASE_URL="https://github.com/balena-os/wifi-connect/releases" &&\
DETECTED_ARCH=$(uname -m) &&\
case $DETECTED_ARCH in \
"aarch64") \
BINARY_ARCH_NAME="aarch64-unknown-linux-gnu" ;; \
"x86_64") \
BINARY_ARCH_NAME="x86_64-unknown-linux-gnu" ;;\
"armv7l") \
BINARY_ARCH_NAME="armv7-unknown-linux-gnueabihf" ;;\
*) \
echo >&2 "error: unsupported architecture ($DETECTED_ARCH)"; exit 1 ;; \
esac;\
if [ ${VERSION} = "latest" ]; then \
export URL_PARTIAL="latest/download" ; \
else \
export URL_PARTIAL="download/${VERSION}" ; \
fi; \
curl -Ls "$BASE_URL/$URL_PARTIAL/wifi-connect-$BINARY_ARCH_NAME.tar.gz" \
| tar -xvz -C /usr/src/app/ && \
curl -Ls "$BASE_URL/$URL_PARTIAL/wifi-connect-ui.tar.gz" \
| tar -xvz -C /usr/src/app/ui

# Copy requirements.txt first for better cache on later pushes
COPY requirements.txt requirements.txt

Expand All @@ -13,5 +46,9 @@ RUN pip install -r requirements.txt
# This will copy all files in our root to the working directory in the container
COPY . ./

COPY scripts/start.sh .

ENV DBUS_SYSTEM_BUS_ADDRESS unix:path=/host/run/dbus/system_bus_socket

# main.py will run when container starts up on the device
CMD ["python","-u","src/app.py"]
CMD ["sh", "./start.sh"]
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ services:
balena-hello-world:
build: .
ports:
- "80:80"
- "80:80"
volumes:
- /run/dbus:/host/run/dbus:ro
labels:
io.balena.features.dbus: "1"
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
click==8.1.8
Flask==2.3.3
importlib-metadata==4.13.0
itsdangerous==2.2.0
Jinja2==3.1.6
MarkupSafe==2.1.5
Werkzeug==2.0.3
zipp==3.21.0
click
Flask
importlib-metadata
itsdangerous
Jinja2
MarkupSafe
Werkzeug
zipp
34 changes: 34 additions & 0 deletions scripts/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
sleep 1 # give Supervisor time to attach log stream
set -x

export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket

# Optional step - it takes couple of seconds (or longer) to establish a WiFi connection
# sometimes. In this case, following checks will fail and wifi-connect
# will be launched even if the device will be able to connect to a WiFi network.
# If this is your case, you can wait for a while and then check for the connection.
# sleep 15

# Choose a condition for running WiFi Connect according to your use case:

# 1. Is there a default gateway?
# ip route | grep default

# 2. Is there Internet connectivity?
# nmcli -t g | grep full

# 3. Is there Internet connectivity via a google ping?
# wget --spider http://google.com 2>&1

# 4. Is there an active WiFi connection?
iwgetid -r

if [ $? -eq 0 ]; then
printf 'Skipping WiFi Connect\n'
else
printf 'Starting WiFi Connect\n'
./wifi-connect
fi

python -u src/app.py
1 change: 1 addition & 0 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ def hello_world():
return render_template('index.html')

if __name__ == '__main__':
print('Starting Hello World')
app.run(host='0.0.0.0', port=80)
Loading