forked from cdklabs/cdk-ecr-deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.ecr-deployment.ts
64 lines (53 loc) · 1.91 KB
/
example.ecr-deployment.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import * as path from 'path';
import {
aws_iam as iam,
aws_ecr as ecr,
aws_ecr_assets as assets,
Stack,
App,
StackProps,
RemovalPolicy,
} from 'aws-cdk-lib';
// eslint-disable-next-line no-duplicate-imports
import * as ecrDeploy from '../src/index';
class TestECRDeployment extends Stack {
constructor(scope: App, id: string, props?: StackProps) {
super(scope, id, props);
const repo = new ecr.Repository(this, 'NginxRepo', {
repositoryName: 'nginx',
removalPolicy: RemovalPolicy.DESTROY,
});
// const repo = ecr.Repository.fromRepositoryName(this, 'Repo', 'test');
const image = new assets.DockerImageAsset(this, 'CDKDockerImage', {
directory: path.join(__dirname, 'docker'),
});
new ecrDeploy.ECRDeployment(this, 'DeployECRImage', {
src: new ecrDeploy.DockerImageName(image.imageUri),
dest: new ecrDeploy.DockerImageName(`${repo.repositoryUri}:latest`),
architecture: 'arm64',
});
new ecrDeploy.ECRDeployment(this, 'DeployDockerImage', {
src: new ecrDeploy.DockerImageName('javacs3/javacs3:latest', 'dockerhub'),
dest: new ecrDeploy.DockerImageName(`${repo.repositoryUri}:dockerhub`),
architecture: 'arm64',
}).addToPrincipalPolicy(new iam.PolicyStatement({
effect: iam.Effect.ALLOW,
actions: [
'secretsmanager:GetSecretValue',
],
resources: ['*'],
}));
// Your can also copy a docker archive image tarball from s3
// new ecrDeploy.ECRDeployment(this, 'DeployDockerImage', {
// src: new ecrDeploy.S3ArchiveName('bucket-name/nginx.tar', 'nginx:latest'),
// dest: new ecrDeploy.DockerImageName(`${repo.repositoryUri}:latest`),
// });
}
}
const app = new App();
new TestECRDeployment(app, 'test-ecr-deployments', {
env: { region: 'ap-northeast-1' },
});
app.synth();