capistrano_dockerbuild 1.0.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
+ SHA1:
3
+ metadata.gz: 4d0d051fdc506aceb1bbc232079f1f04fb2e0b9f
4
+ data.tar.gz: c0182416f4b9c3fc338fc63d6f89c8d933fe6847
5
+ SHA512:
6
+ metadata.gz: b94b0a4e491a17c8a1c32fc2f3898031296438dd3603c40b21606871f6d607acf031a70f49b3e37e1b37fb6988c58ce4d5bed9007755f42cc6cd9239e07092d1
7
+ data.tar.gz: e483d3ff6866501200b070b7910d218cc73cc1fbeff7ca8cc77f85b9d80f5ee8f187c4f92c1c5b579773beba045c9fa96d8e333387a157d69790dfd89710eb16
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,56 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/FrozenStringLiteralComment:
5
+ Enabled: true
6
+
7
+ Style/StringLiterals:
8
+ EnforcedStyle: single_quotes
9
+ # Exclude:
10
+ # - 'db/schema.rb'
11
+ # - 'db/migrate/*.rb'
12
+
13
+ Style/RedundantReturn:
14
+ Enabled: false
15
+ Style/HashSyntax:
16
+ Enabled: false
17
+ Style/UnneededPercentQ:
18
+ Enabled: false
19
+ Style/GuardClause:
20
+ Enabled: false
21
+ Style/IfUnlessModifier:
22
+ Enabled: false
23
+ Style/UnlessElse:
24
+ Enabled: false
25
+ Style/SymbolArray:
26
+ Enabled: false
27
+ Style/Documentation:
28
+ Enabled: false
29
+
30
+ Style/TrailingCommaInLiteral:
31
+ EnforcedStyleForMultiline: comma
32
+
33
+
34
+ Layout/EmptyLinesAroundBlockBody:
35
+ Enabled: false
36
+ Layout/SpaceBeforeBlockBraces:
37
+ Enabled: false
38
+ Layout/SpaceInsideBlockBraces:
39
+ Enabled: false
40
+ Layout/EmptyLinesAroundModuleBody:
41
+ Enabled: false
42
+ Layout/EmptyLinesAroundClassBody:
43
+ Enabled: false
44
+ Layout/EmptyLines:
45
+ Enabled: false
46
+
47
+ Metrics/BlockLength:
48
+ Enabled: false
49
+ Metrics/AbcSize:
50
+ Enabled: false
51
+ Metrics/LineLength:
52
+ Enabled: false
53
+ Max: 160
54
+
55
+ Bundler/OrderedGems:
56
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in capistrano-docker-build.gemspec
6
+ gemspec
7
+
8
+ gem 'byebug'
9
+ gem 'rspec'
10
+ gem 'rspec-core'
11
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Eric Shorkey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,45 @@
1
+ This content is specific to deployments using docker-compose; if you haven't yet reviewed README.md, you should probably start there.
2
+
3
+ # docker:compose
4
+
5
+ This deploy strategy copies a docker-compose.yml file to all the servers you specify, and then runs `docker-compose up` across the whole lot.
6
+
7
+ This is a very basic deployment strategy; I wouldn't recommend for anything complex, but it will probably work fine for small projects with a single deploy target, or if you just want to make sure all the servers are running the same set of containers and don't mind getting your hands dirty if/when it randomly breaks in the middle.
8
+
9
+ There is no blue/green, rolling update, auto rollback on failure, or anything even close. Have fun!
10
+
11
+
12
+ ### Roles:
13
+
14
+ This gem adds the `docker_compose` role, identifying hosts where the docker_compose_file should be copied and ran.
15
+
16
+ If the `docker_build` role is defined, it will identify the source of the docker_compose_file
17
+
18
+ ```ruby
19
+ # using the `server` command
20
+ server 'my.remote.server', roles: %w{docker_compose}
21
+ server 'my_other.remote.server', roles: %w{docker_compose}
22
+
23
+ # or using the `role` command
24
+ role :docker_compose, %w{localhost} # places localhost within the docker_compose role
25
+
26
+ # The docker_build role is used to identify the source of the docker_compose_file
27
+ role :docker_build, %w{my.build.server} # copies the docker_compose_file from my.build.server and distributes it to all docker_compose roles
28
+
29
+ # It is also acceptable to have no docker_build role defined
30
+ # role :docker_build, %w{commented.out} # no docker_build role (commented out), so the docker_compose_file is copied from local workstation project directory
31
+ ```
32
+
33
+
34
+ ### Configurable options:
35
+
36
+ ```ruby
37
+ set :docker_compose_project -> { fetch(:application) } # (required) name of the docker-compose project
38
+ set :docker_compose_file, 'docker-compose.yml' # name of compose file to use for deploy
39
+ set :docker_compose_cmd, 'docker-compose' # name/path to `docker-compose` command on host
40
+ set :docker_compose_opts, nil # general args for `docker-compose`; default is none; (ex: '--project-name myproject --tls')
41
+ set :docker_compose_up_opts, '-d --no-build --remove-orphans' # args for `docker-compose up` command; these are the defaults
42
+ set :docker_compose_stop_opts, nil # args for `docker-compose stop` command; default is none; (ex: '--timeout 20')
43
+ set :docker_compose_path -> { deploy_path } # path on remote hosts for docker-compose deployments
44
+ set :dockercompose_deployhook, true # set false to skip default deploy hook; default is true
45
+ ```
@@ -0,0 +1,30 @@
1
+ This content is specific to deployments using Docker Swarm; if you haven't yet reviewed README.md, you should probably start there.
2
+
3
+ # docker:swarm
4
+
5
+
6
+
7
+
8
+ ### Configurable options:
9
+
10
+ ```ruby
11
+ set :docker_stack_name -> { fetch(:application) } # (required) name of the docker swarm stack
12
+ set :docker_compose_file, 'docker-compose.yml' # name of compose file to use for stack deploys
13
+ set :docker_swarm_docker_cmd -> { fetch(:docker_cmd, 'docker') } # name/path to `docker-compose` command on docker_swarm hosts
14
+ set :docker_stack_deploy_opts, '--prune' # args for `docker stack deploy` command; this is the default
15
+ set :docker_compose_path -> { deploy_path } # path on remote hosts for docker_compose_file deployments
16
+
17
+ set :dockerswarm_deployhook, true # set false to skip default deploy hook; default is true
18
+ ```
19
+
20
+ ----
21
+
22
+ ```ruby
23
+ set :docker_compose_project -> { fetch(:application) } # (required) name of the docker-compose project
24
+ set :docker_compose_file, 'docker-compose.yml' # name of compose file to use for deploy
25
+ set :docker_compose_cmd, 'docker-compose' # name/path to `docker-compose` command on host
26
+ set :docker_compose_opts, nil # general args for `docker-compose`; default is none; (ex: '--project-name myproject --tls')
27
+ set :docker_compose_up_opts, '-d --no-build --remove-orphans' # args for `docker-compose up` command; these are the defaults
28
+ set :docker_compose_stop_opts, nil # args for `docker-compose stop` command; default is none; (ex: '--timeout 20')
29
+ set :dockercompose_deployhook, true # set false to skip default deploy hook; default is true
30
+ ```
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # capistrano_dockerbuild
2
+
3
+ Docker image creation, tagging, and repository tasks (and a few optional deployment schemes) for Capistrano v3
4
+
5
+ ```sh
6
+ cap production docker:build_push # build image and then push to repository
7
+ ```
8
+
9
+ This plugin also hooks into the default `cap <environment> deploy` flow as a build action. See [Usage](#usage) for more details.
10
+
11
+
12
+
13
+ ## Installation
14
+
15
+ Add these lines to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'capistrano', '~> 3.11'
19
+ gem 'capistrano_dockerbuild', '~> 1.0'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ ```sh
25
+ $ bundle
26
+ ```
27
+
28
+ Or install it yourself as:
29
+
30
+ ```sh
31
+ $ gem install capistrano_dockerbuild
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ #### Require in Capfile:
37
+
38
+ ```ruby
39
+ require 'capistrano/dockerbuild'
40
+ ```
41
+
42
+ #### Optionally define a docker_build host:
43
+
44
+ ```ruby
45
+ role :docker_build, %w{localhost} # role syntax, making localhost the build agent
46
+ # or...
47
+ server 'my.build.server', roles: %w{docker_build} # server syntax, declaring a remote server
48
+ ```
49
+
50
+ If no `:docker_build` host is defined, the docker image will be built directly from the current working project directory. A maximum of one `:docker_build` host can be defined; any additional should raise an error.
51
+
52
+ #### Run a deploy:
53
+
54
+ The plugin automatically hooks the [Capistrano deploy flow](https://capistranorb.com/documentation/getting-started/flow/) after `deploy:published` (ie, you can run `cap <environment> deploy`).
55
+
56
+ To opt-out of the default deploy hook, add this line to your `config/deploy.rb` or to a specific `config/deploy/<stage>.rb` file:
57
+
58
+ ```ruby
59
+ set :dockerbuild_deployhook, false
60
+ ```
61
+
62
+ You can also run tasks in isolation. For example:
63
+
64
+ - `cap development docker:build`
65
+ - `cap development docker:push`
66
+ - `cap test docker:build_push`
67
+
68
+ Run `cap -T docker:` for details
69
+
70
+ *Be aware that `docker:build` tasks ran in isolation currently only generate the `:latest` and `:release-<timestamp>` docker image tags.*
71
+
72
+ ### Configurable options:
73
+
74
+ ```ruby
75
+ set :docker_build_image -> { fetch(:application) } # (required) name of the image
76
+ set :docker_build_opts, nil # additional `docker build` args; default is none; (ex: '--pull --no-cache --force-rm')
77
+ set :docker_build_tag, 'latest' # specific tag name for this build; you can change this and 'latest' tag will still be applied
78
+ set :docker_repo_url, nil # name/url of remote docker image repository for push
79
+ set :docker_build_context, '.' # context passed to `docker build` (within :build_from)
80
+ set :dockerfile, 'Dockerfile' # name of Dockerfile to use for build
81
+ set :docker_cmd, 'docker' # name/path to `docker` command on build host
82
+ set :build_from, '.' # directory within source repo to run build from
83
+ set :dockerbuild_deployhook, true # set false to skip default deploy hook; default is true
84
+ set :dockerbuild_trim_release_roles, true # set false to prevent no_release from being auto-added to all non docker_build servers
85
+ ```
86
+
87
+ ### Created Docker image tags
88
+ Under most use cases the `docker:build` task creates several image tags on the build host upon completion, all pointing to the same image SHA. By default, all of these tags are also pushed up to the docker image repository during the `docker:push` task. You may not want your repository (or build host) filled with a ton of tags, so this gem offers a few ways to control that sprawl.
89
+
90
+ docker_build_image_latest_tag,
91
+ docker_build_image_revision_tag,
92
+ docker_build_image_shortrev_tag,
93
+ docker_build_image_release_tag,
94
+ docker_build_image_tag,
95
+
96
+ ### Deployment to docker-compose, Docker Swarm, Kubernetes, Marathon, etc
97
+ The primary purpose of this gem is currently to provide tasks for Docker image creation and repository push/transfer. However, some basic deployment tasks are included as optionals, should you decide to use them. Each deploy strategy needs to be specifically enabled by a separate `requires` statement within your Capfile.
98
+
99
+ Refer to the specific deployment documentation for details:
100
+
101
+ - [Deploying with Docker Compose](README-deploy-compose.md)
102
+ - [Deploying with Docker Swarm](README-deploy-swarm.md)
103
+
104
+ ## Why?
105
+
106
+ Because.
107
+
108
+ ## Development
109
+
110
+ 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.
111
+
112
+ 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).
113
+
114
+ ## Contributing
115
+
116
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eshork/capistrano_dockerbuild
117
+
118
+
119
+ ## License
120
+
121
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
122
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'capistrano/docker/build'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'capistrano_dockerbuild'
9
+ spec.version = '1.0.0'
10
+ spec.authors = ['Eric Shorkey']
11
+ spec.email = ['eric.shorkey@gmail.com']
12
+
13
+ spec.summary = 'docker build/push plugin for Capistrano'
14
+ spec.description = 'Build, push and deploy your Docker container images as part of your Capistrano workflow. Pretty simple.'
15
+ spec.homepage = 'https://github.com/eshork/capistrano_dockerbuild'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
22
+ # else
23
+ # raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
24
+ # end
25
+
26
+ # spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ # f.match(%r{^(test|spec|features)/})
28
+ # end
29
+
30
+ spec.files = `git ls-files`.split($/)
31
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ spec.add_dependency 'capistrano', '>= 3.11'
35
+
36
+ spec.add_development_dependency 'bundler', '~> 1.14'
37
+ spec.add_development_dependency 'rake', '~> 12.0'
38
+ # spec.add_development_dependency 'rspec', '~> 3.0'
39
+ end
data/examples/.keep ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ load File.expand_path('../../tasks/dockerbuild_hooks.rake', __FILE__)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ load File.expand_path('../../tasks/dockerbuild.rake', __FILE__)
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Capistrano::DSL::Paths re-open
4
+ require_relative 'dsl/paths.rb'
5
+
6
+ # dockerbuild standard tasks and cap flow hooks
7
+ require_relative 'dockerbuild/tasks'
8
+ require_relative 'dockerbuild/hooks'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ load File.expand_path('../../tasks/dockercompose_hooks.rake', __FILE__)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ load File.expand_path('../../tasks/dockercompose.rake', __FILE__)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # dockercompose standard tasks and cap flow hooks
4
+ require_relative 'dockercompose/tasks'
5
+ require_relative 'dockercompose/hooks'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ load File.expand_path('../../tasks/dockerswarm_hooks.rake', __FILE__)
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ load File.expand_path('../../tasks/dockerswarm.rake', __FILE__)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # dockerswarm standard tasks and cap flow hooks
4
+ require_relative 'dockerswarm/tasks'
5
+ require_relative 'dockerswarm/hooks'
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Capistrano
4
+ module DSL
5
+ module Paths
6
+
7
+ def build_from
8
+ fetch(:build_from)
9
+ end
10
+
11
+ # directory within which the build is to be executed
12
+ # respects relative paths (not starting with /)
13
+ def build_path
14
+ return deploy_path.join(fetch(:current_directory, 'current')) if build_from.nil?
15
+ return Pathname.new(build_from.strip) if build_from.strip[0] == '/'
16
+ return deploy_path.join(fetch(:current_directory, 'current'), build_from)
17
+ end
18
+
19
+ end
20
+ end
21
+ end