snap_deploy 0.1.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d8d9e4179a487d4a6aa85d83a412b745bab0f687
4
+ data.tar.gz: 2d07e7c5385d0376e52fff147434ca5409240b8c
5
+ SHA512:
6
+ metadata.gz: 79a97f7af1d18b4ec11908e80fcb2f60afdd3ed299e12c7d4299d2059a19095ea3107b8169dfd2f6e43cc5da44685b821cc91072ba609a9ca6c953fe34895738
7
+ data.tar.gz: 7fb6da9d40a0fd9b0e7df77698fe0266adcc796fe09d740afccfff3b2051a4e83e9f577566e292ab10ff63d1806bad48afa9ebb71c3b9e1dcfb301d798284b95
@@ -0,0 +1,21 @@
1
+ *.rbc
2
+ .bundle
3
+ .config
4
+ .yardoc
5
+ InstalledFiles
6
+ _yardoc
7
+ coverage
8
+ doc/
9
+ lib/bundler/man
10
+ pkg
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
16
+ vendor/bundle
17
+ bundle
18
+ .tags
19
+ .tags_sorted_by_file
20
+ .idea/
21
+
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ export PATH="/opt/local/ruby/2.0.0-p598/bin:$PATH"
3
+
4
+ export NOKOGIRI_USE_SYSTEM_LIBRARIES=1
5
+
6
+ while read line; do
7
+ [[ -n ${SNAP_CI} || -n ${GO_SERVER_URL} ]] || echo -ne "Doing $((C++)) things...\r"
8
+ done < <(bundle check || bundle install --local --standalone --clean )
@@ -0,0 +1 @@
1
+ snap-deploy
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1 @@
1
+ snap-deploy
@@ -0,0 +1 @@
1
+ 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in snap_deploy.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'simplecov'
8
+ gem 'rspec'
9
+ gem 'fpm'
10
+ gem 'rake'
11
+ gem 'byebug'
12
+ gem 'webmock'
13
+ end
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ snap_deploy (0.1.1)
5
+ ansi
6
+ aws-sdk (= 1.53.0)
7
+ clamp
8
+ heroics
9
+ mime-types
10
+ rendezvous
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ addressable (2.3.7)
16
+ ansi (1.5.0)
17
+ arr-pm (0.0.9)
18
+ cabin (> 0)
19
+ aws-sdk (1.53.0)
20
+ aws-sdk-v1 (= 1.53.0)
21
+ aws-sdk-v1 (1.53.0)
22
+ json (~> 1.4)
23
+ nokogiri (>= 1.4.4)
24
+ backports (3.6.0)
25
+ byebug (3.5.1)
26
+ columnize (~> 0.8)
27
+ debugger-linecache (~> 1.2)
28
+ slop (~> 3.6)
29
+ cabin (0.6.1)
30
+ childprocess (0.5.3)
31
+ ffi (~> 1.0, >= 1.0.11)
32
+ clamp (0.6.3)
33
+ columnize (0.9.0)
34
+ crack (0.4.2)
35
+ safe_yaml (~> 1.0.0)
36
+ debugger-linecache (1.2.0)
37
+ diff-lcs (1.2.5)
38
+ docile (1.1.5)
39
+ erubis (2.7.0)
40
+ excon (0.44.2)
41
+ ffi (1.9.3)
42
+ fpm (1.2.0)
43
+ arr-pm (~> 0.0.9)
44
+ backports (>= 2.6.2)
45
+ cabin (>= 0.6.0)
46
+ childprocess
47
+ clamp (~> 0.6)
48
+ ffi
49
+ json (>= 1.7.7)
50
+ heroics (0.0.12)
51
+ erubis (~> 2.7.0)
52
+ excon
53
+ moneta
54
+ multi_json (>= 1.9.2)
55
+ netrc
56
+ json (1.8.1)
57
+ mime-types (2.3)
58
+ mini_portile (0.6.0)
59
+ moneta (0.8.0)
60
+ multi_json (1.10.1)
61
+ netrc (0.10.2)
62
+ nokogiri (1.6.3.1)
63
+ mini_portile (= 0.6.0)
64
+ rake (10.3.2)
65
+ rendezvous (0.1.2)
66
+ rspec (3.1.0)
67
+ rspec-core (~> 3.1.0)
68
+ rspec-expectations (~> 3.1.0)
69
+ rspec-mocks (~> 3.1.0)
70
+ rspec-core (3.1.3)
71
+ rspec-support (~> 3.1.0)
72
+ rspec-expectations (3.1.1)
73
+ diff-lcs (>= 1.2.0, < 2.0)
74
+ rspec-support (~> 3.1.0)
75
+ rspec-mocks (3.1.0)
76
+ rspec-support (~> 3.1.0)
77
+ rspec-support (3.1.0)
78
+ safe_yaml (1.0.4)
79
+ simplecov (0.9.0)
80
+ docile (~> 1.1.0)
81
+ multi_json
82
+ simplecov-html (~> 0.8.0)
83
+ simplecov-html (0.8.0)
84
+ slop (3.6.0)
85
+ webmock (1.20.4)
86
+ addressable (>= 2.3.6)
87
+ crack (>= 0.3.2)
88
+
89
+ PLATFORMS
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ bundler (~> 1.6)
94
+ byebug
95
+ fpm
96
+ rake
97
+ rspec
98
+ simplecov
99
+ snap_deploy!
100
+ webmock
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 ThoughtWorks, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ [![Build Status](https://snap-ci.com/snap-ci/snap-deploy/branch/master/build_image)](https://snap-ci.com/snap-ci/snap-deploy/branch/master)
2
+
3
+ # SnapDeploy
4
+
5
+ A deploy tool for continuous deployment. Used by [Snap CI](https://snap-ci.com)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'snap_deploy'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install snap_deploy
20
+
21
+ ## Usage
22
+
23
+ Currently, it supports aws and heroku deploy. You can use the commands below for more informations:
24
+
25
+ $ snap-deploy heroku --help
26
+ $ snap-deploy aws --help
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/[my-github-username]/snap_deploy/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
@@ -0,0 +1,25 @@
1
+ require 'bundler/setup'
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+ require 'tmpdir'
5
+
6
+ desc 'build heroku api'
7
+ task "build-heroku-api" do
8
+ sh('curl --silent --fail https://api.heroku.com/schema -H "Accept: application/vnd.heroku+json; version=3" > /tmp/heroku-schema.json')
9
+ sh('bundle exec heroics-generate -H "Accept: application/vnd.heroku+json; version=3" SnapDeploy::Provider::Heroku::API /tmp/heroku-schema.json https://api.heroku.com > lib/snap_deploy/provider/heroku/api.rb')
10
+ end
11
+
12
+ desc "Run units"
13
+ RSpec::Core::RakeTask.new("spec:unit") do |t|
14
+ t.pattern = "spec/unit/**/*_spec.rb"
15
+ t.rspec_opts = "--format documentation"
16
+ end
17
+
18
+ desc "Run integrations"
19
+ RSpec::Core::RakeTask.new("spec:integration") do |t|
20
+ t.pattern = "spec/integration/**/*_spec.rb"
21
+ t.rspec_opts = "--format documentation"
22
+ end
23
+
24
+ task :spec => ['spec:unit', 'spec:integration']
25
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.expand_path('../../', __FILE__), 'bundle'))
4
+ require 'bundler/setup'
5
+
6
+ Process.respond_to?(:setproctitle) ? Process.setproctitle('snap-deploy') : $0 = 'snap-deploy'
7
+
8
+ require 'snap_deploy'
9
+
10
+ SnapDeploy::CLI.run
@@ -0,0 +1,18 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd)"
6
+ cd $SCRIPT_DIR
7
+
8
+ export NOKOGIRI_USE_SYSTEM_LIBRARIES=1
9
+ export PATH="/opt/local/ruby/2.0.0-p598/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
10
+
11
+ # change ownership to nobody to not screw up things (even accidentally)
12
+ chown nobody -R $SCRIPT_DIR
13
+
14
+ # perform the bundle install
15
+ su -l nobody -s /bin/bash -c "cd $SCRIPT_DIR && env PATH=$PATH NOKOGIRI_USE_SYSTEM_LIBRARIES=1 $(which bundle) install --local --standalone --clean"
16
+
17
+ # change ownership back to root
18
+ chown root -R $SCRIPT_DIR
@@ -0,0 +1,4 @@
1
+ require "snap_deploy/version"
2
+ require 'snap_deploy/cli'
3
+ require 'snap_deploy/helpers'
4
+ require 'snap_deploy/provider'
@@ -0,0 +1,24 @@
1
+ require 'clamp'
2
+
3
+ module SnapDeploy
4
+
5
+ class CLI < Clamp::Command
6
+
7
+ module DefaultOptions
8
+ def self.included(receiver)
9
+ receiver.send :option, '--verbose', :flag, 'increase verbosity'
10
+ receiver.send :option, '--version', :flag, 'display the version' do
11
+ puts "Snap Deploy v#{SnapDeploy::VERSION}"
12
+ exit(0)
13
+ end
14
+ end
15
+ end
16
+
17
+ include DefaultOptions
18
+
19
+ def execute
20
+
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,74 @@
1
+ module SnapDeploy
2
+ module Helpers
3
+ def log(message)
4
+ puts message
5
+ end
6
+
7
+ def info(message)
8
+ puts message
9
+ end
10
+
11
+ def error(message)
12
+ puts message
13
+ end
14
+
15
+ def snap_commit
16
+ ENV['SNAP_COMMIT'] or raise
17
+ end
18
+
19
+ def snap_branch
20
+ ENV['SNAP_BRANCH'] or raise
21
+ end
22
+
23
+ def snap_upstream_branch
24
+ ENV['SNAP_UPSTREAM_BRANCH']
25
+ end
26
+
27
+ def pull_request_number
28
+ ENV['SNAP_PULL_REQUEST_NUMBER']
29
+ end
30
+
31
+ def access_key_id
32
+ ENV['AWS_ACCESS_KEY_ID'] or raise "AWS_ACCESS_KEY_ID is not defined"
33
+ end
34
+
35
+ def pipeline_counter
36
+ ENV['SNAP_PIPELINE_COUNTER'] or raise
37
+ end
38
+
39
+ def short_commit
40
+ ENV['SNAP_COMMIT_SHORT'] or raise
41
+ end
42
+
43
+ def manually_triggered_by
44
+ ENV['SNAP_STAGE_TRIGGERED_BY']
45
+ end
46
+
47
+ def secret_access_key
48
+ ENV['AWS_SECRET_ACCESS_KEY'] or raise "AWS_SECRET_ACCESS_KEY is not defined"
49
+ end
50
+
51
+ def logger
52
+ @logger ||= Logger.new($stdout).tap do |logger|
53
+ $stdout.sync = true
54
+ logger.level = verbose? ? Logger::DEBUG : Logger::WARN
55
+ end
56
+ end
57
+
58
+ def deploy_comment
59
+ comment = "Deploy build #{pipeline_counter}(rev #{short_commit}) via Snap CI"
60
+ comment << " by #{manually_triggered_by}" if manually_triggered_by
61
+ comment
62
+ end
63
+
64
+ def encoding_for(path)
65
+ file_cmd_output = `file #{path}`
66
+ case file_cmd_output
67
+ when /gzip compressed/
68
+ 'gzip'
69
+ when /compress'd/
70
+ 'compress'
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,8 @@
1
+ module SnapDeploy
2
+ module Provider
3
+ end
4
+ end
5
+
6
+ require 'snap_deploy/provider/aws'
7
+ require 'snap_deploy/provider/heroku'
8
+ require 'snap_deploy/provider/update'
@@ -0,0 +1,17 @@
1
+ class SnapDeploy::Provider::AWS < Clamp::Command
2
+
3
+ require 'snap_deploy/provider/aws/ops_works'
4
+ require 'snap_deploy/provider/aws/s3'
5
+ require 'snap_deploy/provider/aws/elastic_beanstalk'
6
+
7
+ SnapDeploy::CLI.subcommand 'aws', 'Perform AWS deployments', self
8
+ SnapDeploy::Provider::AWS.subcommand 'opsworks', 'manage opsworks deployments', SnapDeploy::Provider::AWS::OpsWorks
9
+ SnapDeploy::Provider::AWS.subcommand 's3', 'manage s3 deployments', SnapDeploy::Provider::AWS::S3
10
+ SnapDeploy::Provider::AWS.subcommand 'eb', 'manage elastic beanstalk deployments', SnapDeploy::Provider::AWS::ElasticBeanstalk
11
+
12
+
13
+ def execute
14
+ help
15
+ end
16
+
17
+ end
@@ -0,0 +1,156 @@
1
+ require 'timeout'
2
+ require 'json'
3
+ require 'rake'
4
+ require 'rake/file_utils_ext'
5
+
6
+ class SnapDeploy::Provider::AWS::ElasticBeanstalk < Clamp::Command
7
+
8
+ option '--app-name',
9
+ 'APP_NAME',
10
+ "Elastic Beanstalk application name",
11
+ :required => true
12
+
13
+ option '--env-name',
14
+ 'ENV_NAME' ,
15
+ 'Elastic Beanstalk environment name which will be updated',
16
+ :required => true
17
+
18
+ option '--bucket',
19
+ 'BUCKET_NAME',
20
+ 'S3 Bucket.',
21
+ :required => true
22
+
23
+ option '--bucket-base-dir',
24
+ 'BUCKET_BASE_DIR',
25
+ 'S3 Bucket base directory'
26
+
27
+ option '--application-version',
28
+ 'VERSION',
29
+ 'Specify an Application Version'
30
+
31
+ option '--region',
32
+ 'REGION',
33
+ 'EC2 Region.',
34
+ :default => 'us-east-1'
35
+
36
+ option '--archive',
37
+ 'ARCHIVE',
38
+ 'Specify application archive file'
39
+
40
+ include SnapDeploy::CLI::DefaultOptions
41
+ include SnapDeploy::Helpers
42
+ include Rake::FileUtilsExt
43
+
44
+ def execute
45
+ require 'aws-sdk'
46
+ setup_aws_auth
47
+ create_bucket unless bucket_exists?
48
+
49
+ info "Deploying application version `#{version_label}' to application `#{app_name}' on environment `#{env_name}'"
50
+ sleep 5 #s3 eventual consistency
51
+ create_app_version unless application_exists?
52
+ update_environment
53
+ end
54
+
55
+ private
56
+ def upload(key, file)
57
+ obj = s3.buckets[bucket].objects[key]
58
+ obj.write(Pathname.new(file))
59
+ obj
60
+ end
61
+
62
+ def application_exists?
63
+ application_versions = eb.describe_application_versions({
64
+ :application_name => app_name,
65
+ :version_labels => [version_label]
66
+ })[:application_versions]
67
+
68
+ if application_versions.any?
69
+ info "Application version already exists, will not create an application version or upload it to S3"
70
+ true
71
+ end
72
+ end
73
+
74
+ def create_app_version
75
+ file_path = bucket_base_dir ? File.join(bucket_base_dir, archive_name) : archive_name
76
+ s3_object = upload(file_path, archive_file)
77
+ options = {
78
+ :application_name => app_name,
79
+ :version_label => version_label,
80
+ :description => deploy_comment,
81
+ :source_bundle => {
82
+ :s3_bucket => bucket,
83
+ :s3_key => s3_object.key
84
+ },
85
+ :auto_create_application => false
86
+ }
87
+ eb.create_application_version(options)
88
+ end
89
+
90
+ def update_environment
91
+ options = {
92
+ :environment_name => env_name,
93
+ :version_label => version_label
94
+ }
95
+ info "Updating environment `#{env_name}' with application version `#{version_label}'"
96
+ eb.update_environment(options)
97
+ end
98
+
99
+ def archive_file
100
+ archive ? archive : create_zip
101
+ end
102
+
103
+ def create_zip
104
+ sh("git ls-files | zip -q -@ #{archive_name}", :verbose => !!verbose?)
105
+ archive_name
106
+ end
107
+
108
+ def files_to_pack
109
+ `git ls-files -z`.split("\x0")
110
+ end
111
+
112
+ def archive_name
113
+ archive ? "#{archive_base_name}-#{version_label}#{archive_ext_name}" : "#{version_label}.zip"
114
+ end
115
+
116
+ def archive_base_name
117
+ File.basename(archive, archive_ext_name)
118
+ end
119
+
120
+ def archive_ext_name
121
+ File.extname(archive)
122
+ end
123
+
124
+ def version_label
125
+ application_version ? application_version : "snap-ci-#{pipeline_counter}-#{short_commit}"
126
+ end
127
+
128
+ def create_bucket
129
+ s3.buckets.create(bucket)
130
+ end
131
+
132
+ def bucket_exists?
133
+ s3.buckets.map(&:name).include?(bucket)
134
+ end
135
+
136
+ def eb
137
+ @eb ||= AWS::ElasticBeanstalk.new.client
138
+ end
139
+
140
+ def s3
141
+ @s3 ||= AWS::S3.new
142
+ end
143
+
144
+ def setup_aws_auth
145
+ info "Logging in using Access Key ending with : #{access_key_id[-4..-1]}" unless @aws_configured
146
+ AWS.config(
147
+ access_key_id: access_key_id,
148
+ region: region,
149
+ secret_access_key: secret_access_key,
150
+ logger: logger,
151
+ log_formatter: AWS::Core::LogFormatter.colored
152
+ )
153
+ @aws_configured = true
154
+ end
155
+
156
+ end