New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate floating IP change in deployments #36

Merged
merged 2 commits into from Jan 19, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+81 −26
Diff settings

Always

Just for now

Copy path View file
@@ -6,6 +6,7 @@ install_plugin Capistrano::SCM::Git

require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

Copy path View file
@@ -42,6 +42,7 @@ group :development do
gem 'capistrano-bundler', '~> 1.3', require: false
gem 'capistrano-rails', '~> 1.3', require: false
gem 'capistrano-rvm', require: false
gem 'droplet_kit'
gem 'listen', '>= 3.0.5', '< 3.2'
end

Copy path View file
@@ -44,6 +44,10 @@ GEM
sshkit (>= 1.6.1, != 1.7.0)
arel (8.0.0)
ast (2.4.0)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
bcrypt (3.1.12)
builder (3.2.3)
capistrano (3.11.0)
@@ -74,10 +78,14 @@ GEM
simplecov
url
coderay (1.1.2)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
commonmarker (0.17.13)
ruby-enum (~> 0.5)
concurrent-ruby (1.0.5)
crass (1.0.4)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.4.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
@@ -86,6 +94,13 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.3)
docile (1.3.1)
droplet_kit (2.8.0)
activesupport (> 3.0, < 6)
faraday (~> 0.15)
kartograph (~> 0.2.3)
resource_kit (~> 0.1.5)
virtus (~> 1.0.3)
equalizer (0.0.11)
erubi (1.7.1)
exception_notification (4.2.2)
actionmailer (>= 4.0, < 6)
@@ -96,11 +111,14 @@ GEM
factory_bot_rails (4.11.1)
factory_bot (~> 4.11.1)
railties (>= 3.0.0)
faraday (0.15.4)
multipart-post (>= 1.2, < 3)
ffi (1.9.25)
globalid (0.4.1)
activesupport (>= 4.2.0)
i18n (1.1.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
jaro_winkler (1.5.1)
jbuilder (2.7.0)
activesupport (>= 4.2.0)
@@ -118,6 +136,7 @@ GEM
activerecord
kaminari-core (= 1.1.1)
kaminari-core (1.1.1)
kartograph (0.2.7)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
@@ -132,6 +151,7 @@ GEM
mini_portile2 (2.4.0)
minitest (5.11.3)
multi_json (1.13.1)
multipart-post (2.0.0)
mustermann (1.0.3)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
@@ -187,6 +207,8 @@ GEM
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
resource_kit (0.1.7)
addressable (>= 2.3.6, < 3.0.0)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
@@ -269,6 +291,11 @@ GEM
execjs (>= 0.3.0, < 3)
unicode-display_width (1.4.0)
url (0.3.2)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
warden (1.2.7)
rack (>= 1.0)
websocket-driver (0.6.5)
@@ -290,6 +317,7 @@ DEPENDENCIES
codecov
commonmarker
devise (~> 4.4.3)
droplet_kit
exception_notification
factory_bot_rails
jbuilder (~> 2.5)
Copy path View file
@@ -11,6 +11,15 @@
execute 'service quasars restart'
end
end

task :floating_ip do
if `curl https://quasa.rs/healthcheck`.include?('green')
`RAILS_ENV=development rake digital_ocean:floating_ip['blue']`
else
`RAILS_ENV=development rake digital_ocean:floating_ip['green']`
end
end
end

after 'deploy:symlink:release', 'deploy:restart_quasars'
after 'deploy:restart_quasars', 'deploy:floating_ip'
Copy path View file

This file was deleted.

Oops, something went wrong.
Copy path View file

This file was deleted.

Oops, something went wrong.
Copy path View file
@@ -0,0 +1,14 @@
if `curl https://quasa.rs/healthcheck`.include?('green')
set :deploy_target, 'blue'
else
set :deploy_target, 'green'
end

set :stage, 'production'
server "#{fetch(:deploy_target)}.quasa.rs", user: 'root', roles: %w[app web]

set :branch do
default_tag = `git tag`.split("\n").last
ask(:tag, default_tag)
fetch(:tag)
end
Copy path View file
@@ -4,18 +4,17 @@

1. Create a [new release][2] and bump tag version (e.g. `0.0.1` to `0.0.2`).
2. Do a `git pull` in your local codebase on `master`.
3. Initiate a capistrano deploy (e.g. `cap green deploy`)
3. Initiate a capistrano deploy (e.g. `cap production deploy`)
4. Supply tag when prompted (it should default to latest tag).
5. Monitor release and post-deploy.

In these examples `green` is the stage and `0.0.1` is the tag. You may
supply a branch instead of a tag to deploy a branch.
Floating IP assignment is completely automated during deploy.

### Rollbacks

In the case of a bad deploy, issue the `cap green deploy:rollback`
command. For more information, refer to the capistrano
[rollback documentation][1].
In the case of a bad deploy, issue the `rake digital_ocean:floating_ip[DEPLOY]`
command where `DEPLOY` is the previous deployment environment. For more
information, refer to the capistrano [rollback documentation][1].

[1]: https://capistranorb.com/documentation/getting-started/rollbacks/
[2]: https://github.com/kineticdial/quasars/releases/new
Copy path View file
@@ -0,0 +1,23 @@
require 'droplet_kit'

TOKEN = ENV['DO_ACCESS_TOKEN']
FLOATING_IP_ID = '138.68.38.119'.freeze
QUASARS_APP_GREEN_ID = 94_899_103
QUASARS_APP_BLUE_ID = 129_410_947

namespace :digital_ocean do
desc 'Change floating IP assignment'
task :floating_ip, [:deploy] => :environment do |_tasks, args|
deploy_target_id = if args[:deploy] == 'green'
QUASARS_APP_GREEN_ID
else
QUASARS_APP_BLUE_ID
end

client = DropletKit::Client.new(access_token: TOKEN)
client.floating_ip_actions.assign(
ip: FLOATING_IP_ID,
droplet_id: deploy_target_id
)
end
end
ProTip! Use n and p to navigate between commits in a pull request.