Skip to content

Commit

Permalink
fix: Docker image build and deployment process for Pi 4 (#2199)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomiguelino authored Jan 15, 2025
1 parent 13073e3 commit a92c462
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 19 deletions.
28 changes: 23 additions & 5 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
needs: run-tests
strategy:
matrix:
board: ['pi1', 'pi2', 'pi3', 'pi4', 'pi5', 'x86']
board: ['pi1', 'pi2', 'pi3', 'pi4', 'pi4-64', 'pi5', 'x86']
python-version: ["3.11"]
runs-on: ubuntu-latest

Expand Down Expand Up @@ -80,9 +80,21 @@ jobs:

- name: Build Containers
run: |
poetry run python -m tools.image_builder \
--build-target=${{ matrix.board }} \
--push
if [ "${{ matrix.board }}" == "pi4" ]; then
poetry run python -m tools.image_builder \
--build-target=pi4 \
--target-platform=linux/arm/v8 \
--push
elif [ "${{ matrix.board }}" == "pi4-64" ]; then
poetry run python -m tools.image_builder \
--build-target=pi4 \
--target-platform=linux/arm64/v8 \
--push
else
poetry run python -m tools.image_builder \
--build-target=${{ matrix.board }} \
--push
fi
balena:
if: ${{ github.ref == 'refs/heads/master' }}
Expand All @@ -98,7 +110,13 @@ jobs:
- name: Set Docker tag
run: |
echo "GIT_SHORT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "BOARD=${{ matrix.board }}" >> $GITHUB_ENV
if [ "${{ matrix.board }}" == "pi4" ]; then
echo "BOARD=${{ matrix.board }}-64" >> $GITHUB_ENV
else
echo "BOARD=${{ matrix.board }}" >> $GITHUB_ENV
fi
echo "SHM_SIZE=256mb" >> $GITHUB_ENV
- name: Prepare Balena file
Expand Down
4 changes: 4 additions & 0 deletions bin/deploy_to_balena.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ if [[ -z "${SHM_SIZE+x}" ]]; then
fi

function prepare_balena_file() {
if [[ "$BOARD" == "pi4" ]]; then
export BOARD="pi4-64"
fi

mkdir -p balena-deploy
cp balena.yml balena-deploy/
cat docker-compose.balena.yml.tmpl | \
Expand Down
41 changes: 30 additions & 11 deletions tools/image_builder/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def build_image(
default='x86',
type=click.Choice(BUILD_TARGET_OPTIONS),
)
@click.option(
'--target-platform',
help='Override the default target platform',
)
@click.option(
'--service',
default=['all'],
Expand Down Expand Up @@ -156,6 +160,7 @@ def build_image(
def main(
clean_build: bool,
build_target: str,
target_platform: str,
service,
disable_cache_mounts: bool,
environment: str,
Expand All @@ -168,24 +173,38 @@ def main(

build_parameters = get_build_parameters(build_target)
board = build_parameters['board']
target_platform = build_parameters['target_platform']
base_image = build_parameters['base_image']

docker_tag = get_docker_tag(git_branch, board)
# Override target platform if specified
platform = target_platform or build_parameters['target_platform']
docker_tag = get_docker_tag(git_branch, board, platform)

# Determine which services to build
services_to_build = SERVICES if 'all' in service else list(set(service))

for service in services_to_build:
docker_tags = [
f'screenly/anthias-{service}:{docker_tag}',
f'screenly/anthias-{service}:{git_short_hash}-{board}',
f'screenly/srly-ose-{service}:{docker_tag}',
f'screenly/srly-ose-{service}:{git_short_hash}-{board}',
]
# Build Docker images
for service_name in services_to_build:
# Define tag components
namespaces = ['screenly/anthias', 'screenly/srly-ose']
version_suffix = (
f'{board}-64' if board == 'pi4' and platform == 'linux/arm64/v8'
else f'{board}'
)

# Generate all tags
docker_tags = []
for namespace in namespaces:
# Add latest/branch tags
docker_tags.append(f'{namespace}-{service_name}:{docker_tag}')
# Add version tags
docker_tags.append(
f'{namespace}-{service_name}:{git_short_hash}-{version_suffix}'
)

build_image(
service,
service_name,
board,
target_platform,
platform,
disable_cache_mounts,
git_hash,
git_short_hash,
Expand Down
11 changes: 8 additions & 3 deletions tools/image_builder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ def get_build_parameters(build_target: str) -> dict:
return default_build_parameters


def get_docker_tag(git_branch: str, board: str) -> str:
def get_docker_tag(git_branch: str, board: str, platform: str) -> str:
result_board = board

if platform == 'linux/arm64/v8' and board == 'pi4':
result_board = f'{board}-64'

if git_branch == 'master':
return f'latest-{board}'
return f'latest-{result_board}'
else:
return f'{git_branch}-{board}'
return f'{git_branch}-{result_board}'


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

0 comments on commit a92c462

Please sign in to comment.