blob: ba79450d7a75a36706fc9c75a1e7e05a6ceb5b29 [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: Build the Static Base Image
# ==========================================
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args: ['-c', 'docker pull us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:latest || exit 0']
- name: 'gcr.io/cloud-builders/docker'
dir: 'cloud_build/flutter_agy_docker/'
args:
- 'build'
- '--cache-from'
- 'us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:latest'
- '--build-arg'
- 'FLUTTER_VERSION=$_FLUTTER_VERSION'
- '-t'
- 'us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:$_FLUTTER_VERSION'
- '-f'
- 'Dockerfile.base'
- '.'
# ==========================================
# STEP 2: Build the Auto-Updating Dev Image
# ==========================================
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args: ['-c', 'docker pull us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:latest || exit 0']
- name: 'gcr.io/cloud-builders/docker'
dir: 'cloud_build/flutter_agy_docker/'
args:
- 'build'
- '--cache-from'
- 'us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:latest'
- '--build-arg'
- 'FLUTTER_VERSION=$_FLUTTER_VERSION'
# Force apt-get to run by injecting the unique build ID
- '--build-arg'
- 'CACHE_BUSTER=$BUILD_ID'
- '-t'
- 'us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:$_FLUTTER_VERSION'
- '-f'
- 'Dockerfile'
- '.'
# ==========================================
# STEP 3: Conditionally Tag and Push 'latest', 'stable', or 'beta'
# ==========================================
- name: 'gcr.io/cloud-builders/docker'
entrypoint: 'bash'
args:
- '-c'
- |
set -euo pipefail
# Install curl and jq (handles both Debian and Alpine builder variants)
# We temporarily disable exit-on-error to allow the fallback to work cleanly
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)
# Validate that the versions were successfully parsed.
# -z "$$STABLE_VERSION" checks if the variable is an empty string (e.g., if jq failed entirely).
# "$$STABLE_VERSION" == "null" checks if jq succeeded but couldn't find the requested data in the JSON.
if [ -z "$$STABLE_VERSION" ] || [ "$$STABLE_VERSION" == "null" ]; then
echo "Error: STABLE_VERSION could not be parsed from JSON. The JSON structure may have changed."
exit 1
fi
if [ -z "$$BETA_VERSION" ] || [ "$$BETA_VERSION" == "null" ]; then
echo "Error: BETA_VERSION could not be parsed from JSON. The JSON structure may have changed."
exit 1
fi
echo "Current stable version is: $$STABLE_VERSION"
echo "Current beta version is: $$BETA_VERSION"
echo "Building for version: $_FLUTTER_VERSION"
if [ "$_FLUTTER_VERSION" == "$$STABLE_VERSION" ]; then
echo "Version $_FLUTTER_VERSION is stable. Tagging and pushing as latest and stable."
# Tag the previously built versioned images
docker tag us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:$_FLUTTER_VERSION us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:stable
docker tag us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:$_FLUTTER_VERSION us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:latest
docker tag us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:$_FLUTTER_VERSION us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:stable
docker tag us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:$_FLUTTER_VERSION us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:latest
# Push the new tags
docker push us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:stable
docker push us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:latest
docker push us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:stable
docker push us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:latest
elif [ "$_FLUTTER_VERSION" == "$$BETA_VERSION" ]; then
echo "Version $_FLUTTER_VERSION is beta. Tagging and pushing as beta."
# Tag the previously built versioned images
docker tag us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:$_FLUTTER_VERSION us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:beta
docker tag us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:$_FLUTTER_VERSION us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:beta
# Push the new tags
docker push us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:beta
docker push us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:beta
else
echo "Version $_FLUTTER_VERSION is neither the stable nor beta release. Skipping extra tags."
fi
substitutions:
_FLUTTER_VERSION: "3.44.3"
# Push both the base and the final developer image to the registry
images:
- 'us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_base:$_FLUTTER_VERSION'
- 'us-docker.pkg.dev/flutter-infra/flutter-infra/flutter_docker:$_FLUTTER_VERSION'
# Force Cloud Build to send logs directly to Cloud Logging
# instead of an autogenerated GCS bucket
options:
logging: CLOUD_LOGGING_ONLY