mirror of
https://github.com/Screenly/Anthias.git
synced 2025-12-23 22:38:05 -05:00
fix: Docker image build and deployment process for Pi 4 (#2199)
This commit is contained in:
28
.github/workflows/docker-build.yaml
vendored
28
.github/workflows/docker-build.yaml
vendored
@@ -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' }}
|
||||
@@ -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
|
||||
|
||||
@@ -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 | \
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user