blob: 6785012ce4a1d069f0a24a5130b20bfac3fe4b67 [file] [edit]
# Copyright 2022 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
steps:
# ==========================================
# STEP 1: Determine tags based on version
# ==========================================
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
set -euo pipefail
# Install curl and jq
set +e
apt-get update && apt-get install -y curl jq 2>/dev/null || apk add curl jq 2>/dev/null
set -e
# Fetch the JSON release data
echo "Fetching Flutter release data..."
JSON_DATA=$$(curl -sf https://storage.googleapis.com/flutter_infra_release/releases/releases_linux.json)
if [ -z "$$JSON_DATA" ]; then
echo "Error: Failed to fetch JSON release data from Google Cloud Storage."
exit 1
fi
# Extract the stable and beta versions
STABLE_VERSION=$$(echo "$$JSON_DATA" | \
jq -r '.current_release.stable as $$stable_hash | .releases[] | select(.hash == $$stable_hash) | .version' | head -n 1)
BETA_VERSION=$$(echo "$$JSON_DATA" | \
jq -r '.current_release.beta as $$beta_hash | .releases[] | select(.hash == $$beta_hash) | .version' | head -n 1)
if [ -z "$$STABLE_VERSION" ] || [ "$$STABLE_VERSION" == "null" ]; then
echo "Error: STABLE_VERSION could not be parsed."
exit 1
fi
if [ -z "$$BETA_VERSION" ] || [ "$$BETA_VERSION" == "null" ]; then
echo "Error: BETA_VERSION could not be parsed."
exit 1
fi
echo "Current stable version is: $$STABLE_VERSION"
echo "Current beta version is: $$BETA_VERSION"
echo "Building for version: $_FLUTTER_VERSION"
BASE_TAGS="us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:$_FLUTTER_VERSION"
DEV_TAGS="us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:$_FLUTTER_VERSION"
if [ "$_FLUTTER_VERSION" == "$$STABLE_VERSION" ]; then
echo "Version $_FLUTTER_VERSION is stable. Tagging as stable and latest."
BASE_TAGS="$$BASE_TAGS,us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:stable,us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:latest"
DEV_TAGS="$$DEV_TAGS,us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:stable,us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:latest"
elif [ "$_FLUTTER_VERSION" == "$$BETA_VERSION" ]; then
echo "Version $_FLUTTER_VERSION is beta. Tagging as beta."
BASE_TAGS="$$BASE_TAGS,us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:beta"
DEV_TAGS="$$DEV_TAGS,us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:beta"
else
echo "Version $_FLUTTER_VERSION is neither stable nor beta. Using version tag only."
fi
echo "BASE_TAGS=$$BASE_TAGS" > /workspace/tags.env
echo "DEV_TAGS=$$DEV_TAGS" >> /workspace/tags.env
# ==========================================
# STEP 2: Build the Multi-Arch Base Image
# ==========================================
- name: 'gcr.io/cloud-builders/docker'
dir: 'cloud_build/flutter_agy_docker/'
entrypoint: 'bash'
args:
- '-c'
- |
set -euo pipefail
# Register QEMU emulators for multi-arch build
docker run --privileged --rm tonistiigi/binfmt --install all
# Create a new buildx builder
docker buildx create --use
# Read tags
source /workspace/tags.env
# Convert comma-separated tags to -t arguments
IFS=',' read -ra ADDR <<< "$$BASE_TAGS"
TAG_ARGS=()
for tag in "$${ADDR[@]}"; do
TAG_ARGS+=("-t" "$$tag")
done
# Build and push the base image
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:latest \
--cache-to type=inline \
--build-arg FLUTTER_VERSION=$_FLUTTER_VERSION \
"$${TAG_ARGS[@]}" \
-f Dockerfile.base \
--push \
.
# ==========================================
# STEP 3: Build the Multi-Arch Dev Image
# ==========================================
- name: 'gcr.io/cloud-builders/docker'
dir: 'cloud_build/flutter_agy_docker/'
entrypoint: 'bash'
args:
- '-c'
- |
set -euo pipefail
# Register QEMU emulators
docker run --privileged --rm tonistiigi/binfmt --install all
# Create a new buildx builder
docker buildx create --use
# Read tags
source /workspace/tags.env
# Convert comma-separated tags to -t arguments
IFS=',' read -ra ADDR <<< "$$DEV_TAGS"
TAG_ARGS=()
for tag in "$${ADDR[@]}"; do
TAG_ARGS+=("-t" "$$tag")
done
# Build and push the developer image
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:latest \
--cache-to type=inline \
--build-arg FLUTTER_VERSION=$_FLUTTER_VERSION \
--build-arg CACHE_BUSTER=$BUILD_ID \
"$${TAG_ARGS[@]}" \
-f Dockerfile \
--push \
.
substitutions:
_FLUTTER_VERSION: "3.44.3"
options:
logging: CLOUD_LOGGING_ONLY