Skip to content

Commit

Permalink
Add configuration files for Cloud Build (#2579)
Browse files Browse the repository at this point in the history
* Add configuration files for Cloud Build

Cloud Build YAML files to:
- Deploy dart_pad to Firebase Hosting
- Deploy sketch_pad to Firebase Hosting
- Deploy dart-services to Cloud Run
- Build and upload a Docker image with the Flutter SDK to
  Artifact Registry
- Build and upload a Docker image with the Firebase SDK to
  Artifact Registry

add deploy-dartpad.yaml file

Add .firebaserc files for Cloud Build

Add Cloud Build trigger configuration for dart-services.

Add Cloud Build configuration files

test: avoid N1 machine type

specify dir in flutter/cloudbuild.yaml

update .cloud_build/README.md

specify dir in firebase/cloudbuild.yaml

use "main" in sketch_pad cloud build config

* Update README.md

* Update project names

* run 'precache --web' after 'fluter upgrade' in Dockerfile
  • Loading branch information
johnpryan committed Jun 30, 2023
1 parent e2751fb commit 49533f7
Show file tree
Hide file tree
Showing 22 changed files with 581 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .cloud_build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Cloud Build configuration

Cloud Build configuration files for dart-pad and dart-services.


# Contents

- `dart-services/` - Deploys the dart_services server to Cloud Run - `flutter/`
- `dart_pad.yaml` - Deploys `dart_pad` to Firebase Hosting
- `sketch_pad.yaml` - Deploys `sketch_pad` to Firebase Hosting

This folder also has configuration files from [cloud-builders-community][], which are
needed to build and deploy `dart_pad` and `sketch_pad` to Firebase Hosting:
- Uploads an image that contains the Flutter SDK to Container Registry -
`firebase/`
- Uploads an image that contains the Firebase SDK to Container
Registry

# Deploying

These steps are configured as triggers in GCP, but you can also run
them manually.

Deploy dart_pad:

```bash
gcloud builds submit --config .cloud_build/dart_pad.yaml
```

To deploy sketch_pad:

```bash
gcloud builds submit --config .cloud_build/sketch_pad.yaml
```

Update the Flutter SDK images:

```bash
gcloud builds submit . --config=.cloud_build/flutter/cloudbuild.yaml
```

Update the Firebase SDK images:

```bash
gcloud builds submit . --config=.cloud_build/firebase/cloudbuild.yaml
```


[cloud-builders-community]: https://github.com/GoogleCloudPlatform/cloud-builders-community/blob/master/flutter/Dockerfile
18 changes: 18 additions & 0 deletions .cloud_build/dart-services/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Dart-services Cloud Build configuration

Cloud Build configuration for dart-services. This runs automatically
using a Cloud Build trigger.

To deploy a new version manually, run:

```
gcloud builds submit \
--config $FLUTTER_CHANNEL.yaml \
--project=dart-services \
--substitutions \
REPO_NAME=dart-pad \
COMMIT_SHA=$COMMIT_SHA
```

Where `$FLUTTER_CHANNEL` is `stable`, `beta`, `dev`, `main`, or `old`. The REPO_NAME and COMMIT_SHA are for adding tags to the Docker image.

50 changes: 50 additions & 0 deletions .cloud_build/dart-services/beta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '--no-cache'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- .
- '-f'
- cloud_run_beta.Dockerfile
id: Build
dir: pkgs/dart_services
- name: gcr.io/cloud-builders/docker
args:
- push
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
id: Push
dir: pkgs/dart_services
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
args:
- run
- services
- update
- $_SERVICE_NAME
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS
- '--region=$_DEPLOY_REGION'
- '--quiet'
id: Deploy
entrypoint: gcloud
dir: pkgs/dart_services
timeout: 1200s
images:
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
options:
machineType: N1_HIGHCPU_8
substitutionOption: ALLOW_LOOSE
substitutions:
_LABELS: gcb-trigger-id=a38ddc5d-884e-4db1-a491-a5e9ff22c262
_TRIGGER_ID: a38ddc5d-884e-4db1-a491-a5e9ff22c262
_SERVICE_NAME: flutter-beta-channel
_DEPLOY_REGION: us-central1
_GCR_HOSTNAME: us.gcr.io
_PLATFORM: managed
tags:
- gcp-cloud-build-deploy-cloud-run
- gcp-cloud-build-deploy-cloud-run-managed
- flutter-beta-channel
50 changes: 50 additions & 0 deletions .cloud_build/dart-services/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '--no-cache'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- .
- '-f'
- cloud_run_dev.Dockerfile
id: Build
dir: pkgs/dart_services
- name: gcr.io/cloud-builders/docker
args:
- push
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
id: Push
dir: pkgs/dart_services
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
args:
- run
- services
- update
- $_SERVICE_NAME
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS
- '--region=$_DEPLOY_REGION'
- '--quiet'
id: Deploy
entrypoint: gcloud
dir: pkgs/dart_services
timeout: 1200s
images:
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
options:
machineType: N1_HIGHCPU_8
substitutionOption: ALLOW_LOOSE
substitutions:
_SERVICE_NAME: flutter-dev-channel
_DEPLOY_REGION: us-central1
_GCR_HOSTNAME: us.gcr.io
_PLATFORM: managed
_LABELS: gcb-trigger-id=34c44e1d-d415-413a-9af6-005b575e1800
_TRIGGER_ID: 34c44e1d-d415-413a-9af6-005b575e1800
tags:
- gcp-cloud-build-deploy-cloud-run
- gcp-cloud-build-deploy-cloud-run-managed
- flutter-dev-channel
50 changes: 50 additions & 0 deletions .cloud_build/dart-services/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '--no-cache'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- .
- '-f'
- cloud_run_main.Dockerfile
id: Build
dir: pkgs/dart_services
- name: gcr.io/cloud-builders/docker
args:
- push
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
id: Push
dir: pkgs/dart_services
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
args:
- run
- services
- update
- $_SERVICE_NAME
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS
- '--region=$_DEPLOY_REGION'
- '--quiet'
id: Deploy
entrypoint: gcloud
dir: pkgs/dart_services
timeout: 1200s
images:
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
options:
machineType: E2_HIGHCPU_8
substitutionOption: ALLOW_LOOSE
substitutions:
_DEPLOY_REGION: us-central1
_GCR_HOSTNAME: us.gcr.io
_PLATFORM: managed
_LABELS: gcb-trigger-id=1ce24c6a-c6b4-4368-bbd7-2ea13a839f48
_TRIGGER_ID: 1ce24c6a-c6b4-4368-bbd7-2ea13a839f48
_SERVICE_NAME: flutter-master-channel
tags:
- gcp-cloud-build-deploy-cloud-run
- gcp-cloud-build-deploy-cloud-run-managed
- flutter-master-channel
50 changes: 50 additions & 0 deletions .cloud_build/dart-services/old.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '--no-cache'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- .
- '-f'
- cloud_run_old.Dockerfile
id: Build
dir: pkgs/dart_services
- name: gcr.io/cloud-builders/docker
args:
- push
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
id: Push
dir: pkgs/dart_services
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
args:
- run
- services
- update
- $_SERVICE_NAME
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS
- '--region=$_DEPLOY_REGION'
- '--quiet'
id: Deploy
entrypoint: gcloud
dir: pkgs/dart_services
timeout: 1200s
images:
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA'
options:
machineType: N1_HIGHCPU_8
substitutionOption: ALLOW_LOOSE
substitutions:
_GCR_HOSTNAME: us.gcr.io
_PLATFORM: managed
_LABELS: gcb-trigger-id=e6472250-2fe8-44de-985f-7822fa767bc7
_TRIGGER_ID: e6472250-2fe8-44de-985f-7822fa767bc7
_SERVICE_NAME: flutter-old-channel
_DEPLOY_REGION: us-central1
tags:
- gcp-cloud-build-deploy-cloud-run
- gcp-cloud-build-deploy-cloud-run-managed
- flutter-old-channel
50 changes: 50 additions & 0 deletions .cloud_build/dart-services/stable.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- '--no-cache'
- '-t'
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'
- .
- '-f'
- cloud_run.Dockerfile
id: Build
dir: pkgs/dart_services
- name: gcr.io/cloud-builders/docker
args:
- push
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'
id: Push
dir: pkgs/dart_services
- name: gcr.io/google.com/cloudsdktool/cloud-sdk
args:
- run
- services
- update
- $_SERVICE_NAME
- '--platform=managed'
- '--image=$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID,$_LABELS
- '--region=$_DEPLOY_REGION'
- '--quiet'
id: Deploy
entrypoint: gcloud
dir: pkgs/dart_services
timeout: 1200s
images:
- '$_GCR_HOSTNAME/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA'
options:
# machineType: N1_HIGHCPU_8
substitutionOption: ALLOW_LOOSE
substitutions:
_TRIGGER_ID: 6104a3eb-7116-4b2f-a864-2418bd8173bf
_DEPLOY_REGION: us-central1
_GCR_HOSTNAME: us.gcr.io
_PLATFORM: managed
_SERVICE_NAME: dart-service-stable
_LABELS: gcb-trigger-id=6104a3eb-7116-4b2f-a864-2418bd8173bf
tags:
- gcp-cloud-build-deploy-cloud-run
- gcp-cloud-build-deploy-cloud-run-managed
- dart-service-cloud-run
12 changes: 12 additions & 0 deletions .cloud_build/dart_pad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
steps:
- name: gcr.io/$PROJECT_ID/flutter:stable
entrypoint: 'dart'
args: ['pub', 'get']
dir: pkgs/dart_pad
- name: gcr.io/$PROJECT_ID/flutter:stable
entrypoint: 'dart'
args: ['run', 'tool/grind.dart', 'build']
dir: pkgs/dart_pad
- name: gcr.io/$PROJECT_ID/firebase
args: ['deploy', '--project=$PROJECT_ID', '--only=hosting']
dir: pkgs/dart_pad
16 changes: 16 additions & 0 deletions .cloud_build/firebase/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:lts-alpine3.14 AS app-env

# Install Python and Java and pre-cache emulator dependencies.
RUN apk add --no-cache python3 py3-pip openjdk11-jre bash && \
npm install -g firebase-tools && \
firebase setup:emulators:database && \
firebase setup:emulators:firestore && \
firebase setup:emulators:pubsub && \
firebase setup:emulators:storage && \
firebase setup:emulators:ui && \
rm -rf /var/cache/apk/*

ADD firebase.bash /usr/bin
RUN chmod +x /usr/bin/firebase.bash

ENTRYPOINT [ "/usr/bin/firebase.bash" ]
15 changes: 15 additions & 0 deletions .cloud_build/firebase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Cloud Build configuration for the Firebase SDK

To build and upload to Container Registry, run:

```bash
gcloud builds submit . \
--config=cloudbuild.yaml \
--project=$GCP_PROJECT
```

Where `$GCP_PROJECT` is the Google Cloud project name.

Original source: [cloud-builders-community][].

[cloud-builders-community]: https://github.com/GoogleCloudPlatform/cloud-builders-community/blob/master/flutter/Dockerfile
7 changes: 7 additions & 0 deletions .cloud_build/firebase/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/firebase', '.']
dir: .cloud_build/firebase
images:
- 'gcr.io/$PROJECT_ID/firebase'
tags: ['cloud-builders-community']
8 changes: 8 additions & 0 deletions .cloud_build/firebase/firebase.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# run the original firebase
if [ $FIREBASE_TOKEN ]; then
firebase "$@" --token $FIREBASE_TOKEN
else
firebase "$@"
fi
Loading

0 comments on commit 49533f7

Please sign in to comment.