deliv-deploy 0.0.1

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: bd9d56a184a2493c47584afe203c611af1fc6d2523c12d0df4fb4cd0a9134b44
4
+ data.tar.gz: 41413a0c34f55518223e9eeaf171356596e0338fb2a3897e2f956a4c8989e07f
5
+ SHA512:
6
+ metadata.gz: 107a47e5daaa497e57a559927f528df3a68e20ecefc6a4c1c0bba38b90b8ea7337c9b4566b0f8918c3c7c7ccf2d94a2d551450795be08b59a849cddc2c9e2659
7
+ data.tar.gz: 2508f30bf214369af763eba2e3d1546944b060b31f4d80a7ea0f4ad31b202c7a796312a6e5524e9a44c746e83c589809825fd9b72356f33742f73b85bc1b7d1a
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ *.rbc
3
+ .DS_Store
4
+ .rspec_status
5
+ .ruby-gemset
6
+ .rvmrc
7
+ /.bundle/
8
+ /.yardoc
9
+ /coverage/
10
+ /doc/
11
+ /pkg/
12
+ /spec/reports/
13
+ /tmp/
14
+ /_yardoc/
15
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ TargetRailsVersion: 5.2
4
+
5
+ Documentation:
6
+ Enabled: false
7
+
8
+ Lint/ScriptPermission:
9
+ Enabled: false
10
+
11
+ Metrics/LineLength:
12
+ Max: 240
13
+
14
+ Metrics/MethodLength:
15
+ Max: 20
16
+
17
+ Metrics/AbcSize:
18
+ Max: 20
19
+
20
+ Style/FrozenStringLiteralComment:
21
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at david@ramaboo.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Deliv Inc
4
+ Copyright (c) 2014 Geoff Hayes
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Deliv::Deploy
2
+
3
+ Pushes code to [OpsWorks](https://aws.amazon.com/opsworks/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'deliv-deploy'
10
+
11
+ ## Usage
12
+
13
+ Deploy with the following commands:
14
+
15
+ * `rake deploy:staging`
16
+ * `rake deploy:qa`
17
+ * `rake deploy:sandbox`
18
+ * `rake deploy:production`
19
+
20
+ ## Environment
21
+
22
+ You will need to have the following environmental variables set:
23
+
24
+ * AWS_ACCESS_KEY_ID
25
+ * AWS_SECRET_ACCESS_KEY
26
+ * AWS_REGION
27
+ * AWS_OPSWORKS_STACK_ID
28
+ * AWS_OPSWORKS_APP_ID
29
+
30
+ ## Release Gem
31
+
32
+ TODO: delete old release stuff
33
+
34
+ $ rake release
35
+
36
+ ## Acknowledgements
37
+
38
+ Based on [opsworks-deploy](https://github.com/hayesgm/opsworks-deploy).
39
+
40
+ Fork it and make it your own.
41
+ This gem is **not** intended to be used outside [Deliv](https://www.deliv.co/). It's API is subject to change without notice.
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/build ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'awesome_print'
5
+ require 'deliv/deploy'
6
+
7
+ puts "Building deliv-deploy #{Deliv::Deploy::VERSION}.".white
8
+ system('git pull origin master')
9
+ system('gem build deliv-deploy.gemspec')
10
+ system("gem install deliv-deploy-#{Deliv::Deploy::VERSION}.gem")
11
+ puts 'Done.'.green
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'deliv/deploy'
5
+ require 'pry'
6
+
7
+ Pry.start
8
+
9
+ require 'irb'
10
+ IRB.start(__FILE__)
data/bin/release ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'awesome_print'
5
+ require 'deliv/deploy'
6
+
7
+ puts "Releasing deliv-deploy #{Deliv::Deploy::VERSION}.".white
8
+ system('git pull origin master')
9
+ system('git add --all')
10
+ system(%(git commit --all --message='Releasing #{Deliv::Deploy::VERSION}'))
11
+ system('git push origin master')
12
+ system('gem build deliv-deploy.gemspec')
13
+ system("gem install deliv-deploy-#{Deliv::Deploy::VERSION}.gem")
14
+ system("gem push deliv-deploy-#{Deliv::Deploy::VERSION}.gem")
15
+ puts "Done. deliv-deploy #{Deliv::Deploy::VERSION} has been released.".green
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'deliv/deploy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'deliv-deploy'
8
+ spec.version = Deliv::Deploy::VERSION
9
+ spec.author = 'David Singer'
10
+ spec.email = 'david@ramaboo.com'
11
+
12
+ spec.summary = 'Puses code to OpsWorks.'
13
+ spec.description = 'A simple set of rake commands to automate deploys though OpsWorks.'
14
+ spec.homepage = 'https://github.com/deliv/deliv-deploy'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_runtime_dependency 'awesome_print', '~> 1.8'
25
+ spec.add_runtime_dependency 'aws-sdk', '~> 3.0.1'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.16'
28
+ spec.add_development_dependency 'pry', '~> 0.11'
29
+ spec.add_development_dependency 'rake', '~> 12'
30
+ spec.add_development_dependency 'rspec', '~> 3.6'
31
+ spec.add_development_dependency 'rubocop', '~> 0.56.0'
32
+ end
@@ -0,0 +1,30 @@
1
+ require 'awesome_print'
2
+
3
+ require 'deliv/deploy/config'
4
+ require 'deliv/deploy/git'
5
+ require 'deliv/deploy/railtie' if defined?(Rails)
6
+ require 'deliv/deploy/version'
7
+
8
+ module Deliv
9
+ module Deploy
10
+ REQUIRED_ENV = %w[AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION].freeze
11
+
12
+ class ConfigError < StandardError; end
13
+
14
+ def self.verify_env!
15
+ REQUIRED_ENV.each { |e| raise "Missing `ENV['#{e}']`" unless ENV[e].present? }
16
+ end
17
+
18
+ def self.environments
19
+ Dir[Rails.root.join('config', 'environments', '*.rb')].map { |f| File.basename(f, '.*').to_sym }
20
+ end
21
+
22
+ def self.local_environments
23
+ %i[test development]
24
+ end
25
+
26
+ def self.remote_environments
27
+ environments - local_environments
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ module Deliv
2
+ module Deploy
3
+ class Config
4
+ def initialize(environment, filename = nil)
5
+ @environment = environment
6
+ load!(filename)
7
+ verify_environments!
8
+ end
9
+
10
+ def method_missing(name, *_args, &_block)
11
+ OpenStruct.new(@config[@environment]).send(name)
12
+ end
13
+
14
+ private
15
+
16
+ def load!(filename = nil)
17
+ @filename = filename || Rails.root.join('.deploy.yml') if defined?(Rails)
18
+ file = File.read(@filename)
19
+ @config = YAML.safe_load(file).with_indifferent_access
20
+ end
21
+
22
+ def verify_environments!
23
+ Deliv::Deploy.remote_environments.each { |environment| verify_environment!(environment) }
24
+ end
25
+
26
+ def verify_environment!(environment)
27
+ raise ConfigError, "Missing `#{environment}` from `#{@filename}`" unless @config[environment].present?
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,46 @@
1
+ module Deliv
2
+ module Deploy
3
+ class Git
4
+ attr_accessor :source_remote, :source_branch, :release_remote, :release_branch, :release_tag
5
+
6
+ def initialize(environment)
7
+ @environment = environment
8
+ @source_remote = 'origin'
9
+ @source_branch = current_branch
10
+ @release_remote = 'upstream'
11
+ @release_branch = "release-#{@environment}"
12
+ @release_tag = "#{@release_branch}-#{Time.current.to_i}"
13
+ end
14
+
15
+ def deploy
16
+ print_debug
17
+ old_branch = current_branch
18
+
19
+ `git commit --all --message='Saving before #{release_tag}'`
20
+ `git push #{source_remote} #{source_branch}`
21
+ `git fetch #{source_remote} #{source_branch}`
22
+ `git checkout --quiet #{source_remote}/#{source_branch}`
23
+ `git tag --message='#{user_name} pointed #{release_branch} at #{current_branch}' #{release_tag}`
24
+ `git push --force --follow-tags #{release_remote} HEAD:#{release_branch}`
25
+ `git checkout #{old_branch}`
26
+ end
27
+
28
+ def current_branch
29
+ `git rev-parse --abbrev-ref HEAD`&.squish
30
+ end
31
+
32
+ def user_name
33
+ `git config --get user.name`&.squish
34
+ end
35
+
36
+ def print_debug
37
+ puts "User Name: #{user_name}".blue
38
+ puts "Current Branc: #{current_branch}".blue
39
+ puts "Source Remote: #{source_remote}".blue
40
+ puts "Source Branch: #{source_branch}".blue
41
+ puts "Release Remote: #{release_remote}".blue
42
+ puts "Release Branch: #{release_branch}".blue
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ module Deliv
2
+ module Deploy
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ Dir[File.join(File.expand_path('../tasks', __dir__), '*.rake')].each { |f| load f }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Deliv
2
+ module Deploy
3
+ VERSION = '0.0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ require 'aws-sdk'
2
+
3
+ namespace :deploy do
4
+ desc 'Deploy staging'
5
+
6
+ Deliv::Deploy.remote_environments.each do |environment|
7
+ task environment, [:branch] => :environment do |_t, _args|
8
+ puts "Starting #{environment}...".white
9
+
10
+ Deliv::Deploy.verify_env!
11
+ config = Deliv::Deploy::Config.new(environment)
12
+
13
+ client = Aws::OpsWorks::Client.new
14
+
15
+ git = Deliv::Deploy::Git.new(environment)
16
+ git.deploy
17
+
18
+ resp = client.create_deployment(
19
+ stack_id: config.stack_id,
20
+ app_id: config.app_id,
21
+ command: {
22
+ name: 'deploy'
23
+ },
24
+ comment: "#{git.user_name} deployed to #{environment} at #{Time.current.iso8601}"
25
+ )
26
+
27
+ deployment_id = resp[:deployment_id]
28
+
29
+ if deployment_id.present?
30
+ puts "Deployed: #{deployment_id}".green
31
+ else
32
+ puts 'Error!'.red
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ require 'aws-sdk'
2
+
3
+ namespace :rollback do
4
+ Deliv::Deploy.verify_env!
5
+ client = Aws::OpsWorks::Client.new
6
+ # TODO: Fix this.
7
+ task test: :environment do
8
+ resp = client.create_deployment(
9
+ stack_id: 'be987488-25e0-405f-b5c2-7aee42dc3e84',
10
+ app_id: 'e30a40bf-7f06-42a4-a15f-01329ac3f605',
11
+ command: {
12
+ name: 'rollback'
13
+ },
14
+ comment: 'Test'
15
+ )
16
+
17
+ ap resp
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deliv-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Singer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.56.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.56.0
111
+ description: A simple set of rake commands to automate deploys though OpsWorks.
112
+ email: david@ramaboo.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - ".gitignore"
118
+ - ".rspec"
119
+ - ".rubocop.yml"
120
+ - ".ruby-version"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/build
127
+ - bin/console
128
+ - bin/release
129
+ - bin/setup
130
+ - deliv-deploy.gemspec
131
+ - lib/deliv/deploy.rb
132
+ - lib/deliv/deploy/config.rb
133
+ - lib/deliv/deploy/git.rb
134
+ - lib/deliv/deploy/railtie.rb
135
+ - lib/deliv/deploy/version.rb
136
+ - lib/deliv/tasks/deploy.rake
137
+ - lib/deliv/tasks/rollback.rake
138
+ homepage: https://github.com/deliv/deliv-deploy
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.7.6
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Puses code to OpsWorks.
162
+ test_files: []