Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Build and Push Flutter Image

on:
push:
branches:
- main
paths:
- 'Dockerfile'
- '.github/workflows/build-push.yml'
workflow_dispatch:
inputs:
flutter_version:
description: 'Flutter version to build (leave empty to use Dockerfile default)'
required: false
type: string

env:
REGISTRY: ghcr.io
IMAGE_NAME: opsdev-ws/flutter

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Extract Flutter version from Dockerfile
id: version
run: |
if [ -n "${{ inputs.flutter_version }}" ]; then
VERSION="${{ inputs.flutter_version }}"
else
VERSION=$(grep -m1 'ARG flutter_ver=' Dockerfile | cut -d'=' -f2)
fi
echo "flutter_version=${VERSION}" >> $GITHUB_OUTPUT
echo "Building Flutter version: ${VERSION}"

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.version.outputs.flutter_version }}
type=raw,value=latest

- name: Build and push multi-arch image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
flutter_ver=${{ steps.version.outputs.flutter_version }}
24 changes: 8 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,24 @@ RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends --no-install-suggests \
ca-certificates \
git \
&& update-ca-certificates \
\
# Install dependencies for Linux toolchain
&& apt-get install -y --no-install-recommends --no-install-suggests \
build-essential \
clang cmake \
lcov \
libgtk-3-dev liblzma-dev \
ninja-build \
pkg-config \
\
# Install Flutter itself
&& curl -fL -o /tmp/flutter.tar.xz \
https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${flutter_ver}-stable.tar.xz \
&& tar -xf /tmp/flutter.tar.xz -C /usr/local/ \
# Install Flutter via git clone (works on both x64 and arm64)
&& git clone --depth 1 --branch ${flutter_ver} https://github.com/flutter/flutter.git /usr/local/flutter \
&& git config --global --add safe.directory /usr/local/flutter \
&& git config --system --add safe.directory /usr/local/flutter \
&& flutter config --enable-android \
--enable-linux-desktop \
--enable-web \
--no-enable-linux-desktop \
--no-enable-ios \
&& flutter precache --universal --linux --web --no-ios \
&& flutter precache --universal --android --web --no-ios \
&& (yes | flutter doctor --android-licenses) \
&& flutter --version \
\
# Make Flutter tools available for non-root usage
# Make Flutter cache writable for non-root users
&& chown -R 1000:1000 /usr/local/flutter/packages/flutter_tools/.dart_tool/ \
&& chmod -R a+w /usr/local/flutter/bin/cache \
\
&& rm -rf /var/lib/apt/lists/* \
/tmp/*
48 changes: 25 additions & 23 deletions tests/main.bats
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env bats


@test "clang is installed" {
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'which clang'
[ "$status" -eq 0 ]
}

@test "clang runs ok" {
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'clang --help'
[ "$status" -eq 0 ]
}
# Disabled: clang not needed for web+Android builds
#@test "clang is installed" {
# run docker run --rm --pull never --entrypoint sh $IMAGE -c \
# 'which clang'
# [ "$status" -eq 0 ]
#}
#
#@test "clang runs ok" {
# run docker run --rm --pull never --entrypoint sh $IMAGE -c \
# 'clang --help'
# [ "$status" -eq 0 ]
#}


@test "flutter is installed" {
Expand Down Expand Up @@ -70,18 +71,19 @@
}


@test "Linux toolchain is enabled" {
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'flutter config --list | grep "enable-linux-desktop: true"'
[ "$status" -eq 0 ]
}

@test "Linux toolchain is present" {
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
'flutter doctor | grep "Linux toolchain"'
[ "$status" -eq 0 ]
[[ "$output" == *"[✓] Linux toolchain"* ]]
}
# Disabled: Linux desktop toolchain not needed for web+Android builds
#@test "Linux toolchain is enabled" {
# run docker run --rm --pull never --entrypoint sh $IMAGE -c \
# 'flutter config --list | grep "enable-linux-desktop: true"'
# [ "$status" -eq 0 ]
#}
#
#@test "Linux toolchain is present" {
# run docker run --rm --pull never --entrypoint sh $IMAGE -c \
# 'flutter doctor | grep "Linux toolchain"'
# [ "$status" -eq 0 ]
# [[ "$output" == *"[✓] Linux toolchain"* ]]
#}


@test "Web toolchain is enabled" {
Expand Down