capistrano-docker-deploy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.gitlab-ci.yml +25 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +21 -0
- data/README.md +88 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/capistrano-docker-deploy.gemspec +43 -0
- data/lib/capistrano/docker/deploy.rb +7 -0
- data/lib/capistrano/docker/deploy/version.rb +7 -0
- data/lib/capistrano/tasks/deploy.rake +7 -0
- data/lib/capistrano/tasks/docker.rake +21 -0
- data/lib/capistrano/tasks/docker/application.rake +44 -0
- data/lib/capistrano/tasks/docker/database.rake +62 -0
- data/lib/capistrano/tasks/docker/default.rake +17 -0
- data/lib/capistrano/tasks/docker/registry.rake +21 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b811998f2a726e6a303703dc14170f7e3fe78c94f6023efd73e206f29b5f797f
|
4
|
+
data.tar.gz: 7417ddfd667978c15c258088e83e60657c87b7212511e4d716dc3e6f19a8c6d1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 447aede702d6a31fce7078256349ce3d31388fa5e0aeb3b36e1fd1cdfd92d6739b424b41708a338568e8ad2ccd62dda0b96fddc5e56cf9ea3a8e042a8e03d9c8
|
7
|
+
data.tar.gz: 776929759a100c3dfe1a85572f08475b1b825ea2cf6224f71e72ad2dc8fb3dff3cca5642d0fee9d7c70fa306437cd6dcc79a01b04250d73d3fcbbf3845d1dddb
|
data/.gitignore
ADDED
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
stages:
|
2
|
+
- test
|
3
|
+
- publish
|
4
|
+
|
5
|
+
image: ruby:2.5
|
6
|
+
|
7
|
+
before_script:
|
8
|
+
- bundle install --path vendor
|
9
|
+
|
10
|
+
cache:
|
11
|
+
paths:
|
12
|
+
- vendor/ruby
|
13
|
+
|
14
|
+
test:
|
15
|
+
stage: test
|
16
|
+
script:
|
17
|
+
- bundle exec rspec
|
18
|
+
|
19
|
+
publish:
|
20
|
+
stage: publish
|
21
|
+
script:
|
22
|
+
- gem install dpl
|
23
|
+
- dpl --provider=rubygems --api-key=${RUBYGEMS_API_KEY}
|
24
|
+
only:
|
25
|
+
- tags
|
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 tom@initforthe.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
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
capistrano-docker-deploy (0.1.0)
|
5
|
+
capistrano (>= 3.8.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
airbrussh (1.3.1)
|
11
|
+
sshkit (>= 1.6.1, != 1.7.0)
|
12
|
+
capistrano (3.11.0)
|
13
|
+
airbrussh (>= 1.0.0)
|
14
|
+
i18n
|
15
|
+
rake (>= 10.0.0)
|
16
|
+
sshkit (>= 1.9.0)
|
17
|
+
concurrent-ruby (1.1.5)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
i18n (1.6.0)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
net-scp (2.0.0)
|
22
|
+
net-ssh (>= 2.6.5, < 6.0.0)
|
23
|
+
net-ssh (5.2.0)
|
24
|
+
rake (10.5.0)
|
25
|
+
rspec (3.8.0)
|
26
|
+
rspec-core (~> 3.8.0)
|
27
|
+
rspec-expectations (~> 3.8.0)
|
28
|
+
rspec-mocks (~> 3.8.0)
|
29
|
+
rspec-core (3.8.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-expectations (3.8.2)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.8.0)
|
34
|
+
rspec-mocks (3.8.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.8.0)
|
37
|
+
rspec-support (3.8.0)
|
38
|
+
sshkit (1.18.2)
|
39
|
+
net-scp (>= 1.1.2)
|
40
|
+
net-ssh (>= 2.8.0)
|
41
|
+
|
42
|
+
PLATFORMS
|
43
|
+
ruby
|
44
|
+
|
45
|
+
DEPENDENCIES
|
46
|
+
bundler (~> 1.17)
|
47
|
+
capistrano-docker-deploy!
|
48
|
+
rake (~> 10.0)
|
49
|
+
rspec (~> 3.0)
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Tomislav Simnett
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# Capistrano Docker Deployment strategy
|
2
|
+
|
3
|
+
This gem allows you to deploy a pre-built docker image of a rails app and associated dependendent images.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'capistrano-docker-deploy', require: false
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install capistrano-docker-deploy
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
It is assumed that capistrano is already set up on the project, and that a docker repository exists that holds images for deployment (and that it can be accessed)
|
24
|
+
|
25
|
+
<!-- You will need to set `:scm` to `nil` as we don't use version control for deployment with this strategy:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
set :scm, nil
|
29
|
+
``` -->
|
30
|
+
|
31
|
+
### Options
|
32
|
+
|
33
|
+
| Name | Default Value | Type | Description |
|
34
|
+
|------|---------------|------|-------------|
|
35
|
+
| `:database_image` | `nil` | `String` | Image to use for the database. Set to `nil` for external database server |
|
36
|
+
| `:docker_image_tag` | `latest` | `String` | Docker tag to deploy |
|
37
|
+
| `:docker_labels` | `[]` | `Array[String]` | Labels to apply to the docker container (eg for Traefik) |
|
38
|
+
| `:docker_network` | `nil` | `String` | Network to attach docker container to |
|
39
|
+
| `:docker_registry` | `nil` | `String` | Docker registry from which to pull your image (if not the Docker Hub) |
|
40
|
+
| `:docker_registry_user` | `nil` | `String` | Docker registry username (for `:docker_registry`) |
|
41
|
+
| `:docker_registry_password` | `nil` | `String` | Docker registry password (for `:docker_registry`) |
|
42
|
+
| `:docker_registry_image` | `nil` | `String` | Docker registry image |
|
43
|
+
| `:database_url` | `"postgres://postgres@#{fetch(:slug)}-db/#{fetch(:application)}"` | `String` | Database URL |
|
44
|
+
| `:environment_variables` | `[]` | `Array[String]` | Environment variables to pass through from the deployer to the docker container |
|
45
|
+
| `:exposed_ports` | `[]` | `Array[String]` | Ports for docker to expose |
|
46
|
+
| `:slug` | `"#{fetch(:application)}-#{fetch(:stage)}"` | `String` | Name for the docker container |
|
47
|
+
|
48
|
+
### Additional configuration settings
|
49
|
+
|
50
|
+
The `server` method can take two further parameters:
|
51
|
+
|
52
|
+
| Name | Description |
|
53
|
+
|------|-------------|
|
54
|
+
| `reset_on_deploy` | Perform a `rake db:reset` on deployment |
|
55
|
+
| `migrate_on_deploy` | Perform a `rake db:migrate` on deployment |
|
56
|
+
|
57
|
+
To ensure migrations run once and only once, set one server running the Rails application as having the `db` role and set `primary: true` on it.
|
58
|
+
|
59
|
+
### To use with Gitlab CI:
|
60
|
+
|
61
|
+
Set the following options in `config/deploy.rb`:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
set :docker_registry, ENV.fetch('CI_REGISTRY')
|
65
|
+
set :docker_registry_user, ENV.fetch('CI_REGISTRY_USER')
|
66
|
+
set :docker_registry_password, ENV.fetch('CI_REGISTRY_PASSWORD')
|
67
|
+
set :docker_registry_image, ENV.fetch('CI_REGISTRY_IMAGE')
|
68
|
+
```
|
69
|
+
|
70
|
+
For other CD/CI environments, refer to their specific documentation.
|
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 Gitlab at https://gitlab.com/initforthe/capistrano-docker-deploy. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
85
|
+
|
86
|
+
## Code of Conduct
|
87
|
+
|
88
|
+
Everyone interacting in the Capistrano::Docker::Deploy project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/initforthe/capistrano-docker-deploy/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "capistrano/docker/deploy"
|
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,43 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'capistrano/docker/deploy/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'capistrano-docker-deploy'
|
7
|
+
spec.version = Capistrano::Docker::Deploy::VERSION
|
8
|
+
spec.authors = ['Tomislav Simnett']
|
9
|
+
spec.email = ['tom@initforthe.com']
|
10
|
+
|
11
|
+
spec.summary = 'Docker deployment for capistrano'
|
12
|
+
spec.description = 'Deploys applications and dependencies from a registry'
|
13
|
+
spec.homepage = 'https://gitlab.com/initforthe/capistrano-docker-deploy'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = 'https://gitlab.com/initforthe/capistrano-docker-deploy.git'
|
23
|
+
# spec.metadata['changelog_uri'] = "TODO: Put your gem's CHANGELOG.md URL here."
|
24
|
+
else
|
25
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
26
|
+
'public gem pushes.'
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ['lib']
|
37
|
+
|
38
|
+
spec.add_dependency 'capistrano', '>= 3.8.0'
|
39
|
+
|
40
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
41
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
42
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
43
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
load File.expand_path('../tasks/docker/default.rake', __dir__)
|
2
|
+
load File.expand_path('../tasks/docker/registry.rake', __dir__)
|
3
|
+
load File.expand_path('../tasks/docker/application.rake', __dir__)
|
4
|
+
load File.expand_path('../tasks/docker/database.rake', __dir__)
|
5
|
+
|
6
|
+
load File.expand_path('../tasks/docker.rake', __dir__)
|
7
|
+
load File.expand_path('../tasks/deploy.rake', __dir__)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :docker do
|
2
|
+
task :starting do
|
3
|
+
invoke 'docker:login'
|
4
|
+
end
|
5
|
+
|
6
|
+
task :updating do
|
7
|
+
invoke 'docker:pull'
|
8
|
+
end
|
9
|
+
|
10
|
+
task :publishing do
|
11
|
+
invoke 'docker:app:stop'
|
12
|
+
invoke 'docker:db:start'
|
13
|
+
invoke 'docker:app:start'
|
14
|
+
invoke 'docker:db:setup'
|
15
|
+
end
|
16
|
+
|
17
|
+
task :terminate do
|
18
|
+
invoke 'docker:app:terminate'
|
19
|
+
invoke 'docker:db:terminate'
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
namespace :docker do
|
2
|
+
namespace :app do
|
3
|
+
task :start do
|
4
|
+
on roles(:app), in: :parallel do
|
5
|
+
env_vars = fetch(:environment_variables).map do |key|
|
6
|
+
value = ENV.fetch(key) { nil }
|
7
|
+
['-e', "#{key}='#{value}'"] if value
|
8
|
+
end.compact.flatten.join(' ')
|
9
|
+
fetch(:docker_network, nil) &&
|
10
|
+
network = "--network #{fetch(:docker_network)}"
|
11
|
+
labels = fetch(:docker_labels).map do |label|
|
12
|
+
['--label', label]
|
13
|
+
end.compact.flatten.join(' ')
|
14
|
+
|
15
|
+
execute 'docker', 'run', '-d', '--restart', 'always',
|
16
|
+
'--name', fetch(:slug),
|
17
|
+
'-e', "RAILS_ENV=#{fetch(:stage)}", redact(env_vars),
|
18
|
+
'-e', "DATABASE_URL=#{fetch(:database_url)}", network, labels,
|
19
|
+
fetch(:exposed_ports).map { |pgp| ['-p', pgp] }.flatten
|
20
|
+
.join(' '),
|
21
|
+
"#{fetch(:docker_registry_image)}:#{fetch(:docker_image_tag)}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
task :stop do
|
26
|
+
on roles(:app), in: :parallel do
|
27
|
+
%w[stop rm].each do |command|
|
28
|
+
execute 'docker', command, fetch(:slug), '||', 'true'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
task :terminate do
|
34
|
+
invoke 'docker:app:stop'
|
35
|
+
invoke 'docker:app:clean'
|
36
|
+
end
|
37
|
+
|
38
|
+
task :clean do
|
39
|
+
on roles(:app) do
|
40
|
+
execute 'docker', 'rmi', fetch(:docker_registry_image), '||', 'true'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
roles(:db).any? &&
|
4
|
+
set(
|
5
|
+
:database_url,
|
6
|
+
"postgres://postgres@#{fetch(:slug)}-db/#{fetch(:application)}"
|
7
|
+
)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :docker do
|
12
|
+
namespace :db do
|
13
|
+
desc 'Attempt to start the database container'
|
14
|
+
task :start do
|
15
|
+
on primary(:db) do
|
16
|
+
fetch(:docker_network, nil) &&
|
17
|
+
network = "--network #{fetch(:docker_network)}"
|
18
|
+
execute 'docker', 'run', '-d', '--restart', 'always',
|
19
|
+
'--name', "#{fetch(:slug)}-db",
|
20
|
+
network, fetch(:database_image), '||', 'true'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
task :stop do
|
25
|
+
on roles(:db), in: :parallel do
|
26
|
+
%w[stop rm].each do |command|
|
27
|
+
execute 'docker', command, "#{fetch(:slug)}-db", '||', 'true'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
task :terminate do
|
33
|
+
invoke 'docker:db:stop'
|
34
|
+
invoke 'docker:db:clean'
|
35
|
+
end
|
36
|
+
|
37
|
+
task :clean do
|
38
|
+
on roles(:db), in: :parallel do
|
39
|
+
execute 'docker', 'rmi', fetch(:database_image), '||', 'true'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :setup do
|
44
|
+
invoke 'docker:db:migrate'
|
45
|
+
invoke 'docker:db:reset'
|
46
|
+
end
|
47
|
+
|
48
|
+
task :migrate do
|
49
|
+
on roles(:app, select: :primary, migrate_on_deploy: true) do
|
50
|
+
execute 'docker', 'exec', fetch(:slug), 'bin/rails',
|
51
|
+
'db:migrate', "RAILS_ENV=#{fetch(:stage)}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
task :reset do
|
56
|
+
on roles(:app, select: :primary, reset_on_deploy: true) do
|
57
|
+
execute 'docker', 'exec', fetch(:slug), 'bin/rails',
|
58
|
+
'db:reset', "RAILS_ENV=#{fetch(:stage)}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
namespace :load do
|
4
|
+
task :defaults do
|
5
|
+
set :scm, nil
|
6
|
+
set :exposed_ports, []
|
7
|
+
set :database_image, nil
|
8
|
+
set :docker_image_tag, 'latest'
|
9
|
+
set :docker_labels, []
|
10
|
+
set :docker_network, nil
|
11
|
+
set :docker_registry, nil
|
12
|
+
set :docker_registry_user, nil
|
13
|
+
set :docker_registry_password, nil
|
14
|
+
set :docker_registry_image, nil
|
15
|
+
set :slug, "#{fetch(:application)}-#{fetch(:stage)}"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :docker do
|
2
|
+
desc 'Log in to the CI docker registry'
|
3
|
+
task :login do
|
4
|
+
return unless fetch(:docker_registry, nil)
|
5
|
+
|
6
|
+
on roles(:app), in: :parallel do
|
7
|
+
execute 'echo', redact(fetch(:docker_registry_password).dup), '|',
|
8
|
+
'docker', 'login',
|
9
|
+
'-u', fetch(:docker_registry_user), '--password-stdin',
|
10
|
+
fetch(:docker_registry)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'Pull the docker image'
|
15
|
+
task :pull do
|
16
|
+
on roles(:app), in: :parallel do
|
17
|
+
execute 'docker', 'pull',
|
18
|
+
"#{fetch(:docker_registry_image)}:#{fetch(:docker_image_tag)}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capistrano-docker-deploy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomislav Simnett
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Deploys applications and dependencies from a registry
|
70
|
+
email:
|
71
|
+
- tom@initforthe.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".gitlab-ci.yml"
|
78
|
+
- ".rspec"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- Gemfile.lock
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- capistrano-docker-deploy.gemspec
|
88
|
+
- lib/capistrano/docker/deploy.rb
|
89
|
+
- lib/capistrano/docker/deploy/version.rb
|
90
|
+
- lib/capistrano/tasks/deploy.rake
|
91
|
+
- lib/capistrano/tasks/docker.rake
|
92
|
+
- lib/capistrano/tasks/docker/application.rake
|
93
|
+
- lib/capistrano/tasks/docker/database.rake
|
94
|
+
- lib/capistrano/tasks/docker/default.rake
|
95
|
+
- lib/capistrano/tasks/docker/registry.rake
|
96
|
+
homepage: https://gitlab.com/initforthe/capistrano-docker-deploy
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata:
|
100
|
+
allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
|
101
|
+
homepage_uri: https://gitlab.com/initforthe/capistrano-docker-deploy
|
102
|
+
source_code_uri: https://gitlab.com/initforthe/capistrano-docker-deploy.git
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubygems_version: 3.0.3
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Docker deployment for capistrano
|
122
|
+
test_files: []
|