Skip to content

Commit 3523d3a

Browse files
committed
Working version on Alpine except wifi connect
1 parent c595ee4 commit 3523d3a

File tree

4 files changed

+83
-12
lines changed

4 files changed

+83
-12
lines changed

Dockerfile.template

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
1-
# see more about dockerfile templates here: https://www.balena.io/docs/learn/develop/dockerfile/
2-
FROM python:3.13-slim-bookworm
1+
FROM python:3.12-alpine3.22
2+
3+
RUN apk add --no-cache grep dnsmasq curl wireless-tools
4+
# freetype-dev \
5+
# libjpeg-turbo-dev \
6+
# gcc \
7+
# musl-dev \
8+
# linux-headers
9+
10+
# use latest version. If specific version is required, it should be provided as vX.Y.Z, e.g v4.11.37
11+
ARG VERSION="latest"
12+
13+
# create /usr/src/app/ui directory where we will extract pre-built UI
14+
WORKDIR /usr/src/app/ui
315

4-
# Set our working directory
516
WORKDIR /usr/src/app
617

18+
RUN \
19+
export BASE_URL="https://github.com/balena-os/wifi-connect/releases" &&\
20+
DETECTED_ARCH=$(uname -m) &&\
21+
case $DETECTED_ARCH in \
22+
"aarch64") \
23+
BINARY_ARCH_NAME="aarch64-unknown-linux-gnu" ;; \
24+
"x86_64") \
25+
BINARY_ARCH_NAME="x86_64-unknown-linux-gnu" ;;\
26+
"armv7l") \
27+
BINARY_ARCH_NAME="armv7-unknown-linux-gnueabihf" ;;\
28+
*) \
29+
echo >&2 "error: unsupported architecture ($DETECTED_ARCH)"; exit 1 ;; \
30+
esac;\
31+
if [ ${VERSION} = "latest" ]; then \
32+
export URL_PARTIAL="latest/download" ; \
33+
else \
34+
export URL_PARTIAL="download/${VERSION}" ; \
35+
fi; \
36+
curl -Ls "$BASE_URL/$URL_PARTIAL/wifi-connect-$BINARY_ARCH_NAME.tar.gz" \
37+
| tar -xvz -C /usr/src/app/ && \
38+
curl -Ls "$BASE_URL/$URL_PARTIAL/wifi-connect-ui.tar.gz" \
39+
| tar -xvz -C /usr/src/app/ui
40+
741
# Copy requirements.txt first for better cache on later pushes
842
COPY requirements.txt requirements.txt
943

@@ -13,5 +47,7 @@ RUN pip install -r requirements.txt
1347
# This will copy all files in our root to the working directory in the container
1448
COPY . ./
1549

50+
COPY scripts/start.sh .
51+
1652
# main.py will run when container starts up on the device
17-
CMD ["python","-u","src/app.py"]
53+
CMD ["sh", "./start.sh"]

requirements.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
click==8.1.8
2-
Flask==2.3.3
3-
importlib-metadata==4.13.0
4-
itsdangerous==2.2.0
5-
Jinja2==3.1.6
6-
MarkupSafe==2.1.5
7-
Werkzeug==2.0.3
8-
zipp==3.21.0
1+
click
2+
Flask
3+
importlib-metadata
4+
itsdangerous
5+
Jinja2
6+
MarkupSafe
7+
Werkzeug
8+
zipp

scripts/start.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
sleep 1 # give Supervisor time to attach log stream
3+
set -x
4+
5+
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket
6+
7+
# Optional step - it takes couple of seconds (or longer) to establish a WiFi connection
8+
# sometimes. In this case, following checks will fail and wifi-connect
9+
# will be launched even if the device will be able to connect to a WiFi network.
10+
# If this is your case, you can wait for a while and then check for the connection.
11+
# sleep 15
12+
13+
# Choose a condition for running WiFi Connect according to your use case:
14+
15+
# 1. Is there a default gateway?
16+
# ip route | grep default
17+
18+
# 2. Is there Internet connectivity?
19+
# nmcli -t g | grep full
20+
21+
# 3. Is there Internet connectivity via a google ping?
22+
# wget --spider http://google.com 2>&1
23+
24+
# 4. Is there an active WiFi connection?
25+
iwgetid -r
26+
27+
if [ $? -eq 0 ]; then
28+
printf 'Skipping WiFi Connect\n'
29+
else
30+
printf 'Starting WiFi Connect\n'
31+
./wifi-connect
32+
fi
33+
34+
python -u src/app.py

src/app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ def hello_world():
66
return render_template('index.html')
77

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

0 commit comments

Comments
 (0)