jets 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8dbba7d45f12322d2e782fa668a76f36a6818967e237681af10007bf95f2bdd
4
- data.tar.gz: 4a9be05f3d832828ad0362b3f897ac57ad7c47a450b457f7b38fa4bdd3e6ab3e
3
+ metadata.gz: bb8be5eb8194cd0e2d6ac3f718e4ecdb2a4a14ef785b513e32bb097a9402e417
4
+ data.tar.gz: e70d4f88f3e0b8701a16c2115cdc5ad8a463447ba45ffc6adcf32e494a431690
5
5
  SHA512:
6
- metadata.gz: 64b4ea7178ecfda89454067f08232b3f2cdb0f6df32ca6ff626026b7d5709dd1ac69fec5833da1a29762910f5fcb0963f5cc9f20895444c26666cea873601111
7
- data.tar.gz: 6c008490354e438e024e839a48c26917a01e3d62e4727183314884ec19f7dde5404175ec971c30e7e7cb35e53c95a3f854830de53fe466a9ffb936de9b85432e
6
+ metadata.gz: eef24ef7e8533bab5e98b3ca06205f219ec46ad7e0a8ba84cdf9a687ee9122253b17942e661990b2fb82be4aa28501076eae9626b8aea4958b2347241ca7a75f
7
+ data.tar.gz: 98f1272457a69bc6ae50f093f32c2f130c3ca32dbf0235fbf82bd449612f2001edc3faab2f0957c7df7dd7c823548806d4329a62f1e11d9fa1346ca48d66c267
@@ -50,8 +50,19 @@ If you want to manually build the Docker base image. Run:
50
50
  -e "IMAGE_NAME=tongueroo/jets:base" \
51
51
  -e "ARTIFACTS=/tmp/artifacts" \
52
52
  -e "SOURCE=/home/ec2-user/environment/jets" \
53
+ -e "DB_USER=$DB_USER" \
54
+ -e "DB_PASS=$DB_PASS" \
55
+ -e "DB_HOST=$DB_HOST" \
53
56
  amazon/aws-codebuild-local
54
57
 
55
- ## Docker base image
58
+ ## Run ingreration.sh
56
59
 
60
+ Can run the integration.sh test locally by running:
57
61
 
62
+ export DB_NAME=demo
63
+ export DB_USER=dbuser
64
+ export DB_PASS=dbpass
65
+ export DB_HOST=rdshost
66
+ .codebuild/integration.sh
67
+
68
+ Note, you'll need to use a real RDS db instance. Make sure DATABASE_URL is not set, this is working with the DB_* vars.
@@ -1,20 +1,37 @@
1
1
  #!/bin/bash -exu
2
2
 
3
- cp .codebuild/bin/jets /usr/local/bin/jets
4
- chmod a+x /usr/local/bin/jets
5
- export PATH=/usr/local/bin:$PATH
3
+ # on codebuild make sure we use the bin/jets that was checked out
4
+ set +u
5
+ if [ -n "$CODEBUILD_SRC_DIR" ]; then
6
+ cp .codebuild/bin/jets /usr/local/bin/jets
7
+ chmod a+x /usr/local/bin/jets
8
+ export PATH=/usr/local/bin:$PATH
9
+ which jets
10
+ fi
6
11
 
7
- which jets
12
+ # Locally set the CODEBUILD_SRC_DIR to make script simpler
13
+ # Do this before the cd-ing into the newly created directory.
14
+ if [ -z $CODEBUILD_SRC_DIR ]; then
15
+ CODEBUILD_SRC_DIR=$(pwd)
16
+ fi
17
+ set -u
8
18
 
9
19
  APP_NAME=demo$(date +%s)
10
20
  jets new $APP_NAME # jets new runs bundle and webpacker:install
11
21
  cd $APP_NAME
12
22
 
13
- cat >>.env.development <<EOL
23
+ cat >.env.development <<EOL
24
+ DB_NAME=$DB_NAME
14
25
  DB_USER=$DB_USER
15
26
  DB_PASS=$DB_PASS
16
27
  DB_HOST=$DB_HOST
17
28
  EOL
29
+ # IE: replace demo with demo1535227161 in case locally using demo and forget to set
30
+ perl -i -pe "s/DB_NAME=demo/DB_NAME=${APP_NAME}_dev/" .env.development
31
+ # Make sure database env vars matches whats in the file
32
+ eval $(cat .env.development | sed 's/^/export /')
33
+ # Make sure that nothing is .env.development.remote, dont want to use it for this case
34
+ cp /dev/null .env.development.remote
18
35
 
19
36
  jets generate scaffold Post title:string
20
37
  # The DB_ environment variables are set up in the circleci environment variables
@@ -42,6 +59,7 @@ cat > jets.postman_environment.json <<EOL
42
59
  "_postman_exported_using": "Postman/6.2.3"
43
60
  }
44
61
  EOL
62
+
45
63
  cp $CODEBUILD_SRC_DIR/.codebuild/jets.postman_collection.json .
46
64
 
47
65
  npm install -g newman
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ tmp
17
17
 
18
18
  spec/fixtures/project/handlers
19
19
  .codebuild/definitions
20
+ demo1*
@@ -1,7 +1,11 @@
1
1
  # Change Log
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
- This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
4
+ This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
+
6
+ ## [0.6.8]
7
+ - add jets clean:log and clean:build commands pull request #17
8
+ - allow integration.sh test script to run locally
5
9
 
6
10
  ## [0.6.7]
7
11
  - eager load jets lib also, pull request #16
@@ -11,12 +11,13 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- jets (0.6.7)
14
+ jets (0.6.8)
15
15
  actionpack (>= 5.2.1)
16
16
  actionview (>= 5.2.1)
17
17
  activerecord (>= 5.2.1)
18
18
  activesupport (>= 5.2.1)
19
19
  aws-sdk-cloudformation
20
+ aws-sdk-cloudwatchlogs
20
21
  aws-sdk-dynamodb
21
22
  aws-sdk-lambda
22
23
  aws-sdk-s3
@@ -67,6 +68,9 @@ GEM
67
68
  aws-sdk-cloudformation (1.6.0)
68
69
  aws-sdk-core (~> 3)
69
70
  aws-sigv4 (~> 1.0)
71
+ aws-sdk-cloudwatchlogs (1.5.0)
72
+ aws-sdk-core (~> 3)
73
+ aws-sigv4 (~> 1.0)
70
74
  aws-sdk-core (3.24.1)
71
75
  aws-eventstream (~> 1.0)
72
76
  aws-partitions (~> 1.0)
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_dependency "recursive-open-struct"
37
37
  spec.add_dependency "aws-sdk-s3"
38
38
  spec.add_dependency "aws-sdk-cloudformation"
39
+ spec.add_dependency "aws-sdk-cloudwatchlogs"
39
40
  spec.add_dependency "aws-sdk-dynamodb"
40
41
  spec.add_dependency "aws-sdk-lambda"
41
42
  spec.add_dependency "kramdown"
@@ -1,5 +1,6 @@
1
1
  require "aws-sdk-s3"
2
2
  require "aws-sdk-cloudformation"
3
+ require "aws-sdk-cloudwatchlogs"
3
4
  require "aws-sdk-lambda"
4
5
  require "aws-sdk-sts"
5
6
 
@@ -24,6 +25,10 @@ module Jets::AwsServices
24
25
  @sts ||= Aws::STS::Client.new
25
26
  end
26
27
 
28
+ def logs
29
+ @logs ||= Aws::CloudWatchLogs::Client.new
30
+ end
31
+
27
32
  def stack_exists?(stack_name)
28
33
  return false if ENV['TEST']
29
34
 
@@ -19,4 +19,5 @@ module Jets::Commands
19
19
  autoload :Dbconsole, "jets/commands/dbconsole"
20
20
  autoload :Url, "jets/commands/url"
21
21
  autoload :Markdown, "jets/commands/markdown"
22
+ autoload :Clean, "jets/commands/clean"
22
23
  end
@@ -0,0 +1,23 @@
1
+ module Jets::Commands
2
+ class Clean < Jets::Commands::Base
3
+ autoload :Base, 'jets/commands/clean/base'
4
+ autoload :Log, 'jets/commands/clean/log'
5
+ autoload :Build, 'jets/commands/clean/build'
6
+
7
+ class_option :noop, type: :boolean, desc: "noop or dry-run mode"
8
+ class_option :mute, type: :boolean, desc: "mute output"
9
+ class_option :sure, type: :boolean, desc: "bypass are you sure prompt"
10
+
11
+ desc "log", "Cleans CloudWatch log groups assocated with app"
12
+ long_desc Help.text('clean:log')
13
+ def log
14
+ Log.new(options).clean
15
+ end
16
+
17
+ desc "build", "Cleans jets build"
18
+ long_desc Help.text('clean:build')
19
+ def build
20
+ Build.new(options).clean
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ class Jets::Commands::Clean
2
+ class Base
3
+ def initialize(options={})
4
+ @options = options
5
+ end
6
+
7
+ private
8
+ def say(message)
9
+ prefix = 'NOOP ' if @options[:noop]
10
+ puts "#{prefix}#{message}" unless @options[:mute]
11
+ end
12
+
13
+ def are_you_sure?(message)
14
+ return true if @options[:sure]
15
+
16
+ puts "Are you sure that you want to #{message}? (y/N)"
17
+ yes = $stdin.gets.strip
18
+ unless yes =~ /^y/
19
+ puts "Phew that was close!"
20
+ exit 0
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'fileutils'
2
+
3
+ class Jets::Commands::Clean
4
+ class Build < Base
5
+ def clean
6
+ are_you_sure?("delete /tmp/jets")
7
+
8
+ say "Removing /tmp/jets..."
9
+ FileUtils.rm_rf("/tmp/jets") unless @options[:noop]
10
+ say "Removed /tmp/jets"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,89 @@
1
+ # The thing that limits this implementation is that there needs to be at least
2
+ # one lambda function created from an internal jets function. Example:
3
+ #
4
+ # /aws/lambda/demo-dev-2-jets-preheat_job-warm
5
+ # /aws/lambda/demo-dev-2-jets-public_controller-show
6
+ #
7
+ # We're doing this because JETS_ENV_EXTRA environments can create additional matching
8
+ # log groups and we don't want to overly-aggressively delete them.
9
+ #
10
+ # The `keep_prefixes(log_group_names)` method calcuates the log groups to keep.
11
+ class Jets::Commands::Clean
12
+ class Log < Base
13
+ extend Memoist
14
+ include Jets::AwsServices
15
+
16
+ def clean
17
+ are_you_sure?("delete CloudWatch logs")
18
+
19
+ say "Removing CloudWatch logs for #{prefix_guess}..."
20
+ log_groups.each do |g|
21
+ next if keep_log_group?(g.log_group_name)
22
+ logs.delete_log_group(log_group_name: g.log_group_name) unless @options[:noop]
23
+ say "Removed log group: #{g.log_group_name}"
24
+ end
25
+ say "Removed CloudWatch logs for #{prefix_guess}"
26
+ end
27
+
28
+ private
29
+ def prefix_guess
30
+ Jets::Naming.parent_stack_name
31
+ end
32
+
33
+ def log_groups
34
+ groups, next_token = [], true
35
+ while next_token
36
+ next_token = nil if next_token == true # just at start the loop
37
+ resp = logs.describe_log_groups(
38
+ log_group_name_prefix: "/aws/lambda/#{prefix_guess}-",
39
+ next_token: next_token,
40
+ )
41
+ groups += resp.log_groups
42
+ next_token = resp.next_token
43
+ end
44
+ groups
45
+ end
46
+ memoize :log_groups
47
+
48
+ def log_group_names
49
+ log_groups.map(&:log_group_name)
50
+ end
51
+
52
+ def all_prefixes(log_group_names)
53
+ log_prefixes(log_group_names)
54
+ end
55
+ memoize :all_prefixes
56
+
57
+ # Check for the prefixes to keep. The slightly tricky thing to watch for is
58
+ # for the prefix matching addiitonal log groups that belong to other
59
+ # JETS_ENV_EXTRA=xxx created environments.
60
+ #
61
+ # We find and store the prefixes to keep so we don't over aggressively delete
62
+ # log groups.
63
+ def keep_prefixes(log_group_names)
64
+ names = log_group_names.reject do |name|
65
+ name =~ %r{/aws/lambda/#{prefix_guess}-jets}
66
+ end
67
+ log_prefixes(names)
68
+ end
69
+ memoize :keep_prefixes
70
+
71
+ # Strips -jets.* from the full log group name to leave only the prefix behind
72
+ def log_prefixes(names)
73
+ names = names.select do |name|
74
+ name.match(Regexp.new("#{prefix_guess}-.*jets"))
75
+ end
76
+ names.map do |name|
77
+ name.sub(/-jets.*/,'')
78
+ end.uniq.sort
79
+ end
80
+
81
+ # Check if it is safe to delete the log group
82
+ def keep_log_group?(log_group_name)
83
+ keep_prefixes = keep_prefixes(log_group_names)
84
+ !!keep_prefixes.detect do |keep_prefix|
85
+ log_group_name =~ Regexp.new(keep_prefix)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -23,6 +23,9 @@ class Jets::Commands::Delete
23
23
  puts "Deleting #{Jets.config.project_namespace.colorize(:green)}..."
24
24
 
25
25
  wait_for_stack if @options[:wait]
26
+
27
+ delete_logs
28
+
26
29
  puts "Project #{Jets.config.project_namespace.colorize(:green)} deleted!"
27
30
  end
28
31
 
@@ -34,6 +37,12 @@ class Jets::Commands::Delete
34
37
  puts "Time took for deletion: #{status.pretty_time(took).green}."
35
38
  end
36
39
 
40
+ def delete_logs
41
+ puts "Deleting CloudWatch logs"
42
+ log = Jets::Commands::Clean::Log.new(mute: true, sure: true)
43
+ log.clean
44
+ end
45
+
37
46
  def confirm_project_exists
38
47
  begin
39
48
  resp = cfn.describe_stacks(stack_name: parent_stack_name)
@@ -0,0 +1,5 @@
1
+ Removes the build files that jets creates. Essentially, deletes `/tmp/jets`. This will remove all build files for all jets projects. This is safe as jets uses `/tmp/jets` merely as a cache to speed up incrementally builds. Cleaning this out can clean up cruft in the `/tmp/jets` directory that builds over time.
2
+
3
+ ## Example
4
+
5
+ jets clean:build
@@ -0,0 +1,5 @@
1
+ Essentially removes the CloudWatch groups assocated with the app. Lambda requests re-create the log groups so this is pretty safe to do.
2
+
3
+ ## Example
4
+
5
+ jets log:clean
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "0.6.7"
2
+ VERSION = "0.6.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-25 00:00:00.000000000 Z
11
+ date: 2018-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: aws-sdk-cloudwatchlogs
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: aws-sdk-dynamodb
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -461,6 +475,10 @@ files:
461
475
  - lib/jets/commands/call/autoload_guesser.rb
462
476
  - lib/jets/commands/call/base_guesser.rb
463
477
  - lib/jets/commands/call/guesser.rb
478
+ - lib/jets/commands/clean.rb
479
+ - lib/jets/commands/clean/base.rb
480
+ - lib/jets/commands/clean/build.rb
481
+ - lib/jets/commands/clean/log.rb
464
482
  - lib/jets/commands/console.rb
465
483
  - lib/jets/commands/db.rb
466
484
  - lib/jets/commands/db/environment-task.rake
@@ -474,6 +492,8 @@ files:
474
492
  - lib/jets/commands/help.rb
475
493
  - lib/jets/commands/help/build.md
476
494
  - lib/jets/commands/help/call.md
495
+ - lib/jets/commands/help/clean/build.md
496
+ - lib/jets/commands/help/clean/log.md
477
497
  - lib/jets/commands/help/console.md
478
498
  - lib/jets/commands/help/db/generate.md
479
499
  - lib/jets/commands/help/dbconsole.md