lamby 2.2.2 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/lamby/templates/alb.rb +10 -2
  5. data/lib/lamby/templates/alb/Dockerfile +3 -0
  6. data/lib/lamby/templates/alb/Dockerfile-build +15 -0
  7. data/lib/lamby/templates/alb/_build +40 -0
  8. data/lib/lamby/templates/alb/_deploy +52 -0
  9. data/lib/lamby/templates/alb/app.rb +2 -0
  10. data/lib/lamby/templates/alb/deploy +5 -35
  11. data/lib/lamby/templates/alb/docker-compose.yml +17 -0
  12. data/lib/lamby/templates/alb/template.yaml +11 -11
  13. data/lib/lamby/templates/http.rb +10 -2
  14. data/lib/lamby/templates/http/Dockerfile +3 -0
  15. data/lib/lamby/templates/http/Dockerfile-build +15 -0
  16. data/lib/lamby/templates/http/_build +40 -0
  17. data/lib/lamby/templates/http/_deploy +35 -0
  18. data/lib/lamby/templates/http/app.rb +2 -0
  19. data/lib/lamby/templates/http/deploy +5 -18
  20. data/lib/lamby/templates/http/docker-compose.yml +17 -0
  21. data/lib/lamby/templates/http/template.yaml +7 -7
  22. data/lib/lamby/templates/rest.rb +10 -2
  23. data/lib/lamby/templates/rest/Dockerfile +3 -0
  24. data/lib/lamby/templates/rest/Dockerfile-build +15 -0
  25. data/lib/lamby/templates/rest/_build +40 -0
  26. data/lib/lamby/templates/rest/_deploy +35 -0
  27. data/lib/lamby/templates/rest/app.rb +2 -0
  28. data/lib/lamby/templates/rest/deploy +5 -18
  29. data/lib/lamby/templates/rest/docker-compose.yml +17 -0
  30. data/lib/lamby/templates/rest/template.yaml +9 -9
  31. data/lib/lamby/version.rb +1 -1
  32. metadata +17 -5
  33. data/lib/lamby/templates/alb/build +0 -23
  34. data/lib/lamby/templates/http/build +0 -23
  35. data/lib/lamby/templates/rest/build +0 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 149e90cb77c4ba7fa86e278f1b5faff11e271eec286de22564f423c7510b9b41
4
- data.tar.gz: 804d1d2df7a4ed8f61b3d7fdde9ee8d3c73c9902d5b846ced5f39b4680b3f672
3
+ metadata.gz: e8846dc8b26074a2887d0f5d0a605cd19345c4f1c5d36e2be5f856606c95f12e
4
+ data.tar.gz: 2251ce4c68c2e7d1160f1917cce9e858dab4e19d068edcaf310e997ac698d2ce
5
5
  SHA512:
6
- metadata.gz: '0911fda5872e2ea6b74c0fc0d358da8c641f89ebaf59c7ea143c62fb80baa35f5e0e301d21b4222535b42bdb0c3bad3d028083355321e0b8178d0b4e18b9c6c0'
7
- data.tar.gz: 7d827e35e4c19f714ddfb30182d00d51b944513c9ccf667782218be2429eb397f27c0cfdc2737b00aa2c992075061c8e5b3e7fdad59be2efb9097542156311cf
6
+ metadata.gz: 197fb20357ba00b1dd50a2c2ef6a6804532a861afe9fa2ae4490c1fa1d5ea8648e02ba505070afc06f96051a913ae89f2a1403c41e3750ac96d8af239468d633
7
+ data.tar.gz: 258e6f51dbc28f483286068e2b749a843e50a082fc18a198bf5242f27b509eb93f845bf06ab4bd49b2a6daacb00759794b77fd4b88991f088ce8ae59d38427f9
@@ -3,6 +3,12 @@
3
3
 
4
4
  See this http://keepachangelog.com link for information on how we want this documented formatted.
5
5
 
6
+ ## v2.5.0
7
+
8
+ #### Changed
9
+
10
+ * Install files to favor containers.
11
+
6
12
  ## v2.2.2
7
13
 
8
14
  #### Changed
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lamby (2.2.2)
4
+ lamby (2.5.0)
5
5
  rack
6
6
 
7
7
  GEM
@@ -7,19 +7,27 @@ say 'Copying files...'
7
7
  copy_file tpl_file('app.rb'), app_file('app.rb')
8
8
  copy_file tpl_file('template.yaml'), app_file('template.yaml')
9
9
  gsub_file app_file('template.yaml'), /APPNAMEHERE/, appname
10
+ copy_file tpl_file('Dockerfile'), app_file('Dockerfile')
11
+ copy_file tpl_file('Dockerfile-build'), app_file('Dockerfile-build')
12
+ copy_file tpl_file('docker-compose.yml'), app_file('docker-compose.yml')
10
13
 
11
14
  say 'Adding to .gitignore...'
12
15
  FileUtils.touch app_file('.gitignore')
13
16
  append_to_file app_file('.gitignore'), <<~GITIGNORE
14
17
  # Lamby
15
18
  /.aws-sam
19
+ /.lamby
16
20
  GITIGNORE
17
21
 
18
22
  say 'Creating ./bin files for build and deploy...'
19
- copy_file tpl_file('build'), app_file('bin/build')
20
- chmod app_file('bin/build'), 0755
23
+ copy_file tpl_file('_build'), app_file('bin/_build')
24
+ gsub_file app_file('bin/_build'), /APPNAMEHERE/, appname.downcase
25
+ chmod app_file('bin/_build'), 0755
21
26
  copy_file tpl_file('deploy'), app_file('bin/deploy')
22
27
  chmod app_file('bin/deploy'), 0755
28
+ copy_file tpl_file('_deploy'), app_file('bin/_deploy')
29
+ gsub_file app_file('bin/_deploy'), /APPNAMEHERE/, appname.downcase
30
+ chmod app_file('bin/_deploy'), 0755
23
31
  gsub_file app_file('bin/deploy'), /APPNAMEHERE/, appname.downcase
24
32
 
25
33
  say 'Welcome to AWS Lambda and Rails 🎉', :green
@@ -0,0 +1,3 @@
1
+ FROM public.ecr.aws/lambda/ruby:2.7
2
+ COPY . .
3
+ CMD ["app.handler"]
@@ -0,0 +1,15 @@
1
+ FROM amazon/aws-sam-cli-build-image-ruby2.7
2
+
3
+ # Ensure minimum required SAM version.
4
+ # RUN pip install awscli && \
5
+ # pip uninstall --yes aws-sam-cli && \
6
+ # pip install aws-sam-cli==v1.13.2
7
+
8
+ # Node for JavaScript.
9
+ # RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash - && \
10
+ # yum install -y nodejs && \
11
+ # curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo && \
12
+ # rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg && \
13
+ # yum install -y yarn
14
+
15
+ WORKDIR /var/task
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ echo '== Simulate SAM Build Directory =='
5
+ RESOURCE="RailsLambda"
6
+ SAM_TEMP=$(mktemp -d -t sam.XXXXXX)
7
+ rm -rf ./.lamby ./.aws-sam
8
+ cp -r . "$SAM_TEMP"
9
+ mkdir -p ./.lamby
10
+ cp -r "$SAM_TEMP" "./.lamby/$RESOURCE"
11
+ pushd "./.lamby/$RESOURCE"
12
+
13
+ echo '== Cleaning Dev Dependencies =='
14
+ rm -rf ./.bundle \
15
+ ./vendor/bundle
16
+
17
+ echo '== Bundle For Deployment =='
18
+ bundle config --local deployment true
19
+ bundle config --local without 'development test'
20
+ bundle config --local path './vendor/bundle'
21
+ bundle install --quiet --jobs 4
22
+
23
+ echo "== Environments & Configuration =="
24
+ # ./bin/rails \
25
+ # -rlamby \
26
+ # lamby:ssm:dotenv \
27
+ # LAMBY_SSM_PARAMS_PATH="/APPNAMEHERE/${RAILS_ENV}/env"
28
+
29
+ echo "== Asset Hosts & Precompiling =="
30
+ # NODE_ENV='production' \
31
+ # RAILS_GROUPS=assets \
32
+ # ./bin/rails assets:precompile
33
+
34
+ echo "== Cleanup Unused Files & Directories =="
35
+ rm -rf \
36
+ log \
37
+ node_modules \
38
+ test \
39
+ tmp \
40
+ vendor/bundle/ruby/2.7.0/cache
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ export RAILS_ENV=${RAILS_ENV:="production"}
5
+ export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:=us-east-1}
6
+ export CLOUDFORMATION_BUCKET=${CLOUDFORMATION_BUCKET:="lamby.cloudformation.$(whoami)"}
7
+
8
+ # https://github.com/aws/aws-sam-cli/issues/2447
9
+ export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
10
+ export IMAGE_REPOSITORY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/myorg/APPNAMEHERE"
11
+
12
+ ./bin/_build
13
+
14
+ export VPCID=${VPCID:=$(
15
+ aws ec2 describe-vpcs \
16
+ --output text \
17
+ --filters 'Name=state,Values=available' \
18
+ --query 'Vpcs[0].VpcId'
19
+ )}
20
+
21
+ export SUBNETS=${SUBNETS:=$(
22
+ aws ec2 describe-subnets \
23
+ --output text \
24
+ --filters "Name=state,Values=available,Name=vpc-id,Values=$VPCID" \
25
+ --query 'Subnets[*].SubnetId' | \
26
+ tr -s '[:blank:]' ','
27
+ )}
28
+
29
+ sam build \
30
+ --parameter-overrides \
31
+ RailsEnv="${RAILS_ENV}"
32
+
33
+ echo "== SAM package..."
34
+ sam package \
35
+ --region "$AWS_DEFAULT_REGION" \
36
+ --template-file ./.aws-sam/build/template.yaml \
37
+ --output-template-file ./.aws-sam/build/packaged.yaml \
38
+ --image-repository "$IMAGE_REPOSITORY" \
39
+ --s3-bucket "${CLOUDFORMATION_BUCKET}" \
40
+ --s3-prefix "APPNAMEHERE-${RAILS_ENV}"
41
+
42
+ echo "== SAM deploy..."
43
+ sam deploy \
44
+ --region "$AWS_DEFAULT_REGION" \
45
+ --template-file ./.aws-sam/build/packaged.yaml \
46
+ --stack-name "APPNAMEHERE-${RAILS_ENV}" \
47
+ --image-repository "$IMAGE_REPOSITORY" \
48
+ --capabilities "CAPABILITY_IAM" \
49
+ --parameter-overrides \
50
+ RailsEnv="${RAILS_ENV}" \
51
+ VpcId=${VPCID} \
52
+ Subnets=${SUBNETS}
@@ -1,4 +1,6 @@
1
+ ENV['RAILS_SERVE_STATIC_FILES'] = '1'
1
2
  require_relative 'config/boot'
3
+ require 'dotenv' ; Dotenv.load ".env.#{ENV['RAILS_ENV']}"
2
4
  require 'lamby'
3
5
  require_relative 'config/application'
4
6
  require_relative 'config/environment'
@@ -1,39 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  set -e
3
3
 
4
- export RAILS_ENV=${RAILS_ENV:="production"}
5
- export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:=us-east-1}
6
- export CLOUDFORMATION_BUCKET=${CLOUDFORMATION_BUCKET:="lamby.cloudformation.$(whoami)"}
4
+ export RAILS_ENV=${RAILS_ENV:=production}
7
5
 
8
- ./bin/build
9
-
10
- export VPCID=${VPCID:=$(
11
- aws ec2 describe-vpcs \
12
- --output text \
13
- --filters 'Name=state,Values=available' \
14
- --query 'Vpcs[0].VpcId'
15
- )}
16
-
17
- export SUBNETS=${SUBNETS:=$(
18
- aws ec2 describe-subnets \
19
- --output text \
20
- --filters "Name=state,Values=available,Name=vpc-id,Values=$VPCID" \
21
- --query 'Subnets[*].SubnetId' | \
22
- tr -s '[:blank:]' ','
23
- )}
24
-
25
- sam package \
26
- --region ${AWS_DEFAULT_REGION} \
27
- --template-file ./.aws-sam/build/template.yaml \
28
- --output-template-file ./.aws-sam/build/packaged.yaml \
29
- --s3-bucket $CLOUDFORMATION_BUCKET \
30
- --s3-prefix "APPNAMEHERE-${RAILS_ENV}"
31
-
32
- sam deploy \
33
- --template-file ./.aws-sam/build/packaged.yaml \
34
- --stack-name "APPNAMEHERE-${RAILS_ENV}-${AWS_DEFAULT_REGION}" \
35
- --capabilities "CAPABILITY_IAM" \
36
- --parameter-overrides \
37
- RailsEnv=${RAILS_ENV} \
38
- VpcId=${VPCID} \
39
- Subnets=${SUBNETS}
6
+ docker-compose run \
7
+ -e CLOUDFORMATION_BUCKET \
8
+ cicd \
9
+ ./bin/_deploy
@@ -0,0 +1,17 @@
1
+ version: '3.7'
2
+ services:
3
+ cicd:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile-build
7
+ environment:
8
+ - RAILS_ENV=${RAILS_ENV-development}
9
+ - AWS_PROFILE=${AWS_PROFILE-default}
10
+ - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION-us-east-1}
11
+ - SSH_AUTH_SOCK=${SSH_AUTH_SOCK}
12
+ volumes:
13
+ - ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK}
14
+ - ~/.aws:/root/.aws:delegated
15
+ - ~/.ssh/known_hosts:/root/.ssh/known_hosts
16
+ - .:/var/task:delegated
17
+ - /var/run/docker.sock:/var/run/docker.sock
@@ -28,14 +28,14 @@ Resources:
28
28
 
29
29
  RailsLoadBalancerTargetGroup:
30
30
  Type: AWS::ElasticLoadBalancingV2::TargetGroup
31
- DependsOn: RailsFunctionInvokePermission
31
+ DependsOn: RailsLambdaInvokePermission
32
32
  Properties:
33
33
  TargetType: lambda
34
34
  TargetGroupAttributes:
35
35
  - Key: lambda.multi_value_headers.enabled
36
36
  Value: true
37
37
  Targets:
38
- - Id: !GetAtt RailsFunction.Arn
38
+ - Id: !GetAtt RailsLambda.Arn
39
39
 
40
40
  RailsLoadBalancerHttpListener:
41
41
  Type: 'AWS::ElasticLoadBalancingV2::Listener'
@@ -58,26 +58,26 @@ Resources:
58
58
  ToPort: 80
59
59
  CidrIp: 0.0.0.0/0
60
60
 
61
- RailsFunctionInvokePermission:
61
+ RailsLambdaInvokePermission:
62
62
  Type: AWS::Lambda::Permission
63
63
  Properties:
64
- FunctionName: !GetAtt RailsFunction.Arn
64
+ FunctionName: !GetAtt RailsLambda.Arn
65
65
  Action: 'lambda:InvokeFunction'
66
66
  Principal: elasticloadbalancing.amazonaws.com
67
67
 
68
- RailsFunction:
68
+ RailsLambda:
69
69
  Type: AWS::Serverless::Function
70
+ Metadata:
71
+ DockerContext: ./.lamby/RailsLambda
72
+ Dockerfile: Dockerfile
70
73
  Properties:
71
- CodeUri: .
72
- Handler: app.handler
73
- Runtime: ruby2.7
74
74
  MemorySize: 512
75
75
  Timeout: 30
76
76
  Environment:
77
77
  Variables:
78
78
  RAILS_ENV: !Ref RailsEnv
79
79
  FunctionName: !Join [ '', [ 'APPNAMEHERE-', !Ref RailsEnv, '-', !Ref 'AWS::Region' ] ]
80
- AutoPublishAlias: live
80
+ PackageType: Image
81
81
 
82
82
  Outputs:
83
83
 
@@ -85,6 +85,6 @@ Outputs:
85
85
  Description: Application Load Balancer DNS Name
86
86
  Value: !GetAtt RailsLoadBalancer.DNSName
87
87
 
88
- RailsFunctionArn:
88
+ RailsLambdaArn:
89
89
  Description: Lambda ARN
90
- Value: !GetAtt RailsFunction.Arn
90
+ Value: !GetAtt RailsLambda.Arn
@@ -7,19 +7,27 @@ say 'Copying files...'
7
7
  copy_file tpl_file('app.rb'), app_file('app.rb')
8
8
  copy_file tpl_file('template.yaml'), app_file('template.yaml')
9
9
  gsub_file app_file('template.yaml'), /APPNAMEHERE/, appname
10
+ copy_file tpl_file('Dockerfile'), app_file('Dockerfile')
11
+ copy_file tpl_file('Dockerfile-build'), app_file('Dockerfile-build')
12
+ copy_file tpl_file('docker-compose.yml'), app_file('docker-compose.yml')
10
13
 
11
14
  say 'Adding to .gitignore...'
12
15
  FileUtils.touch app_file('.gitignore')
13
16
  append_to_file app_file('.gitignore'), <<~GITIGNORE
14
17
  # Lamby
15
18
  /.aws-sam
19
+ /.lamby
16
20
  GITIGNORE
17
21
 
18
22
  say 'Creating ./bin files for build and deploy...'
19
- copy_file tpl_file('build'), app_file('bin/build')
20
- chmod app_file('bin/build'), 0755
23
+ copy_file tpl_file('_build'), app_file('bin/_build')
24
+ gsub_file app_file('bin/_build'), /APPNAMEHERE/, appname.downcase
25
+ chmod app_file('bin/_build'), 0755
21
26
  copy_file tpl_file('deploy'), app_file('bin/deploy')
22
27
  chmod app_file('bin/deploy'), 0755
28
+ copy_file tpl_file('_deploy'), app_file('bin/_deploy')
29
+ gsub_file app_file('bin/_deploy'), /APPNAMEHERE/, appname.downcase
30
+ chmod app_file('bin/_deploy'), 0755
23
31
  gsub_file app_file('bin/deploy'), /APPNAMEHERE/, appname.downcase
24
32
 
25
33
  say 'Welcome to AWS Lambda and Rails 🎉', :green
@@ -0,0 +1,3 @@
1
+ FROM public.ecr.aws/lambda/ruby:2.7
2
+ COPY . .
3
+ CMD ["app.handler"]
@@ -0,0 +1,15 @@
1
+ FROM amazon/aws-sam-cli-build-image-ruby2.7
2
+
3
+ # Ensure minimum required SAM version.
4
+ # RUN pip install awscli && \
5
+ # pip uninstall --yes aws-sam-cli && \
6
+ # pip install aws-sam-cli==v1.13.2
7
+
8
+ # Node for JavaScript.
9
+ # RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash - && \
10
+ # yum install -y nodejs && \
11
+ # curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo && \
12
+ # rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg && \
13
+ # yum install -y yarn
14
+
15
+ WORKDIR /var/task
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ echo '== Simulate SAM Build Directory =='
5
+ RESOURCE="RailsLambda"
6
+ SAM_TEMP=$(mktemp -d -t sam.XXXXXX)
7
+ rm -rf ./.lamby ./.aws-sam
8
+ cp -r . "$SAM_TEMP"
9
+ mkdir -p ./.lamby
10
+ cp -r "$SAM_TEMP" "./.lamby/$RESOURCE"
11
+ pushd "./.lamby/$RESOURCE"
12
+
13
+ echo '== Cleaning Dev Dependencies =='
14
+ rm -rf ./.bundle \
15
+ ./vendor/bundle
16
+
17
+ echo '== Bundle For Deployment =='
18
+ bundle config --local deployment true
19
+ bundle config --local without 'development test'
20
+ bundle config --local path './vendor/bundle'
21
+ bundle install --quiet --jobs 4
22
+
23
+ echo "== Environments & Configuration =="
24
+ # ./bin/rails \
25
+ # -rlamby \
26
+ # lamby:ssm:dotenv \
27
+ # LAMBY_SSM_PARAMS_PATH="/APPNAMEHERE/${RAILS_ENV}/env"
28
+
29
+ echo "== Asset Hosts & Precompiling =="
30
+ # NODE_ENV='production' \
31
+ # RAILS_GROUPS=assets \
32
+ # ./bin/rails assets:precompile
33
+
34
+ echo "== Cleanup Unused Files & Directories =="
35
+ rm -rf \
36
+ log \
37
+ node_modules \
38
+ test \
39
+ tmp \
40
+ vendor/bundle/ruby/2.7.0/cache
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ export RAILS_ENV=${RAILS_ENV:="production"}
5
+ export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:=us-east-1}
6
+ export CLOUDFORMATION_BUCKET=${CLOUDFORMATION_BUCKET:="lamby.cloudformation.$(whoami)"}
7
+
8
+ # https://github.com/aws/aws-sam-cli/issues/2447
9
+ export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
10
+ export IMAGE_REPOSITORY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/myorg/APPNAMEHERE"
11
+
12
+ ./bin/_build
13
+
14
+ sam build \
15
+ --parameter-overrides \
16
+ RailsEnv="${RAILS_ENV}"
17
+
18
+ echo "== SAM package..."
19
+ sam package \
20
+ --region "$AWS_DEFAULT_REGION" \
21
+ --template-file ./.aws-sam/build/template.yaml \
22
+ --output-template-file ./.aws-sam/build/packaged.yaml \
23
+ --image-repository "$IMAGE_REPOSITORY" \
24
+ --s3-bucket "${CLOUDFORMATION_BUCKET}" \
25
+ --s3-prefix "APPNAMEHERE-${RAILS_ENV}"
26
+
27
+ echo "== SAM deploy..."
28
+ sam deploy \
29
+ --region "$AWS_DEFAULT_REGION" \
30
+ --template-file ./.aws-sam/build/packaged.yaml \
31
+ --stack-name "APPNAMEHERE-${RAILS_ENV}" \
32
+ --image-repository "$IMAGE_REPOSITORY" \
33
+ --capabilities "CAPABILITY_IAM" \
34
+ --parameter-overrides \
35
+ RailsEnv="${RAILS_ENV}"
@@ -1,4 +1,6 @@
1
+ ENV['RAILS_SERVE_STATIC_FILES'] = '1'
1
2
  require_relative 'config/boot'
3
+ require 'dotenv' ; Dotenv.load ".env.#{ENV['RAILS_ENV']}"
2
4
  require 'lamby'
3
5
  require_relative 'config/application'
4
6
  require_relative 'config/environment'
@@ -1,22 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  set -e
3
3
 
4
- export RAILS_ENV=${RAILS_ENV:="production"}
5
- export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:=us-east-1}
6
- export CLOUDFORMATION_BUCKET=${CLOUDFORMATION_BUCKET:="lamby.cloudformation.$(whoami)"}
4
+ export RAILS_ENV=${RAILS_ENV:=production}
7
5
 
8
- ./bin/build
9
-
10
- sam package \
11
- --region ${AWS_DEFAULT_REGION} \
12
- --template-file ./.aws-sam/build/template.yaml \
13
- --output-template-file ./.aws-sam/build/packaged.yaml \
14
- --s3-bucket $CLOUDFORMATION_BUCKET \
15
- --s3-prefix "APPNAMEHERE-${RAILS_ENV}"
16
-
17
- sam deploy \
18
- --template-file ./.aws-sam/build/packaged.yaml \
19
- --stack-name "APPNAMEHERE-${RAILS_ENV}-${AWS_DEFAULT_REGION}" \
20
- --capabilities "CAPABILITY_IAM" \
21
- --parameter-overrides \
22
- RailsEnv=${RAILS_ENV}
6
+ docker-compose run \
7
+ -e CLOUDFORMATION_BUCKET \
8
+ cicd \
9
+ ./bin/_deploy
@@ -0,0 +1,17 @@
1
+ version: '3.7'
2
+ services:
3
+ cicd:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile-build
7
+ environment:
8
+ - RAILS_ENV=${RAILS_ENV-development}
9
+ - AWS_PROFILE=${AWS_PROFILE-default}
10
+ - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION-us-east-1}
11
+ - SSH_AUTH_SOCK=${SSH_AUTH_SOCK}
12
+ volumes:
13
+ - ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK}
14
+ - ~/.aws:/root/.aws:delegated
15
+ - ~/.ssh/known_hosts:/root/.ssh/known_hosts
16
+ - .:/var/task:delegated
17
+ - /var/run/docker.sock:/var/run/docker.sock
@@ -13,12 +13,12 @@ Parameters:
13
13
 
14
14
  Resources:
15
15
 
16
- RailsFunction:
16
+ RailsLambda:
17
17
  Type: AWS::Serverless::Function
18
+ Metadata:
19
+ DockerContext: ./.lamby/RailsLambda
20
+ Dockerfile: Dockerfile
18
21
  Properties:
19
- CodeUri: .
20
- Handler: app.handler
21
- Runtime: ruby2.7
22
22
  MemorySize: 512
23
23
  Timeout: 30
24
24
  Environment:
@@ -30,7 +30,7 @@ Resources:
30
30
  Type: HttpApi
31
31
  Properties:
32
32
  ApiId: !Ref RailsApi
33
- AutoPublishAlias: live
33
+ PackageType: Image
34
34
 
35
35
  RailsApi:
36
36
  Type: AWS::Serverless::HttpApi
@@ -43,6 +43,6 @@ Outputs:
43
43
  Description: API Gateway Endpoint
44
44
  Value: !Sub "https://${RailsApi}.execute-api.${AWS::Region}.amazonaws.com/${RailsEnv}/"
45
45
 
46
- RailsFunctionArn:
46
+ RailsLambdaArn:
47
47
  Description: Lambda ARN
48
- Value: !GetAtt RailsFunction.Arn
48
+ Value: !GetAtt RailsLambda.Arn
@@ -7,19 +7,27 @@ say 'Copying files...'
7
7
  copy_file tpl_file('app.rb'), app_file('app.rb')
8
8
  copy_file tpl_file('template.yaml'), app_file('template.yaml')
9
9
  gsub_file app_file('template.yaml'), /APPNAMEHERE/, appname
10
+ copy_file tpl_file('Dockerfile'), app_file('Dockerfile')
11
+ copy_file tpl_file('Dockerfile-build'), app_file('Dockerfile-build')
12
+ copy_file tpl_file('docker-compose.yml'), app_file('docker-compose.yml')
10
13
 
11
14
  say 'Adding to .gitignore...'
12
15
  FileUtils.touch app_file('.gitignore')
13
16
  append_to_file app_file('.gitignore'), <<~GITIGNORE
14
17
  # Lamby
15
18
  /.aws-sam
19
+ /.lamby
16
20
  GITIGNORE
17
21
 
18
22
  say 'Creating ./bin files for build and deploy...'
19
- copy_file tpl_file('build'), app_file('bin/build')
20
- chmod app_file('bin/build'), 0755
23
+ copy_file tpl_file('_build'), app_file('bin/_build')
24
+ gsub_file app_file('bin/_build'), /APPNAMEHERE/, appname.downcase
25
+ chmod app_file('bin/_build'), 0755
21
26
  copy_file tpl_file('deploy'), app_file('bin/deploy')
22
27
  chmod app_file('bin/deploy'), 0755
28
+ copy_file tpl_file('_deploy'), app_file('bin/_deploy')
29
+ gsub_file app_file('bin/_deploy'), /APPNAMEHERE/, appname.downcase
30
+ chmod app_file('bin/_deploy'), 0755
23
31
  gsub_file app_file('bin/deploy'), /APPNAMEHERE/, appname.downcase
24
32
 
25
33
  say 'Welcome to AWS Lambda and Rails 🎉', :green
@@ -0,0 +1,3 @@
1
+ FROM public.ecr.aws/lambda/ruby:2.7
2
+ COPY . .
3
+ CMD ["app.handler"]
@@ -0,0 +1,15 @@
1
+ FROM amazon/aws-sam-cli-build-image-ruby2.7
2
+
3
+ # Ensure minimum required SAM version.
4
+ # RUN pip install awscli && \
5
+ # pip uninstall --yes aws-sam-cli && \
6
+ # pip install aws-sam-cli==v1.13.2
7
+
8
+ # Node for JavaScript.
9
+ # RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash - && \
10
+ # yum install -y nodejs && \
11
+ # curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo && \
12
+ # rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg && \
13
+ # yum install -y yarn
14
+
15
+ WORKDIR /var/task
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ echo '== Simulate SAM Build Directory =='
5
+ RESOURCE="RailsLambda"
6
+ SAM_TEMP=$(mktemp -d -t sam.XXXXXX)
7
+ rm -rf ./.lamby ./.aws-sam
8
+ cp -r . "$SAM_TEMP"
9
+ mkdir -p ./.lamby
10
+ cp -r "$SAM_TEMP" "./.lamby/$RESOURCE"
11
+ pushd "./.lamby/$RESOURCE"
12
+
13
+ echo '== Cleaning Dev Dependencies =='
14
+ rm -rf ./.bundle \
15
+ ./vendor/bundle
16
+
17
+ echo '== Bundle For Deployment =='
18
+ bundle config --local deployment true
19
+ bundle config --local without 'development test'
20
+ bundle config --local path './vendor/bundle'
21
+ bundle install --quiet --jobs 4
22
+
23
+ echo "== Environments & Configuration =="
24
+ # ./bin/rails \
25
+ # -rlamby \
26
+ # lamby:ssm:dotenv \
27
+ # LAMBY_SSM_PARAMS_PATH="/APPNAMEHERE/${RAILS_ENV}/env"
28
+
29
+ echo "== Asset Hosts & Precompiling =="
30
+ # NODE_ENV='production' \
31
+ # RAILS_GROUPS=assets \
32
+ # ./bin/rails assets:precompile
33
+
34
+ echo "== Cleanup Unused Files & Directories =="
35
+ rm -rf \
36
+ log \
37
+ node_modules \
38
+ test \
39
+ tmp \
40
+ vendor/bundle/ruby/2.7.0/cache
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ export RAILS_ENV=${RAILS_ENV:="production"}
5
+ export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:=us-east-1}
6
+ export CLOUDFORMATION_BUCKET=${CLOUDFORMATION_BUCKET:="lamby.cloudformation.$(whoami)"}
7
+
8
+ # https://github.com/aws/aws-sam-cli/issues/2447
9
+ export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
10
+ export IMAGE_REPOSITORY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/myorg/APPNAMEHERE"
11
+
12
+ ./bin/_build
13
+
14
+ sam build \
15
+ --parameter-overrides \
16
+ RailsEnv="${RAILS_ENV}"
17
+
18
+ echo "== SAM package..."
19
+ sam package \
20
+ --region "$AWS_DEFAULT_REGION" \
21
+ --template-file ./.aws-sam/build/template.yaml \
22
+ --output-template-file ./.aws-sam/build/packaged.yaml \
23
+ --image-repository "$IMAGE_REPOSITORY" \
24
+ --s3-bucket "${CLOUDFORMATION_BUCKET}" \
25
+ --s3-prefix "APPNAMEHERE-${RAILS_ENV}"
26
+
27
+ echo "== SAM deploy..."
28
+ sam deploy \
29
+ --region "$AWS_DEFAULT_REGION" \
30
+ --template-file ./.aws-sam/build/packaged.yaml \
31
+ --stack-name "APPNAMEHERE-${RAILS_ENV}" \
32
+ --image-repository "$IMAGE_REPOSITORY" \
33
+ --capabilities "CAPABILITY_IAM" \
34
+ --parameter-overrides \
35
+ RailsEnv="${RAILS_ENV}"
@@ -1,4 +1,6 @@
1
+ ENV['RAILS_SERVE_STATIC_FILES'] = '1'
1
2
  require_relative 'config/boot'
3
+ require 'dotenv' ; Dotenv.load ".env.#{ENV['RAILS_ENV']}"
2
4
  require 'lamby'
3
5
  require_relative 'config/application'
4
6
  require_relative 'config/environment'
@@ -1,22 +1,9 @@
1
1
  #!/usr/bin/env bash
2
2
  set -e
3
3
 
4
- export RAILS_ENV=${RAILS_ENV:="production"}
5
- export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:=us-east-1}
6
- export CLOUDFORMATION_BUCKET=${CLOUDFORMATION_BUCKET:="lamby.cloudformation.$(whoami)"}
4
+ export RAILS_ENV=${RAILS_ENV:=production}
7
5
 
8
- ./bin/build
9
-
10
- sam package \
11
- --region ${AWS_DEFAULT_REGION} \
12
- --template-file ./.aws-sam/build/template.yaml \
13
- --output-template-file ./.aws-sam/build/packaged.yaml \
14
- --s3-bucket $CLOUDFORMATION_BUCKET \
15
- --s3-prefix "APPNAMEHERE-${RAILS_ENV}"
16
-
17
- sam deploy \
18
- --template-file ./.aws-sam/build/packaged.yaml \
19
- --stack-name "APPNAMEHERE-${RAILS_ENV}-${AWS_DEFAULT_REGION}" \
20
- --capabilities "CAPABILITY_IAM" \
21
- --parameter-overrides \
22
- RailsEnv=${RAILS_ENV}
6
+ docker-compose run \
7
+ -e CLOUDFORMATION_BUCKET \
8
+ cicd \
9
+ ./bin/_deploy
@@ -0,0 +1,17 @@
1
+ version: '3.7'
2
+ services:
3
+ cicd:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile-build
7
+ environment:
8
+ - RAILS_ENV=${RAILS_ENV-development}
9
+ - AWS_PROFILE=${AWS_PROFILE-default}
10
+ - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION-us-east-1}
11
+ - SSH_AUTH_SOCK=${SSH_AUTH_SOCK}
12
+ volumes:
13
+ - ${SSH_AUTH_SOCK}:${SSH_AUTH_SOCK}
14
+ - ~/.aws:/root/.aws:delegated
15
+ - ~/.ssh/known_hosts:/root/.ssh/known_hosts
16
+ - .:/var/task:delegated
17
+ - /var/run/docker.sock:/var/run/docker.sock
@@ -28,7 +28,7 @@ Resources:
28
28
  x-amazon-apigateway-any-method:
29
29
  x-amazon-apigateway-integration:
30
30
  uri:
31
- Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RailsFunction.Arn}:live/invocations
31
+ Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RailsLambda.Arn}:live/invocations
32
32
  httpMethod: POST
33
33
  type: aws_proxy
34
34
  /{resource+}:
@@ -40,18 +40,18 @@ Resources:
40
40
  type: string
41
41
  x-amazon-apigateway-integration:
42
42
  uri:
43
- Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RailsFunction.Arn}:live/invocations
43
+ Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RailsLambda.Arn}:live/invocations
44
44
  httpMethod: POST
45
45
  type: aws_proxy
46
46
  x-amazon-apigateway-binary-media-types:
47
47
  - '*/*'
48
48
 
49
- RailsFunction:
49
+ RailsLambda:
50
50
  Type: AWS::Serverless::Function
51
+ Metadata:
52
+ DockerContext: ./.lamby/RailsLambda
53
+ Dockerfile: Dockerfile
51
54
  Properties:
52
- CodeUri: .
53
- Handler: app.handler
54
- Runtime: ruby2.7
55
55
  MemorySize: 512
56
56
  Timeout: 30
57
57
  Environment:
@@ -71,7 +71,7 @@ Resources:
71
71
  Path: /{resource+}
72
72
  Method: ANY
73
73
  RestApiId: !Ref RailsApi
74
- AutoPublishAlias: live
74
+ PackageType: Image
75
75
 
76
76
  Outputs:
77
77
 
@@ -79,6 +79,6 @@ Outputs:
79
79
  Description: API Gateway Endpoint
80
80
  Value: !Sub "https://${RailsApi}.execute-api.${AWS::Region}.amazonaws.com/${RailsEnv}/"
81
81
 
82
- RailsFunctionArn:
82
+ RailsLambdaArn:
83
83
  Description: Lambda ARN
84
- Value: !GetAtt RailsFunction.Arn
84
+ Value: !GetAtt RailsLambda.Arn
@@ -1,3 +1,3 @@
1
1
  module Lamby
2
- VERSION = '2.2.2'
2
+ VERSION = '2.5.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lamby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-06 00:00:00.000000000 Z
11
+ date: 2020-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -163,19 +163,31 @@ files:
163
163
  - lib/lamby/tasks.rake
164
164
  - lib/lamby/templates.rake
165
165
  - lib/lamby/templates/alb.rb
166
+ - lib/lamby/templates/alb/Dockerfile
167
+ - lib/lamby/templates/alb/Dockerfile-build
168
+ - lib/lamby/templates/alb/_build
169
+ - lib/lamby/templates/alb/_deploy
166
170
  - lib/lamby/templates/alb/app.rb
167
- - lib/lamby/templates/alb/build
168
171
  - lib/lamby/templates/alb/deploy
172
+ - lib/lamby/templates/alb/docker-compose.yml
169
173
  - lib/lamby/templates/alb/template.yaml
170
174
  - lib/lamby/templates/http.rb
175
+ - lib/lamby/templates/http/Dockerfile
176
+ - lib/lamby/templates/http/Dockerfile-build
177
+ - lib/lamby/templates/http/_build
178
+ - lib/lamby/templates/http/_deploy
171
179
  - lib/lamby/templates/http/app.rb
172
- - lib/lamby/templates/http/build
173
180
  - lib/lamby/templates/http/deploy
181
+ - lib/lamby/templates/http/docker-compose.yml
174
182
  - lib/lamby/templates/http/template.yaml
175
183
  - lib/lamby/templates/rest.rb
184
+ - lib/lamby/templates/rest/Dockerfile
185
+ - lib/lamby/templates/rest/Dockerfile-build
186
+ - lib/lamby/templates/rest/_build
187
+ - lib/lamby/templates/rest/_deploy
176
188
  - lib/lamby/templates/rest/app.rb
177
- - lib/lamby/templates/rest/build
178
189
  - lib/lamby/templates/rest/deploy
190
+ - lib/lamby/templates/rest/docker-compose.yml
179
191
  - lib/lamby/templates/rest/template.yaml
180
192
  - lib/lamby/templates/shared.rb
181
193
  - lib/lamby/version.rb
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- # Clean any previous bundle/builds.
5
- rm -rf ./.aws-sam/build
6
-
7
- # Ensure native extensions built for platform.
8
- sam build --use-container
9
-
10
- # [HOOK] Environments & Configuration
11
- # https://lamby.custominktech.com/docs/environment_and_configuration
12
-
13
- # [HOOK] Asset Hosts & Precompiling
14
- # https://lamby.custominktech.com/docs/asset_host_and_precompiling
15
-
16
- # Clean un-needed artifacts.
17
- pushd ./.aws-sam/build/RailsFunction/
18
- rm -rf .aws-sam \
19
- .git \
20
- log \
21
- test \
22
- tmp
23
- popd
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- # Clean any previous bundle/builds.
5
- rm -rf ./.aws-sam/build
6
-
7
- # Ensure native extensions built for platform.
8
- sam build --use-container
9
-
10
- # [HOOK] Environments & Configuration
11
- # https://lamby.custominktech.com/docs/environment_and_configuration
12
-
13
- # [HOOK] Asset Hosts & Precompiling
14
- # https://lamby.custominktech.com/docs/asset_host_and_precompiling
15
-
16
- # Clean un-needed artifacts.
17
- pushd ./.aws-sam/build/RailsFunction/
18
- rm -rf .aws-sam \
19
- .git \
20
- log \
21
- test \
22
- tmp
23
- popd
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
-
4
- # Clean any previous bundle/builds.
5
- rm -rf ./.aws-sam/build
6
-
7
- # Ensure native extensions built for platform.
8
- sam build --use-container
9
-
10
- # [HOOK] Environments & Configuration
11
- # https://lamby.custominktech.com/docs/environment_and_configuration
12
-
13
- # [HOOK] Asset Hosts & Precompiling
14
- # https://lamby.custominktech.com/docs/asset_host_and_precompiling
15
-
16
- # Clean un-needed artifacts.
17
- pushd ./.aws-sam/build/RailsFunction/
18
- rm -rf .aws-sam \
19
- .git \
20
- log \
21
- test \
22
- tmp
23
- popd