Skip to content

Commit 316c9ae

Browse files
authored
Merge pull request #1 from opsdev-ws/Dockerfile-adjustments
Optimize Dockerfile for web+Android, add ARM64 multi-arch build
2 parents 999c18d + d74001a commit 316c9ae

3 files changed

Lines changed: 109 additions & 39 deletions

File tree

.github/workflows/build-push.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build and Push Flutter Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'Dockerfile'
9+
- '.github/workflows/build-push.yml'
10+
workflow_dispatch:
11+
inputs:
12+
flutter_version:
13+
description: 'Flutter version to build (leave empty to use Dockerfile default)'
14+
required: false
15+
type: string
16+
17+
env:
18+
REGISTRY: ghcr.io
19+
IMAGE_NAME: opsdev-ws/flutter
20+
21+
jobs:
22+
build:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Extract Flutter version from Dockerfile
33+
id: version
34+
run: |
35+
if [ -n "${{ inputs.flutter_version }}" ]; then
36+
VERSION="${{ inputs.flutter_version }}"
37+
else
38+
VERSION=$(grep -m1 'ARG flutter_ver=' Dockerfile | cut -d'=' -f2)
39+
fi
40+
echo "flutter_version=${VERSION}" >> $GITHUB_OUTPUT
41+
echo "Building Flutter version: ${VERSION}"
42+
43+
- name: Set up QEMU
44+
uses: docker/setup-qemu-action@v3
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Log in to GitHub Container Registry
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Extract metadata
57+
id: meta
58+
uses: docker/metadata-action@v5
59+
with:
60+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
61+
tags: |
62+
type=raw,value=${{ steps.version.outputs.flutter_version }}
63+
type=raw,value=latest
64+
65+
- name: Build and push multi-arch image
66+
uses: docker/build-push-action@v5
67+
with:
68+
context: .
69+
platforms: linux/amd64,linux/arm64
70+
push: true
71+
tags: ${{ steps.meta.outputs.tags }}
72+
labels: ${{ steps.meta.outputs.labels }}
73+
cache-from: type=gha
74+
cache-to: type=gha,mode=max
75+
build-args: |
76+
flutter_ver=${{ steps.version.outputs.flutter_version }}

Dockerfile

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,24 @@ RUN apt-get update \
1515
&& apt-get upgrade -y \
1616
&& apt-get install -y --no-install-recommends --no-install-suggests \
1717
ca-certificates \
18+
git \
1819
&& update-ca-certificates \
1920
\
20-
# Install dependencies for Linux toolchain
21-
&& apt-get install -y --no-install-recommends --no-install-suggests \
22-
build-essential \
23-
clang cmake \
24-
lcov \
25-
libgtk-3-dev liblzma-dev \
26-
ninja-build \
27-
pkg-config \
28-
\
29-
# Install Flutter itself
30-
&& curl -fL -o /tmp/flutter.tar.xz \
31-
https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_${flutter_ver}-stable.tar.xz \
32-
&& tar -xf /tmp/flutter.tar.xz -C /usr/local/ \
21+
# Install Flutter via git clone (works on both x64 and arm64)
22+
&& git clone --depth 1 --branch ${flutter_ver} https://github.com/flutter/flutter.git /usr/local/flutter \
3323
&& git config --global --add safe.directory /usr/local/flutter \
24+
&& git config --system --add safe.directory /usr/local/flutter \
3425
&& flutter config --enable-android \
35-
--enable-linux-desktop \
3626
--enable-web \
27+
--no-enable-linux-desktop \
3728
--no-enable-ios \
38-
&& flutter precache --universal --linux --web --no-ios \
29+
&& flutter precache --universal --android --web --no-ios \
3930
&& (yes | flutter doctor --android-licenses) \
4031
&& flutter --version \
4132
\
42-
# Make Flutter tools available for non-root usage
33+
# Make Flutter cache writable for non-root users
4334
&& chown -R 1000:1000 /usr/local/flutter/packages/flutter_tools/.dart_tool/ \
35+
&& chmod -R a+w /usr/local/flutter/bin/cache \
4436
\
4537
&& rm -rf /var/lib/apt/lists/* \
4638
/tmp/*

tests/main.bats

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#!/usr/bin/env bats
22

33

4-
@test "clang is installed" {
5-
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
6-
'which clang'
7-
[ "$status" -eq 0 ]
8-
}
9-
10-
@test "clang runs ok" {
11-
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
12-
'clang --help'
13-
[ "$status" -eq 0 ]
14-
}
4+
# Disabled: clang not needed for web+Android builds
5+
#@test "clang is installed" {
6+
# run docker run --rm --pull never --entrypoint sh $IMAGE -c \
7+
# 'which clang'
8+
# [ "$status" -eq 0 ]
9+
#}
10+
#
11+
#@test "clang runs ok" {
12+
# run docker run --rm --pull never --entrypoint sh $IMAGE -c \
13+
# 'clang --help'
14+
# [ "$status" -eq 0 ]
15+
#}
1516

1617

1718
@test "flutter is installed" {
@@ -70,18 +71,19 @@
7071
}
7172

7273

73-
@test "Linux toolchain is enabled" {
74-
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
75-
'flutter config --list | grep "enable-linux-desktop: true"'
76-
[ "$status" -eq 0 ]
77-
}
78-
79-
@test "Linux toolchain is present" {
80-
run docker run --rm --pull never --entrypoint sh $IMAGE -c \
81-
'flutter doctor | grep "Linux toolchain"'
82-
[ "$status" -eq 0 ]
83-
[[ "$output" == *"[✓] Linux toolchain"* ]]
84-
}
74+
# Disabled: Linux desktop toolchain not needed for web+Android builds
75+
#@test "Linux toolchain is enabled" {
76+
# run docker run --rm --pull never --entrypoint sh $IMAGE -c \
77+
# 'flutter config --list | grep "enable-linux-desktop: true"'
78+
# [ "$status" -eq 0 ]
79+
#}
80+
#
81+
#@test "Linux toolchain is present" {
82+
# run docker run --rm --pull never --entrypoint sh $IMAGE -c \
83+
# 'flutter doctor | grep "Linux toolchain"'
84+
# [ "$status" -eq 0 ]
85+
# [[ "$output" == *"[✓] Linux toolchain"* ]]
86+
#}
8587

8688

8789
@test "Web toolchain is enabled" {

0 commit comments

Comments
 (0)