diff --git a/README.md b/README.md index 027f954e..d54f3e2b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # MRSK -MRSK deploys Rails 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. +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. ## Installation -Install MRSK globally with `gem install mrsk`. Then, inside your app directory, run `mrsk install`. Now edit the new file `config/deploy.yml`. It could look as simple as this: +Install MRSK globally with `gem install mrsk`. Then, inside your app directory, run `mrsk init` (or `mrsk init --bundle` within Rails apps where you want a bin/mrsk binstub). Now edit the new file `config/deploy.yml`. It could look as simple as this: ```yaml service: hey @@ -20,10 +20,12 @@ env: - RAILS_MASTER_KEY ``` -Now you're ready to deploy a multi-arch image to the servers: +Then edit your `.env` file to add your registry password as `MRSK_REGISTRY_PASSWORD` (and your `RAILS_MASTER_KEY` for production with a Rails app). + +Now you're ready to deploy to the servers: ``` -RAILS_MASTER_KEY=123 MRSK_REGISTRY_PASSWORD=pw mrsk deploy +mrsk deploy ``` This will: diff --git a/lib/mrsk/cli/main.rb b/lib/mrsk/cli/main.rb index c1b985c3..29e43c5b 100644 --- a/lib/mrsk/cli/main.rb +++ b/lib/mrsk/cli/main.rb @@ -74,22 +74,29 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base end end - desc "install", "Create config stub in config/deploy.yml and binstub in bin/mrsk" - option :skip_binstub, type: :boolean, default: false, desc: "Skip adding MRSK to the Gemfile and creating bin/mrsk binstub" - def install + desc "init", "Create config stub in config/deploy.yml and env stub in .env" + option :bundle, type: :boolean, default: false, desc: "Add MRSK to the Gemfile and create a bin/mrsk binstub" + def init require "fileutils" if (deploy_file = Pathname.new(File.expand_path("config/deploy.yml"))).exist? puts "Config file already exists in config/deploy.yml (remove first to create a new one)" else + FileUtils.mkdir_p deploy_file.dirname FileUtils.cp_r Pathname.new(File.expand_path("templates/deploy.yml", __dir__)), deploy_file puts "Created configuration file in config/deploy.yml" end - unless options[:skip_binstub] + unless (deploy_file = Pathname.new(File.expand_path(".env"))).exist? + FileUtils.cp_r Pathname.new(File.expand_path("templates/template.env", __dir__)), deploy_file + puts "Created .env file" + end + + if options[:bundle] if (binstub = Pathname.new(File.expand_path("bin/mrsk"))).exist? puts "Binstub already exists in bin/mrsk (remove first to create a new one)" else + puts "Adding MRSK to Gemfile and bundle..." `bundle add mrsk` `bundle binstubs mrsk` puts "Created binstub file in bin/mrsk" diff --git a/lib/mrsk/cli/templates/template.env b/lib/mrsk/cli/templates/template.env new file mode 100644 index 00000000..315a5e00 --- /dev/null +++ b/lib/mrsk/cli/templates/template.env @@ -0,0 +1,2 @@ +MRSK_REGISTRY_PASSWORD=change-this +RAILS_MASTER_KEY=another-env