amazon_kamal 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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +89 -0
- data/bin/amazon-kamal +9 -0
- data/lib/amazon_kamal/cli/main.rb +48 -0
- data/lib/amazon_kamal/cli/runner.rb +23 -0
- data/lib/amazon_kamal/cli/timers.rb +77 -0
- data/lib/amazon_kamal/version.rb +3 -0
- data/lib/amazon_kamal.rb +6 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8db14a7ce60a9ac6b3450f9d57d14b50948f681dfe5645bdd3a7fba0494fbcc3
|
4
|
+
data.tar.gz: 38745a121879d8ea5050d04714d9f8b9abc79725ac739f73bbe774ccd9e14298
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c8946f5804e3d6d75ba8756ae8611f6df87379de14ccef0165ea9d828156a5e58007c8db233ccad196de92ba032ef048997f3cc56f53bf832baa3ea262040c92
|
7
|
+
data.tar.gz: 45c2f165d124a485cb8cde9aef14625b9cd3ed3ff6794827b78dab5affa6a4b04d08efd99a9f76835e60e86795fa6fae4be75549aaf5797276a091b320d07a25
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2023 Brightways Learning
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# Amazon Kamal
|
2
|
+
A set of command line tools for bootstrapping and managing Amazon Linux servers running Kamal.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application’s Gemfile:
|
6
|
+
```ruby
|
7
|
+
gem "amazon_kamal"
|
8
|
+
```
|
9
|
+
|
10
|
+
And then execute:
|
11
|
+
```sh
|
12
|
+
bundle install
|
13
|
+
```
|
14
|
+
|
15
|
+
## Commands
|
16
|
+
### Bootstrap
|
17
|
+
Bootstraps an Amazon Linux 2023 server by updating packages, installing and configuring Docker, and disabling unnecessary services.
|
18
|
+
|
19
|
+
```sh
|
20
|
+
amazon-kamal bootstrap # Update packages and setup docker
|
21
|
+
```
|
22
|
+
|
23
|
+
### Runner
|
24
|
+
Installs the **kamal-rails-runner** script into `/usr/local/bin` and makes it executable. This script simplifies running `rails runner` commands inside Kamal containers.
|
25
|
+
|
26
|
+
See [kamal-rails-runner](https://github.com/wwidea/kamal-rails-runner) for more information.
|
27
|
+
|
28
|
+
```sh
|
29
|
+
amazon-kamal runner add # Install kamal-rails-runner
|
30
|
+
amazon-kamal runner remove # Remove kamal-rails-runner
|
31
|
+
```
|
32
|
+
|
33
|
+
### Timers
|
34
|
+
Installs systemd services and timers located in the `config/systemd` directory on the primary Kamal server.
|
35
|
+
|
36
|
+
#### Usage
|
37
|
+
1. Create a service and corresponding timer file in `config/systemd`
|
38
|
+
2. Run **amazon-kamal timers add** to copy the files to the primary server and enable the timer
|
39
|
+
3. Run **amazon-kamal timers show** to display the timers installed on the primary server.
|
40
|
+
4. Run **amazon-kamal timers remove** to remove the timers defined in **config/systemd** from the primary server.
|
41
|
+
|
42
|
+
```sh
|
43
|
+
amazon-kamal timers add # Add systemd timers
|
44
|
+
amazon-kamal timers remove # Remove systemd timers
|
45
|
+
amazon-kamal timers show # Show timers
|
46
|
+
```
|
47
|
+
|
48
|
+
#### Example systemd files
|
49
|
+
```ini
|
50
|
+
# config/systemd/app-cleanup-job.service
|
51
|
+
[Unit]
|
52
|
+
Description=Run App CleanupJob
|
53
|
+
|
54
|
+
[Service]
|
55
|
+
Type=oneshot
|
56
|
+
ExecStart=/usr/local/bin/kamal-rails-runner app "CleanupJob.perform_now"
|
57
|
+
```
|
58
|
+
|
59
|
+
```ini
|
60
|
+
# config/systemd/app-cleanup-job.timer
|
61
|
+
[Unit]
|
62
|
+
Description=Schedule App CleanupJob
|
63
|
+
|
64
|
+
[Timer]
|
65
|
+
OnCalendar=*-*-* 00:00:00
|
66
|
+
Persistent=true
|
67
|
+
|
68
|
+
[Install]
|
69
|
+
WantedBy=timers.target
|
70
|
+
```
|
71
|
+
|
72
|
+
### Version
|
73
|
+
```sh
|
74
|
+
amazon-kamal version # Show AmazonKamal version
|
75
|
+
```
|
76
|
+
|
77
|
+
## Options
|
78
|
+
Specify the destination option to run commands on a defined Kamal destination.
|
79
|
+
|
80
|
+
```sh
|
81
|
+
# Bootstrap production servers
|
82
|
+
amazon-kamal bootstrap -d production
|
83
|
+
|
84
|
+
# Show timers on primary staging server
|
85
|
+
amazon-kamal timers show -d staging
|
86
|
+
```
|
87
|
+
|
88
|
+
## License
|
89
|
+
Amazon Kamal is available as open source under the terms of the [MIT License](https://opensource.org/license/MIT).
|
data/bin/amazon-kamal
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
class AmazonKamal::Cli::Main < Kamal::Cli::Base
|
2
|
+
# include SSHKit::DSL
|
3
|
+
|
4
|
+
desc "bootstrap", "Update packages and setup docker"
|
5
|
+
def bootstrap
|
6
|
+
say "Bootstrapping hosts...", :magenta
|
7
|
+
|
8
|
+
with_lock do
|
9
|
+
on(KAMAL.hosts) do |host|
|
10
|
+
info("Bootstrapping #{host}")
|
11
|
+
|
12
|
+
as "root" do
|
13
|
+
# Update and install packages
|
14
|
+
execute :dnf, "update -y"
|
15
|
+
execute :dnf, "install -y docker htop git"
|
16
|
+
|
17
|
+
# Add ssh user to docker group
|
18
|
+
execute :usermod, "-a -G docker #{KAMAL.config.ssh.user}"
|
19
|
+
|
20
|
+
# Start and enable docker service
|
21
|
+
execute :systemctl, "enable --now docker"
|
22
|
+
|
23
|
+
# Disable unnecessary services
|
24
|
+
%w[
|
25
|
+
amazon-ssm-agent
|
26
|
+
gssproxy
|
27
|
+
systemd-homed
|
28
|
+
systemd-userdbd.socket
|
29
|
+
systemd-userdbd
|
30
|
+
].each do |service|
|
31
|
+
execute :systemctl, "disable --now #{service}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "version", "Show AmazonKamal version"
|
39
|
+
def version
|
40
|
+
puts AmazonKamal::VERSION
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "runner", "Manage kamal-rails-runner"
|
44
|
+
subcommand "runner", AmazonKamal::Cli::Runner
|
45
|
+
|
46
|
+
desc "timers", "Manage systemd timers"
|
47
|
+
subcommand "timers", AmazonKamal::Cli::Timers
|
48
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class AmazonKamal::Cli::Runner < Kamal::Cli::Base
|
2
|
+
KAMAL_RAILS_RUNNER_URL = "https://raw.githubusercontent.com/wwidea/kamal-rails-runner/main/kamal-rails-runner.sh"
|
3
|
+
KAMAL_RAILS_RUNNER_PATH = "/usr/local/bin/kamal-rails-runner"
|
4
|
+
|
5
|
+
desc "add", "Install kamal-rails-runner"
|
6
|
+
def add
|
7
|
+
say "Installing kamal-rails-runner on #{KAMAL.primary_host}...", :magenta
|
8
|
+
on(KAMAL.primary_host) do
|
9
|
+
as "root" do
|
10
|
+
execute :curl, "-sSL #{KAMAL_RAILS_RUNNER_URL} -o #{KAMAL_RAILS_RUNNER_PATH}"
|
11
|
+
execute :chmod, "+x #{KAMAL_RAILS_RUNNER_PATH}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "remove", "Remove kamal-rails-runner"
|
17
|
+
def remove
|
18
|
+
say "Removing kamal-rails-runner from #{KAMAL.primary_host}...", :magenta
|
19
|
+
on(KAMAL.primary_host) do
|
20
|
+
execute :sudo, :rm, KAMAL_RAILS_RUNNER_PATH
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class AmazonKamal::Cli::Timers < Kamal::Cli::Base
|
2
|
+
class_option :systemd_path, default: "config/systemd", desc: "Path to systemd files"
|
3
|
+
|
4
|
+
desc "add", "Add systemd timers"
|
5
|
+
def add
|
6
|
+
say "Adding systemd timers to #{KAMAL.primary_host}...", :magenta
|
7
|
+
|
8
|
+
path = options[:systemd_path]
|
9
|
+
|
10
|
+
timers do |timer|
|
11
|
+
say "Adding timer: #{timer}"
|
12
|
+
|
13
|
+
on(KAMAL.primary_host) do
|
14
|
+
# Upload files
|
15
|
+
puts method(:upload!).source_location.inspect
|
16
|
+
upload!("#{path}/#{timer}.timer", "/tmp")
|
17
|
+
upload!("#{path}/#{timer}.service", "/tmp")
|
18
|
+
|
19
|
+
as "root" do
|
20
|
+
# Move files to systemd directory and set permissions
|
21
|
+
execute :mv, "/tmp/#{timer}.*", "/etc/systemd/system/"
|
22
|
+
execute :chown, "root:root", "/etc/systemd/system/#{timer}.*"
|
23
|
+
execute :chmod, "644", "/etc/systemd/system/#{timer}.*"
|
24
|
+
|
25
|
+
# Enable and start the timer
|
26
|
+
execute :systemctl, "daemon-reload"
|
27
|
+
execute :systemctl, "enable --now #{timer}.timer"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "remove", "Remove systemd timers"
|
34
|
+
def remove
|
35
|
+
say "Removing systemd timers from #{KAMAL.primary_host}...", :magenta
|
36
|
+
|
37
|
+
timers do |timer|
|
38
|
+
puts "Removing timer: #{timer}"
|
39
|
+
|
40
|
+
on(KAMAL.primary_host) do
|
41
|
+
as "root" do
|
42
|
+
# Stop and disable the timer
|
43
|
+
execute :systemctl, "stop #{timer}.timer"
|
44
|
+
execute :systemctl, "disable #{timer}.timer"
|
45
|
+
|
46
|
+
# Remove timer files
|
47
|
+
execute :rm, "/etc/systemd/system/#{timer}.*"
|
48
|
+
|
49
|
+
# Reload systemd daemon
|
50
|
+
execute :systemctl, "daemon-reload"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "show", "Show timers"
|
57
|
+
def show
|
58
|
+
say "Calling systemctl list-timers on #{KAMAL.primary_host}...", :magenta
|
59
|
+
on(KAMAL.primary_host) do
|
60
|
+
puts capture(:systemctl, "list-timers")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def timers(&)
|
67
|
+
timer_files = Dir.glob("#{options[:systemd_path]}/*.timer")
|
68
|
+
|
69
|
+
if timer_files.empty?
|
70
|
+
say "No timers found in #{options[:systemd_path]}.", :red
|
71
|
+
else
|
72
|
+
timer_files.each do |path|
|
73
|
+
yield File.basename(path, ".timer")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/amazon_kamal.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: amazon_kamal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Baldwin
|
8
|
+
- Brightways Learning
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: kamal
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.5'
|
27
|
+
email: baldwina@brightwayslearning.org
|
28
|
+
executables:
|
29
|
+
- amazon-kamal
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- MIT-LICENSE
|
34
|
+
- README.md
|
35
|
+
- bin/amazon-kamal
|
36
|
+
- lib/amazon_kamal.rb
|
37
|
+
- lib/amazon_kamal/cli/main.rb
|
38
|
+
- lib/amazon_kamal/cli/runner.rb
|
39
|
+
- lib/amazon_kamal/cli/timers.rb
|
40
|
+
- lib/amazon_kamal/version.rb
|
41
|
+
homepage: https://github.com/wwidea/amazon_kamal
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata: {}
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 3.2.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.6.8
|
60
|
+
specification_version: 4
|
61
|
+
summary: Provision Amazon Linux servers for use with Kamal.
|
62
|
+
test_files: []
|