forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
83 lines (71 loc) · 2.44 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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";
// Location to deploy Cloud Run services
const location = gcp.config.region || "us-central1";
// Enable Cloud Run service for the current project
// Commented out not to disable the service at every destroy
// 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" },
],
},
},
});
// Open the service to public unrestricted access
const iamHello = new gcp.cloudrun.IamMember("hello-everyone", {
service: helloService.name,
location,
role: "roles/run.invoker",
member: "allUsers",
});
// Export the URL
export const helloUrl = helloService.statuses[0].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,
},
},
});
// 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 the URL
export const rubyUrl = rubyService.statuses[0].url;