rat_deployer 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 262cf16b057028e511cd9d5e4e9396248c0cd725
4
- data.tar.gz: c08531236e1d4ec9257344c42e367812239b7f19
3
+ metadata.gz: 651e4b450f1f05eb1a0279f7f845b37fdb092e27
4
+ data.tar.gz: a8598ab364a0f71b3f559776a9e8cc4ac5e9ffd7
5
5
  SHA512:
6
- metadata.gz: cbbc4deeef649ba8bf002bfdd14bdcf99633624a301bf074e494ea4c3393a11c2b72e1d3fca01915a8e2e4f8dfedf929cc767576b79af8d8296791a37cd2ecd7
7
- data.tar.gz: dec480736bdfc188b5b3e9c66e0f88b8651fc4d5063950d7741a69b3b2a3a01c84b809b1cc77f3e56c516dff1f850a1c8b0f65305a7827db98f056b4273075be
6
+ metadata.gz: 5385a41194697d5e64cada895388125cc2795b1f1b6b6b621f785d79474ded56296626a66e45ad586515228ea261ced93ba3c29bb13c13eda10019c7ca2fb799
7
+ data.tar.gz: a4adc275b24fbf132979fc6bb1d2631b3d8e9f0e9fdde86017d416bac1f4bb09725a029f267405b0300a78eaa320de5dc108f24dfdec7ff3b88ca2470cf74098
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ [![build status](https://gitlab.alfred.yavende.com/dev_ops/rat_deployer/badges/master/build.svg)](https://gitlab.alfred.yavende.com/dev_ops/rat_deployer/commits/master)
2
+ [![coverage report](https://gitlab.alfred.yavende.com/dev_ops/rat_deployer/badges/master/coverage.svg)](https://gitlab.alfred.yavende.com/dev_ops/rat_deployer/commits/master)
3
+
4
+ # Rat
5
+
6
+ Rat is a deploy tool for docker users. It implements a facade around 2 docker CLIs:
7
+ - docker
8
+ - docker-compose
9
+
10
+ It is not very flexible and it is ~~**untested**~~ lightly tested.
11
+ I wrote this to avoid running a bunch of time consuming commands in a row.
12
+
13
+ ![rat](http://mauveart.esy.es/img/rats/1_big.jpg)
14
+
15
+ I named it rat because it is a rather little and ugly ball of code, but it does the job for now.
16
+
17
+ ## Features
18
+ Rat deployer adds a thin layer of abstraction over docker-compose to make commands more DRY.
19
+ Main features it adds are:
20
+
21
+ - Enviromental overrides by using multiple compose files
22
+ - Easier remote usage by linking environments to machines
23
+ - Slack notifier
24
+
25
+ ## Installation
26
+
27
+ ~~~bash
28
+ $ gem install rat_deployer
29
+ ~~~
30
+
31
+ ## Configuration
32
+ Rat searches for a file called `rat_config.yml` in the working dir. The options are:
33
+
34
+ - **project_name**: together with the environment, is part of the prefix passed to the `--project` option for `docker-compose`
35
+ - **environments**: holds environemntal config
36
+ - **[*env*]**: parametric environment name
37
+ - **machine**: configuration for remote usage. Links environment to a remote host. All paths can be relative to `rat_config.yml` file
38
+ - **host**: IP for the remote machine
39
+ - **ca_cert**: path to CA certificate
40
+ - **cert**: path to SSL certificate used
41
+ - **key**: path to SSL certificate key
42
+
43
+ Example config file:
44
+
45
+ ~~~yaml
46
+ project_name: myapp
47
+
48
+ environments:
49
+ staging:
50
+ machine:
51
+ host: tcp://107.170.36.78:2376
52
+ ca_cert: certs/ca.pem
53
+ cert: certs/cert.pem
54
+ key: certs/key.pem
55
+ ~~~
56
+
57
+ ## Env variable configuration
58
+ Rat most used options are set via environent variables to avoid having to type them all the time.
59
+
60
+ - **RAT_ENV**: current enviroment.
61
+ - **RAT_REMOTE**: whether or not to execute commands on remote host. Acceptable values are `true` and `false`. Defaults to `true`.
62
+
63
+ I recommend to export them if you are going to work on a environment for a long time:
64
+
65
+ ~~~bash
66
+ $ export RAT_ENV=production RAT_REMOTE=false
67
+ ~~~
68
+
69
+ ## Usage
70
+
71
+ - `rat compose cmd`: proxies command to docker-compose adding flags `-f config/default.yml -f config/<env>.yml -p <prefix>`. If `RAT_REMOTE` is `true` adds flags for running on remote host.
72
+ - `rat deploy [services]`: just an alias for `rat compose pull [services] && rat compose up -d [services]`.
73
+ - `rat docker cmd`: proxies command to docker-compose adding flags for remote host ff `RAT_REMOTE` is `true`.
74
+
75
+ Example usage:
76
+
77
+ ~~~base
78
+ $ export RAT_ENV=staging
79
+ $ rat compose up -d
80
+ ||=> Running command `docker-compose -f config/default.yml -f config/staging.yml -p cognituz_staging up -d`
81
+ ~~~
82
+
83
+ ## Development
84
+
85
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
86
+
87
+ 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).
88
+
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rat_deployer.
92
+
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'rat_deployer'
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 'pry'
14
+ Pry.start
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,67 @@
1
+ require 'rat_deployer/command'
2
+ require 'rat_deployer/config'
3
+ require 'active_support/concern'
4
+
5
+ module RatDeployer
6
+ module Commands
7
+ # This command proxies to `docker-compose` binary,
8
+ # adding the following flags:
9
+ #
10
+ # - -f for each config file.
11
+ #
12
+ # Defaults to current_env.config_files or
13
+ # config/default.yml and config/<current_env>.yml
14
+ #
15
+ # - -p with the configured project_name
16
+ #
17
+ # It is possible to include the current_env in the
18
+ # prohect name by using the token `{env}`, E.g.: project_name_{env}
19
+ module Compose
20
+ extend Command
21
+
22
+ def self.perform(cmd, *cmd_flags, silent: false)
23
+ run(
24
+ [
25
+ 'docker-compose',
26
+ flags,
27
+ cmd,
28
+ cmd_flags
29
+ ].flatten.join(' '),
30
+ silent: silent
31
+ )
32
+ .fetch(:output)
33
+ end
34
+
35
+ def self.flags
36
+ config_files =
37
+ Config.for_env['config_files'] || %W[
38
+ config/default.yml
39
+ config/#{Config.env}.yml
40
+ ]
41
+
42
+ flags = [
43
+ config_files.map { |cf| "-f #{cf}" },
44
+ "-p #{Config.project_name}"
45
+ ]
46
+
47
+ flags.unshift(Config.remote_machine_flags) if Config.remote
48
+
49
+ flags
50
+ end
51
+
52
+ # Meant to be included in RatDeployer::Cli
53
+ module Extension
54
+ extend ActiveSupport::Concern
55
+
56
+ included do
57
+ desc \
58
+ 'compose ARGS...',
59
+ 'runs docker-compose command with default flags'
60
+ def compose(cmd, *cmd_flags, silent: false)
61
+ Commands::Compose.perform(cmd, *cmd_flags, silent: silent)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,53 @@
1
+ require 'active_support/concern'
2
+ require 'active_support/core_ext/string/strip'
3
+
4
+ require 'rat_deployer/config'
5
+ require 'rat_deployer/notifier'
6
+ require 'rat_deployer/commands/compose'
7
+
8
+ module RatDeployer
9
+ module Commands
10
+ # This command runs `compose pull` and
11
+ # `compose up -d` for the given services.
12
+ # Adittionally, notifies to slack if configured to do so.
13
+ module Deploy
14
+ extend Command
15
+
16
+ def self.perform(*services)
17
+ Notifier.notify_deploy_start
18
+ deploy(*services)
19
+ Notifier.notify_deploy_end
20
+ rescue StandardError => e
21
+ Notifier.notify <<-STR.strip_heredoc
22
+ Failed deploy on #{Config.env}
23
+ Reason:
24
+ #{e.message}
25
+ STR
26
+ raise e
27
+ end
28
+
29
+ def self.deploy(*services)
30
+ if services.any?
31
+ services_str = services.join(' ')
32
+ Compose.perform("pull #{services_str}")
33
+ Compose.perform("up -d --no-deps --force-recreate #{services_str}")
34
+ else
35
+ Compose.perform('pull')
36
+ Compose.perform('up -d')
37
+ end
38
+ end
39
+
40
+ # Meant to be included in RatDeployer::Cli
41
+ module Extension
42
+ extend ActiveSupport::Concern
43
+
44
+ included do
45
+ desc 'deploy', 'deploys current environment'
46
+ def deploy(*services)
47
+ Commands::Deploy.perform(*services)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,34 @@
1
+ require 'active_support/concern'
2
+
3
+ require 'rat_deployer/command'
4
+ require 'rat_deployer/config'
5
+
6
+ module RatDeployer
7
+ module Commands
8
+ # This command proxies to the `docker` binary
9
+ # adding remote flags if configuration for
10
+ # remote machine is present
11
+ module Docker
12
+ extend Command
13
+
14
+ def self.perform(cmd, *cmd_flags)
15
+ flags = []
16
+ flags.unshift(Config.remote_machine_flags) if Config.remote
17
+ cmd = run "docker #{flags.join(' ')} #{cmd} #{cmd_flags.join(' ')}"
18
+ cmd.fetch(:output)
19
+ end
20
+
21
+ # Meant to be included in RatDeployer::Cli
22
+ module Extension
23
+ extend ActiveSupport::Concern
24
+
25
+ included do
26
+ desc 'docker ARGS...', 'runs docker command with default flags'
27
+ def docker(cmd, *cmd_flags)
28
+ Commands::Docker.perform(cmd, *cmd_flags)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module RatDeployer
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rat_deployer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Oga
@@ -200,10 +200,16 @@ executables:
200
200
  extensions: []
201
201
  extra_rdoc_files: []
202
202
  files:
203
+ - README.md
204
+ - bin/console
203
205
  - bin/rat
206
+ - bin/setup
204
207
  - lib/rat_deployer.rb
205
208
  - lib/rat_deployer/cli.rb
206
209
  - lib/rat_deployer/command.rb
210
+ - lib/rat_deployer/commands/compose.rb
211
+ - lib/rat_deployer/commands/deploy.rb
212
+ - lib/rat_deployer/commands/docker.rb
207
213
  - lib/rat_deployer/config.rb
208
214
  - lib/rat_deployer/notifier.rb
209
215
  - lib/rat_deployer/version.rb