kitsune-kit 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 57456c12dd12944d84cfd91365faf9997f14b6612ac9530e0d59612a2127f7c3
4
+ data.tar.gz: 171c5324395c519e83c3ee95dc1fb301a93813113e3b95a01129c905be634525
5
+ SHA512:
6
+ metadata.gz: 3aff57085a3a9d071c183a2d8ebfda9fd729f6a1ea6da7dc38436aaefca10e3d24001c6cdd6ae4aa8a76c71b7448f6b180724e3ed7014974c58c57bb9cb81eca
7
+ data.tar.gz: c767d70f51be75dd80b6d8f111afb8d3c89fea9074337ff7df5eb66c83b96526ab52f4ac184988c5b28d9772ced5c9f67637467a94808f86b26f0fc26a57fbaf
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2025-04-29
4
+ ### Added
5
+ - First public release
6
+ - Bootstrap commands for DigitalOcean + Docker + PostgreSQL
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Omar Herrera
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,192 @@
1
+ # Kitsune Kit 🦊
2
+
3
+ <p align="center">
4
+ <img src="kitsune-kit-logo.jpg" alt="Kitsune Logo" width="180"/>
5
+ </p>
6
+
7
+ **Kitsune Kit** is a Ruby gem that automates the provisioning, configuration, and setup of remote Linux servers (VPS) to host applications deployed with [Kamal](https://github.com/basecamp/kamal) or Docker Compose. It is designed to work on DigitalOcean infrastructure (for now), featuring reversible commands and a clear workflow.
8
+
9
+ > 🛠️ *Ideal for Ruby developers who want to launch production without relying on other services.*
10
+
11
+ ---
12
+
13
+ ## 🔍 Main Features
14
+
15
+ - 🧪 **Automatically provisions** a Droplet on DigitalOcean
16
+ - 👤 Configures a secure, passwordless `deploy` user
17
+ - 🔐 Applies firewall rules (UFW) for SSH, HTTP, HTTPS
18
+ - ♻️ Enables automatic security updates (unattended-upgrades)
19
+ - 🐳 Installs and configures Docker Engine and private networking
20
+ - 🐘 Deploys PostgreSQL via Docker Compose with healthcheck and `.env`
21
+ - 🔄 All steps can be rolled back (`--rollback`)
22
+ - ⚡ Fast, reproducible and without relying on YAML or complex external tools
23
+
24
+ ---
25
+
26
+ ## 📦 Installation
27
+
28
+ Add this line to your `Gemfile`:
29
+
30
+ ```ruby
31
+ gem "kitsune-kit"
32
+ ```
33
+
34
+ Or install it manually:
35
+
36
+ ```bash
37
+ gem install kitsune-kit
38
+ ```
39
+
40
+ ---
41
+
42
+ ## ⚙️ Prerequisites
43
+
44
+ 1. Configure a DigitalOcean API token:
45
+ ```bash
46
+ export DO_API_TOKEN="your_token"
47
+ ```
48
+
49
+ 2. Have the SSH key ID uploaded to DigitalOcean:
50
+ ```bash
51
+ export SSH_KEY_ID="123456"
52
+ ```
53
+
54
+ 3. Have the private key installed on your local machine:
55
+ ```bash
56
+ export SSH_KEY_PATH="~/.ssh/id_rsa"
57
+ ```
58
+
59
+ ---
60
+
61
+ ## 🚀 Getting Started
62
+
63
+ Initialize the Kitsune project structure:
64
+
65
+ ```bash
66
+ kit init
67
+ ```
68
+
69
+ This will create the `.kitsune/` directory, multiple `.env` files, and the necessary Docker templates. Run it in your project's root directory.
70
+
71
+ ---
72
+
73
+ ## 🔧 Main Commands
74
+
75
+ ### 🧱 Server Provisioning
76
+
77
+ ```bash
78
+ kit bootstrap execute
79
+ ```
80
+
81
+ This creates a Droplet and executes:
82
+
83
+ 1. `setup_user create`
84
+ 2. `setup_firewall create`
85
+ 3. `setup_unattended create`
86
+
87
+ ### 🐳 Full Docker Installation
88
+
89
+ ```bash
90
+ kit bootstrap_docker execute --server-ip 123.123.123.123
91
+ ```
92
+
93
+ This applies in order:
94
+
95
+ 1. `setup_docker_prereqs create`
96
+ 2. `install_docker_engine create`
97
+ 3. `postinstall_docker create`
98
+
99
+ ### 🐘 Install PostgreSQL with Docker Compose
100
+
101
+ ```bash
102
+ kit setup_postgres_docker create --server-ip 123.123.123.123
103
+ ```
104
+
105
+ It will provide you with a `DATABASE_URL` ready for Rails or any other app.
106
+
107
+ ---
108
+
109
+ ## ♻️ Rollback for Each Step
110
+
111
+ Each command accepts the `--rollback` flag. For example:
112
+
113
+ ```bash
114
+ kit bootstrap execute --rollback --keep-server
115
+ ```
116
+
117
+ This:
118
+ - Reverts the server configuration (`unattended`, `firewall`, `user`)
119
+ - Optionally **deletes the Droplet** (if you don't use `--keep-server`)
120
+
121
+ The same applies to any other subcommand, such as:
122
+
123
+ ```bash
124
+ kit bootstrap_docker execute --rollback --server-ip ...
125
+ kit setup_postgres_docker rollback --server-ip ...
126
+ ```
127
+
128
+ ---
129
+
130
+ ## 🌎 Support for Multiple Environments
131
+
132
+ Use `switch_env` to change between environments:
133
+
134
+ ```bash
135
+ kit switch_env to production
136
+ ```
137
+
138
+ This updates `.kitsune/kit.env` and creates (if it doesn't exist) `.kitsune/infra.production.env`.
139
+
140
+ ---
141
+
142
+ ## 🔗 Integration with Kamal
143
+
144
+ Once the server is configured:
145
+
146
+ 1. Define your `kamal.yml` pointing to the created droplet
147
+ 2. Run `kamal setup` to initialize the deployment
148
+ 3. Use `kamal deploy` as usual
149
+
150
+ ---
151
+
152
+ ## 💡 Tips
153
+
154
+ - Use `kit init` in every new project.
155
+ - Customize `.kitsune/docker/postgres.yml` if you need additional services.
156
+
157
+ ---
158
+
159
+ ## 📘 Quick Example
160
+
161
+ ```bash
162
+ # Initialize project structure
163
+ kit init
164
+
165
+ # Provision Droplet and configure everything
166
+ kit bootstrap execute
167
+
168
+ # Install Docker
169
+ kit bootstrap_docker execute --server-ip 123.123.123.123
170
+
171
+ # Set up the database
172
+ kit setup_postgres_docker create --server-ip 123.123.123.123
173
+ ```
174
+
175
+ ---
176
+
177
+ ## 🧪 In Development
178
+
179
+ - [ ] Support for other providers (Hetzner)
180
+ - [ ] Create databases on another server
181
+
182
+ ---
183
+
184
+ ## 🔐 Security
185
+
186
+ Never upload your `.env` files to public repositories. Kitsune does not encrypt them: it assumes you control your machine and your repo. Add `.kitsune/` to your project's `.gitignore`.
187
+
188
+ ---
189
+
190
+ ## 📄 License
191
+
192
+ MIT License © [Omar Herrera / OmarHrra]
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/kit ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "dotenv/load"
4
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
5
+ require "kitsune/kit"
6
+ require "kitsune/kit/cli"
7
+
8
+ Kitsune::Kit::CLI.start(ARGV)
Binary file
@@ -0,0 +1,17 @@
1
+ # DigitalOcean Droplet defaults
2
+ DO_API_TOKEN=
3
+ DROPLET_NAME=
4
+ REGION=
5
+ SIZE=
6
+ IMAGE=
7
+ SSH_KEY_ID=
8
+ TAG_NAME=
9
+
10
+ # SSH configuration
11
+ SSH_KEY_PATH=
12
+ # SSH_PORT=22 (optional)
13
+
14
+ # PostgreSQL Docker defaults
15
+ POSTGRES_DB=
16
+ POSTGRES_USER=
17
+ POSTGRES_PASSWORD=
@@ -0,0 +1,20 @@
1
+ services:
2
+ postgres:
3
+ image: postgres:17
4
+ restart: always
5
+ environment:
6
+ POSTGRES_DB: ${POSTGRES_DB}
7
+ POSTGRES_USER: ${POSTGRES_USER}
8
+ POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
9
+ ports:
10
+ - "${POSTGRES_PORT:-5432}:5432"
11
+ volumes:
12
+ - pgdata:/var/lib/postgresql/data
13
+ healthcheck:
14
+ test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER}"]
15
+ interval: 30s
16
+ timeout: 10s
17
+ retries: 5
18
+
19
+ volumes:
20
+ pgdata:
@@ -0,0 +1 @@
1
+ KIT_ENV=development
@@ -0,0 +1,64 @@
1
+ require "thor"
2
+ require_relative "env_loader"
3
+ require_relative "commands/init"
4
+ require_relative "commands/switch_env"
5
+ require_relative "commands/provision"
6
+ require_relative "commands/setup_user"
7
+ require_relative "commands/setup_firewall"
8
+ require_relative "commands/setup_unattended"
9
+ require_relative "commands/bootstrap"
10
+ require_relative "commands/setup_docker_prereqs"
11
+ require_relative "commands/install_docker_engine"
12
+ require_relative "commands/postinstall_docker"
13
+ require_relative "commands/bootstrap_docker"
14
+ require_relative "commands/setup_postgres_docker"
15
+
16
+ module Kitsune
17
+ module Kit
18
+ class CLI < Thor
19
+ def self.dispatch(m, args, options, config)
20
+ unless ["init", "switch_env", "help", nil].include?(args.first)
21
+ Kitsune::Kit::EnvLoader.load!
22
+ end
23
+
24
+ super
25
+ end
26
+
27
+ desc "init", "Initialize Kitsune Kit project structure"
28
+ subcommand "init", Kitsune::Kit::Commands::Init
29
+
30
+ desc "switch_env SUBCOMMAND", "Switch the active Kitsune environment"
31
+ subcommand "switch_env", Kitsune::Kit::Commands::SwitchEnv
32
+
33
+ desc "provision SUBCOMMAND", "Provisioning tasks"
34
+ subcommand "provision", Kitsune::Kit::Commands::Provision
35
+
36
+ desc "setup_user SUBCOMMAND", "Create or rollback deploy user on remote server"
37
+ subcommand "setup_user", Kitsune::Kit::Commands::SetupUser
38
+
39
+ desc "setup_firewall SUBCOMMAND", "Configure or rollback UFW firewall rules"
40
+ subcommand "setup_firewall", Kitsune::Kit::Commands::SetupFirewall
41
+
42
+ desc "setup_unattended SUBCOMMAND", "Configure or rollback unattended-upgrades"
43
+ subcommand "setup_unattended", Kitsune::Kit::Commands::SetupUnattended
44
+
45
+ desc "bootstrap SUBCOMMAND", "Run full server setup or rollback"
46
+ subcommand "bootstrap", Kitsune::Kit::Commands::Bootstrap
47
+
48
+ desc "setup_docker_prereqs SUBCOMMAND", "Install or rollback docker prerequisites"
49
+ subcommand "setup_docker_prereqs", Kitsune::Kit::Commands::SetupDockerPrereqs
50
+
51
+ desc "install_docker_engine SUBCOMMAND", "Install or rollback Docker Engine"
52
+ subcommand "install_docker_engine", Kitsune::Kit::Commands::InstallDockerEngine
53
+
54
+ desc "postinstall_docker SUBCOMMAND", "Apply or rollback Docker post-installation tasks"
55
+ subcommand "postinstall_docker", Kitsune::Kit::Commands::PostinstallDocker
56
+
57
+ desc "bootstrap_docker SUBCOMMAND", "Run full docker setup or rollback"
58
+ subcommand "bootstrap_docker", Kitsune::Kit::Commands::BootstrapDocker
59
+
60
+ desc "setup_postgres_docker SUBCOMMAND", "Setup PostgreSQL via Docker Compose on remote server"
61
+ subcommand "setup_postgres_docker", Kitsune::Kit::Commands::SetupPostgresDocker
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,118 @@
1
+ require "thor"
2
+ require "open3"
3
+ require_relative "../defaults"
4
+ require_relative "../options_builder"
5
+ require_relative "../provisioner"
6
+
7
+ module Kitsune
8
+ module Kit
9
+ module Commands
10
+ class Bootstrap < Thor
11
+ namespace "bootstrap"
12
+
13
+ class_option :rollback, type: :boolean, default: false, desc: "Rollback the setup"
14
+ class_option :keep_server, type: :boolean, default: false, desc: "Keep server after rollback"
15
+ class_option :ssh_port, type: :string, desc: "SSH port for server"
16
+ class_option :ssh_key_path, type: :string, desc: "SSH private key path"
17
+
18
+ desc "execute", "Run the full bootstrap process or rollback"
19
+ def execute
20
+ filled_options = Kitsune::Kit::OptionsBuilder.build(
21
+ options,
22
+ defaults: Kitsune::Kit::Defaults.ssh
23
+ )
24
+
25
+ if filled_options[:rollback]
26
+ say "🔄 Rolling back server configurations...", :yellow
27
+ rollback_sequence(filled_options)
28
+ else
29
+ say "🏗️ Setting up server from scratch...", :green
30
+ setup_sequence(filled_options)
31
+ end
32
+
33
+ say "🎉 Done!", :green
34
+ end
35
+
36
+ no_commands do
37
+ def setup_sequence(filled_options)
38
+ droplet_ip = fetch_droplet_ip
39
+
40
+ say "→ Droplet IP: #{droplet_ip}", :cyan
41
+
42
+ run_cli("setup_user create", droplet_ip, filled_options)
43
+ run_cli("setup_firewall create", droplet_ip, filled_options)
44
+ run_cli("setup_unattended create", droplet_ip, filled_options)
45
+ end
46
+
47
+ def rollback_sequence(filled_options)
48
+ provision_options = Kitsune::Kit::OptionsBuilder.build(
49
+ {},
50
+ defaults: Kitsune::Kit::Defaults::infra
51
+ )
52
+
53
+ provisioner = Kitsune::Kit::Provisioner.new(provision_options)
54
+
55
+ if (droplet = provisioner.find_droplet).nil?
56
+ say "💡 Nothing to rollback.", :green
57
+ return
58
+ end
59
+
60
+ droplet_ip = provisioner.send(:public_ip, droplet)
61
+ say "→ Using Droplet IP: #{droplet_ip}", :cyan
62
+
63
+ if ssh_accessible?(droplet_ip, filled_options)
64
+ run_cli("setup_unattended rollback", droplet_ip, filled_options)
65
+ run_cli("setup_firewall rollback", droplet_ip, filled_options)
66
+ else
67
+ say "⏭️ Skipping unattended-upgrades and firewall rollback (no deploy user)", :yellow
68
+ end
69
+
70
+ run_cli("setup_user rollback", droplet_ip, filled_options)
71
+
72
+ unless filled_options[:keep_server]
73
+ say "▶️ Running: kitsune kit provision rollback", :blue
74
+ Kitsune::Kit::CLI.start(%w[provision rollback])
75
+ else
76
+ say "⏭️ Skipping droplet deletion (--keep-server enabled)", :yellow
77
+ end
78
+ end
79
+
80
+ def fetch_droplet_ip
81
+ output, status = Open3.capture2e("bin/kit provision create")
82
+ unless status.success?
83
+ abort "❌ Error fetching or creating droplet"
84
+ end
85
+
86
+ ip = output.match(/(\d{1,3}\.){3}\d{1,3}/).to_s
87
+ abort "❌ Could not detect droplet IP!" if ip.empty?
88
+ ip
89
+ end
90
+
91
+ def run_cli(command, droplet_ip, filled_options)
92
+ say "▶️ Running: kitsune kit #{command} --server-ip #{droplet_ip}", :blue
93
+ subcommand, action = command.split(" ", 2)
94
+ Kitsune::Kit::CLI.start([
95
+ subcommand, action,
96
+ "--server-ip", droplet_ip,
97
+ "--ssh-port", filled_options[:ssh_port],
98
+ "--ssh-key-path", filled_options[:ssh_key_path]
99
+ ])
100
+ rescue SystemExit => e
101
+ abort "❌ Command failed: #{command} (exit #{e.status})"
102
+ end
103
+
104
+ def ssh_accessible?(droplet_ip, filled_options)
105
+ system(
106
+ "ssh -o BatchMode=yes -o StrictHostKeyChecking=accept-new " \
107
+ "-p #{filled_options[:ssh_port]} " \
108
+ "-i #{File.expand_path(filled_options[:ssh_key_path])} " \
109
+ "deploy@#{droplet_ip} true",
110
+ out: File::NULL,
111
+ err: File::NULL
112
+ )
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,66 @@
1
+ require "thor"
2
+ require "open3"
3
+ require_relative "../defaults"
4
+ require_relative "../options_builder"
5
+
6
+ module Kitsune
7
+ module Kit
8
+ module Commands
9
+ class BootstrapDocker < Thor
10
+ namespace "bootstrap_docker"
11
+
12
+ class_option :server_ip, aliases: "-s", required: true, desc: "Server IP address or hostname"
13
+ class_option :ssh_port, aliases: "-p", desc: "SSH port for server"
14
+ class_option :ssh_key_path, aliases: "-k", desc: "SSH private key path"
15
+ class_option :rollback, type: :boolean, default: false, desc: "Rollback Docker setup steps"
16
+
17
+ desc "execute", "Run full Docker setup or rollback sequence"
18
+ def execute
19
+ filled_options = Kitsune::Kit::OptionsBuilder.build(
20
+ options,
21
+ required: [:server_ip],
22
+ defaults: Kitsune::Kit::Defaults.ssh
23
+ )
24
+
25
+ if filled_options[:rollback]
26
+ say "🔄 Rolling back full Docker setup...", :yellow
27
+ rollback_sequence(filled_options)
28
+ else
29
+ say "🐳 Running full Docker setup...", :green
30
+ setup_sequence(filled_options)
31
+ end
32
+
33
+ say "🎉 Done!", :green
34
+ end
35
+
36
+ no_commands do
37
+ def setup_sequence(filled_options)
38
+ run_cli("setup_docker_prereqs create", filled_options)
39
+ run_cli("install_docker_engine create", filled_options)
40
+ run_cli("postinstall_docker create", filled_options)
41
+ end
42
+
43
+ def rollback_sequence(filled_options)
44
+ run_cli("postinstall_docker rollback", filled_options)
45
+ run_cli("install_docker_engine rollback", filled_options)
46
+ run_cli("setup_docker_prereqs rollback", filled_options)
47
+ end
48
+
49
+ def run_cli(command, filled_options)
50
+ say "▶️ Running: kitsune kit #{command} --server-ip #{filled_options[:server_ip]}", :blue
51
+
52
+ subcommand, action = command.split(" ", 2)
53
+ Kitsune::Kit::CLI.start([
54
+ subcommand, action,
55
+ "--server-ip", filled_options[:server_ip],
56
+ "--ssh-port", filled_options[:ssh_port],
57
+ "--ssh-key-path", filled_options[:ssh_key_path]
58
+ ])
59
+ rescue SystemExit => e
60
+ abort "❌ Command failed: #{command} (exit #{e.status})"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end