-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for ECR getCredentials function
- Loading branch information
1 parent
82da9b2
commit 25505b9
Showing
7 changed files
with
131 additions
and
0 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,3 @@ | ||
name: ecr-image | ||
runtime: nodejs | ||
description: Publish docker images to ECR |
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,41 @@ | ||
# examples/ecr-image | ||
|
||
This example demonstrates how to use Pulumi to publish a Docker image to Amazon Elastic Container Registry (ECR). | ||
|
||
## Steps | ||
|
||
1. **Install Dependencies** | ||
|
||
Ensure you have the necessary dependencies installed: | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
2. **Run Pulumi Up** | ||
|
||
Run Pulumi to create the ECR repository and push the Docker image: | ||
|
||
```sh | ||
pulumi up | ||
``` | ||
|
||
Confirm the changes and wait for the process to complete. | ||
|
||
## Files | ||
|
||
- `index.ts`: Contains the Pulumi program to create the ECR repository and push the Docker image. | ||
- `Dockerfile`: Dockerfile for building the Docker image. | ||
|
||
## Clean Up | ||
|
||
To clean up the resources created by Pulumi: | ||
|
||
```sh | ||
pulumi destroy | ||
``` | ||
|
||
## Additional Resources | ||
|
||
- [Pulumi AWS Documentation](https://www.pulumi.com/docs/intro/cloud-providers/aws/) | ||
- [Amazon ECR Documentation](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.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,3 @@ | ||
FROM public.ecr.aws/nginx/nginx | ||
RUN echo "<h1>Hello Pulumi!</h1>" > \ | ||
/usr/share/nginx/html/index.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,36 @@ | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as aws from "@pulumi/aws"; | ||
import * as docker from "@pulumi/docker-build"; | ||
|
||
const config = new pulumi.Config("aws"); | ||
const providerOpts = { provider: new aws.Provider("prov", { region: <aws.Region>config.require("envRegion") }) }; | ||
|
||
const repository = new aws.ecr.Repository("myrepository", { | ||
forceDelete: true, | ||
}, providerOpts); | ||
|
||
// Get registry info (credentials and endpoint) so we can publish to it. | ||
const credentials = aws.ecr.getCredentialsOutput({ registryId: repository.registryId }, providerOpts); | ||
const decodedCredentials = credentials.authorizationToken.apply(tok => Buffer.from(tok, "base64").toString()); | ||
const registryInfo = decodedCredentials.apply(creds => { | ||
const [username, password] = creds.split(":"); | ||
if (!password || !username) { | ||
throw new Error("Invalid credentials"); | ||
} | ||
return { | ||
address: credentials.proxyEndpoint, | ||
username: username, | ||
password: password, | ||
}; | ||
}); | ||
|
||
const image = new docker.Image("myimage", { | ||
push: true, | ||
tags: [pulumi.interpolate`${repository.repositoryUrl}:latest`], | ||
context: { | ||
location: "./app", | ||
}, | ||
registries: [registryInfo], | ||
}); | ||
|
||
export const digest = image.digest; |
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,16 @@ | ||
{ | ||
"name": "ecr-image", | ||
"version": "0.0.1", | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@pulumi/aws": "^6.0.0", | ||
"@pulumi/docker-build": "^0.0.7" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^8.0.0" | ||
} | ||
} |
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,18 @@ | ||
{ | ||
"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" | ||
] | ||
} |
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