diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml index f9477d762..f87c6bbc2 100644 --- a/.github/workflows/docker-build.yaml +++ b/.github/workflows/docker-build.yaml @@ -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 @@ -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' }} @@ -97,11 +109,15 @@ jobs: - name: Set Docker tag run: | - { - echo "GIT_SHORT_HASH=$(git rev-parse --short HEAD)" - echo "BOARD=${{ matrix.board }}" - echo "SHM_SIZE=256mb" - } >> "$GITHUB_ENV" + echo "GIT_SHORT_HASH=$(git rev-parse --short HEAD)" >> $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 run: | diff --git a/bin/deploy_to_balena.sh b/bin/deploy_to_balena.sh index a8ac15689..e6266f85e 100755 --- a/bin/deploy_to_balena.sh +++ b/bin/deploy_to_balena.sh @@ -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 | \ diff --git a/tools/image_builder/__main__.py b/tools/image_builder/__main__.py index 5dd3258ab..20be6fb55 100644 --- a/tools/image_builder/__main__.py +++ b/tools/image_builder/__main__.py @@ -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'], @@ -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, @@ -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, diff --git a/tools/image_builder/utils.py b/tools/image_builder/utils.py index 7d0391e9b..9b7605b49 100644 --- a/tools/image_builder/utils.py +++ b/tools/image_builder/utils.py @@ -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: