Google Cloud Run example
ADD
gcp-ts-cloudrun/Pulumi.yaml
+name: gcp-cloudrun
+runtime: nodejs
+description: Google Cloud Run example
+template:
+ config:
+ gcp:project:
+ description: The Google Cloud project to deploy into
+ gcp:region:
+ description: The Google Cloud region

ADD
gcp-ts-cloudrun/app/Dockerfile
+# Use the official lightweight Ruby image.
+FROM ruby:2.7-slim
+
+# Install production dependencies.
+WORKDIR /usr/src/app
+COPY Gemfile Gemfile.lock ./
+ENV BUNDLE_FROZEN=true
+RUN bundle install
+
+# Copy local code to the container image.
+COPY . ./
+
+# Run the web service on container startup.
+CMD ["ruby", "./app.rb"]

ADD
gcp-ts-cloudrun/app/Gemfile
+source 'https://rubygems.org'
+
+gem 'sinatra'
+gem 'rack', '>= 2.0.6'

ADD
gcp-ts-cloudrun/app/Gemfile.lock
+GEM
+ remote: https://rubygems.org/
+ specs:
+ mustermann (1.1.1)
+ ruby2_keywords (~> 0.0.1)
+ rack (2.1.1)
+ rack-protection (2.0.8.1)
+ rack
+ ruby2_keywords (0.0.2)
+ sinatra (2.0.8.1)
+ mustermann (~> 1.0)
+ rack (~> 2.0)
+ rack-protection (= 2.0.8.1)
+ tilt (~> 2.0)
+ tilt (2.0.10)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rack (>= 2.0.6)
+ sinatra
+
+BUNDLED WITH
+ 2.1.4

ADD
gcp-ts-cloudrun/app/app.rb
+require 'sinatra'
+
+set :bind, '0.0.0.0'
+
+get '/' do
+ target = ENV['TARGET'] || 'Pulumi'
+ "Hello #{target}!\n"
+end

ADD
gcp-ts-cloudrun/index.ts
+// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
+
+import * as pulumi from "@pulumi/pulumi";
+import * as docker from "@pulumi/docker";
+import * as gcp from "@pulumi/gcp";
+
+// Location to deploy Cloud Run services
+const location = gcp.config.region || "us-central1";
+
+// Enable Cloud Run service for the current project
+const enableCloudRun = new gcp.projects.Service("EnableCloudRun", {
+ service: "run.googleapis.com",
+});
+
+// ----------------------------------------------- //
+// Deploy a pre-existing Hello Cloud Run container //
+// ----------------------------------------------- //
+const helloService = new gcp.cloudrun.Service("hello", {
+ location,
+ template: {
+ spec: {
+ containers: [
+ { image: "gcr.io/cloudrun/hello" }
+ ]
+ }
+ },
+}, { dependsOn: enableCloudRun });
+
+// Open the service to public unrestricted access
+new gcp.cloudrun.IamMember("hello-everyone", {
+ service: helloService.name,
+ location,
+ role: "roles/run.invoker",
+ member: "allUsers",
+});
+
+// Export the URL
+export const helloUrl = helloService.status.url;
+
+
+// -------------------------------------- //
+// Deploy a custom container to Cloud Run //
+// -------------------------------------- //
+
+// Build a Docker image from our sample Ruby app and put it to Google Container Registry.
+// Note: Run `gcloud auth configure-docker` in your command line to configure auth to GCR.
+const imageName = "ruby-app";
+const myImage = new docker.Image(imageName, {
+ imageName: pulumi.interpolate`gcr.io/${gcp.config.project}/${imageName}:v1.0.0`,
+ build: {
+ context: "./app",
+ },
+});
+
+// Deploy to Cloud Run. Some extra parameters like concurrency and memory are set for illustration purpose.
+const rubyService = new gcp.cloudrun.Service("ruby", {
+ location,
+ template: {
+ spec: {
+ containers: [{
+ image: myImage.imageName,
+ resources: {
+ limits: {
+ memory: "1Gi",
+ },
+ },
+ }],
+ containerConcurrency: 50,
+ },
+ },
+}, { dependsOn: enableCloudRun });
+
+// Open the service to public unrestricted access
+new gcp.cloudrun.IamMember("ruby-everyone", {
+ service: rubyService.name,
+ location,
+ role: "roles/run.invoker",
+ member: "allUsers",
+});
+
+// Export the URL
+export const rubyUrl = rubyService.status.url;

ADD
gcp-ts-cloudrun/package.json
+{
+ "name": "gcp-ts-cloudrun",
+ "version": "1.0.0",
+ "devDependencies": {
+ "@types/node": "^8.0.0",
+ "@types/express": "^4.16.0"
+ },
+ "dependencies": {
+ "@pulumi/gcp": "^2.0.0",
+ "@pulumi/docker": "^1.0.0",
+ "@pulumi/pulumi": "^1.0.0"
+ }
+}

ADD
gcp-ts-cloudrun/tsconfig.json
+{
+ "compilerOptions": {
+ "outDir": "bin",
+ "target": "es2016",
+ "module": "commonjs",
+ "moduleResolution": "node",
+ "sourceMap": true,
+ "experimentalDecorators": true,
+ "pretty": true,
+ "noFallthroughCasesInSwitch": true,
+ "noImplicitAny": true,
+ "noImplicitReturns": true,
+ "forceConsistentCasingInFileNames": true,
+ "strictNullChecks": true
+ },
+ "files": [
+ "index.ts",
+ ]
+}

Google Cloud Run example