lamby 3.1.3 → 4.0.0.beta1

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +1 -0
  3. data/.devcontainer/devcontainer.json +20 -0
  4. data/.github/workflows/test.yml +25 -0
  5. data/CHANGELOG.md +19 -2
  6. data/Gemfile.lock +106 -101
  7. data/README.md +10 -7
  8. data/bin/bootstrap +1 -4
  9. data/bin/setup +4 -4
  10. data/bin/test +4 -4
  11. data/bin/update +1 -3
  12. data/images/social.png +0 -0
  13. data/images/social2.png +0 -0
  14. data/lib/lamby/config.rb +9 -0
  15. data/lib/lamby/debug.rb +0 -6
  16. data/lib/lamby/logger.rb +3 -12
  17. data/lib/lamby/rack.rb +0 -3
  18. data/lib/lamby/railtie.rb +1 -6
  19. data/lib/lamby/version.rb +1 -1
  20. data/lib/lamby.rb +4 -1
  21. metadata +9 -41
  22. data/.github/workflows/cicd.yml +0 -17
  23. data/.ruby-version +0 -1
  24. data/Dockerfile +0 -7
  25. data/bin/_setup +0 -7
  26. data/bin/_test +0 -8
  27. data/docker-compose.yml +0 -15
  28. data/lib/lamby/sam_helpers.rb +0 -9
  29. data/lib/lamby/tasks.rake +0 -15
  30. data/lib/lamby/templates/alb/Dockerfile +0 -15
  31. data/lib/lamby/templates/alb/Dockerfile-build +0 -18
  32. data/lib/lamby/templates/alb/_build +0 -25
  33. data/lib/lamby/templates/alb/_deploy +0 -31
  34. data/lib/lamby/templates/alb/app.rb +0 -12
  35. data/lib/lamby/templates/alb/deploy +0 -8
  36. data/lib/lamby/templates/alb/docker-compose.yml +0 -19
  37. data/lib/lamby/templates/alb/template.yaml +0 -90
  38. data/lib/lamby/templates/alb.rb +0 -33
  39. data/lib/lamby/templates/http/Dockerfile +0 -15
  40. data/lib/lamby/templates/http/Dockerfile-build +0 -18
  41. data/lib/lamby/templates/http/_build +0 -25
  42. data/lib/lamby/templates/http/_deploy +0 -31
  43. data/lib/lamby/templates/http/app.rb +0 -12
  44. data/lib/lamby/templates/http/deploy +0 -8
  45. data/lib/lamby/templates/http/docker-compose.yml +0 -19
  46. data/lib/lamby/templates/http/template.yaml +0 -48
  47. data/lib/lamby/templates/http.rb +0 -33
  48. data/lib/lamby/templates/rest/Dockerfile +0 -15
  49. data/lib/lamby/templates/rest/Dockerfile-build +0 -18
  50. data/lib/lamby/templates/rest/_build +0 -25
  51. data/lib/lamby/templates/rest/_deploy +0 -31
  52. data/lib/lamby/templates/rest/app.rb +0 -12
  53. data/lib/lamby/templates/rest/deploy +0 -8
  54. data/lib/lamby/templates/rest/docker-compose.yml +0 -19
  55. data/lib/lamby/templates/rest/template.yaml +0 -84
  56. data/lib/lamby/templates/rest.rb +0 -33
  57. data/lib/lamby/templates/shared.rb +0 -17
  58. data/lib/lamby/templates.rake +0 -37
@@ -1,15 +0,0 @@
1
- FROM public.ecr.aws/lambda/ruby:2.7
2
- ARG RAILS_ENV
3
- ENV RAILS_ENV=$RAILS_ENV
4
-
5
- COPY . .
6
-
7
- # == Cleanup Unused Files & Directories ==
8
- RUN rm -rf \
9
- log \
10
- node_modules \
11
- test \
12
- tmp \
13
- vendor/bundle/ruby/2.7.0/cache
14
-
15
- CMD ["app.handler"]
@@ -1,18 +0,0 @@
1
- FROM amazon/aws-sam-cli-build-image-ruby2.7
2
-
3
- # Ensure minimum required SAM version.
4
- ENV SAM_CLI_VERSION=1.23.0
5
- RUN curl -L "https://github.com/aws/aws-sam-cli/releases/download/v${SAM_CLI_VERSION}/aws-sam-cli-linux-x86_64.zip" \
6
- -o "aws-sam-cli-linux-x86_64.zip" && \
7
- unzip -q aws-sam-cli-linux-x86_64.zip -d sam-installation && \
8
- ./sam-installation/install && \
9
- rm -rf ./sam-installation ./aws-sam-cli-linux-x86_64.zip
10
-
11
- # Node for JavaScript.
12
- RUN curl -sL https://rpm.nodesource.com/setup_14.x | bash - && \
13
- yum install -y nodejs && \
14
- curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo && \
15
- rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg && \
16
- yum install -y yarn
17
-
18
- WORKDIR /var/task
@@ -1,25 +0,0 @@
1
- #!/bin/sh
2
- set -e
3
-
4
- if [ "$CI" != "true" ]; then
5
- echo "== Cleaning dev dependencies for local deploy. Run ./bin/setup again afterward! =="
6
- rm -rf ./.bundle \
7
- ./vendor/bundle \
8
- ./node_modules
9
- fi
10
-
11
- echo '== Bundle For Deployment =='
12
- bundle lock --add-platform x86_64-linux
13
- bundle config --local deployment true
14
- bundle config --local without 'development test'
15
- bundle config --local path './vendor/bundle'
16
- bundle install --quiet --jobs 4
17
-
18
- echo "== Environments & Configuration =="
19
- # ./bin/rails \
20
- # -rlamby \
21
- # lamby:ssm:dotenv \
22
- # LAMBY_SSM_PARAMS_PATH="/APPNAMEHERE/${RAILS_ENV}/env"
23
-
24
- echo "== Asset Hosts & Precompiling =="
25
- NODE_ENV='production' ./bin/rails assets:precompile
@@ -1,31 +0,0 @@
1
- #!/bin/sh
2
- set -e
3
-
4
- # https://github.com/aws/aws-sam-cli/issues/2447
5
- AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
6
- IMAGE_REPOSITORY="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/APPNAMEHERE"
7
-
8
- echo "== Lamby build =="
9
- ./bin/_build
10
-
11
- echo "== SAM build =="
12
- sam build \
13
- --parameter-overrides \
14
- RailsEnv="${RAILS_ENV}"
15
-
16
- echo "== SAM package =="
17
- sam package \
18
- --region "$AWS_DEFAULT_REGION" \
19
- --template-file ./.aws-sam/build/template.yaml \
20
- --output-template-file ./.aws-sam/build/packaged.yaml \
21
- --image-repository "$IMAGE_REPOSITORY" \
22
-
23
- echo "== SAM deploy =="
24
- sam deploy \
25
- --region "$AWS_DEFAULT_REGION" \
26
- --template-file ./.aws-sam/build/packaged.yaml \
27
- --stack-name "APPNAMEHERE-${RAILS_ENV}" \
28
- --image-repository "$IMAGE_REPOSITORY" \
29
- --capabilities "CAPABILITY_IAM" \
30
- --parameter-overrides \
31
- RailsEnv="${RAILS_ENV}"
@@ -1,12 +0,0 @@
1
- ENV['RAILS_SERVE_STATIC_FILES'] = '1'
2
- require_relative 'config/boot'
3
- require 'dotenv' ; Dotenv.load ".env.#{ENV['RAILS_ENV']}"
4
- require 'lamby'
5
- require_relative 'config/application'
6
- require_relative 'config/environment'
7
-
8
- $app = Rack::Builder.new { run Rails.application }.to_app
9
-
10
- def handler(event:, context:)
11
- Lamby.handler $app, event, context
12
- end
@@ -1,8 +0,0 @@
1
- #!/bin/sh
2
- set -e
3
-
4
- export RAILS_ENV=${RAILS_ENV:=production}
5
-
6
- docker-compose run \
7
- APPNAMEHERE \
8
- ./bin/_deploy
@@ -1,19 +0,0 @@
1
- version: '3.7'
2
- services:
3
- APPNAMEHERE:
4
- build:
5
- context: '.'
6
- dockerfile: Dockerfile-build
7
- entrypoint: ./bin/entrypoint
8
- environment:
9
- - RAILS_ENV=${RAILS_ENV-development}
10
- - SAM_CLI_TELEMETRY=0
11
- - AWS_PROFILE=${AWS_PROFILE-default}
12
- - AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
13
- - AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
14
- - AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION-us-east-1}
15
- - CI=${CI}
16
- volumes:
17
- - ${PWD}:/var/task
18
- - ${HOME}/.aws:/root/.aws
19
- - /var/run/docker.sock:/var/run/docker.sock
@@ -1,84 +0,0 @@
1
- AWSTemplateFormatVersion: '2010-09-09'
2
- Transform: AWS::Serverless-2016-10-31
3
- Description: APPNAMEHERE Lambda (REST API)
4
-
5
- Parameters:
6
-
7
- RailsEnv:
8
- Type: String
9
- Default: production
10
- AllowedValues:
11
- - staging
12
- - production
13
-
14
- Resources:
15
-
16
- RailsApi:
17
- Type: AWS::Serverless::Api
18
- Properties:
19
- StageName: !Ref RailsEnv
20
- EndpointConfiguration: REGIONAL
21
- DefinitionBody:
22
- swagger: 2.0
23
- info: { title: !Ref 'AWS::StackName' }
24
- basePath: !Join [ '', [ '/', !Ref RailsEnv ] ]
25
- schemes: [ 'https' ]
26
- paths:
27
- /:
28
- x-amazon-apigateway-any-method:
29
- x-amazon-apigateway-integration:
30
- uri:
31
- Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RailsLambda.Arn}:live/invocations
32
- httpMethod: POST
33
- type: aws_proxy
34
- /{resource+}:
35
- x-amazon-apigateway-any-method:
36
- parameters:
37
- - name: resource
38
- in: path
39
- required: true
40
- type: string
41
- x-amazon-apigateway-integration:
42
- uri:
43
- Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RailsLambda.Arn}:live/invocations
44
- httpMethod: POST
45
- type: aws_proxy
46
- x-amazon-apigateway-binary-media-types:
47
- - '*/*'
48
-
49
- RailsLambda:
50
- Type: AWS::Serverless::Function
51
- Metadata:
52
- DockerContext: .
53
- Dockerfile: Dockerfile
54
- Properties:
55
- MemorySize: 512
56
- Timeout: 30
57
- Environment:
58
- Variables:
59
- RAILS_ENV: !Ref RailsEnv
60
- FunctionName: !Join [ '', [ 'APPNAMEHERE-', !Ref RailsEnv, '-', !Ref 'AWS::Region' ] ]
61
- Events:
62
- Root:
63
- Type: Api
64
- Properties:
65
- Path: /
66
- Method: ANY
67
- RestApiId: !Ref RailsApi
68
- RailsAppAll:
69
- Type: Api
70
- Properties:
71
- Path: /{resource+}
72
- Method: ANY
73
- RestApiId: !Ref RailsApi
74
- PackageType: Image
75
-
76
- Outputs:
77
-
78
- RailsApiUrl:
79
- Description: API Gateway Endpoint
80
- Value: !Sub "https://${RailsApi}.execute-api.${AWS::Region}.amazonaws.com/${RailsEnv}/"
81
-
82
- RailsLambdaArn:
83
- Description: Lambda ARN
84
- Value: !GetAtt RailsLambda.Arn
@@ -1,33 +0,0 @@
1
- $LAMBY_INSTALLER_NAME = 'rest'
2
- load 'lamby/templates/shared.rb'
3
-
4
- say '==> Running Lamby API Gateway (REST API) installer...'
5
-
6
- say 'Copying files...'
7
- copy_file tpl_file('app.rb'), app_file('app.rb')
8
- copy_file tpl_file('template.yaml'), app_file('template.yaml')
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')
13
- gsub_file app_file('docker-compose.yml'), /APPNAMEHERE/, appname.downcase
14
-
15
- say 'Adding to .gitignore...'
16
- FileUtils.touch app_file('.gitignore')
17
- append_to_file app_file('.gitignore'), <<~GITIGNORE
18
- # Lamby
19
- /.aws-sam
20
- GITIGNORE
21
-
22
- say 'Creating ./bin files for build and deploy...'
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
26
- copy_file tpl_file('deploy'), app_file('bin/deploy')
27
- gsub_file app_file('bin/deploy'), /APPNAMEHERE/, appname.downcase
28
- chmod app_file('bin/deploy'), 0755
29
- copy_file tpl_file('_deploy'), app_file('bin/_deploy')
30
- gsub_file app_file('bin/_deploy'), /APPNAMEHERE/, appname.downcase
31
- chmod app_file('bin/_deploy'), 0755
32
-
33
- say 'Welcome to AWS Lambda and Rails 🎉', :green
@@ -1,17 +0,0 @@
1
- def inst_name
2
- $LAMBY_INSTALLER_NAME
3
- end
4
-
5
- def app_file(path)
6
- Rails.root.join(path)
7
- end
8
-
9
- def tpl_file(path)
10
- "#{__dir__}/#{inst_name}/#{path}"
11
- end
12
-
13
- def appname
14
- k = Rails.application.class
15
- p = k.respond_to?(:module_parent) ? k.module_parent : k.parent
16
- p.name
17
- end
@@ -1,37 +0,0 @@
1
- installers = {
2
- 'API Gateway (HTTP API)' => :http,
3
- 'API Gateway (REST API)' => :rest,
4
- 'Application Load Balancer' => :alb
5
- }.freeze
6
-
7
- namespace :lamby do
8
- namespace :install do
9
-
10
- installers.each do |name, task_name|
11
- desc "Install Lamby files for #{name}"
12
- task task_name do
13
- exec "#{base_path} LOCATION=#{template(task_name)}"
14
- end
15
- end
16
-
17
- def template(task_name)
18
- File.expand_path "../lamby/templates/#{task_name}.rb", __dir__
19
- end
20
-
21
- def bin_path
22
- ENV['BUNDLE_BIN'] || './bin'
23
- end
24
-
25
- def base_path
26
- if Rails::VERSION::MAJOR >= 5
27
- "#{RbConfig.ruby} #{bin_path}/rails app:template"
28
- else
29
- "#{RbConfig.ruby} #{bin_path}/rake rails:template"
30
- end
31
- end
32
-
33
- end
34
-
35
- desc "Install Lamby files for #{installers.first.first}"
36
- task install: 'install:http'
37
- end