forked from pulumi/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
51 lines (45 loc) · 2.01 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
// Copyright 2016-2019, Pulumi Corporation. All rights reserved.
import * as awsx from "@pulumi/awsx";
import * as pulumi from "@pulumi/pulumi";
// Get the password to use for Redis from config.
const config = new pulumi.Config();
const redisPassword = config.require("redisPassword");
const redisPort = 6379;
// The data layer for the application
// Use the 'image' property to point to a pre-built Docker image.
const redisListener = new awsx.elasticloadbalancingv2.NetworkListener("voting-app-cache", { port: redisPort });
const redisCache = new awsx.ecs.FargateService("voting-app-cache", {
taskDefinitionArgs: {
containers: {
redis: {
image: "redis:alpine",
memory: 512,
portMappings: [redisListener],
command: ["redis-server", "--requirepass", redisPassword],
},
},
},
});
const redisEndpoint = redisListener.endpoint;
// A custom container for the frontend, which is a Python Flask app
// Use the 'build' property to specify a folder that contains a Dockerfile.
// Pulumi builds the container for you and pushes to an ECR registry
const frontendListener = new awsx.elasticloadbalancingv2.NetworkListener("voting-app-frontend", { port: 80 });
const frontend = new awsx.ecs.FargateService("voting-app-frontend", {
taskDefinitionArgs: {
containers: {
votingAppFrontend: {
image: awsx.ecs.Image.fromPath("voting-app-frontend", "./frontend"), // path to the folder containing the Dockerfile
memory: 512,
portMappings: [frontendListener],
environment: redisEndpoint.apply(e => [
{ name: "REDIS", value: e.hostname },
{ name: "REDIS_PORT", value: e.port.toString() },
{ name: "REDIS_PWD", value: redisPassword },
]),
},
},
},
});
// Export a variable that will be displayed during 'pulumi up'
export let frontendURL = frontendListener.endpoint;