Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fcf226f790 | ||
|
|
2004cdaa0d | ||
|
|
b8413b3ab5 | ||
|
|
701f6ff237 | ||
|
|
27279c6c82 | ||
|
|
08dd468d87 | ||
|
|
9a4f502cc4 | ||
|
|
11e6f7914d | ||
|
|
bc6963e6bf | ||
|
|
f4f2b5cb17 | ||
|
|
817336df49 | ||
|
|
4c399a74bb | ||
|
|
e12436a1db | ||
|
|
b244e919bf | ||
|
|
c1013543f9 | ||
|
|
eb46d0507e | ||
|
|
7ad416f029 | ||
|
|
371f98d67f | ||
|
|
b879412a6f | ||
|
|
e678775a18 | ||
|
|
689b81014b | ||
|
|
01a4eecf98 | ||
|
|
6f7422af44 |
@@ -1,7 +1,7 @@
|
|||||||
PATH
|
PATH
|
||||||
remote: .
|
remote: .
|
||||||
specs:
|
specs:
|
||||||
mrsk (0.8.1)
|
mrsk (0.8.4)
|
||||||
activesupport (>= 7.0)
|
activesupport (>= 7.0)
|
||||||
dotenv (~> 2.8)
|
dotenv (~> 2.8)
|
||||||
sshkit (~> 1.21)
|
sshkit (~> 1.21)
|
||||||
|
|||||||
63
README.md
63
README.md
@@ -1,6 +1,6 @@
|
|||||||
# MRSK
|
# MRSK
|
||||||
|
|
||||||
MRSK deploys web apps in containers to servers running Docker with zero downtime. It uses the dynamic reverse-proxy Traefik to hold requests while the new application container is started and the old one is stopped. It works seamlessly across multiple hosts, using SSHKit to execute commands. It was built for Rails applications, but works with any type of web app that can be bundled with Docker.
|
MRSK deploys web apps anywhere from bare metal to cloud VMs using Docker with zero downtime. It uses the dynamic reverse-proxy Traefik to hold requests while the new application container is started and the old one is stopped. It works seamlessly across multiple hosts, using SSHKit to execute commands. It was built for Rails applications, but works with any type of web app that can be containerized with Docker.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -31,38 +31,40 @@ mrsk deploy
|
|||||||
|
|
||||||
This will:
|
This will:
|
||||||
|
|
||||||
1. Connect to the servers over SSH (using root by default, authenticated by your loaded ssh key)
|
1. Connect to the servers over SSH (using root by default, authenticated by your ssh key)
|
||||||
2. Install Docker on any server that might be missing it (using apt-get)
|
2. Install Docker on any server that might be missing it (using apt-get)
|
||||||
3. Log into the registry both locally and remotely
|
3. Log into the registry both locally and remotely
|
||||||
4. Build the image using the standard Dockerfile in the root of the application.
|
4. Build the image using the standard Dockerfile in the root of the application.
|
||||||
5. Push the image to the registry.
|
5. Push the image to the registry.
|
||||||
6. Pull the image from the registry on the servers.
|
6. Pull the image from the registry onto the servers.
|
||||||
7. Ensure Traefik is running and accepting traffic on port 80.
|
7. Ensure Traefik is running and accepting traffic on port 80.
|
||||||
8. Ensure your app responds with `200 OK` to `GET /up`.
|
8. Ensure your app responds with `200 OK` to `GET /up`.
|
||||||
9. Stop any containers running a previous versions of the app.
|
9. Start a new container with the version of the app that matches the current git version hash.
|
||||||
10. Start a new container with the version of the app that matches the current git version hash.
|
10. Stop the old container running the previous version of the app.
|
||||||
11. Prune unused images and stopped containers to ensure servers don't fill up.
|
11. Prune unused images and stopped containers to ensure servers don't fill up.
|
||||||
|
|
||||||
Voila! All the servers are now serving the app on port 80. If you're just running a single server, you're ready to go. If you're running multiple servers, you need to put a load balancer in front of them.
|
Voila! All the servers are now serving the app on port 80. If you're just running a single server, you're ready to go. If you're running multiple servers, you need to put a load balancer in front of them.
|
||||||
|
|
||||||
## Vision
|
## Vision
|
||||||
|
|
||||||
In the past decade+, there's been an explosion in commercial offerings that make deploying web apps easier. Heroku kicked it off with an incredible offering that stayed ahead of the competition seemingly forever. These days we have excellent alternatives like Fly.io and Render. And hosted Kubernetes is making things easier too on AWS, GCP, Digital Ocean, and elsewhere. But these are all offerings that have you renting computers in the cloud at a premium. If you want to run on our own hardware, or even just have a clear migration path to do so, you need to carefully consider how locked in you get to these commercial platforms. Preferably before the bills swallow your business whole!
|
In the past decade+, there's been an explosion in commercial offerings that make deploying web apps easier. Heroku kicked it off with an incredible offering that stayed ahead of the competition seemingly forever. These days we have excellent alternatives like Fly.io and Render. And hosted Kubernetes is making things easier too on AWS, GCP, Digital Ocean, and elsewhere. But these are all offerings that have you renting computers in the cloud at a premium. If you want to run on our own hardware, or even just have a clear migration path to do so in the future, you need to carefully consider how locked in you get to these commercial platforms. Preferably before the bills swallow your business whole!
|
||||||
|
|
||||||
MRSK seeks to bring the advance in ergonomics pioneered by these commercial offerings to deploying web apps anywhere. Whether that's low-cost cloud options without the managed-service markup from the likes of Digital Ocean, Hetzner, OVH, etc, or it's your own colocated metal. To MRSK, it's all the same. Feed the config file a list of IP addresses with vanilla Ubuntu servers that have seen no prep beyond an added SSH key, and you'll be running in literally minutes.
|
MRSK seeks to bring the advance in ergonomics pioneered by these commercial offerings to deploying web apps anywhere. Whether that's low-cost cloud options without the managed-service markup from the likes of Digital Ocean, Hetzner, OVH, etc, or it's your own colocated bare metal. To MRSK, it's all the same. Feed the config file a list of IP addresses with vanilla Ubuntu servers that have seen no prep beyond an added SSH key, and you'll be running in literally minutes.
|
||||||
|
|
||||||
This structure also gives you enormous portability. You can have your web app deployed on several clouds at ease like this. Or you can buy the baseline with your own hardware, then deploy to a cloud before a big seasonal spike to get more capacity. When you're not locked into a single provider from a tooling perspective, there's a lot of compelling options available.
|
This approach gives you enormous portability. You can have your web app deployed on several clouds at ease like this. Or you can buy the baseline with your own hardware, then deploy to a cloud before a big seasonal spike to get more capacity. When you're not locked into a single provider from a tooling perspective, there's a lot of compelling options available.
|
||||||
|
|
||||||
Ultimately, MRSK is meant to compress the complexity of going to production using open source tooling that isn't tied to any commercial offering. Not to zero, though. You're probably still better off with a fully managed service if basic Linux or Docker is still difficult, but from an early stage when those concepts are familiar.
|
Ultimately, MRSK is meant to compress the complexity of going to production using open source tooling that isn't tied to any commercial offering. Not to zero, mind you. You're probably still better off with a fully managed service if basic Linux or Docker is still difficult, but as soon as those concepts are familiar, you'll be ready to go with MRSK.
|
||||||
|
|
||||||
## Why not just run Capistrano, Kubernetes or Docker Swarm?
|
## Why not just run Capistrano, Kubernetes or Docker Swarm?
|
||||||
|
|
||||||
MRSK basically is Capistrano for Containers, which allow us to use vanilla servers as the hosts. No need to ensure that the servers have just the right version of Ruby or other dependencies you need. That all lives in the Docker image now. You can boot a brand new Ubuntu (or whatever) server, add it to the deploy servers of MRSK, and it'll be auto-provisioned with Docker, and run right away. Docker's layer caching also allows for quicker deployments with less mucking about on the server. And the images built for MRSK can be used for CI or later introspection.
|
MRSK basically is Capistrano for Containers, without the need to carefully prepare servers in advance. No need to ensure that the servers have just the right version of Ruby or other dependencies you need. That all lives in the Docker image now. You can boot a brand new Ubuntu (or whatever) server, add it to the list servers in MRSK, and it'll be auto-provisioned with Docker, and run right away. Docker's layer caching also speeds up deployments with less mucking about on the server. And the images built for MRSK can be used for CI or later introspection.
|
||||||
|
|
||||||
Kubernetes is a beast. Running it yourself on your own hardware is not for the faint of heart. It's a fine option if you want to run on someone else's platform, either transparently [like Render](https://thenewstack.io/render-cloud-deployment-with-less-engineering/) or explicitly on AWS/GCP, but if you'd like the freedom to move between cloud and your own hardware, or even mix the two, MRSK is much simpler. You can see everything that's going on, it's just basic Docker commands being called.
|
Kubernetes is a beast. Running it yourself on your own hardware is not for the faint of heart. It's a fine option if you want to run on someone else's platform, either transparently [like Render](https://thenewstack.io/render-cloud-deployment-with-less-engineering/) or explicitly on AWS/GCP, but if you'd like the freedom to move between cloud and your own hardware, or even mix the two, MRSK is much simpler. You can see everything that's going on, it's just basic Docker commands being called.
|
||||||
|
|
||||||
Docker Swarm is much simpler than Kubernetes, but it's still built on the same declarative model that uses state reconciliation. MRSK is intentionally designed to around imperative commands, like Capistrano.
|
Docker Swarm is much simpler than Kubernetes, but it's still built on the same declarative model that uses state reconciliation. MRSK is intentionally designed to around imperative commands, like Capistrano.
|
||||||
|
|
||||||
|
Ultimately, there are a myriad of ways to deploy web apps, but this is the toolkit we're using at [37signals](https://37signals.com) to bring [HEY](https://www.hey.com) [home from the cloud](https://world.hey.com/dhh/why-we-re-leaving-the-cloud-654b47e0) without losing the advantages of modern containerization tooling.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
### Using .env file to load required environment variables
|
### Using .env file to load required environment variables
|
||||||
@@ -74,6 +76,23 @@ MRSK_REGISTRY_PASSWORD=pw
|
|||||||
DB_PASSWORD=secret123
|
DB_PASSWORD=secret123
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using a generated .env file
|
||||||
|
|
||||||
|
If you're using a centralized secret store, like 1Password, you can create `.env.erb` as a template which looks up the secrets. Example of a .env.erb file:
|
||||||
|
|
||||||
|
```erb
|
||||||
|
<% if (session_token = `op signin --account my-one-password-account --raw`.strip) != "" %># Generated by mrsk envify
|
||||||
|
GITHUB_TOKEN=<%= `gh config get -h github.com oauth_token`.strip %>
|
||||||
|
MRSK_REGISTRY_PASSWORD=<%= `op read "op://Vault/Docker Hub/password" -n --session #{session_token}` %>
|
||||||
|
RAILS_MASTER_KEY=<%= `op read "op://Vault/My App/RAILS_MASTER_SECRET" -n --session #{session_token}` %>
|
||||||
|
MYSQL_ROOT_PASSWORD=<%= `op read "op://Vault/My App/MYSQL_ROOT_PASSWORD" -n --session #{session_token}` %>
|
||||||
|
<% else raise ArgumentError, "Session token missing" end %>
|
||||||
|
```
|
||||||
|
|
||||||
|
This template can safely be checked into git. Then everyone deploying the app can run `mrsk envify` when they setup the app for the first time or passwords change to get the correct `.env` file.
|
||||||
|
|
||||||
|
If you need separate env variables for different destinations, you can set them with `.env.destination.erb` for the template, which will generate `.env.staging` when run with `mrsk envify -d staging`.
|
||||||
|
|
||||||
### Using another registry than Docker Hub
|
### Using another registry than Docker Hub
|
||||||
|
|
||||||
The default registry is Docker Hub, but you can change it using `registry/server`:
|
The default registry is Docker Hub, but you can change it using `registry/server`:
|
||||||
@@ -330,22 +349,20 @@ accessories:
|
|||||||
|
|
||||||
Now run `mrsk accessory start mysql` to start the MySQL server on 1.1.1.3. See `mrsk accessory` for all the commands possible.
|
Now run `mrsk accessory start mysql` to start the MySQL server on 1.1.1.3. See `mrsk accessory` for all the commands possible.
|
||||||
|
|
||||||
### Using a generated .env file
|
### Using Cron
|
||||||
|
|
||||||
If you're using a centralized secret store, like 1Password, you can create `.env.erb` as a template which looks up the secrets. Example of a .env.erb file:
|
You can use a specific container to run your Cron jobs:
|
||||||
|
|
||||||
```erb
|
```yaml
|
||||||
<% if (session_token = `op signin --account my-one-password-account --raw`.strip) != "" %># Generated by mrsk envify
|
servers:
|
||||||
GITHUB_TOKEN=<%= `gh config get -h github.com oauth_token`.strip %>
|
cron:
|
||||||
MRSK_REGISTRY_PASSWORD=<%= `op read "op://Vault/Docker Hub/password" -n --session #{session_token}` %>
|
hosts:
|
||||||
RAILS_MASTER_KEY=<%= `op read "op://Vault/My App/RAILS_MASTER_SECRET" -n --session #{session_token}` %>
|
- 192.168.0.1
|
||||||
MYSQL_ROOT_PASSWORD=<%= `op read "op://Vault/My App/MYSQL_ROOT_PASSWORD" -n --session #{session_token}` %>
|
cmd:
|
||||||
<% else raise ArgumentError, "Session token missing" end %>
|
bash -c "cat config/crontab | crontab - && cron -f"
|
||||||
```
|
```
|
||||||
|
|
||||||
This template can safely be checked into git. Then everyone deploying the app can run `mrsk envify` when they setup the app for the first time or passwords change to get the correct `.env` file.
|
This assumes the Cron settings are stored in `config/crontab`.
|
||||||
|
|
||||||
If you need separate env variables for different destinations, you can set them with `.env.destination.erb` for the template, which will generate `.env.staging` when run with `mrsk envify -d staging`.
|
|
||||||
|
|
||||||
### Using audit broadcasts
|
### Using audit broadcasts
|
||||||
|
|
||||||
@@ -498,7 +515,7 @@ If you wish to remove the entire application, including Traefik, containers, ima
|
|||||||
|
|
||||||
## Stage of development
|
## Stage of development
|
||||||
|
|
||||||
This is alpha software. Lots of stuff is missing. Lots of stuff will keep moving around for a while.
|
This is beta software. Commands may still move around. But we're live in production at [37signals](https://37signals.com).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|||||||
execute *accessory.run
|
execute *accessory.run
|
||||||
end
|
end
|
||||||
|
|
||||||
audit_broadcast "Booted accessory #{name}"
|
audit_broadcast "Booted accessory #{name}" unless options[:skip_broadcast]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -153,9 +153,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
|
|||||||
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
||||||
def remove(name)
|
def remove(name)
|
||||||
if name == "all"
|
if name == "all"
|
||||||
if options[:confirmed] || ask("This will remove all containers and images for all accessories. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
|
|
||||||
MRSK.accessory_names.each { |accessory_name| remove(accessory_name) }
|
MRSK.accessory_names.each { |accessory_name| remove(accessory_name) }
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if options[:confirmed] || ask("This will remove all containers and images for #{name}. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
|
if options[:confirmed] || ask("This will remove all containers and images for #{name}. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
|
||||||
with_accessory(name) do
|
with_accessory(name) do
|
||||||
|
|||||||
@@ -3,20 +3,26 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
|
|||||||
def boot
|
def boot
|
||||||
say "Get most recent version available as an image...", :magenta unless options[:version]
|
say "Get most recent version available as an image...", :magenta unless options[:version]
|
||||||
using_version(options[:version] || most_recent_version_available) do |version|
|
using_version(options[:version] || most_recent_version_available) do |version|
|
||||||
say "Start container with version #{version} (or reboot if already running)...", :magenta
|
say "Start container with version #{version} using a #{MRSK.config.readiness_delay}s readiness delay (or reboot if already running)...", :magenta
|
||||||
|
|
||||||
|
cli = self
|
||||||
|
|
||||||
MRSK.config.roles.each do |role|
|
MRSK.config.roles.each do |role|
|
||||||
on(role.hosts) do |host|
|
on(role.hosts) do |host|
|
||||||
execute *MRSK.auditor.record("Booted app version #{version}"), verbosity: :debug
|
execute *MRSK.auditor.record("Booted app version #{version}"), verbosity: :debug
|
||||||
|
|
||||||
begin
|
begin
|
||||||
execute *MRSK.app.stop, raise_on_non_zero_exit: false
|
old_version = capture_with_info(*MRSK.app.current_running_version).strip
|
||||||
execute *MRSK.app.run(role: role.name)
|
execute *MRSK.app.run(role: role.name)
|
||||||
|
sleep MRSK.config.readiness_delay
|
||||||
|
execute *MRSK.app.stop(version: old_version), raise_on_non_zero_exit: false if old_version.present?
|
||||||
|
|
||||||
rescue SSHKit::Command::Failed => e
|
rescue SSHKit::Command::Failed => e
|
||||||
if e.message =~ /already in use/
|
if e.message =~ /already in use/
|
||||||
error "Rebooting container with same version already deployed on #{host}"
|
error "Rebooting container with same version #{version} already deployed on #{host} (may cause gap in zero-downtime promise!)"
|
||||||
execute *MRSK.auditor.record("Rebooted app version #{version}"), verbosity: :debug
|
execute *MRSK.auditor.record("Rebooted app version #{version}"), verbosity: :debug
|
||||||
|
|
||||||
|
execute *MRSK.app.stop(version: version)
|
||||||
execute *MRSK.app.remove_container(version: version)
|
execute *MRSK.app.remove_container(version: version)
|
||||||
execute *MRSK.app.run(role: role.name)
|
execute *MRSK.app.run(role: role.name)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ module Mrsk::Cli
|
|||||||
class_option :config_file, aliases: "-c", default: "config/deploy.yml", desc: "Path to config file"
|
class_option :config_file, aliases: "-c", default: "config/deploy.yml", desc: "Path to config file"
|
||||||
class_option :destination, aliases: "-d", desc: "Specify destination to be used for config file (staging -> deploy.staging.yml)"
|
class_option :destination, aliases: "-d", desc: "Specify destination to be used for config file (staging -> deploy.staging.yml)"
|
||||||
|
|
||||||
|
class_option :skip_broadcast, aliases: "-B", type: :boolean, default: false, desc: "Skip audit broadcasts"
|
||||||
|
|
||||||
def initialize(*)
|
def initialize(*)
|
||||||
super
|
super
|
||||||
load_envs
|
load_envs
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
||||||
MAX_ATTEMPTS = 5
|
MAX_ATTEMPTS = 7
|
||||||
|
|
||||||
|
class HealthcheckError < StandardError; end
|
||||||
|
|
||||||
default_command :perform
|
default_command :perform
|
||||||
|
|
||||||
@@ -18,7 +20,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
|||||||
if status == "200"
|
if status == "200"
|
||||||
info "#{target} succeeded with 200 OK!"
|
info "#{target} succeeded with 200 OK!"
|
||||||
else
|
else
|
||||||
raise "#{target} failed with status #{status}"
|
raise HealthcheckError, "#{target} failed with status #{status}"
|
||||||
end
|
end
|
||||||
rescue SSHKit::Command::Failed
|
rescue SSHKit::Command::Failed
|
||||||
if attempt <= MAX_ATTEMPTS
|
if attempt <= MAX_ATTEMPTS
|
||||||
@@ -31,7 +33,7 @@ class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
|||||||
raise
|
raise
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue SSHKit::Command::Failed => e
|
rescue SSHKit::Command::Failed, HealthcheckError => e
|
||||||
error capture_with_info(*MRSK.healthcheck.logs)
|
error capture_with_info(*MRSK.healthcheck.logs)
|
||||||
|
|
||||||
if e.message =~ /curl/
|
if e.message =~ /curl/
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
invoke "mrsk:cli:prune:all"
|
invoke "mrsk:cli:prune:all"
|
||||||
end
|
end
|
||||||
|
|
||||||
audit_broadcast "Deployed app in #{runtime.to_i} seconds"
|
audit_broadcast "Deployed app in #{runtime.to_i} seconds" unless options[:skip_broadcast]
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
||||||
@@ -47,7 +47,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
invoke "mrsk:cli:app:boot"
|
invoke "mrsk:cli:app:boot"
|
||||||
end
|
end
|
||||||
|
|
||||||
audit_broadcast "Redeployed app in #{runtime.to_i} seconds"
|
audit_broadcast "Redeployed app in #{runtime.to_i} seconds" unless options[:skip_broadcast]
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "rollback [VERSION]", "Rollback app to VERSION"
|
desc "rollback [VERSION]", "Rollback app to VERSION"
|
||||||
@@ -55,14 +55,21 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
MRSK.version = version
|
MRSK.version = version
|
||||||
|
|
||||||
if container_name_available?(MRSK.config.service_with_version)
|
if container_name_available?(MRSK.config.service_with_version)
|
||||||
say "Stop current version, then start version #{version}...", :magenta
|
say "Start version #{version}, then wait #{MRSK.config.readiness_delay}s for app to boot before stopping the old version...", :magenta
|
||||||
|
|
||||||
|
cli = self
|
||||||
|
|
||||||
on(MRSK.hosts) do |host|
|
on(MRSK.hosts) do |host|
|
||||||
execute *MRSK.app.stop, raise_on_non_zero_exit: false
|
old_version = capture_with_info(*MRSK.app.current_running_version).strip.presence
|
||||||
|
|
||||||
execute *MRSK.app.start
|
execute *MRSK.app.start
|
||||||
|
|
||||||
|
sleep MRSK.config.readiness_delay
|
||||||
|
|
||||||
|
execute *MRSK.app.stop(version: old_version), raise_on_non_zero_exit: false
|
||||||
end
|
end
|
||||||
|
|
||||||
audit_broadcast "Rolled back app to version #{version}"
|
audit_broadcast "Rolled back app to version #{version}" unless options[:skip_broadcast]
|
||||||
else
|
else
|
||||||
say "The app version '#{version}' is not available as a container (use 'mrsk app containers' for available versions)", :red
|
say "The app version '#{version}' is not available as a container (use 'mrsk app containers' for available versions)", :red
|
||||||
end
|
end
|
||||||
@@ -135,10 +142,10 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
desc "remove", "Remove Traefik, app, accessories, and registry session from servers"
|
desc "remove", "Remove Traefik, app, accessories, and registry session from servers"
|
||||||
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
option :confirmed, aliases: "-y", type: :boolean, default: false, desc: "Proceed without confirmation question"
|
||||||
def remove
|
def remove
|
||||||
if options[:confirmed] || ask(remove_confirmation_question, limited_to: %w( y N ), default: "N") == "y"
|
if options[:confirmed] || ask("This will remove all containers and images. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
|
||||||
invoke "mrsk:cli:traefik:remove", [], options.without(:confirmed)
|
invoke "mrsk:cli:traefik:remove", [], options.without(:confirmed)
|
||||||
invoke "mrsk:cli:app:remove", [], options.without(:confirmed)
|
invoke "mrsk:cli:app:remove", [], options.without(:confirmed)
|
||||||
invoke "mrsk:cli:accessory:remove", [ "all" ]
|
invoke "mrsk:cli:accessory:remove", [ "all" ], options
|
||||||
invoke "mrsk:cli:registry:logout", [], options.without(:confirmed)
|
invoke "mrsk:cli:registry:logout", [], options.without(:confirmed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -178,10 +185,4 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
on(host) { container_names = capture_with_info(*MRSK.app.list_container_names).split("\n") }
|
on(host) { container_names = capture_with_info(*MRSK.app.list_container_names).split("\n") }
|
||||||
Array(container_names).include?(container_name)
|
Array(container_names).include?(container_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_confirmation_question
|
|
||||||
"This will remove all containers and images. " +
|
|
||||||
(MRSK.config.accessories.any? ? "Including #{MRSK.config.accessories.collect(&:name).to_sentence}. " : "") +
|
|
||||||
"Are you sure?"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,8 +18,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
docker :start, service_with_version
|
docker :start, service_with_version
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop
|
def stop(version: nil)
|
||||||
pipe current_container_id, xargs(docker(:stop))
|
pipe \
|
||||||
|
version ? container_id_for_version(version) : current_container_id,
|
||||||
|
xargs(docker(:stop))
|
||||||
end
|
end
|
||||||
|
|
||||||
def info
|
def info
|
||||||
@@ -132,6 +134,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def container_id_for_version(version)
|
||||||
|
container_id_for(container_name: service_with_version(version))
|
||||||
|
end
|
||||||
|
|
||||||
def service_filter
|
def service_filter
|
||||||
[ "--filter", "label=service=#{config.service}" ]
|
[ "--filter", "label=service=#{config.service}" ]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -136,6 +136,9 @@ class Mrsk::Configuration
|
|||||||
{ "path" => "/up", "port" => 3000 }.merge(raw_config.healthcheck || {})
|
{ "path" => "/up", "port" => 3000 }.merge(raw_config.healthcheck || {})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def readiness_delay
|
||||||
|
raw_config.readiness_delay || 7
|
||||||
|
end
|
||||||
|
|
||||||
def valid?
|
def valid?
|
||||||
ensure_required_keys_present && ensure_env_available
|
ensure_required_keys_present && ensure_env_available
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class Mrsk::Configuration::Role
|
|||||||
"traefik.http.routers.#{config.service}.rule" => "PathPrefix(`/`)",
|
"traefik.http.routers.#{config.service}.rule" => "PathPrefix(`/`)",
|
||||||
"traefik.http.services.#{config.service}.loadbalancer.healthcheck.path" => config.healthcheck["path"],
|
"traefik.http.services.#{config.service}.loadbalancer.healthcheck.path" => config.healthcheck["path"],
|
||||||
"traefik.http.services.#{config.service}.loadbalancer.healthcheck.interval" => "1s",
|
"traefik.http.services.#{config.service}.loadbalancer.healthcheck.interval" => "1s",
|
||||||
"traefik.http.middlewares.#{config.service}.retry.attempts" => "3",
|
"traefik.http.middlewares.#{config.service}.retry.attempts" => "5",
|
||||||
"traefik.http.middlewares.#{config.service}.retry.initialinterval" => "500ms"
|
"traefik.http.middlewares.#{config.service}.retry.initialinterval" => "500ms"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
module Mrsk
|
module Mrsk
|
||||||
VERSION = "0.8.1"
|
VERSION = "0.8.4"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,16 @@ require_relative "cli_test_case"
|
|||||||
|
|
||||||
class CliAppTest < CliTestCase
|
class CliAppTest < CliTestCase
|
||||||
test "boot" do
|
test "boot" do
|
||||||
assert_match /Running docker run --detach --restart unless-stopped/, run_command("boot")
|
# Stub current version fetch
|
||||||
|
SSHKit::Backend::Abstract.any_instance.stubs(:capture)
|
||||||
|
.returns("999") # new version
|
||||||
|
.then
|
||||||
|
.returns("123") # old version
|
||||||
|
|
||||||
|
run_command("boot").tap do |output|
|
||||||
|
assert_match /docker run --detach --restart unless-stopped/, output
|
||||||
|
assert_match /docker container ls --all --filter name=app-123 --quiet | xargs docker stop/, output
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "boot will reboot if same version is already running" do
|
test "boot will reboot if same version is already running" do
|
||||||
@@ -11,12 +20,17 @@ class CliAppTest < CliTestCase
|
|||||||
# Prevent expected failures from outputting to terminal
|
# Prevent expected failures from outputting to terminal
|
||||||
Thread.report_on_exception = false
|
Thread.report_on_exception = false
|
||||||
|
|
||||||
MRSK.app.stubs(:run).raises(SSHKit::Command::Failed.new("already in use")).then.returns([ :docker, :run ])
|
MRSK.app.stubs(:run)
|
||||||
|
.raises(SSHKit::Command::Failed.new("already in use"))
|
||||||
|
.then
|
||||||
|
.raises(SSHKit::Command::Failed.new("already in use"))
|
||||||
|
.then
|
||||||
|
.returns([ :docker, :run ])
|
||||||
|
|
||||||
run_command("boot").tap do |output|
|
run_command("boot").tap do |output|
|
||||||
assert_match /Rebooting container with same version already deployed/, output # Can't start what's already running
|
assert_match /Rebooting container with same version 999 already deployed/, output # Can't start what's already running
|
||||||
assert_match /docker ps --quiet --filter label=service=app \| xargs docker stop/, output # Stop what's running
|
assert_match /docker container ls --all --filter name=app-999 --quiet | xargs docker container rm/, output # Stop old running
|
||||||
assert_match /docker container ls --all --filter name=app-999 --quiet \| xargs docker container rm/, output # Remove old container
|
assert_match /docker container ls --all --filter name=app-999 --quiet | xargs docker container rm/, output # Remove old container
|
||||||
assert_match /docker run/, output # Start new container
|
assert_match /docker run/, output # Start new container
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class CliMainTest < CliTestCase
|
|||||||
Mrsk::Cli::Main.any_instance.stubs(:container_name_available?).returns(true)
|
Mrsk::Cli::Main.any_instance.stubs(:container_name_available?).returns(true)
|
||||||
|
|
||||||
run_command("rollback", "123").tap do |output|
|
run_command("rollback", "123").tap do |output|
|
||||||
assert_match /Stop current version, then start version 123/, output
|
assert_match /Start version 123/, output
|
||||||
assert_match /docker ps -q --filter label=service=app | xargs docker stop/, output
|
assert_match /docker ps -q --filter label=service=app | xargs docker stop/, output
|
||||||
assert_match /docker start app-123/, output
|
assert_match /docker start app-123/, output
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
test "run" do
|
test "run" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"3\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"5\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
||||||
@app.run.join(" ")
|
@app.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
@config[:volumes] = ["/local/path:/container/path" ]
|
@config[:volumes] = ["/local/path:/container/path" ]
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --volume /local/path:/container/path --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"3\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --volume /local/path:/container/path --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"5\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
||||||
@app.run.join(" ")
|
@app.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ class CommandsAppTest < ActiveSupport::TestCase
|
|||||||
@config[:healthcheck] = { "path" => "/healthz" }
|
@config[:healthcheck] = { "path" => "/healthz" }
|
||||||
|
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/healthz\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"3\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
"docker run --detach --restart unless-stopped --log-opt max-size=10m --name app-999 -e RAILS_MASTER_KEY=\"456\" --label service=\"app\" --label role=\"web\" --label traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.services.app.loadbalancer.healthcheck.path=\"/healthz\" --label traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\" --label traefik.http.middlewares.app.retry.attempts=\"5\" --label traefik.http.middlewares.app.retry.initialinterval=\"500ms\" dhh/app:999",
|
||||||
@app.run.join(" ")
|
@app.run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "special label args for web" do
|
test "special label args for web" do
|
||||||
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"web\"", "--label", "traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\"", "--label", "traefik.http.middlewares.app.retry.attempts=\"3\"", "--label", "traefik.http.middlewares.app.retry.initialinterval=\"500ms\""], @config.role(:web).label_args
|
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"web\"", "--label", "traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\"", "--label", "traefik.http.middlewares.app.retry.attempts=\"5\"", "--label", "traefik.http.middlewares.app.retry.initialinterval=\"500ms\""], @config.role(:web).label_args
|
||||||
end
|
end
|
||||||
|
|
||||||
test "custom labels" do
|
test "custom labels" do
|
||||||
@@ -66,7 +66,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
|
|||||||
c[:servers]["beta"] = { "traefik" => "true", "hosts" => [ "1.1.1.5" ] }
|
c[:servers]["beta"] = { "traefik" => "true", "hosts" => [ "1.1.1.5" ] }
|
||||||
})
|
})
|
||||||
|
|
||||||
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"beta\"", "--label", "traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\"", "--label", "traefik.http.middlewares.app.retry.attempts=\"3\"", "--label", "traefik.http.middlewares.app.retry.initialinterval=\"500ms\"" ], config.role(:beta).label_args
|
assert_equal [ "--label", "service=\"app\"", "--label", "role=\"beta\"", "--label", "traefik.http.routers.app.rule=\"PathPrefix(\\`/\\`)\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.path=\"/up\"", "--label", "traefik.http.services.app.loadbalancer.healthcheck.interval=\"1s\"", "--label", "traefik.http.middlewares.app.retry.attempts=\"5\"", "--label", "traefik.http.middlewares.app.retry.initialinterval=\"500ms\"" ], config.role(:beta).label_args
|
||||||
end
|
end
|
||||||
|
|
||||||
test "env overwritten by role" do
|
test "env overwritten by role" do
|
||||||
|
|||||||
2
test/fixtures/deploy_with_accessories.yml
vendored
2
test/fixtures/deploy_with_accessories.yml
vendored
@@ -27,3 +27,5 @@ accessories:
|
|||||||
port: 6379
|
port: 6379
|
||||||
directories:
|
directories:
|
||||||
- data:/data
|
- data:/data
|
||||||
|
|
||||||
|
readiness_delay: 0
|
||||||
Reference in New Issue
Block a user