-
Notifications
You must be signed in to change notification settings - Fork 875
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
diana esteves
committed
May 8, 2024
1 parent
81d71fa
commit b3cc7d8
Showing
14 changed files
with
325 additions
and
4 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 |
---|---|---|
|
@@ -29,3 +29,4 @@ Gopkg.lock | |
.project | ||
.classpath | ||
target/ | ||
*-test/ |
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,12 @@ | ||
name: ${PROJECT} | ||
description: ${DESCRIPTION} | ||
runtime: nodejs | ||
|
||
template: | ||
description: An example that builds a Docker image in DBC and deploys a container to AWS Fargate. | ||
config: | ||
builder: | ||
description: Your existing Docker Build Cloud builder. (e.g., cloud-pulumi-my-cool-builder) | ||
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,70 @@ | ||
# Deploy a container with a DBC-built image on AWS Fargate | ||
|
||
Deploys a AWS Fargate service. The service uses a Docker image that is build with Docker Build Cloud (DBC). The image is pushed to AWS ECR. This template prompts the user for an existing DBC builder. | ||
|
||
Last revision: May 2024. | ||
|
||
## 📋 Pre-requisites | ||
|
||
- [Docker Build Cloud (DBC) builder](https://build.docker.com/) | ||
- 🚨 You **must** complete the [DBC builder setup steps](https://docs.docker.com/build/cloud/setup/#steps) 🚨 | ||
- Docker Desktop / CLI | ||
- [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 local 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-dbc | ||
$ npm install | ||
``` | ||
|
||
Once copied to your machine, feel free to edit as needed. | ||
|
||
Alternatively, click the button below to use [Pulumi Deployments](https://www.pulumi.com/docs/pulumi-cloud/deployments/) to deploy this app: | ||
|
||
[![Deploy](../.buttons/deploy-with-pulumi-dark.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/aws-ts-containers-dbc/README.md#gh-light-mode-only) | ||
[![Deploy](../.buttons/deploy-with-pulumi-light.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/aws-ts-containers-dbc/README.md#gh-dark-mode-only) | ||
|
||
## 🎬 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 | ||
``` | ||
|
||
## 🧐 Useful resources | ||
|
||
- [🤖Try Pulumi AI](https://www.pulumi.com/ai) - Use natural-language prompts to generate Pulumi infrastructure-as-code programs in any language. | ||
- [📋 Registry](https://www.pulumi.com/registry/) - Search for packages and learn about the supported resources you need. Install the package directly into your project, browse the API documentation, and start building. | ||
- [📚 Documentation](https://www.pulumi.com/docs/) - Learn about Pulumi concepts, follow user guides, and consult the reference documentation. | ||
|
||
## 🏘️ Community and Social | ||
|
||
Engage with our community to elevate your developer experience: | ||
|
||
- **Join our online [Pulumi Community on Slack](https://slack.pulumi.com/)** - Interact with over 13K Pulumi developers for collaborative problem-solving and knowledge-sharing! | ||
- **Join a [Local Pulumi User Groups (PUGs)](https://www.meetup.com/pro/pugs/)** - Attend tech-packed meetups and hands-on virtual or in-person workshops. | ||
- **Follow [@PulumiCorp](https://twitter.com/PulumiCorp) on X (Twitter)** - Get real-time updates, technical insights, and sneak peeks into the latest features. | ||
- **Subscribe to our YouTube Channel, [PulumiTV](https://www.youtube.com/@PulumiTV)** - Learn about AI / ML essentials, launches, workshops, demos and more. | ||
- **Follow our [LinkedIn](https://www.linkedin.com/company/pulumi/)** - Uncover company news, achievements, and behind-the-scenes glimpses. |
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></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,151 @@ | ||
// Copyright 2024, Pulumi Corporation. All rights reserved. | ||
|
||
// Pulumi program to build with DBC and push a Docker image | ||
// to AWS ECR and deploys it in AWS Fargate with an ALB. | ||
|
||
// Pre-requisites: | ||
// - AWS Credentials | ||
// - Docker Build Cloud (DBC) | ||
// - Docker Desktop / CLI | ||
// - Pulumi CLI (https://www.pulumi.com/docs/get-started/install/) | ||
// - *Recommended* Pulumi Cloud account (https://app.pulumi.com/signup) | ||
|
||
// This Pulumi template is meant to be copied via: | ||
// $ pulumi new https://github.com/pulumi/examples/tree/master/aws-ts-containers-dbc | ||
// Once copied to your machine, feel free to edit as needed. | ||
|
||
// As a good practice, update any dependencies to the latest version. | ||
// $ npm update --save | ||
|
||
// How to run this program in your terminal: | ||
// $ pulumi up | ||
|
||
// Import required libraries, update package.json if you add more. | ||
// (Recommended to run `npm update --save` after adding more libraries) | ||
import * as docker_build from "@pulumi/docker-build"; | ||
import * as pulumi from "@pulumi/pulumi"; // Required for Config and interpolation | ||
import * as aws from "@pulumi/aws"; // Required for ECS | ||
import * as awsx from "@pulumi/awsx"; | ||
|
||
// 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(); | ||
// Docker Build Cloud (DBC) builder name | ||
const builder = config.require("builder"); // Example, "cloud-pulumi-my-cool-builder" | ||
|
||
// 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. | ||
// This image will be built with Docker Build Cloud (DBC) and pushed to ECR. | ||
// It uses the Docker Build provider | ||
const image = new docker_build.Image("image", { | ||
// ____ _ ____ _ _ _ | ||
// | _ \ ___ ___| | _____ _ __ | __ ) _ _(_) | __| | | ||
// | | | |/ _ \ / __| |/ / _ \ '__| | _ \| | | | | |/ _` | | ||
// | |_| | (_) | (__| < __/ | | |_) | |_| | | | (_| | | ||
// |____/ \___/ \___|_|\_\___|_| |____/ \__,_|_|_|\__,_| | ||
// / ___| | ___ _ _ __| | | ||
// | | | |/ _ \| | | |/ _` | | ||
// | |___| | (_) | |_| | (_| | | ||
// \____|_|\___/ \__,_|\__,_| | ||
// Enable exec to run a custom docker-buildx binary with support | ||
// for Docker Build Cloud (DBC). | ||
exec: true, | ||
// Configures the name of your existing buildx builder to use. | ||
builder: { | ||
name: builder, // Example, "cloud-pulumi-my-cool-builder", | ||
}, | ||
// _ _ | ||
// ___ __ _ ___| |__ (_)_ __ __ _ | ||
// / __/ _` |/ __| '_ \| | '_ \ / _` | | ||
// | (_| (_| | (__| | | | | | | | (_| | | ||
// \___\__,_|\___|_| |_|_|_| |_|\__, | | ||
// |___/ | ||
// 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`, | ||
}, | ||
}], | ||
// (Learn more about interpolation with Pulumi) | ||
// https://www.pulumi.com/docs/concepts/inputs-outputs/all/#using-string-interpolation | ||
|
||
// _ _ _ _ _ __ | ||
// _ __ ___ _ _| | |_(_) _ __ | | __ _| |_ / _| ___ _ __ _ __ ___ | ||
// | '_ ` _ \| | | | | __| |_____| '_ \| |/ _` | __| |_ / _ \| '__| '_ ` _ \ | ||
// | | | | | | |_| | | |_| |_____| |_) | | (_| | |_| _| (_) | | | | | | | | | ||
// |_| |_| |_|\__,_|_|\__|_| | .__/|_|\__,_|\__|_| \___/|_| |_| |_| |_| | ||
// |_| | ||
// Build multi-platforms | ||
platforms: [ | ||
docker_build.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-dbc", | ||
"main": "index.ts", | ||
"dependencies": { | ||
"@pulumi/aws": "^6.33.1", | ||
"@pulumi/awsx": "^2.9.0", | ||
"@pulumi/docker-build": "^0.0.2", | ||
"@pulumi/pulumi": "^3.115.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.12.11" | ||
} | ||
} |
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
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,64 @@ | ||
# Example to build a docker image with Docker Build Cloud (DBC) | ||
|
||
Builds a Docker Image from an NGINX local Dockerfile. This template prompts the user for an existing DBC builder. | ||
|
||
Last revision: May 2024. | ||
|
||
## 📋 Pre-requisites | ||
|
||
- [Docker Build Cloud (DBC) builder](https://build.docker.com/) | ||
- 🚨 You **must** complete the [DBC builder setup steps](https://docs.docker.com/build/cloud/setup/#steps) 🚨 | ||
- Docker Desktop / CLI | ||
- [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) | ||
|
||
## 👩🏫 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/dockerbuild-ts-dbc | ||
$ npm install | ||
``` | ||
Once copied to your machine, feel free to edit as needed. | ||
|
||
Alternatively, click the button below to use [Pulumi Deployments](https://www.pulumi.com/docs/pulumi-cloud/deployments/) to deploy this app: | ||
|
||
[![Deploy](../.buttons/deploy-with-pulumi-dark.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/dockerbuild-ts-dbc/README.md#gh-light-mode-only) | ||
[![Deploy](../.buttons/deploy-with-pulumi-light.svg)](https://app.pulumi.com/new?template=https://github.com/pulumi/examples/blob/master/dockerbuild-ts-dbc/README.md#gh-dark-mode-only) | ||
|
||
## 🎬 How to run | ||
|
||
To deploy your infrastructure, run: | ||
|
||
```bash | ||
$ pulumi up | ||
# select 'yes' to confirm the expected changes | ||
# 🎉 Ta-Da! | ||
``` | ||
|
||
## 🧹 Clean up | ||
|
||
To clean up your infrastructure, run: | ||
|
||
```bash | ||
$ pulumi destroy | ||
# select 'yes' to confirm the expected changes | ||
``` | ||
|
||
## 🧐 Useful resources | ||
|
||
- [🤖Try Pulumi AI](https://www.pulumi.com/ai) - Use natural-language prompts to generate Pulumi infrastructure-as-code programs in any language. | ||
- [📋 Registry](https://www.pulumi.com/registry/) - Search for packages and learn about the supported resources you need. Install the package directly into your project, browse the API documentation, and start building. | ||
- [📚 Documentation](https://www.pulumi.com/docs/) - Learn about Pulumi concepts, follow user guides, and consult the reference documentation. | ||
|
||
## 🏘️ Community and Social | ||
|
||
Engage with our community to elevate your developer experience: | ||
|
||
- **Join our online [Pulumi Community on Slack](https://slack.pulumi.com/)** - Interact with over 13K Pulumi developers for collaborative problem-solving and knowledge-sharing! | ||
- **Join a [Local Pulumi User Groups (PUGs)](https://www.meetup.com/pro/pugs/)** - Attend tech-packed meetups and hands-on virtual or in-person workshops. | ||
- **Follow [@PulumiCorp](https://twitter.com/PulumiCorp) on X (Twitter)** - Get real-time updates, technical insights, and sneak peeks into the latest features. | ||
- **Subscribe to our YouTube Channel, [PulumiTV](https://www.youtube.com/@PulumiTV)** - Learn about AI / ML essentials, launches, workshops, demos and more. | ||
- **Follow our [LinkedIn](https://www.linkedin.com/company/pulumi/)** - Uncover company news, achievements, and behind-the-scenes glimpses. |
File renamed without 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
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
File renamed without changes.