-
Notifications
You must be signed in to change notification settings - Fork 880
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: ${PROJECT} | ||
description: ${DESCRIPTION} | ||
runtime: nodejs | ||
|
||
template: | ||
description: An example that builds a Docker image and deploys a container to AWS Fargate. | ||
config: | ||
aws:region: | ||
description: The AWS region to deploy into | ||
default: us-west-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Deploys a container with a Docker Build image on AWS Fargate | ||
|
||
Deploys a AWS Fargate service. The service uses a Docker image that is build with the new Docker Build provider. The image is pushed to AWS ECR. | ||
|
||
Last revision: July 2024. | ||
|
||
## 📋 Pre-requisites | ||
|
||
- [Pulumi CLI](https://www.pulumi.com/docs/get-started/install/) | ||
- *Recommended* [Pulumi Cloud account](https://app.pulumi.com/signup) | ||
- [npm](https://www.npmjs.com/get-npm) | ||
- AWS account and credentials configured | ||
|
||
## 👩🏫 Get started | ||
|
||
This Pulumi example is written as a template. It is meant to be copied via `pulumi new` as follows: | ||
|
||
```bash | ||
pulumi new https://github.com/pulumi/examples/tree/master/aws-ts-containers-dockerbuild | ||
npm install | ||
``` | ||
|
||
Once copied to your machine, feel free to edit as needed. | ||
|
||
## 🎬 How to run | ||
|
||
To deploy your infrastructure, run: | ||
|
||
```bash | ||
$ pulumi up | ||
# select 'yes' to confirm the expected changes | ||
# wait a bit for everything to get deployed | ||
# ... | ||
# confirm your service is up and running | ||
$ curl $(pulumi stack output url) | ||
# 🎉 Ta-Da! | ||
``` | ||
|
||
## 🧹 Clean up | ||
|
||
To clean up your infrastructure, run: | ||
|
||
```bash | ||
$ pulumi destroy | ||
# select 'yes' to confirm the expected changes | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM nginx | ||
COPY content /usr/share/nginx/html |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<head><meta charset="UTF-8"> | ||
<title>Hello, Pulumi!</title></head> | ||
<body> | ||
<p>Hello, containers!</p> | ||
<p>Made with ❤️ with <a href="https://pulumi.com">Pulumi</a> and deployed to Fargate</p> | ||
</body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2024, Pulumi Corporation. All rights reserved. | ||
|
||
// Import required libraries | ||
import * as aws from "@pulumi/aws"; // Required for ECS | ||
import * as awsx from "@pulumi/awsx"; | ||
import * as dockerBuild from "@pulumi/docker-build"; | ||
import * as pulumi from "@pulumi/pulumi"; // Required for Config and interpolation | ||
|
||
// Read the current stack configuration, see Pulumi.<STACK>.yaml file | ||
// Configuration values can be set with the pulumi config set command | ||
// OR by editing the Pulumi.<STACK>.yaml file. | ||
// OR during the pulumi new wizard. | ||
const config = new pulumi.Config(); | ||
|
||
// An ECS cluster to deploy into. | ||
const cluster = new aws.ecs.Cluster("cluster", {}); | ||
|
||
// An ALB to serve the container endpoint to the internet. | ||
const loadbalancer = new awsx.lb.ApplicationLoadBalancer("loadbalancer", {}); | ||
|
||
// An ECR repository to store our application's container image. | ||
const ecr = new awsx.ecr.Repository("repo", { | ||
forceDelete: true, | ||
}); | ||
|
||
// Grab auth credentials for ECR. | ||
const auth = aws.ecr.getAuthorizationTokenOutput({ | ||
registryId: ecr.repository.registryId, | ||
}); | ||
|
||
// Build and publish our application's container image from ./app to the ECR repository. | ||
const image = new dockerBuild.Image("image", { | ||
|
||
// Use the pushed image as a cache source. | ||
cacheFrom: [{ | ||
registry: { | ||
ref: pulumi.interpolate`${ecr.repository.repositoryUrl}:cache`, | ||
}, | ||
}], | ||
cacheTo: [{ | ||
registry: { | ||
imageManifest: true, | ||
ociMediaTypes: true, | ||
ref: pulumi.interpolate`${ecr.repository.repositoryUrl}:cache`, | ||
}, | ||
}], | ||
|
||
// Build multi-platforms | ||
platforms: [ | ||
dockerBuild.Platform.Linux_amd64, | ||
// add more as needed | ||
], | ||
push: true, | ||
// Provide our ECR credentials. | ||
registries: [{ | ||
address: ecr.repository.repositoryUrl, | ||
password: auth.password, | ||
username: auth.userName, | ||
}], | ||
// | ||
// Other parameters | ||
// | ||
// Tag our image with our ECR repository's address. | ||
tags: [pulumi.interpolate`${ecr.repository.repositoryUrl}:latest`], | ||
// The Dockerfile resides in the app directory for this example. | ||
context: { | ||
location: "app", | ||
}, | ||
}); | ||
|
||
// Deploy an ECS Service on Fargate to host the application container. | ||
const service = new awsx.ecs.FargateService("service", { | ||
cluster: cluster.arn, | ||
assignPublicIp: true, | ||
taskDefinitionArgs: { | ||
container: { | ||
name: "service-container", | ||
image: image.ref, | ||
cpu: 128, | ||
memory: 512, | ||
essential: true, | ||
portMappings: [{ | ||
containerPort: 80, | ||
targetGroup: loadbalancer.defaultTargetGroup, | ||
}], | ||
}, | ||
}, | ||
}); | ||
|
||
// The URL at which the container's HTTP endpoint will be available. | ||
export const url = pulumi.interpolate`http://${loadbalancer.loadBalancer.dnsName}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "aws-ts-containers-dockerbuildcloud", | ||
"main": "index.ts", | ||
"dependencies": { | ||
"@pulumi/aws": "^6.44.0", | ||
"@pulumi/awsx": "^2.13.0", | ||
"@pulumi/docker-build": "^0.0.3", | ||
"@pulumi/pulumi": "^3.124.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.10" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters