hecks-packager 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ac393f8b10e1459e152a1f627a373aab97631a7
4
+ data.tar.gz: df2748c4d8d9b5eb83e2c844d2b8e5560958bcf5
5
+ SHA512:
6
+ metadata.gz: 53a33b94d4b768d391f9618c3c24679d9865bff9c876fc44cccb36afb57346bdcfee22f874a7676cd043957bde5490b87029707b534366399051f956cae88c05
7
+ data.tar.gz: b85a478e44494f32e7e2f9efa2b6654e1e3f0d8da180e420ca08c7d1a79fb9edb167bbc847e1de2be70c2e5e28b510de96dbe6b6347922d1e1b80fca9964d343
data/lib/cli/cli.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'generate_binary_package'
2
+ require_relative 'generate_lambda_package'
@@ -0,0 +1,97 @@
1
+ module Hecks
2
+ module Packager
3
+ module CLI
4
+ class GenerateBinaryPackage < Thor::Group
5
+ include Thor::Actions
6
+
7
+ class_option :no_cache, aliases: '-n', desc: 'download resources', default: false, type: :boolean
8
+
9
+ HOST = "http://d6r77u77i8pq3.cloudfront.net/releases"
10
+ OSX_BINARY = "traveling-ruby-20150715-2.2.2-osx.tar.gz"
11
+ LINUX_BINARY = 'traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz'
12
+ BUILD_DIR = 'packages/binary/build'
13
+ RESOURCES_DIR = BUILD_DIR + '/resources'
14
+ OSX_DIR = BUILD_DIR + '/osx'
15
+ OSX_LIB_DIR = OSX_DIR + '/lib'
16
+ OSX_APP_DIR = OSX_LIB_DIR + '/app'
17
+ LINUX_DIR = BUILD_DIR + '/linux-x86_64'
18
+ LINUX_LIB_DIR = LINUX_DIR + 'lib'
19
+ LINUX_APP_DIR = LINUX_LIB_DIR + '/app'
20
+
21
+ def self.source_root
22
+ File.dirname(__FILE__) + '/templates'
23
+ end
24
+
25
+ def create_package_folder
26
+ run("rm -rf packages/binary")
27
+ directory('binary_package', './packages/binary')
28
+ end
29
+
30
+ def domain_name
31
+ Dir.pwd.split('/').last
32
+ end
33
+
34
+ def build
35
+ package(OSX_APP_DIR, OSX_LIB_DIR, OSX_BINARY, OSX_DIR)
36
+ package(LINUX_APP_DIR, LINUX_LIB_DIR, LINUX_BINARY, LINUX_DIR)
37
+ end
38
+
39
+ private
40
+
41
+ def package(app_dir, lib_dir, binary, package_dir)
42
+ empty_directory(app_dir)
43
+ empty_directory(lib_dir + '/ruby')
44
+ return unless options[:no_cache]
45
+ download(binary, lib_dir)
46
+ copy_resources(app_dir, package_dir)
47
+ bundle_with_ruby_2_2_2(app_dir)
48
+ reduce_package_size(app_dir)
49
+ end
50
+
51
+ def copy_resources(app_dir, package_dir)
52
+ run("cp #{RESOURCES_DIR}/Gemfile #{app_dir}")
53
+ run("cp -rf #{RESOURCES_DIR}/bundle #{app_dir}/.bundle")
54
+ run("cp -rf #{RESOURCES_DIR}/#{domain_name}.rb #{app_dir}/#{domain_name}.rb")
55
+ run("cp -rf #{RESOURCES_DIR}/wrapper #{package_dir}/#{domain_name}")
56
+ run("cd #{package_dir} && chmod 744 #{domain_name}")
57
+ end
58
+
59
+ def download(binary, lib_dir)
60
+ run("cd #{RESOURCES_DIR} && curl -O #{HOST}/#{binary}")
61
+ run("tar -xzf #{RESOURCES_DIR}/#{binary} -C #{lib_dir}/ruby")
62
+ end
63
+
64
+ def bundle_with_ruby_2_2_2(app_dir)
65
+ run("cp -rf #{RESOURCES_DIR}/Dockerfile #{app_dir}")
66
+ run("cp #{domain_name}-0.0.0.gem #{app_dir}" )
67
+ run("cd #{app_dir} && docker build -t #{domain_name} --no-cache .")
68
+ container = `docker create pizza_builder:latest`.gsub("\n", '')
69
+ run("docker cp #{container}:/usr/src/app/vendor #{app_dir}")
70
+ end
71
+
72
+ def reduce_package_size(app_dir)
73
+ files = %w(test tests spec features benchmark README* CHANGE* Change*
74
+ COPYING* LICENSE* MIT-LICENSE* TODO *.txt *.md *.rdoc doc docs example
75
+ examples sample doc-api
76
+ )
77
+ files.each do |file|
78
+ run("rm -rf #{app_dir}/vendor/ruby/*/gems/*/#{file}")
79
+ end
80
+ run("rm -rf #{app_dir}/vendor/*/*/cache/*")
81
+ %w(.gitignore .travis.yml).each do |file|
82
+ run("rm -rf #{app_dir}/vendor/ruby/*/gems/*/#{file}")
83
+ end
84
+ %w(MAKEfile */Makefile */tmp).each do |file|
85
+ run("rm -f #{app_dir}/vendor/ruby/*/gems/*/ext/#{file}")
86
+ end
87
+ %w(*.c *.cpp *.h *.rl *extconf.rb *.java *.class *.md).each do |file|
88
+ run("find #{app_dir}/vendor/ruby -name '#{file}' | xargs rm -f")
89
+ end
90
+ %w(*.0 *.so *.bundle).each do |file|
91
+ run("find #{app_dir}/vendor/ruby/*/gems -name '#{file}' | xargs rm -f")
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,26 @@
1
+ module Hecks
2
+ module Packager
3
+ module CLI
4
+ class GenerateLambdaPackage < Thor::Group
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__) + '/templates'
9
+ end
10
+
11
+ def create_package_folder
12
+ directory('lambda_package', './packages/lambda')
13
+ end
14
+
15
+ def domain_name
16
+ Dir.pwd.split('/').last
17
+ end
18
+
19
+ def create_function
20
+ run("rm -rf packages/lambda/#{domain_name}")
21
+ run("cp -r packages/binary/build/osx packages/lambda/#{domain_name}")
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'hecks'
2
+ require '<%= domain_name %>'
3
+
4
+ app = Hecks::Application.new(domain: <%= domain_name.camelcase %>)
5
+
6
+ # Ruby 2.2.2 doesn't support Fixnum#positive?, so monkey patch it.
7
+ class Fixnum
8
+ def positive?
9
+ self > 0
10
+ end
11
+ end
12
+
13
+ domain_module = ARGV[0].to_sym
14
+ method = ARGV[1]
15
+ data = JSON.parse(ARGV[2], symbolize_names: true)
16
+
17
+ puts app[domain_module].send(method, data).call.result.inspect
@@ -0,0 +1,8 @@
1
+ FROM ruby:2.2
2
+
3
+ COPY <%= domain_name %>-0.0.0.gem /usr/src/app/<%= domain_name %>-0.0.0.gem
4
+ RUN gem install /usr/src/app/<%= domain_name %>-0.0.0.gem
5
+ COPY Gemfile /usr/src/app/Gemfile
6
+ RUN cd /usr/src/app/ && bundle package
7
+ RUN cd /usr/src/app/ && bundle install --path vendor
8
+ RUN ls /usr/src/app/
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'hecks'
4
+ gem '<%= domain_name %>'
@@ -0,0 +1,3 @@
1
+ BUNDLE_PATH: ./vendor
2
+ BUNDLE_WITHOUT: development
3
+ BUNDLE_DISABLE_SHARED_GEMS: '1'
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Figure out where this script is located.
5
+ SELFDIR="`dirname \"$0\"`"
6
+ SELFDIR="`cd \"$SELFDIR\" && pwd`"
7
+
8
+ # Tell Bundler where the Gemfile and gems are.
9
+ export BUNDLE_GEMFILE="$SELFDIR/lib/app/Gemfile"
10
+ unset BUNDLE_IGNORE_CONFIG
11
+
12
+ # Run the actual app using the bundled Ruby interpreter, with Bundler activated.
13
+ exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/<%= domain_name %>.rb" "$@"
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ const spawn = require('child_process').spawn;
4
+
5
+ module.exports.<%= domain_name %> = (event, context, callback) => {
6
+ var app = '<%= domain_name %>/<%= domain_name %>'
7
+ var data = JSON.stringify(event['data'])
8
+ var command = app + ' ' + event['module'] + ' ' + event['method'] + ' ' + JSON.stringify(data)
9
+ const child = exec(command, (result) => {
10
+ context.done(result);
11
+ });
12
+ };
@@ -0,0 +1,100 @@
1
+ # Welcome to Serverless!
2
+ #
3
+ # This file is the main config file for your service.
4
+ # It's very minimal at this point and uses default values.
5
+ # You can always add more config options for more control.
6
+ # We've included some commented out config examples here.
7
+ # Just uncomment any of them to get that config option.
8
+ #
9
+ # For full config options, check the docs:
10
+ # docs.serverless.com
11
+ #
12
+ # Happy Coding!
13
+
14
+ service: lambda
15
+
16
+ # You can pin your service to only deploy with a specific Serverless version
17
+ # Check out our docs for more details
18
+ # frameworkVersion: "=X.X.X"
19
+
20
+ provider:
21
+ name: aws
22
+ runtime: nodejs4.3
23
+
24
+ # you can overwrite defaults here
25
+ # stage: dev
26
+ # region: us-east-1
27
+
28
+ # you can add statements to the Lambda function's IAM Role here
29
+ # iamRoleStatements:
30
+ # - Effect: "Allow"
31
+ # Action:
32
+ # - "s3:ListBucket"
33
+ # Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] }
34
+ # - Effect: "Allow"
35
+ # Action:
36
+ # - "s3:PutObject"
37
+ # Resource:
38
+ # Fn::Join:
39
+ # - ""
40
+ # - - "arn:aws:s3:::"
41
+ # - "Ref" : "ServerlessDeploymentBucket"
42
+
43
+ # you can define service wide environment variables here
44
+ # environment:
45
+ # variable1: value1
46
+
47
+ # you can add packaging information here
48
+ #package:
49
+ # include:
50
+ # - include-me.js
51
+ # - include-me-dir/**
52
+ # exclude:
53
+ # - exclude-me.js
54
+ # - exclude-me-dir/**
55
+
56
+ functions:
57
+ <%= domain_name %>:
58
+ handler: handler.<%= domain_name %>
59
+
60
+ # The following are a few example events you can configure
61
+ # NOTE: Please make sure to change your handler code to work with those events
62
+ # Check the event documentation for details
63
+ # events:
64
+ # - http:
65
+ # path: users/create
66
+ # method: get
67
+ # - s3: ${env:BUCKET}
68
+ # - schedule: rate(10 minutes)
69
+ # - sns: greeter-topic
70
+ # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
71
+ # - alexaSkill
72
+ # - iot:
73
+ # sql: "SELECT * FROM 'some_topic'"
74
+ # - cloudwatchEvent:
75
+ # event:
76
+ # source:
77
+ # - "aws.ec2"
78
+ # detail-type:
79
+ # - "EC2 Instance State-change Notification"
80
+ # detail:
81
+ # state:
82
+ # - pending
83
+
84
+ # Define function environment variables here
85
+ # environment:
86
+ # variable2: value2
87
+
88
+ # you can add CloudFormation resource templates here
89
+ #resources:
90
+ # Resources:
91
+ # NewResource:
92
+ # Type: AWS::S3::Bucket
93
+ # Properties:
94
+ # BucketName: my-new-bucket
95
+ # Outputs:
96
+ # NewOutput:
97
+ # Description: "Description for the output"
98
+ # Value: "Some output value"
99
+ Plugins:
100
+ - serverless-offline
@@ -0,0 +1 @@
1
+ require_relative 'cli/cli'
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hecks-packager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris Young
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Make the Domain the center of your programming world
14
+ email: chris@example.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/cli/cli.rb
20
+ - lib/cli/generate_binary_package.rb
21
+ - lib/cli/generate_lambda_package.rb
22
+ - lib/cli/templates/binary_package/build/linux-x86_64/lib/app/hello.rb
23
+ - lib/cli/templates/binary_package/build/resources/%domain_name%.rb.tt
24
+ - lib/cli/templates/binary_package/build/resources/Dockerfile.tt
25
+ - lib/cli/templates/binary_package/build/resources/Gemfile.tt
26
+ - lib/cli/templates/binary_package/build/resources/bundle/config
27
+ - lib/cli/templates/binary_package/build/resources/wrapper.tt
28
+ - lib/cli/templates/lambda_package/handler.js.tt
29
+ - lib/cli/templates/lambda_package/serverless.yml.tt
30
+ - lib/hecks-packager.rb
31
+ homepage: https://github.com/chrisyoung/hecks-domain
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.6.10
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: DDD and Hexagonal Code Generators
55
+ test_files: []