Adding gcp typescript example for deploy of image to gcr and cloud run
ADD
gcp-ts-docker-gcr-cloudrun/cloud-run-deploy/.gitignore
+/bin/
+/node_modules/

ADD
gcp-ts-docker-gcr-cloudrun/cloud-run-deploy/Pulumi.yaml
+name: cloud-run-deploy
+runtime: nodejs
+description: A minimal Google Cloud TypeScript Pulumi program

ADD
gcp-ts-docker-gcr-cloudrun/cloud-run-deploy/index.ts
+// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
+
+import * as pulumi from "@pulumi/pulumi";
+import * as gcp from "@pulumi/gcp";
+import * as docker from "@pulumi/docker";
+
+const location = gcp.config.region || "us-central1";
+
+const config = new pulumi.Config();
+
+const configFile = config.require("docker-config-file");
+
+// Default to using ruby-app since that is the name of the image for the example.
+const imageName = config.get("image-name") ?? "ruby-app";
+
+const gcrDockerProvider = new docker.Provider('gcr', {
+ registryAuth: [{
+ address: "gcr.io",
+ configFile: configFile
+ }],
+});
+
+// Used to get the image from the google cloud registry. Output is required to make sure that the provider is in sync with this call.
+const registryImage = pulumi.output(
+ docker.getRegistryImage({
+ name: `gcr.io/${gcp.config.project}/${imageName}:latest`,
+}, {provider: gcrDockerProvider}));
+
+
+// Using the value from the registryImage to pull the image if it's new, pullTriggers looks for a new sha.
+var dockerImage = registryImage.apply(r => new docker.RemoteImage(`${imageName}-docker-image`, {
+ name: r.name!,
+ pullTriggers: [registryImage.sha256Digest!],
+ keepLocally: true
+}, {provider: gcrDockerProvider}));
+
+// String used to force the update using the new image.
+var truncatedSha = registryImage.sha256Digest.apply(d => imageName + "-" + d.substr(8,20));
+
+// Deploy to Cloud Run if there is a difference in the sha, denoted above.
+const rubyService = new gcp.cloudrun.Service("ruby", {
+ location,
+ name: truncatedSha,
+ template: {
+ spec: {
+ containers: [{
+ image: dockerImage.name,
+ }]
+ },
+ },
+}, {dependsOn: dockerImage});
+
+// Open the service to public unrestricted access
+const iamRuby = new gcp.cloudrun.IamMember("ruby-everyone", {
+ service: rubyService.name,
+ location,
+ role: "roles/run.invoker",
+ member: "allUsers",
+});
+
+export const rubyUrl = rubyService.status.url;
+

ADD
gcp-ts-docker-gcr-cloudrun/cloud-run-deploy/package.json
+{
+ "name": "cloud-run-deploy",
+ "devDependencies": {
+ "@types/node": "^8.0.0"
+ },
+ "dependencies": {
+ "@pulumi/pulumi": "^1.0.0",
+ "@pulumi/gcp": "^2.0.0",
+ "@pulumi/docker": "^1.0.0"
+ }
+}

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

ADD
gcp-ts-docker-gcr-cloudrun/docker-build-push-gcr/.gitignore
+/bin/
+/node_modules/

ADD
gcp-ts-docker-gcr-cloudrun/docker-build-push-gcr/Pulumi.yaml
+name: gcr-build-image
+runtime: nodejs
+description: A minimal Google Cloud TypeScript Pulumi program

ADD
gcp-ts-docker-gcr-cloudrun/docker-build-push-gcr/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-docker-gcr-cloudrun/docker-build-push-gcr/app/Gemfile
+source 'https://rubygems.org'
+
+gem 'sinatra'
+gem 'rack', '>= 2.0.6'

ADD
gcp-ts-docker-gcr-cloudrun/docker-build-push-gcr/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-docker-gcr-cloudrun/docker-build-push-gcr/app/app.rb
+require 'sinatra'
+
+set :bind, '0.0.0.0'
+
+get '/' do
+ target = ENV['TARGET'] || 'Pulumi'
+ "Hello #{target}!\n"
+end

ADD
gcp-ts-docker-gcr-cloudrun/docker-build-push-gcr/index.ts
+// Copyright 2016-2020, Pulumi Corporation. All rights reserved.
+
+import * as docker from "@pulumi/docker";
+import * as gcp from "@pulumi/gcp";
+import * as pulumi from "@pulumi/pulumi";
+
+// Build and push image to gcr repository
+
+const imageName = "ruby-app";
+
+const myImage = new docker.Image(imageName, {
+ imageName: pulumi.interpolate`gcr.io/${gcp.config.project}/${imageName}:latest`,
+ build: {
+ context: "./app",
+ },
+});
+
+// Digest exported so it's easy to match updates happening in cloud run project
+export const digest = myImage.digest;

ADD
gcp-ts-docker-gcr-cloudrun/docker-build-push-gcr/package.json
+{
+ "name": "gcr-build-image",
+ "devDependencies": {
+ "@types/node": "^8.0.0"
+ },
+ "dependencies": {
+ "@pulumi/pulumi": "^1.0.0",
+ "@pulumi/docker": "^1.0.0",
+ "@pulumi/gcp": "^2.0.0"
+ }
+}

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

Adding gcp typescript example for deploy of image to gcr and cloud run (#652)

Co-Authored-By: Mikhail Shilkov <github@mikhail.io>