Skip to content

Commit a92c462

Browse files
fix: Docker image build and deployment process for Pi 4 (#2199)
1 parent 13073e3 commit a92c462

File tree

4 files changed

+65
-19
lines changed

4 files changed

+65
-19
lines changed

.github/workflows/docker-build.yaml

+23-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
needs: run-tests
3030
strategy:
3131
matrix:
32-
board: ['pi1', 'pi2', 'pi3', 'pi4', 'pi5', 'x86']
32+
board: ['pi1', 'pi2', 'pi3', 'pi4', 'pi4-64', 'pi5', 'x86']
3333
python-version: ["3.11"]
3434
runs-on: ubuntu-latest
3535

@@ -80,9 +80,21 @@ jobs:
8080

8181
- name: Build Containers
8282
run: |
83-
poetry run python -m tools.image_builder \
84-
--build-target=${{ matrix.board }} \
85-
--push
83+
if [ "${{ matrix.board }}" == "pi4" ]; then
84+
poetry run python -m tools.image_builder \
85+
--build-target=pi4 \
86+
--target-platform=linux/arm/v8 \
87+
--push
88+
elif [ "${{ matrix.board }}" == "pi4-64" ]; then
89+
poetry run python -m tools.image_builder \
90+
--build-target=pi4 \
91+
--target-platform=linux/arm64/v8 \
92+
--push
93+
else
94+
poetry run python -m tools.image_builder \
95+
--build-target=${{ matrix.board }} \
96+
--push
97+
fi
8698
8799
balena:
88100
if: ${{ github.ref == 'refs/heads/master' }}
@@ -98,7 +110,13 @@ jobs:
98110
- name: Set Docker tag
99111
run: |
100112
echo "GIT_SHORT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
101-
echo "BOARD=${{ matrix.board }}" >> $GITHUB_ENV
113+
114+
if [ "${{ matrix.board }}" == "pi4" ]; then
115+
echo "BOARD=${{ matrix.board }}-64" >> $GITHUB_ENV
116+
else
117+
echo "BOARD=${{ matrix.board }}" >> $GITHUB_ENV
118+
fi
119+
102120
echo "SHM_SIZE=256mb" >> $GITHUB_ENV
103121
104122
- name: Prepare Balena file

bin/deploy_to_balena.sh

+4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ if [[ -z "${SHM_SIZE+x}" ]]; then
8282
fi
8383

8484
function prepare_balena_file() {
85+
if [[ "$BOARD" == "pi4" ]]; then
86+
export BOARD="pi4-64"
87+
fi
88+
8589
mkdir -p balena-deploy
8690
cp balena.yml balena-deploy/
8791
cat docker-compose.balena.yml.tmpl | \

tools/image_builder/__main__.py

+30-11
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ def build_image(
127127
default='x86',
128128
type=click.Choice(BUILD_TARGET_OPTIONS),
129129
)
130+
@click.option(
131+
'--target-platform',
132+
help='Override the default target platform',
133+
)
130134
@click.option(
131135
'--service',
132136
default=['all'],
@@ -156,6 +160,7 @@ def build_image(
156160
def main(
157161
clean_build: bool,
158162
build_target: str,
163+
target_platform: str,
159164
service,
160165
disable_cache_mounts: bool,
161166
environment: str,
@@ -168,24 +173,38 @@ def main(
168173

169174
build_parameters = get_build_parameters(build_target)
170175
board = build_parameters['board']
171-
target_platform = build_parameters['target_platform']
172176
base_image = build_parameters['base_image']
173177

174-
docker_tag = get_docker_tag(git_branch, board)
178+
# Override target platform if specified
179+
platform = target_platform or build_parameters['target_platform']
180+
docker_tag = get_docker_tag(git_branch, board, platform)
181+
182+
# Determine which services to build
175183
services_to_build = SERVICES if 'all' in service else list(set(service))
176184

177-
for service in services_to_build:
178-
docker_tags = [
179-
f'screenly/anthias-{service}:{docker_tag}',
180-
f'screenly/anthias-{service}:{git_short_hash}-{board}',
181-
f'screenly/srly-ose-{service}:{docker_tag}',
182-
f'screenly/srly-ose-{service}:{git_short_hash}-{board}',
183-
]
185+
# Build Docker images
186+
for service_name in services_to_build:
187+
# Define tag components
188+
namespaces = ['screenly/anthias', 'screenly/srly-ose']
189+
version_suffix = (
190+
f'{board}-64' if board == 'pi4' and platform == 'linux/arm64/v8'
191+
else f'{board}'
192+
)
193+
194+
# Generate all tags
195+
docker_tags = []
196+
for namespace in namespaces:
197+
# Add latest/branch tags
198+
docker_tags.append(f'{namespace}-{service_name}:{docker_tag}')
199+
# Add version tags
200+
docker_tags.append(
201+
f'{namespace}-{service_name}:{git_short_hash}-{version_suffix}'
202+
)
184203

185204
build_image(
186-
service,
205+
service_name,
187206
board,
188-
target_platform,
207+
platform,
189208
disable_cache_mounts,
190209
git_hash,
191210
git_short_hash,

tools/image_builder/utils.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ def get_build_parameters(build_target: str) -> dict:
4646
return default_build_parameters
4747

4848

49-
def get_docker_tag(git_branch: str, board: str) -> str:
49+
def get_docker_tag(git_branch: str, board: str, platform: str) -> str:
50+
result_board = board
51+
52+
if platform == 'linux/arm64/v8' and board == 'pi4':
53+
result_board = f'{board}-64'
54+
5055
if git_branch == 'master':
51-
return f'latest-{board}'
56+
return f'latest-{result_board}'
5257
else:
53-
return f'{git_branch}-{board}'
58+
return f'{git_branch}-{result_board}'
5459

5560

5661
def generate_dockerfile(service: str, context: dict) -> None:

0 commit comments

Comments
 (0)