hecks-packager 0.0.1 → 0.1.7

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ac393f8b10e1459e152a1f627a373aab97631a7
4
- data.tar.gz: df2748c4d8d9b5eb83e2c844d2b8e5560958bcf5
3
+ metadata.gz: 07d601cb1ef32fab6ba659d35c9f93e27ee47c8a
4
+ data.tar.gz: c913ccb380bc5f4396afa137adcc9eb7ae580c10
5
5
  SHA512:
6
- metadata.gz: 53a33b94d4b768d391f9618c3c24679d9865bff9c876fc44cccb36afb57346bdcfee22f874a7676cd043957bde5490b87029707b534366399051f956cae88c05
7
- data.tar.gz: b85a478e44494f32e7e2f9efa2b6654e1e3f0d8da180e420ca08c7d1a79fb9edb167bbc847e1de2be70c2e5e28b510de96dbe6b6347922d1e1b80fca9964d343
6
+ metadata.gz: 1df5b85f3bd92b4e2a1711fdf84946ed8e2dc74c81a0bdb53377aac19b4cb7c7396c9e30f4ac09f2243398628fb60a3510335706518e20f6982f71cd4356aee9
7
+ data.tar.gz: 7a539b176a59a9eaf4dbdda5a9471aced5b23c77344423f3891c32572834109f8525974faa892e3a270d8d2f8bbc6f528f5a06df7652be9a1c80e5d29f093246
data/bin/hecks-package ADDED
@@ -0,0 +1,59 @@
1
+ resources_path = File.expand_path(File.dirname(__FILE__)) + '/../resources'
2
+ lib_path = File.expand_path(File.dirname(__FILE__)) + '/../lib'
3
+
4
+ bash_script =
5
+ <<-BASH_SCRIPT
6
+ rm -rf package_build
7
+ rm -rf package
8
+ mkdir -p package_build
9
+
10
+ cp Gemfile package_build
11
+ cp Gemfile.lock package_build
12
+ cp Hecksfile package_build
13
+
14
+ bundle package --gemfile package_build/Gemfile
15
+ cp #{resources_path}/Dockerfile package_build
16
+
17
+ mkdir -p package_build/package/linux/ruby
18
+ mkdir -p package_build/package/linux/lib
19
+ mkdir -p package_build/package/linux/.bundle
20
+
21
+ mkdir -p package_build/package/osx/ruby
22
+ mkdir -p package_build/package/osx/lib
23
+ mkdir -p package_build/package/osx/.bundle
24
+
25
+ tar -xzf #{resources_path}/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz -C package_build/package/linux/ruby
26
+ tar -xzf #{resources_path}/traveling-ruby-20150715-2.2.2-osx.tar.gz -C package_build/package/osx/ruby
27
+
28
+ docker build package_build -t binary_builder
29
+
30
+ CONTAINER_ID=`docker create binary_builder:latest`
31
+
32
+ docker cp $CONTAINER_ID:/usr/src/app/vendor package_build
33
+ docker rm $CONTAINER_ID
34
+
35
+ cp -r package_build/Gemfile package_build/package/linux
36
+ cp -r package_build/Gemfile package_build/package/osx
37
+ cp -r package_build/Gemfile.lock package_build/package/linux
38
+ cp -r package_build/Gemfile.lock package_build/package/osx
39
+
40
+ cp -r package_build/vendor package_build/package/linux
41
+ cp -r package_build/vendor package_build/package/osx
42
+
43
+ cp #{resources_path}/app_binary package_build/package/linux/app
44
+ cp #{resources_path}/app_binary package_build/package/osx/app
45
+
46
+ cp #{resources_path}/bundle_config package_build/package/linux/.bundle/config
47
+ cp #{resources_path}/bundle_config package_build/package/osx/.bundle/config
48
+
49
+ cp -r #{lib_path}/** package_build/package/osx/lib
50
+ cp -r #{lib_path}/** package_build/package/linux/lib
51
+
52
+ cp -r package_build/package .
53
+
54
+ rm -rf package_build
55
+ BASH_SCRIPT
56
+
57
+ bash_script.split("/n").each do |command|
58
+ puts `#{command}`
59
+ end
data/lib/app_runner.rb ADDED
@@ -0,0 +1,18 @@
1
+ class AppRunner
2
+ def initialize(args:, application:)
3
+ @args = Args.new(args)
4
+ @application = application
5
+ end
6
+
7
+ def call
8
+ domain_module.send(args.method, args.data).call
9
+ end
10
+
11
+ private
12
+
13
+ attr_reader :args, :application
14
+
15
+ def domain_module
16
+ application[args.domain_module]
17
+ end
18
+ end
data/lib/args.rb ADDED
@@ -0,0 +1,17 @@
1
+ class Args
2
+ attr_reader :method
3
+
4
+ def initialize(command_args)
5
+ @domain_module = command_args[0]
6
+ @method = command_args[1]
7
+ @data = command_args[2]
8
+ end
9
+
10
+ def domain_module
11
+ @domain_module.to_sym
12
+ end
13
+
14
+ def data
15
+ JSON.parse(@data, symbolize_names: true)
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ # Ruby 2.2.2 doesn't support Fixnum#positive?, so monkey patch it.
2
+ class Fixnum
3
+ def positive?
4
+ self > 0
5
+ end
6
+ end
data/lib/hecks.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'bundler'
2
+ require 'getoptlong'
3
+
4
+ Bundler.require
5
+
6
+ require_relative 'args'
7
+ require_relative 'compatibility/fixnum'
8
+ require_relative 'app_runner'
9
+
10
+ load('Hecksfile')
11
+
12
+ opts = GetoptLong.new(
13
+ [ '--module', '-m', GetoptLong::REQUIRED_ARGUMENT ],
14
+ [ '--command', '-c', GetoptLong::REQUIRED_ARGUMENT ],
15
+ [ '--data', '-d', GetoptLong::REQUIRED_ARGUMENT ]
16
+ )
17
+
18
+ domain_module = ''
19
+ command = ''
20
+ data = ''
21
+ opts.each do |opt, arg|
22
+ case opt
23
+ when '--module'
24
+ domain_module = arg
25
+ when '--command'
26
+ command = arg
27
+ when '--data'
28
+ data = arg
29
+ end
30
+ end
31
+
32
+ puts AppRunner.new(args: [domain_module, command, data], application: HecksApp).call.result.to_json
@@ -0,0 +1,10 @@
1
+ FROM ruby:2.2
2
+
3
+ COPY vendor /usr/src/app/vendor
4
+
5
+ COPY Gemfile /usr/src/app/Gemfile
6
+ COPY Gemfile.lock /usr/src/app/Gemfile.lock
7
+
8
+ run gem install bundler
9
+ RUN cd /usr/src/app/ && ls
10
+ RUN cd /usr/src/app/ && bundle install --path vendor
@@ -6,8 +6,8 @@ SELFDIR="`dirname \"$0\"`"
6
6
  SELFDIR="`cd \"$SELFDIR\" && pwd`"
7
7
 
8
8
  # Tell Bundler where the Gemfile and gems are.
9
- export BUNDLE_GEMFILE="$SELFDIR/lib/app/Gemfile"
9
+ export BUNDLE_GEMFILE="$SELFDIR/Gemfile"
10
10
  unset BUNDLE_IGNORE_CONFIG
11
11
 
12
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" "$@"
13
+ exec "$SELFDIR/ruby/bin/ruby" -rbundler/setup -rreadline "$SELFDIR/lib/hecks.rb" "$@"
metadata CHANGED
@@ -1,33 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hecks-packager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Young
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-11 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Make the Domain the center of your programming world
13
+ description: Hecks Packager
14
14
  email: chris@example.com
15
- executables: []
15
+ executables:
16
+ - hecks-package
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  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
20
+ - bin/hecks-package
21
+ - lib/app_runner.rb
22
+ - lib/args.rb
23
+ - lib/compatibility/fixnum.rb
24
+ - lib/hecks.rb
25
+ - resources/Dockerfile
26
+ - resources/app_binary
27
+ - resources/bundle_config
28
+ - resources/traveling-ruby-20150715-2.2.2-linux-x86_64.tar.gz
29
+ - resources/traveling-ruby-20150715-2.2.2-osx.tar.gz
31
30
  homepage: https://github.com/chrisyoung/hecks-domain
32
31
  licenses:
33
32
  - MIT
@@ -51,5 +50,5 @@ rubyforge_project:
51
50
  rubygems_version: 2.6.10
52
51
  signing_key:
53
52
  specification_version: 4
54
- summary: DDD and Hexagonal Code Generators
53
+ summary: Package your domain driven application as a binary
55
54
  test_files: []
data/lib/cli/cli.rb DELETED
@@ -1,2 +0,0 @@
1
- require_relative 'generate_binary_package'
2
- require_relative 'generate_lambda_package'
@@ -1,97 +0,0 @@
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
@@ -1,26 +0,0 @@
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
@@ -1,17 +0,0 @@
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
@@ -1,8 +0,0 @@
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/
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'hecks'
4
- gem '<%= domain_name %>'
@@ -1,12 +0,0 @@
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
- };
@@ -1,100 +0,0 @@
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
@@ -1 +0,0 @@
1
- require_relative 'cli/cli'