dockable 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fd1d7cb100226591b20bbbc26e606c6b803a1d37cf63f71592343d595b031605
4
+ data.tar.gz: 3125f9a01324f6d95abb26973d814c21a7c9f59b7b26778c2c3d6163c79ba14e
5
+ SHA512:
6
+ metadata.gz: cbac6d9368592e07a1b13a449ae82e3b352dac162e6fc78636ab3e8413072b5cf3aa06dce94eb07f2cb5482964b0acf2be6f177a37de518a107d78f11645d464
7
+ data.tar.gz: d1596a20fed5c85bdc9317f24590b1be27c3b2bb39d7ee8a1d8dfcf0c43690642d9860535aeb2d9fc8a484075d7bea03b83051d9da1538d7ee7377ea03e30d7d
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in dockable.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dockable (0.1.0)
5
+ aws-sdk-s3
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aws-partitions (1.64.0)
11
+ aws-sdk-core (3.16.0)
12
+ aws-partitions (~> 1.0)
13
+ aws-sigv4 (~> 1.0)
14
+ jmespath (~> 1.0)
15
+ aws-sdk-kms (1.5.0)
16
+ aws-sdk-core (~> 3)
17
+ aws-sigv4 (~> 1.0)
18
+ aws-sdk-s3 (1.8.1)
19
+ aws-sdk-core (~> 3)
20
+ aws-sdk-kms (~> 1)
21
+ aws-sigv4 (~> 1.0)
22
+ aws-sigv4 (1.0.2)
23
+ diff-lcs (1.3)
24
+ jmespath (1.3.1)
25
+ rake (10.5.0)
26
+ rspec (3.7.0)
27
+ rspec-core (~> 3.7.0)
28
+ rspec-expectations (~> 3.7.0)
29
+ rspec-mocks (~> 3.7.0)
30
+ rspec-core (3.7.1)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-expectations (3.7.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-mocks (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-support (3.7.1)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ bundler (~> 1.16)
45
+ dockable!
46
+ rake (~> 10.0)
47
+ rspec (~> 3.0)
48
+
49
+ BUNDLED WITH
50
+ 1.16.1
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Dockable
2
+
3
+ This is a gem that helps us with getting a common setup for our Ruby apps.
4
+
5
+ Features:
6
+
7
+ * Load environment variables from S3.
8
+ * Execute commands from a Procfile.
9
+
10
+ At Teachable, this gem is preinstalled on our Docker base images that have Ruby.
11
+
12
+ ## Usage
13
+
14
+
15
+ Dockable is a prefix to commands just like "bundle exec" or "time".
16
+
17
+ Say you have the following `Procfile`:
18
+
19
+ ``` yaml
20
+ web: bundle exec puma -c config/puma.rb
21
+ worker: bundle exec sidekiq -C config/sidekiq.yml
22
+ release: bundle exec rake release
23
+ ```
24
+
25
+ You can run puma like this:
26
+
27
+ ```
28
+ $ dockable web
29
+ ```
30
+
31
+ ### Loading environment variables from S3
32
+
33
+ If you've specified the `DOCKABLE_ENV_BUCKET_NAME` and `DOCKABLE_ENV_KEY_NAME` variables, it will try to download an environment file from that location.
34
+
35
+ That environment file is a yaml file, like this:
36
+
37
+ ``` yaml
38
+ RAILS_ENV: production
39
+ DATABASE_URL: postgres://...
40
+ SECRET_KEY_BASE: deadbeef1234...
41
+ ```
42
+
43
+ The reason we do it this way is so we don't have to configure so many environment variables when booting a Docker image.
44
+
45
+ The values of `DOCKABLE_ENV_BUCKET_NAME` would be something like `"teachable-secrets"` and the value of `DOCKABLE_ENV_KEY_NAME` would be `"name-of-app/production.yml"`.
46
+
47
+ Make sure the bucket you store these environment variables in is private, but readable for your docker image, and uses encryption.
48
+
49
+ You can use dockable as an `ENTRYPOINT` option in your Dockerfile.
50
+
51
+ ``` Dockerfile
52
+ RUN gem install dockable
53
+ ENTRYPOINT ["dockable"]
54
+ ```
55
+
56
+ ### Other commands
57
+
58
+ If the command is not available in your Procfile, it will simply be executed.
59
+
60
+ ```
61
+ $ dockable ls -alh
62
+ ```
63
+
64
+ Protip: to check if environments are loaded, try running `dockable env`.
65
+
66
+ ### Other options
67
+
68
+ If `DOCKABLE_ROOT_DIR` is set, it will change the working directory.
69
+
70
+ You can change the location of the Procfile with `DOCKABLE_PROCFILE_LOCATION`
71
+
72
+ ## Development
73
+
74
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://github.com/iain/dockable.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dockable"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dockable.gemspec ADDED
@@ -0,0 +1,26 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dockable/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dockable"
8
+ spec.version = Dockable::VERSION
9
+ spec.authors = ["iain"]
10
+ spec.email = ["iain@iain.nl"]
11
+ spec.summary = %q{Some helpers for launching Ruby apps inside Docker}
12
+ spec.description = %q{Some helpers for launching Ruby apps inside Docker}
13
+ spec.homepage = "https://teachable.com"
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.16"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+
25
+ spec.add_dependency "aws-sdk-s3"
26
+ end
data/exe/dockable ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "dockable"
4
+
5
+ vars = Dockable.load_environment_variables(
6
+ bucket: ENV["DOCKABLE_ENV_BUCKET_NAME"],
7
+ key: ENV["DOCKABLE_ENV_KEY_NAME"],
8
+ )
9
+
10
+ Dir.chdir(ENV["DOCKABLE_ROOT_DIR"]) if ENV["DOCKABLE_ROOT_DIR"]
11
+
12
+ cmd = Dockable.load_command(ARGV, procfile_location: ENV["DOCKABLE_PROCFILE_LOCATION"])
13
+
14
+ Kernel.exec(vars, *cmd)
@@ -0,0 +1,3 @@
1
+ module Dockable
2
+ VERSION = "0.1.0"
3
+ end
data/lib/dockable.rb ADDED
@@ -0,0 +1,52 @@
1
+ require "dockable/version"
2
+
3
+ require "yaml"
4
+
5
+ module Dockable
6
+
7
+ def self.load_environment_variables(bucket:, key:)
8
+ if presence(bucket) && presence(key)
9
+ require "aws-sdk-s3"
10
+ client = Aws::S3::Client.new
11
+ resp = client.get_object(bucket: bucket, key: key)
12
+ body = resp.body.read
13
+ YAML.load(body).map { |k, v| [ k.to_s, v.to_s ] }.to_h
14
+ else
15
+ STDERR.puts "Dockable warning: No bucket or key found, no environment file loaded."
16
+ {}
17
+ end
18
+ end
19
+
20
+ def self.load_command(argv, procfile_location: nil)
21
+ procfile_location = presence(procfile_location) || "Procfile"
22
+ if File.exist?(procfile_location) && argv.size == 1
23
+ commands = YAML.load_file(procfile_location)
24
+ if commands.has_key?(argv[0])
25
+ [ commands[argv[0]].to_s ]
26
+ else
27
+ argv
28
+ end
29
+ elsif argv.size == 0
30
+ fail ArgumentError, "No command specified"
31
+ else
32
+ argv
33
+ end
34
+ end
35
+
36
+ def self.presence(value)
37
+ case value
38
+ when nil, false then nil
39
+ when /\A[[:space:]]*\z/
40
+ nil
41
+ when Array, Hash
42
+ if value.empty?
43
+ nil
44
+ else
45
+ value
46
+ end
47
+ else
48
+ value
49
+ end
50
+ end
51
+
52
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dockable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - iain
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: aws-sdk-s3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Some helpers for launching Ruby apps inside Docker
70
+ email:
71
+ - iain@iain.nl
72
+ executables:
73
+ - dockable
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - dockable.gemspec
87
+ - exe/dockable
88
+ - lib/dockable.rb
89
+ - lib/dockable/version.rb
90
+ homepage: https://teachable.com
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.7.6
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Some helpers for launching Ruby apps inside Docker
113
+ test_files: []