aws-rails-provisioner 0.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ import cdk = require('@aws-cdk/core');
2
+ {{#services}}
3
+ import {{.}} = require('@aws-cdk/aws-{{.}}');
4
+ {{/services}}
5
+
6
+ export class {{stack_prefix}}InitStack extends cdk.Stack {
7
+ public readonly vpc: ec2.IVpc;
8
+ public readonly cluster: ecs.ICluster;
9
+
10
+ constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
11
+ super(scope, id, props);
12
+
13
+ {{#vpc}}
14
+ // Setting up VPC with subnets
15
+ const vpc = new ec2.Vpc(this, 'Vpc', {
16
+ maxAzs: {{max_azs}},
17
+ cidr: '{{cidr}}',
18
+ {{#enable_dns}}
19
+ enableDnsSupport: true,
20
+ {{/enable_dns}}
21
+ natGateways: {{nat_gateways}},
22
+ {{#nat_gateway_subnets}}
23
+ natGatewaySubnets: {
24
+ {{#name}}
25
+ subnetName: '{{.}}'
26
+ {{/name}}
27
+ {{#type}}
28
+ subnetType: ec2.SubnetType.{{.}}
29
+ {{/type}}
30
+ },
31
+ {{/nat_gateway_subnets}}
32
+ subnetConfiguration: [
33
+ {{#subnets}}
34
+ {
35
+ cidrMask: {{cidr_mask}},
36
+ name: '{{subnet_name}}',
37
+ subnetType: ec2.SubnetType.{{type}}
38
+ },
39
+ {{/subnets}}
40
+ ]
41
+ });
42
+ this.vpc = vpc;
43
+ {{/vpc}}
44
+
45
+ this.cluster = new ecs.Cluster(this, 'FargateCluster', {
46
+ vpc: vpc
47
+ });
48
+
49
+ }
50
+ }
@@ -0,0 +1,156 @@
1
+ import cdk = require('@aws-cdk/core');
2
+ {{#services}}
3
+ import {{abbr}} = require('@aws-cdk/aws-{{value}}');
4
+ {{/services}}
5
+
6
+ interface {{stack_prefix}}PipelineStackProps {
7
+ vpc: ec2.IVpc,
8
+ dbUrl: string,
9
+ repoName: string,
10
+ service: ecs.FargateService,
11
+ db: rds.DatabaseCluster
12
+ }
13
+
14
+ export class {{stack_prefix}}PipelineStack extends cdk.Stack {
15
+ constructor(scope: cdk.App, id: string, props: {{stack_prefix}}PipelineStackProps) {
16
+ super(scope, id);
17
+
18
+ const pipeline = new codepipeline.Pipeline(this, 'FargatePipeline', {
19
+ pipelineName: '{{pipeline_name}}',
20
+ });
21
+
22
+ const repo = new codecommit.Repository(this, 'CodeCommitRepo', {
23
+ repositoryName: '{{source_repo}}',
24
+ description: '{{source_description}}'
25
+ });
26
+
27
+ const sourceOutput = new codepipeline.Artifact();
28
+ const sourceStage = pipeline.addStage({
29
+ stageName: 'Source',
30
+ actions: [
31
+ new pipelineactions.CodeCommitSourceAction({
32
+ actionName: 'SourceAction',
33
+ repository: repo,
34
+ output: sourceOutput
35
+ })
36
+ ]
37
+ });
38
+
39
+ const ecrRepo = ecr.Repository.fromRepositoryName(this, 'ImageRepo', props.repoName);
40
+
41
+ const role = new iam.Role(this, 'ImageBuildRole', {
42
+ assumedBy: new iam.ServicePrincipal('codebuild.amazonaws.com')
43
+ });
44
+ const policy = new iam.PolicyStatement();
45
+ policy.addAllResources();
46
+ policy.addActions(
47
+ "ecr:BatchCheckLayerAvailability",
48
+ "ecr:CompleteLayerUpload",
49
+ "ecr:GetAuthorizationToken",
50
+ "ecr:InitiateLayerUpload",
51
+ "ecr:PutImage",
52
+ "ecr:UploadLayerPart"
53
+ );
54
+ role.addToPolicy(policy);
55
+
56
+ {{#build}}
57
+ const build = new codebuild.PipelineProject(this, 'ImageBuildToECR', {
58
+ projectName: '{{project_name}}',
59
+ description: '{{description}}',
60
+ environmentVariables: {
61
+ 'REPO_NAME': {
62
+ value: ecrRepo.repositoryName,
63
+ type: codebuild.BuildEnvironmentVariableType.PLAINTEXT
64
+ },
65
+ 'REPO_PREFIX': {
66
+ value: ecrRepo.repositoryUri,
67
+ type: codebuild.BuildEnvironmentVariableType.PLAINTEXT
68
+ },
69
+ },
70
+ environment: {
71
+ buildImage: codebuild.LinuxBuildImage.{{image}},
72
+ privileged: true
73
+ },
74
+ buildSpec: codebuild.BuildSpec.fromSourceFilename('{{buildspec}}'),
75
+ {{#timeout}}
76
+ timeout: {{.}},
77
+ {{/timeout}}
78
+ role: role
79
+ });
80
+ {{/build}}
81
+
82
+ const buildOutput = new codepipeline.Artifact();
83
+ const buildStage = pipeline.addStage({
84
+ stageName: 'Build',
85
+ placement: {
86
+ justAfter: sourceStage
87
+ },
88
+ actions: [
89
+ new pipelineactions.CodeBuildAction({
90
+ actionName: 'ImageBuildAction',
91
+ input: sourceOutput,
92
+ outputs: [ buildOutput ],
93
+ project: build
94
+ })
95
+ ]
96
+ });
97
+ {{#migration}}
98
+
99
+ const migration = new codebuild.PipelineProject(this, 'DBMigration', {
100
+ projectName: '{{project_name}}',
101
+ description: '{{description}}',
102
+ environmentVariables: {
103
+ 'DATABASE_URL': {
104
+ value: props.dbUrl,
105
+ type: codebuild.BuildEnvironmentVariableType.PLAINTEXT
106
+ }
107
+ },
108
+ environment:{
109
+ buildImage: codebuild.LinuxBuildImage.{{image}}
110
+ },
111
+ buildSpec: codebuild.BuildSpec.fromSourceFilename('{{buildspec}}'),
112
+ {{#timeout}}
113
+ timeout: {{.}},
114
+ {{/timeout}}
115
+ vpc: props.vpc,
116
+ subnetSelection: {
117
+ subnetType: ec2.SubnetType.PRIVATE
118
+ }
119
+ });
120
+ migration.connections.allowToDefaultPort(props.db, 'DB Migration CodeBuild');
121
+
122
+ const migrationStage = pipeline.addStage({
123
+ stageName: 'DBMigration',
124
+ placement: {
125
+ justAfter: buildStage
126
+ },
127
+ actions: [
128
+ new pipelineactions.CodeBuildAction({
129
+ actionName: 'DBMigrationAction',
130
+ project: migration,
131
+ input: sourceOutput
132
+ })
133
+ ]
134
+ });
135
+ {{/migration}}
136
+
137
+ pipeline.addStage({
138
+ stageName: 'Deploy',
139
+ placement: {
140
+ {{#migration}}
141
+ justAfter: migrationStage
142
+ {{/migration}}
143
+ {{#skip_migration}}
144
+ justAfter: buildStage
145
+ {{/skip_migration}}
146
+ },
147
+ actions: [
148
+ new pipelineactions.EcsDeployAction({
149
+ actionName: 'FargateDeployAction',
150
+ service: props.service,
151
+ input: buildOutput
152
+ })
153
+ ]
154
+ });
155
+ }
156
+ }
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env node
2
+
3
+ import cdk = require('@aws-cdk/core');
4
+ import { {{stack_prefix}}InitStack } from '../lib/{{path_prefix}}-init-stack';
5
+ {{#stacks}}
6
+ import { {{stack_prefix}}FargateStack } from '../lib/{{path_prefix}}-fargate-stack';
7
+ {{#enable_cicd}}
8
+ import { {{stack_prefix}}PipelineStack } from '../lib/{{path_prefix}}-pipeline-stack';
9
+ {{/enable_cicd}}
10
+ {{/stacks}}
11
+
12
+ const app = new cdk.App();
13
+ const initStack = new {{stack_prefix}}InitStack(app, '{{stack_prefix}}InitStack');
14
+ {{#stacks}}
15
+
16
+ // for service :{{name}}
17
+ {{#enable_cicd}}const {{const_prefix}}FargateStack = {{/enable_cicd}}new {{stack_prefix}}FargateStack(app, '{{stack_prefix}}FargateStack', {
18
+ vpc: initStack.vpc,
19
+ cluster: initStack.cluster
20
+ });
21
+
22
+ {{#enable_cicd}}
23
+ new {{stack_prefix}}PipelineStack(app, '{{stack_prefix}}PipelineStack', {
24
+ vpc: initStack.vpc,
25
+ dbUrl: {{const_prefix}}FargateStack.dbUrl,
26
+ db: {{const_prefix}}FargateStack.db,
27
+ repoName: {{const_prefix}}FargateStack.repoName,
28
+ service: {{const_prefix}}FargateStack.service
29
+ });
30
+ {{/enable_cicd}}
31
+ {{/stacks}}
32
+
33
+ app.synth();
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aws-rails-provisioner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Amazon Web Services
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-rds
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-secretsmanager
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mustache
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ description: Define and deploy containerized Ruby on Rails Applications on AWS.
56
+ email:
57
+ - chejingy@amazon.com
58
+ executables:
59
+ - aws-rails-provisioner
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - bin/aws-rails-provisioner
64
+ - lib/aws-rails-provisioner.rb
65
+ - lib/aws-rails-provisioner/build.rb
66
+ - lib/aws-rails-provisioner/cdk_builder.rb
67
+ - lib/aws-rails-provisioner/cdk_code_builder.rb
68
+ - lib/aws-rails-provisioner/cdk_deployer.rb
69
+ - lib/aws-rails-provisioner/code_build.rb
70
+ - lib/aws-rails-provisioner/db_cluster.rb
71
+ - lib/aws-rails-provisioner/errors.rb
72
+ - lib/aws-rails-provisioner/fargate.rb
73
+ - lib/aws-rails-provisioner/migration.rb
74
+ - lib/aws-rails-provisioner/parser.rb
75
+ - lib/aws-rails-provisioner/scaling.rb
76
+ - lib/aws-rails-provisioner/service.rb
77
+ - lib/aws-rails-provisioner/services.rb
78
+ - lib/aws-rails-provisioner/subnet_selection.rb
79
+ - lib/aws-rails-provisioner/utils.rb
80
+ - lib/aws-rails-provisioner/version.rb
81
+ - lib/aws-rails-provisioner/view.rb
82
+ - lib/aws-rails-provisioner/views/fargate_stack.rb
83
+ - lib/aws-rails-provisioner/views/init_stack.rb
84
+ - lib/aws-rails-provisioner/views/pipeline_stack.rb
85
+ - lib/aws-rails-provisioner/views/project.rb
86
+ - lib/aws-rails-provisioner/vpc.rb
87
+ - templates/fargate_stack.mustache
88
+ - templates/init_stack.mustache
89
+ - templates/pipeline_stack.mustache
90
+ - templates/project.mustache
91
+ homepage: http://github.com/awslabs/aws-rails-provisioner
92
+ licenses:
93
+ - Apache-2.0
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">"
107
+ - !ruby/object:Gem::Version
108
+ version: 1.3.1
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.5.2
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: aws-rails-provisioner
115
+ test_files: []