Giter VIP home page Giter VIP logo

aws-rails-provisioner's Introduction

aws-rails-provisioner

Build Status

A tool for defining and deploying containerized Ruby on Rails applications on AWS.

aws-rails-provisioner is a command line tool using your configurations defined in aws-rails-provisioner.yml file to generate AWS CDK stacks on your behalf, provisioning required AWS resources for running your containerized Ruby on Rails applications on AWS (current supported platform: AWS Fargate) within a few commands.


Stability: Experimental

This tool is under developer preview (beta) stage, with active development, releases might lack features and might have future breaking changes.


Links of Interest

Getting Started

Prerequisites

Before using the aws-rails-provisioner gem, you need to have:

  • a Ruby on Rails application with a Dockerfile

  • install or update the [AWS CDK Toolkit] from npm (requires Node.js ≥ 8.11.x):

    $ npm i -g aws-cdk
  • docker daemon vailable for building images

Install aws-rails-provisioner

aws-rails-provisioner gem is available from RubyGems, currently with preview versions.

gem install aws-rails-provisioner --pre

Define aws-rails-provisioner.yml

aws-rails-provisioner.yml is a configuration file defining how aws-rails-provisioner bootstraps required AWS resources for your Ruby on Rails applications.

version: '0'

vpc:
  max_az: 2
  enable_dns: true
services:
  my_rails_foo:
    source_path: ./path/to/my_rails_foo # relative path from `aws-rails-provisioner.yml`
    fargate:
      desired_count: 3
      memory: 512
      cpu: 256
      envs:
        PORT: 80
        RAILS_LOG_TO_STDOUT: true
      public: true
    db_cluster:
      engine: aurora-postgresql
      db_name: app_development
    scaling:
      max_capacity: 5
      on_cpu:
        target_util_percent: 80
        scale_in_cool_down: 300
      on_requests:
        requests_per_target: 1000
  my_another_rails:
    ...

See ./examples for more aws-rails-provisioner examples (see tiny.yml for a minimal aws-rails-provisioner.yml configuration example). The full configuration options are documented here.

Build and Deploy

Once aws-rails-provisioner.yml is defined, run the build command. This will boostrap AWS CDK stacks and define all required AWS resources and connections in CDK code.

aws-rails-provisioner build

By default, it defines a VPC with public and private subnets, an Amazon RDS Database Cluster, an ECS cluster with AWS Fargate services containing application images. When building with --with-cicd option a CICD stack will be defined automatically (including a Rails data migration step).

aws-rails-provisioner build --with-cicd

After the build completes, run the deploy command to run CDK code that deploys all defined AWS resources:

aws-rails-provisioner deploy

Instead of deploying everything all at once, you can deploy stack by stack, application by application:

# only deploys the stack creates VPC and ECS cluster
aws-rails-provisioner deploy --init

# deploys fargate service and database cluster when defined
aws-rails-provisioner deploy --fargate

# deploy CICD stack
aws-rails-provisioner deploy --cicd

# deploy only :rails_foo application
aws-rails-provisioner deploy --fargate --service my_rails_foo

After the deployment completes, your applications are now running on AWS Fargate fronted with AWS Application LoadBalancer. You can view your website using the public IP address of the network interface's load balancer.

Note: for applications with databases, rails db migration is needed; the CICD stack contains a migration phase by default, running DB migration commands insides private subnets, connected to the DB Cluster.

CICD

When --with-cicd is enabled at build, a CICD stack is created. Once deployment completes, an AWS CodePipeline is available with source, build, migration, and deploy phases for your Rails application. You need to commit your Rails application to the CodeCommit source repository in the pipeline with buildspec files to activate the pipeline. Sample buildspecs are availble under ./buildspecs handling application image builds and rails migrations.

Full aws-rails-provisioner command line options see:

aws-rails-provisioner -h

Contributing

We welcome community contributions and pull requests. See CONTRIBUTING for details.

Getting Help

Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests.

  • Ask a question on Stack Overflow and tag it with aws-rails-provisioner
  • If it turns out that you may have found a bug, or want to submit a feature request, please open an issue

License

The aws-rails-provisioner is distributed under Apache License, Version 2.0. See LICENSE for more information.

aws-rails-provisioner's People

Contributors

alextwoods avatar cjyclaire avatar jpeddicord avatar mullermp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-rails-provisioner's Issues

Typescript error

Using ruby 2.5.1
Rails 5.1

when I try to build, I get the following error

`lib/inventory-fargate-stack.ts:37:43 - error TS2339: Property 'ClusterParameterGroup' does not exist on type 'typeof import("/home/chrisgeek/Documents/RailsProjects/inventory/cdk-sample/node_modules/@aws-cdk/aws-rds/lib/index")'.

37         const clusterParameterGroup = rds.ClusterParameterGroup.fromParameterGroupName(
                                             ~~~~~~~~~~~~~~~~~~~~~

lib/inventory-fargate-stack.ts:42:13 - error TS2345: Argument of type '{ engine: rds.IClusterEngine; masterUser: { username: string; password: cdk.SecretValue; }; instanceProps: { instanceType: ec2.InstanceType; vpc: ec2.IVpc; vpcSubnets: { ...; }; }; defaultDatabaseName: string; removalPolicy: cdk.RemovalPolicy.RETAIN; instances: number; parameterGroup: any; }' is not assignable to parameter of type 'DatabaseClusterProps'.
  Object literal may only specify known properties, and 'masterUser' does not exist in type 'DatabaseClusterProps'.

42             masterUser: {
               ~~~~~~~~~~~~~
43                 username: username,
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44                 password: password
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45             },
   ~~~~~~~~~~~~~

Found 2 errors`

I am not sure how to resolve this, I tried on a different project and the errors were over 20.

NPM build failed

This is a great gem but when trying to run the build command, I'm getting this error on my machine:

`
Executing npm install...
npm WARN deprecated [email protected]: request has been deprecated, see request/request#3142
npm WARN deprecated [email protected]: request-promise-native has been deprecated because it extends the now deprecated request package, see request/request#3142
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

✅ All done!
creating cdk-sample/lib/cdk-sample-init-stack.ts
creating cdk-sample/lib/vthere-fargate-stack.ts
replacing cdk-sample/bin/cdk-sample.ts
installing pkg: @aws-cdk/aws-ec2 ...
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

installing pkg: @aws-cdk/aws-ecs ...
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

installing pkg: @aws-cdk/aws-ecs-patterns ...
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

installing pkg: @aws-cdk/aws-ecr-assets ...
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

installing pkg: @aws-cdk/aws-rds ...
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

installing pkg: @aws-cdk/aws-certificatemanager ...
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

installing pkg: @aws-cdk/aws-secretsmanager ...
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

running npm run build ...
npm info it worked if it ends with ok
npm verb cli [
npm verb cli '/usr/local/Cellar/node/14.11.0/bin/node',
npm verb cli '/Users/bismark/.npm-global/bin/npm',
npm verb cli 'run',
npm verb cli 'build',
npm verb cli '--verbose'
npm verb cli ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'prebuild', 'build', 'postbuild' ]
npm info lifecycle [email protected]prebuild: [email protected]
npm info lifecycle [email protected]
build: [email protected]
npm verb lifecycle [email protected]build: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]
build: CWD: /Users/bismark/Documents/rails/vthere/cdk-sample
npm info lifecycle [email protected]~build: Failed to exec build script
npm verb stack Error: [email protected] build: tsc
npm verb stack Exit status 2
npm verb stack at EventEmitter. (/Users/bismark/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
npm verb stack at EventEmitter.emit (events.js:314:20)
npm verb stack at ChildProcess. (/Users/bismark/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
npm verb stack at ChildProcess.emit (events.js:314:20)
npm verb stack at maybeClose (internal/child_process.js:1047:16)
npm verb stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
npm verb pkgid [email protected]
npm verb cwd /Users/bismark/Documents/rails/vthere/cdk-sample
npm verb Darwin 19.6.0
npm verb argv "/usr/local/Cellar/node/14.11.0/bin/node" "/Users/bismark/.npm-global/bin/npm" "run" "build" "--verbose"
npm verb node v14.11.0
npm verb npm v6.14.8
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 2, true ]
npm timing npm Completed in 5191ms`

Any ideas why is this happening?

ENAMETOOLONG Error on deploy

When attempting to deploy with aws-rails-provisioner deploy after aws-rails-provisioner build and I'm getting a strange error from the CDK deploy

Very simple repo to reproduce https://github.com/TylerSustare/dinner/tree/aws-rails-provisioner-ENAMETOOLONG-error
Ruby: 2.7.1
Rails 6.0.3.2
Node: 12.13.1
Docker: 19.03.12
Mac OS: 10.15.6 (19G2021)

$ aws-rails-provisioner deploy

The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
ENAMETOOLONG: name too long, copyfile '/Users/tyler/go/src/github.com/tylersustare/projects/dinner/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/.git/logs/refs/heads/react-rails-does-not-run-in-prod-mode' -> 'cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/.git/logs/refs/heads/react-rails-does-not-run-in-prod-mode'
Subprocess exited with error 1

ENAMETOOLONG: name too long, lstat '/Users/tyler/go/src/github.com/tylersustare/projects/dinner/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/.git/logs/refs/remotes/origin/react-rails-does-not-run-in-prod-mode'
Subprocess exited with error 1
ENAMETOOLONG: name too long, lstat '/Users/tyler/go/src/github.com/tylersustare/projects/dinner/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/.git/logs/refs/remotes/origin/react-rails-does-not-run-in-prod-mode'
Subprocess exited with error 1
ENAMETOOLONG: name too long, lstat '/Users/tyler/go/src/github.com/tylersustare/projects/dinner/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/cdk-sample/cdk.out/asset.65cd2742fb521b0ebef1ba382dd70b9feabebb59c700d409e9aeb286c6b4275b/.git/logs/refs/remotes/origin/react-rails-does-not-run-in-prod-mode'
Subprocess exited with error 1

Improvement ideas

I've given the aws-rails-provisioner and whirl and have a few suggestions for improvements that will fill in a few gaps.

  1. Add the ability to easily specify the branch for a staging instance. During development, staging needs to be switched between different feature/release branches for testing. Some kind of environment variable in the docker container, or another flag that can be changed on git push would make this easy.
  2. Add worker process for background jobs
  3. Clean up ECR containers. Have a config variable that specifies how many to keep, so that costs don't go up and there is no reason to keep more than 5 or so.

CdkSampleInitStack was rollbacked.

I created aws-rails-provisioner.yml like below and ran aws-rails-provisioner deploy.

version: '0'

vpc:
  max_az: 2
  enable_dns: true
services:
  provisioner_sample:
    source_path: ./app # relative path from `aws-rails-provisioner.yml`
    fargate:
      desired_count: 2
      memory: 512
      cpu: 256
      envs:
        PORT: 80
        RAILS_LOG_TO_STDOUT: true
      public: true
    scaling:
      max_capacity: 5
      on_cpu:
        target_util_percent: 80
        scale_in_cool_down: 300
      on_requests:
        requests_per_target: 1000

ROLLBACK has occurred in CdkSampleInitStack of CloudFormation. The details of the error are as follows.

ID: VpcapplicationSubnet2Subnet29670962

Value (ap-northeast-1b) for parameter availabilityZone is invalid. Subnets can currently only be created in the following availability zones: ap-northeast-1c, ap-northeast-1d, ap-northeast-1a. (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterValue; Request ID: ec4fb9e1-b9a6-4cd2-9393-b2348ac93068)

Probably, it is caused by the fact that ap-northeast-1b is not selectable among AZ of ap-northeast-1. Is there any workaround?

cdk bootstrap

The first time I ran aws-rails-provisioner deploy, I got the error message, This stack uses assets, so the toolkit stack must be deployed to the environment (Run "cdk bootstrap aws://unknown-account/unknown-region").

After manually running cdk bootstrap I was able to proceed.

Failed at the [email protected] build script

I have an issue when try to build:

$ aws-rails-provisioner build                                                                                                                                                                                          
replacing cdk-sample/lib/cdk-sample-init-stack.ts
replacing cdk-sample/lib/aws-rails-provisioner-fargate-stack.ts
replacing cdk-sample/bin/cdk-sample.ts
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

running npm run build ...

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] build: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/samir/.npm/_logs/2020-02-05T11_24_57_799Z-debug.log

the log file:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   '/usr/local/Cellar/node/12.12.0/bin/node',
1 verbose cli   '/usr/local/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build'
1 verbose cli ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle [email protected]~prebuild: [email protected]
6 info lifecycle [email protected]~build: [email protected]
7 verbose lifecycle [email protected]~build: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/samir/Documents/projects/cdk-sample/node_modules/.bin:/Users/samir/.rvm/gems/ruby-2.7.0/bin:/Users/samir/.rvm/gems/ruby-2.7.0@global/bin:/Users/samir/.rvm/rubies/ruby-2.7.0/bin:/Users/samir/.rvm/bin:/usr/local/opt/dart@1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/samir/Library/Android/sdk/platform-tools
9 verbose lifecycle [email protected]~build: CWD: /Users/samir/Documents/projects/cdk-sample
10 silly lifecycle [email protected]~build: Args: [ '-c', 'tsc' ]
11 silly lifecycle [email protected]~build: Returned: code: 2  signal: null
12 info lifecycle [email protected]~build: Failed to exec build script
13 verbose stack Error: [email protected] build: `tsc`
13 verbose stack Exit status 2
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:210:5)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:210:5)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
14 verbose pkgid [email protected]
15 verbose cwd /Users/samir/Documents/projects/cdk-sample
16 verbose Darwin 19.2.0
17 verbose argv "/usr/local/Cellar/node/12.12.0/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v12.12.0
19 verbose npm  v6.11.3
20 error code ELIFECYCLE
21 error errno 2
22 error [email protected] build: `tsc`
22 error Exit status 2
23 error Failed at the [email protected] build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 2, true ]

settings file:

  1 version: "0"
  2 services: 
  3   aws-rails-provisioner:
  4     source_path: ./docker-test
  5     fargate: 
  6       desired_count: 3
  7       envs: 
  8         AWS_FARGATE_ENV_VAR: "Passed By aws-rails-provisioner"
  9         PORT: 80
 10         RAILS_LOG_TO_STDOUT: true
 11       public: true
 12 vpc:  
 13   cidr: 10.0.0.0/21
 14   enable_dns: true
 15   max_azs: 2

Getting `ENAMETOOLONG: name too long` when deploying

On Mac OS, it looks like it's trying to create a very long filename and hitting a limit. Output:

aws-rails-provisioner deploy --init --cdk-directory cdk-uc

ENAMETOOLONG: name too long, lstat '/Users/johmcgr/repos/usecaser/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/cdk-uc/cdk.out/asset.4277fc160f06a74520bae4cfe28dfd18c5e79b701169cd2f31b397bf069d83d8/app/views/application/_asker_question_nav.html.haml'
Subprocess exited with error 1

Error when deploying Rails 6 app

Overview

I am getting TSError when deploying a Rail 6 app. I have followed all the steps described in the page and the video tutorial, my current stack is as follows:

  • ruby 2.7.2
  • rails 6.0.3.5
  • aws-rails-provisioner 0.0.2.rc4

Here is my aws-rails-provisioner.yml:

version: '0'

vpc:
  max_az: 2
  enable_dns: true
services:
  my-rails-app:
    source_path: /my-rails-app
    fargate:
      desired_count: 3
      memory: 1024
      cpu: 256
      envs:
        PORT: 80
        RAILS_LOG_TO_STDOUT: true
      public: true
    db_cluster:
      engine: aurora-postgresql
      db_name: my-rails-app-backend-db
    scaling:
      max_capacity: 5
      on_cpu:
        target_util_percent: 80
        scale_in_cool_down: 300
      on_requests:
        requests_per_target: 1000

Trace

~/development  aws-rails-provisioner deploy                                                                                                                                                                                                  ✔ │ 5s │ 2.7.2 Ruby 

/development/cdk-sample/node_modules/ts-node/src/index.ts:513
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
bin/cdk-sample.ts(5,16): error TS1141: String literal expected.
bin/cdk-sample.ts(5,44): error TS2304: Cannot find name 'from'.
bin/cdk-sample.ts(11,12): error TS2304: Cannot find name 'core'.
bin/cdk-sample.ts(11,17): error TS2304: Cannot find name 'backendFargateStack'.
bin/cdk-sample.ts(5,16): error TS1005: ',' expected.
bin/cdk-sample.ts(5,42): error TS1128: Declaration or statement expected.
bin/cdk-sample.ts(5,49): error TS1005: ';' expected.

    at createTSError (/development/cdk-sample/node_modules/ts-node/src/index.ts:513:12)
    at reportTSError (/development/cdk-sample/node_modules/ts-node/src/index.ts:517:19)
    at getOutput (/development/cdk-sample/node_modules/ts-node/src/index.ts:752:36)
    at Object.compile (/development/cdk-sample/node_modules/ts-node/src/index.ts:968:32)
    at Module.m._compile (/development/cdk-sample/node_modules/ts-node/src/index.ts:1056:42)
    at Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Object.require.extensions.<computed> [as .ts] (/development/cdk-sample/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
Subprocess exited with error 1


/development/cdk-sample/node_modules/ts-node/src/index.ts:513
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
bin/cdk-sample.ts(5,16): error TS1141: String literal expected.
bin/cdk-sample.ts(5,44): error TS2304: Cannot find name 'from'.
bin/cdk-sample.ts(11,12): error TS2304: Cannot find name 'core'.
bin/cdk-sample.ts(11,17): error TS2304: Cannot find name 'backendFargateStack'.
bin/cdk-sample.ts(5,16): error TS1005: ',' expected.
bin/cdk-sample.ts(5,42): error TS1128: Declaration or statement expected.
bin/cdk-sample.ts(5,49): error TS1005: ';' expected.

    at createTSError (/development/cdk-sample/node_modules/ts-node/src/index.ts:513:12)
    at reportTSError (/development/cdk-sample/node_modules/ts-node/src/index.ts:517:19)
    at getOutput (/development/cdk-sample/node_modules/ts-node/src/index.ts:752:36)
    at Object.compile (/development/cdk-sample/node_modules/ts-node/src/index.ts:968:32)
    at Module.m._compile (/development/cdk-sample/node_modules/ts-node/src/index.ts:1056:42)
    at Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Object.require.extensions.<computed> [as .ts] (/development/cdk-sample/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
Subprocess exited with error 1

/development/cdk-sample/node_modules/ts-node/src/index.ts:513
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
bin/cdk-sample.ts(5,16): error TS1141: String literal expected.
bin/cdk-sample.ts(5,44): error TS2304: Cannot find name 'from'.
bin/cdk-sample.ts(11,12): error TS2304: Cannot find name 'core'.
bin/cdk-sample.ts(11,17): error TS2304: Cannot find name 'backendFargateStack'.
bin/cdk-sample.ts(5,16): error TS1005: ',' expected.
bin/cdk-sample.ts(5,42): error TS1128: Declaration or statement expected.
bin/cdk-sample.ts(5,49): error TS1005: ';' expected.

    at createTSError (/development/cdk-sample/node_modules/ts-node/src/index.ts:513:12)
    at reportTSError (/development/cdk-sample/node_modules/ts-node/src/index.ts:517:19)
    at getOutput (/development/cdk-sample/node_modules/ts-node/src/index.ts:752:36)
    at Object.compile (/development/cdk-sample/node_modules/ts-node/src/index.ts:968:32)
    at Module.m._compile (/development/cdk-sample/node_modules/ts-node/src/index.ts:1056:42)
    at Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Object.require.extensions.<computed> [as .ts] (/development/cdk-sample/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
Subprocess exited with error 1

/development/cdk-sample/node_modules/ts-node/src/index.ts:513
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
bin/cdk-sample.ts(5,16): error TS1141: String literal expected.
bin/cdk-sample.ts(5,44): error TS2304: Cannot find name 'from'.
bin/cdk-sample.ts(11,12): error TS2304: Cannot find name 'core'.
bin/cdk-sample.ts(11,17): error TS2304: Cannot find name 'backendFargateStack'.
bin/cdk-sample.ts(5,16): error TS1005: ',' expected.
bin/cdk-sample.ts(5,42): error TS1128: Declaration or statement expected.
bin/cdk-sample.ts(5,49): error TS1005: ';' expected.

    at createTSError (/development/cdk-sample/node_modules/ts-node/src/index.ts:513:12)
    at reportTSError (/development/cdk-sample/node_modules/ts-node/src/index.ts:517:19)
    at getOutput (/development/cdk-sample/node_modules/ts-node/src/index.ts:752:36)
    at Object.compile (/development/cdk-sample/node_modules/ts-node/src/index.ts:968:32)
    at Module.m._compile (/development/cdk-sample/node_modules/ts-node/src/index.ts:1056:42)
    at Module._extensions..js (node:internal/modules/cjs/loader:1121:10)
    at Object.require.extensions.<computed> [as .ts] (/development/cdk-sample/node_modules/ts-node/src/index.ts:1059:12)
    at Module.load (node:internal/modules/cjs/loader:972:32)
    at Function.Module._load (node:internal/modules/cjs/loader:813:14)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
Subprocess exited with error 1

aurora-postgresql DBParameterGroupFamily error

When selecting postgresql 10.7 I run into an issue

aws-rails-provisioner.yml
...
    db_cluster:
      engine: aurora-postgresql
      engine_version: 10.7
...

I'm getting the following error

11/28 | 4:36:11 PM | CREATE_FAILED | AWS::RDS::DBCluster | DBCluster (DBCluster15AF587F) The Parameter Group aws-rails-provisioner-default-aurora-postgresql with DBParameterGroupFamily aurora-postgresql9.6 cannot be used for this instance. Please use a Parameter Group with DBParameterGroupFamily aurora-postgresql10 (Service: AmazonRDS; Status Code: 400; Error Code: InvalidParameterCombination; Request ID: ...)

Region not provided

When trying to build, I get this error No region was provided. Configure the `:region` option or export the region name to ENV['AWS_REGION'] (Aws::Errors::MissingRegionError) I couldn't find it on the doc or anywhere online.

aws-rails-provisioner.yml

version: '0'

vpc:
  max_az: 2
  enable_dns: true
services:
  hospital-sys:
    source_path: ./hospital-sys
    fargate:
      desired_count: 3
      memory: 512
      cpu: 256
      envs:
        PORT: 80
        RAILS_LOG_TO_STDOUT: true
      public: true
    db_cluster:
      engine: aurora-postgresql
      db_name: app_development
    scaling:
      max_capacity: 5
      on_cpu:
        target_util_percent: 80
        scale_in_cool_down: 300
      on_requests:
        requests_per_target: 1000

Defining other AWS Services

Excellent starting point on this gem! Thanks for building it!

In most of the Rails apps, we work with need Redis(Elasticache) or some form of an in-memory store. It would be nice to be able to define those in the YAML like the db_cluster.

Thanks and let me know if I should make this suggestion somewhere else.

Cannot ask a question in stack overflow using tag aws-rails-provisioner (1500 reputation needed)

There are no questions in stack overflow with the TAG aws-rails-provisioner, maybe because to create a new tag, you need a 1500 reputation, which I do not have, so I can not generate the question with this tag. I like the concept of this tool, but it looks like it has been abandoned due to the difficulty of sharing solutions. Can anyone with such reputation create the TAG in stack overflow, please!

ClusterParameterGroup no longer exists

In the generated fargate stack definition it references ClusterParameterGroup here: https://github.com/awslabs/aws-rails-provisioner/blob/master/templates/fargate_stack.mustache#L37 and here: https://github.com/awslabs/aws-rails-provisioner/blob/master/templates/fargate_stack.mustache#L37

This gives the following error:

lib/rails-foo-fargate-stack.ts:37:43 - error TS2339: Property 'ClusterParameterGroup' does not exist on type 'typeof import("/Users/nweinmeister/Programming/FDIC/test-rails-deploy/cdk-sample/node_modules/@aws-cdk/aws-rds/lib/index")'.

37         const clusterParameterGroup = rds.ClusterParameterGroup.fromParameterGroupName(
                                             ~~~~~~~~~~~~~~~~~~~~~

ClusterParameterGroup no longer exists. I manually replaced it with rds.ParameterGroup and it works fine.

I'm happy to submit a PR to replace this if necessary.

aws-rails-provisioner ignoring --profile option

I created an aws-rails-provisioner project following the guidelines on the GitHub page and copied the default yaml file for a single application. When I ran

aws-rails-provisioner build --profile FargateSandboxAdmin --with-cicd -f ./aws-rails-provisioner.yml

it appeared to accept the profile parameter with no issues, however when I went to deploy it using

aws-rails-provisioner deploy --profile FargateSandboxAdmin

I received an error that --profile was not valid:

/Users/todd/.rbenv/versions/2.4.5/lib/ruby/gems/2.4.0/gems/aws-rails-provisioner-0.0.1.rc2/bin/aws-rails-provisioner:128:in '<top (required)>': undefined local variable or method 'profile' for main:Object (NameError)
from /Users/todd/.rbenv/versions/2.4.5/bin/aws-rails-provisioner:23:in 'load'
from /Users/todd/.rbenv/versions/2.4.5/bin/aws-rails-provisioner:23:in '

'

The same is true when using the -p flag instead of --profile. After running a "regular" deploy with aws-rails-provisioner deploy it created all the objects under my parent account and not the sandbox I set up for it.

Is there any way to use profiles with aws-rails-provisioner or is it not supported at this time?

I posted this to Stack Overflow as well for more visibility. Note that it's not posted under the suggested aws-rails-provisioner tag because that tag does not exist and I don't have the reputation to create it.

npm ERR! [email protected] build: `tsc`

I've got this error running aws-rails-provisioner with cicd flag
aws-rails-provisioner build --with-cicd

Any advice?
Thank you!

running npm run build ...
npm info it worked if it ends with ok
npm verb cli [
npm verb cli '/home/duard/.nvm/versions/node/v14.19.1/bin/node',
npm verb cli '/home/duard/.nvm/versions/node/v14.19.1/bin/npm',
npm verb cli 'run',
npm verb cli 'build',
npm verb cli '--verbose'
npm verb cli ]
npm info using [email protected]
npm info using [email protected]
npm verb run-script [ 'prebuild', 'build', 'postbuild' ]
npm info lifecycle [email protected]~prebuild: [email protected]
npm info lifecycle [email protected]~build: [email protected]
npm verb lifecycle [email protected]~build: unsafe-perm in lifecycle true
npm verb lifecycle [email protected]~build: PATH: /home/duard/.nvm/versions/node/v14.19.1/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/duard/RubymineProjects/server-check/cdk-sample/node_modules/.bin:/home/duard/.rbenv/versions/2.7.5/bin:/home/duard/.rbenv/libexec:/home/duard/.rbenv/plugins/ruby-build/bin:/home/duard/.nvm/versions/node/v14.19.1/bin:/home/duard/.rbenv/plugins/ruby-build/bin:/home/duard/.rbenv/shims:/home/duard/.rbenv/bin:/home/duard/bin:/usr/local/bin:/home/duard/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
npm verb lifecycle [email protected]~build: CWD: /home/duard/RubymineProjects/server-check/cdk-sample
npm info lifecycle [email protected]~build: Failed to exec build script
npm verb stack Error: [email protected] build: tsc `npm verb stack Exit status 2` .... `npm verb node v14.19.1` `npm verb npm v6.14.16` `npm ERR! code ELIFECYCLE` `npm ERR! errno 2` `npm ERR! [email protected] build: `tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm verb exit [ 2, true ]
npm timing npm Completed in 4418ms

rails console

This is a great approach to deploying rails on Fargate! But I've always become stuck when trying to figure out how to open a production console. This is a frequently-used diagnostic and migration tool for most rails deployments.

How do you recommend running an interactive rails console in a production environment on Fargate?

Numerous file errors upon build

I added a cdk_dir option to my aws-rails-provisioner.yml file after encountering errors about a missing cdk-sample directory.

I am now getting errors about a missing cdk file or directory.

Is there a particular directory tree that this tool expects, perhaps relative to the location of the aws-rails-provisioner.yml?

➜  api git:(develop) ✗ aws-rails-provisioner build                      
Traceback (most recent call last):
	7: from /home/eric/.rbenv/versions/2.6.6/bin/aws-rails-provisioner:23:in `<main>'
	6: from /home/eric/.rbenv/versions/2.6.6/bin/aws-rails-provisioner:23:in `load'
	5: from /home/eric/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/aws-rails-provisioner-0.0.2.rc3/bin/aws-rails-provisioner:119:in `<top (required)>'
	4: from /home/eric/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/aws-rails-provisioner-0.0.2.rc3/lib/aws-rails-provisioner/cdk_builder.rb:13:in `run'
	3: from /home/eric/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/aws-rails-provisioner-0.0.2.rc3/lib/aws-rails-provisioner/cdk_builder.rb:37:in `_init_cdk'
	2: from /home/eric/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/aws-rails-provisioner-0.0.2.rc3/lib/aws-rails-provisioner/cdk_builder.rb:37:in `chdir'
	1: from /home/eric/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/aws-rails-provisioner-0.0.2.rc3/lib/aws-rails-provisioner/cdk_builder.rb:39:in `block in _init_cdk'
/home/eric/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/aws-rails-provisioner-0.0.2.rc3/lib/aws-rails-provisioner/cdk_builder.rb:39:in ``': No such file or directory - cdk (Errno::ENOENT)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.