From d43ceb975f004f2f1e4d69d730b6dae4f81ba80b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 8 Jan 2023 13:39:29 +0100 Subject: [PATCH] Create config stub with mrsk:init --- README.md | 11 +++++------ lib/tasks/mrsk/mrsk.rake | 7 +++++-- lib/tasks/mrsk/templates/deploy.yml | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 lib/tasks/mrsk/templates/deploy.yml diff --git a/README.md b/README.md index b1238c52..252eb8ca 100644 --- a/README.md +++ b/README.md @@ -4,19 +4,18 @@ MRSK ships zero-downtime deploys of Rails apps packed as containers to any host. ## Installation -Create a configuration file for MRSK in `config/deploy.yml` that looks like this: +Add the gem with `bundle add mrsk`, then run `rake mrsk:init`, and then edit the new file in `config/deploy.yml` to use the proper service name, image reference, servers to deploy on, and so on. It could look something like this: ```yaml -service: my-app -image: name/my-app +service: hey +image: 37s/hey servers: - xxx.xxx.xxx.xxx - xxx.xxx.xxx.xxx env: - DATABASE_URL: mysql2://localhost/my-app_production/ - REDIS_URL: redis://host:6379/1 + DATABASE_URL: mysql2://db1/hey_production/ + REDIS_URL: redis://redis1:6379/1 registry: - # No server definition needed if using Docker Hub server: registry.digitalocean.com username: <%= Rails.application.credentials.registry["username"] %> password: <%= Rails.application.credentials.registry["password"] %> diff --git a/lib/tasks/mrsk/mrsk.rake b/lib/tasks/mrsk/mrsk.rake index 113e69c4..67f99d0b 100644 --- a/lib/tasks/mrsk/mrsk.rake +++ b/lib/tasks/mrsk/mrsk.rake @@ -13,8 +13,11 @@ namespace :mrsk do desc "Display information about Traefik and app containers" task info: [ "traefik:info", "app:info" ] - desc "Create config stub" + desc "Create config stub in config/deploy.yml" task :init do - Rails.root.join("config/deploy.yml") + require "fileutils" + FileUtils.cp_r \ + Pathname.new(File.expand_path("templates/deploy.yml", __dir__)), + Rails.root.join("config/deploy.yml")) end end diff --git a/lib/tasks/mrsk/templates/deploy.yml b/lib/tasks/mrsk/templates/deploy.yml new file mode 100644 index 00000000..16eacd83 --- /dev/null +++ b/lib/tasks/mrsk/templates/deploy.yml @@ -0,0 +1,20 @@ +# Name of your application will be used for uniquely configuring Traefik and app containers +service: my-app + +# Name of the container image +image: user/chat + +# All the servers targeted for deploy. You can reference a single server for a command by using SERVERS=xxx.xxx.xxx.xxx +servers: + - xxx.xxx.xxx.xxx + +# The following envs are made available to the container when started +env: + # Remember never to put passwords or tokens directly into this file, use encrypted credentials + # REDIS_URL: redis://x/y + +registry: + # Specify the registry server, if you're not using Docker Hub + # server: registry.digitalocean.com / ghcr.io / ... + username: <%= Rails.application.credentials.registry["username"] %> + password: <%= Rails.application.credentials.registry["password"] %>