Compare commits

..

47 Commits

Author SHA1 Message Date
David Heinemeier Hansson
9363b6a464 Bump version for 0.16.1 2023-08-24 09:16:13 -07:00
David Heinemeier Hansson
338fd4e493 Merge pull request #428 from tbuehlmann/main
Fix picking the first available role on primary_host
2023-08-24 08:36:29 -07:00
David Heinemeier Hansson
eb3cb81a79 Merge pull request #368 from tsvallender/main 2023-08-24 06:12:48 -07:00
Tobias Bühlmann
556f7f5a37 Fix picking the first available role on primary_host 2023-08-24 13:50:24 +02:00
Trevor Vallender
c2ec04f8c1 Allow Traefik to run without publishing port
Adds the `publish` option which, if set to false, does not pass `--publish` to
`docker run` when starting Traefik. This is useful when running Traefik
behind a reverse proxy, for example.
2023-08-24 10:52:10 +01:00
David Heinemeier Hansson
519659b84c Merge pull request #422 from fig/fix-421
require ActiveSupport module to provide String#remove
2023-08-23 13:50:04 -07:00
David Heinemeier Hansson
560d0698ac Merge pull request #426 from northeastprince/fix-site-in-gemspec
Fix site URL in gemspec
2023-08-23 13:47:26 -07:00
fig
f40e8e9af1 Merge branch 'fix-421' of https://github.com/fig/mrsk into fix-421 2023-08-23 15:22:41 +01:00
fig
1ab7405e36 require ActiveSupport module to provide String#remove
fixes #421
2023-08-23 15:17:26 +01:00
Matt Almeida
aeadd7c11f Fix site URL in gemspec 2023-08-23 15:15:51 +02:00
Donal McBreen
d0fbf538d3 Add integration test hooks back in 2023-08-23 07:36:48 +01:00
David Heinemeier Hansson
cfe77934e8 Update README.md
Point all docs to the site so we don't duplicate everything.
2023-08-22 17:11:26 -07:00
David Heinemeier Hansson
3f6ca1648e Update docker-publish.yml
Require setting tag
2023-08-22 15:44:07 -07:00
David Heinemeier Hansson
7c6d302baa Update docker-publish.yml
Allow manual invocation
2023-08-22 15:20:02 -07:00
fig
b8eb50b982 require ActiveSupport module to provide String#remove
fixes #421
2023-08-22 20:58:48 +01:00
David Heinemeier Hansson
d981c3c968 Move hooks 2023-08-22 12:47:00 -07:00
David Heinemeier Hansson
416860d9b0 Update docker-publish.yml
Reflect rename
2023-08-22 12:34:57 -07:00
David Heinemeier Hansson
33d5d7e9a2 Update README.md
Point to name change.
2023-08-22 12:20:24 -07:00
David Heinemeier Hansson
99c1102a3a Update README.md
Will do a new video shortly.
2023-08-22 12:13:54 -07:00
David Heinemeier Hansson
ac11089c7a Bump version for 0.16.0 2023-08-22 11:42:32 -07:00
David Heinemeier Hansson
180ca219df Merge pull request #423 from basecamp/rename
Rename project to Kamal
2023-08-22 11:41:42 -07:00
David Heinemeier Hansson
dc1421a1fc Correct casing 2023-08-22 09:22:32 -07:00
David Heinemeier Hansson
c4a203e648 Rename to Kamal 2023-08-22 08:24:31 -07:00
Donal McBreen
e2c3709d74 Merge pull request #417 from manastyretskyi/main
Fix builder registry cache when using default registry
2023-08-17 14:08:05 +01:00
Liubomyr Manastyretskyi
f68a33465f Fix review comments 2023-08-17 11:58:14 +03:00
Donal McBreen
e7bc74d9ee Merge pull request #418 from mrsked/ssh-logging
Configurable log levels
2023-08-16 07:22:18 +01:00
Donal McBreen
1163c3de07 Configurable log levels
Allow ssh log_level to be set - this will help to debug connection
issues.
2023-08-15 16:51:56 +01:00
Donal McBreen
715cd94bbf Merge pull request #413 from mrsked/extract-version-from-container-name-correctly
Extract versions that contains dashes
2023-08-15 15:11:03 +01:00
Donal McBreen
dda7099b2f Merge pull request #414 from mrsked/traefik-start-stop-run-errors
Don't hide Traefik errors
2023-08-15 15:10:47 +01:00
Donal McBreen
4262fce863 Merge pull request #415 from igor-alexandrov/fix-builder-configuration-validation
Removed validation for remote and local builder params
2023-08-15 15:10:23 +01:00
Liubomyr Manastyretskyi
6774675547 Fix builder registry cache when using default registry 2023-08-13 12:04:03 +03:00
Igor Alexandrov
0c52a1053e Removed not needed configuration test 2023-08-08 19:14:03 +04:00
Igor Alexandrov
c24c7abb79 Fix for https://github.com/mrsked/mrsk/issues/407 2023-08-08 19:04:35 +04:00
Donal McBreen
c2d7fd775f Don't hide Traefik errors
When stopping or starting Traefik, don't hide important errors.

Docker doesn't return an error when starting a started container or
stopping a stopped container.

When rebooting we want to know about errors during run as we've just
stopped and removed the previous container.

When booting, we want to leave the running container if it exists,
restart a stopped container and run a new one if none exists.

We can implement this with `docker start ... || docker run ...`:
- if the container is started, `docker start` will exit with 0
- if the container is stopped, `docker start` will start it and exit with 0
- if the container doesn't exist, `docker start` will return a non zero
exit code and `docker run` will create a new container. Any errors in
`docker run` will be returned.
2023-08-08 15:41:16 +01:00
Donal McBreen
4dd8208290 Extract versions that contains dashes
The version extraction assumed that the version is everything after the
last `-` in the container name. This doesn't work if you deploy a
non-MRSK generated version that contains a `-`.

To fix we'll generate the non version prefix and strip it off. In some
places for this to work we need to make sure to pass the role through.

Fixes: https://github.com/mrsked/mrsk/issues/402
2023-08-08 14:16:32 +01:00
Donal McBreen
aa89ededde Merge pull request #399 from mrsked/manage-ssh-connection-starts
Manage SSH connection starts
2023-08-07 14:37:34 +01:00
David Heinemeier Hansson
299b166db7 Merge pull request #389 from brunoprietog/include-role-options-when-executing-commands
Include role options when executing commands
2023-07-26 14:04:28 +02:00
Donal McBreen
94d6a763a8 Extract ssh and sshkit configuration 2023-07-26 12:26:23 +01:00
Donal McBreen
752ff53458 Merge pull request #396 from igor-alexandrov/track-uncommitted-changes
Log uncommitted changes during deploy
2023-07-25 14:35:44 +01:00
Donal McBreen
eb8c97a417 Document new sshkit settings 2023-07-25 13:09:49 +01:00
Donal McBreen
f64b596907 Prevent SSH connection restarts
Set a high idle timeout on the sshkit connection pool. This will
reduce the incidence of re-connection storms when a deployment has been
idle for a while (e.g. when waiting for a docker build).

The default timeout was 30 seconds, so we'll enable keepalives at a
30s interval to match. This is to help prevent connections from being
killed during long idle periods.
2023-07-25 13:09:46 +01:00
Donal McBreen
b25cfa178b Limit SSH start concurrency
Starting many (90+) SSH connections has caused us some issues such as
failed DNS lookups and hitting process file descriptor limits.

To mitigate this, patch SSHKit::Backend::Netssh to limit concurrency of
connection starts. We'll default to 30 at a time which seems to work
without issue, but can be configured via:

```
sshkit:
  max_concurrent_starts: 10
```
2023-07-25 13:08:44 +01:00
Igor Alexandrov
d414253393 Updated uncommitted notification text 2023-07-24 20:12:22 +04:00
Bruno Prieto
cbd180205d Include role options when executing commands 2023-07-24 17:45:24 +02:00
Igor Alexandrov
ea941f33f9 Moved uncommitted changes message out of run_locally block 2023-07-21 22:45:23 +04:00
Igor Alexandrov
9c2a1dc7cd Removed commented code in tests 2023-07-21 18:44:01 +04:00
Igor Alexandrov
0cfafd1d25 Log uncommitted changes during deploy 2023-07-21 18:37:45 +04:00
110 changed files with 1095 additions and 1832 deletions

View File

@@ -1,6 +1,12 @@
name: Docker name: Docker
on: on:
workflow_dispatch:
inputs:
tagInput:
description: 'Tag'
required: true
release: release:
types: [created] types: [created]
tags: tags:
@@ -29,6 +35,14 @@ jobs:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Determine version tag
id: version-tag
run: |
INPUT_VALUE="${{ github.event.inputs.tagInput }}"
if [ -z "$INPUT_VALUE" ]; then
INPUT_VALUE="${{ github.ref_name }}"
fi
echo "::set-output name=value::$INPUT_VALUE"
- -
name: Build and push name: Build and push
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
@@ -37,5 +51,5 @@ jobs:
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
push: true push: true
tags: | tags: |
ghcr.io/mrsked/mrsk:latest ghcr.io/basecamp/kamal:latest
ghcr.io/mrsked/mrsk:${{ github.ref_name }} ghcr.io/basecamp/kamal:${{ steps.version-tag.outputs.value }}

View File

@@ -1,10 +1,10 @@
# Contributor Code of Conduct # Contributor Code of Conduct
As contributors and maintainers of the MRSK project, we pledge to create a welcoming and inclusive environment for everyone. We value the participation of each member of our community and want all contributors to feel respected and valued. As contributors and maintainers of the Kamal project, we pledge to create a welcoming and inclusive environment for everyone. We value the participation of each member of our community and want all contributors to feel respected and valued.
We are committed to providing a harassment-free experience for everyone, regardless of gender, gender identity and expression, sexual orientation, disability, physical appearance, body size, race, age, or religion (or lack thereof). We do not tolerate harassment of participants in any form. We are committed to providing a harassment-free experience for everyone, regardless of gender, gender identity and expression, sexual orientation, disability, physical appearance, body size, race, age, or religion (or lack thereof). We do not tolerate harassment of participants in any form.
This code of conduct applies to all MRSK project spaces, including but not limited to project code, issue trackers, chat rooms, and mailing lists. Violations of this code of conduct may result in removal from the project community. This code of conduct applies to all Kamal project spaces, including but not limited to project code, issue trackers, chat rooms, and mailing lists. Violations of this code of conduct may result in removal from the project community.
## Our standards ## Our standards

View File

@@ -1,18 +1,18 @@
# Contributing to MRSK development # Contributing to Kamal development
Thank you for considering contributing to MRSK! This document outlines some guidelines for contributing to this open source project. Thank you for considering contributing to Kamal! This document outlines some guidelines for contributing to this open source project.
Please make sure to review our [Code of Conduct](CODE_OF_CONDUCT.md) before contributing to MRSK. Please make sure to review our [Code of Conduct](CODE_OF_CONDUCT.md) before contributing to Kamal.
There are several ways you can contribute to the betterment of the project: There are several ways you can contribute to the betterment of the project:
- **Report an issue?** - If the issue isnt reported, we cant fix it. Please report any bugs, feature, and/or improvement requests on the [MRSK GitHub Issues tracker](https://github.com/mrsked/mrsk/issues). - **Report an issue?** - If the issue isnt reported, we cant fix it. Please report any bugs, feature, and/or improvement requests on the [Kamal GitHub Issues tracker](https://github.com/basecamp/kamal/issues).
- **Submit patches** - Do you have a new feature or a fix you'd like to share? [Submit a pull request](https://github.com/mrsked/mrsk/pulls)! - **Submit patches** - Do you have a new feature or a fix you'd like to share? [Submit a pull request](https://github.com/basecamp/kamal/pulls)!
- **Write blog articles** - Are you using MRSK? We'd love to hear how you're using it with your projects. Write a tutorial and post it on your blog! - **Write blog articles** - Are you using Kamal? We'd love to hear how you're using it with your projects. Write a tutorial and post it on your blog!
## Issues ## Issues
If you encounter any issues with the project, please check the [existing issues](https://github.com/mrsked/mrsk/issues) first to see if the issue has already been reported. If the issue hasn't been reported, please open a new issue with a clear description of the problem and steps to reproduce it. If you encounter any issues with the project, please check the [existing issues](https://github.com/basecamp/kamal/issues) first to see if the issue has already been reported. If the issue hasn't been reported, please open a new issue with a clear description of the problem and steps to reproduce it.
## Pull Requests ## Pull Requests
@@ -33,17 +33,17 @@ A good commit message should describe what changed and why.
## Development ## Development
The `main` branch is regularly built and tested, but it is not guaranteed to be completely stable. Tags are created regularly from release branches to indicate new official, stable release versions of MRSK. The `main` branch is regularly built and tested, but it is not guaranteed to be completely stable. Tags are created regularly from release branches to indicate new official, stable release versions of Kamal.
MRSK is written in Ruby. You should have Ruby 3.2+ installed on your machine in order to work on MRSK. If that's already setup, run `bundle` in the root directory to install all dependencies. Then you can run `bin/test` to run all tests. Kamal is written in Ruby. You should have Ruby 3.2+ installed on your machine in order to work on Kamal. If that's already setup, run `bundle` in the root directory to install all dependencies. Then you can run `bin/test` to run all tests.
1. Fork the project repository. 1. Fork the project repository.
2. Create a new branch for your contribution. 2. Create a new branch for your contribution.
3. Write your code or make the desired changes. 3. Write your code or make the desired changes.
4. **Ensure that your code passes the project's minitests by running ./bin/test.** 4. **Ensure that your code passes the project's minitests by running ./bin/test.**
5. Commit your changes and push them to your forked repository. 5. Commit your changes and push them to your forked repository.
6. [Open a pull request](https://github.com/mrsked/mrsk/pulls) to the main project repository with a detailed description of your changes. 6. [Open a pull request](https://github.com/basecamp/kamal/pulls) to the main project repository with a detailed description of your changes.
## License ## License
MRSK is released under the MIT License. By contributing to this project, you agree to license your contributions under the same license. Kamal is released under the MIT License. By contributing to this project, you agree to license your contributions under the same license.

View File

@@ -4,14 +4,14 @@ FROM ruby:3.2.0-alpine
# Install docker/buildx-bin # Install docker/buildx-bin
COPY --from=docker/buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx COPY --from=docker/buildx-bin /buildx /usr/libexec/docker/cli-plugins/docker-buildx
# Set the working directory to /mrsk # Set the working directory to /kamal
WORKDIR /mrsk WORKDIR /kamal
# Copy the Gemfile, Gemfile.lock into the container # Copy the Gemfile, Gemfile.lock into the container
COPY Gemfile Gemfile.lock mrsk.gemspec ./ COPY Gemfile Gemfile.lock kamal.gemspec ./
# Required in mrsk.gemspec # Required in kamal.gemspec
COPY lib/mrsk/version.rb /mrsk/lib/mrsk/version.rb COPY lib/kamal/version.rb /kamal/lib/kamal/version.rb
# Install system dependencies # Install system dependencies
RUN apk add --no-cache --update build-base git docker openrc openssh-client-default \ RUN apk add --no-cache --update build-base git docker openrc openssh-client-default \
@@ -25,8 +25,8 @@ RUN apk add --no-cache --update build-base git docker openrc openssh-client-defa
COPY . . COPY . .
# Install the gem locally from the project folder # Install the gem locally from the project folder
RUN gem build mrsk.gemspec && \ RUN gem build kamal.gemspec && \
gem install ./mrsk-*.gem --no-document gem install ./kamal-*.gem --no-document
# Set the working directory to /workdir # Set the working directory to /workdir
WORKDIR /workdir WORKDIR /workdir
@@ -36,5 +36,5 @@ WORKDIR /workdir
RUN git config --global --add safe.directory /workdir RUN git config --global --add safe.directory /workdir
# Set the entrypoint to run the installed binary in /workdir # Set the entrypoint to run the installed binary in /workdir
# Example: docker run -it -v "$PWD:/workdir" mrsk init # Example: docker run -it -v "$PWD:/workdir" kamal init
ENTRYPOINT ["mrsk"] ENTRYPOINT ["kamal"]

View File

@@ -1,9 +1,10 @@
PATH PATH
remote: . remote: .
specs: specs:
mrsk (0.15.1) kamal (0.16.1)
activesupport (>= 7.0) activesupport (>= 7.0)
bcrypt_pbkdf (~> 1.0) bcrypt_pbkdf (~> 1.0)
concurrent-ruby (~> 1.2)
dotenv (~> 2.8) dotenv (~> 2.8)
ed25519 (~> 1.2) ed25519 (~> 1.2)
net-ssh (~> 7.0) net-ssh (~> 7.0)
@@ -98,8 +99,8 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
debug debug
kamal!
mocha mocha
mrsk!
railties railties
BUNDLED WITH BUNDLED WITH

998
README.md

File diff suppressed because it is too large Load Diff

View File

@@ -3,10 +3,10 @@
# Prevent failures from being reported twice. # Prevent failures from being reported twice.
Thread.report_on_exception = false Thread.report_on_exception = false
require "mrsk" require "kamal"
begin begin
Mrsk::Cli::Main.start(ARGV) Kamal::Cli::Main.start(ARGV)
rescue SSHKit::Runner::ExecuteError => e rescue SSHKit::Runner::ExecuteError => e
puts " \e[31mERROR (#{e.cause.class}): #{e.message}\e[0m" puts " \e[31mERROR (#{e.cause.class}): #{e.message}\e[0m"
puts e.cause.backtrace if ENV["VERBOSE"] puts e.cause.backtrace if ENV["VERBOSE"]

View File

@@ -2,13 +2,13 @@
VERSION=$1 VERSION=$1
printf "module Mrsk\n VERSION = \"$VERSION\"\nend\n" > ./lib/mrsk/version.rb printf "module Kamal\n VERSION = \"$VERSION\"\nend\n" > ./lib/kamal/version.rb
bundle bundle
git add Gemfile.lock lib/mrsk/version.rb git add Gemfile.lock lib/kamal/version.rb
git commit -m "Bump version for $VERSION" git commit -m "Bump version for $VERSION"
git push git push
git tag v$VERSION git tag v$VERSION
git push --tags git push --tags
gem build mrsk.gemspec gem build kamal.gemspec
gem push "mrsk-$VERSION.gem" --host https://rubygems.org gem push "kamal-$VERSION.gem" --host https://rubygems.org
rm "mrsk-$VERSION.gem" rm "kamal-$VERSION.gem"

View File

@@ -1,16 +1,15 @@
require_relative "lib/mrsk/version" require_relative "lib/kamal/version"
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = "mrsk" spec.name = "kamal"
spec.version = Mrsk::VERSION spec.version = Kamal::VERSION
spec.authors = [ "David Heinemeier Hansson" ] spec.authors = [ "David Heinemeier Hansson" ]
spec.email = "dhh@hey.com" spec.email = "dhh@hey.com"
spec.homepage = "https://github.com/rails/mrsk" spec.homepage = "https://github.com/basecamp/kamal"
spec.summary = "Deploy web apps in containers to servers running Docker with zero downtime." spec.summary = "Deploy web apps in containers to servers running Docker with zero downtime."
spec.license = "MIT" spec.license = "MIT"
spec.files = Dir["lib/**/*", "MIT-LICENSE", "README.md"] spec.files = Dir["lib/**/*", "MIT-LICENSE", "README.md"]
spec.executables = %w[ mrsk ] spec.executables = %w[ kamal ]
spec.add_dependency "activesupport", ">= 7.0" spec.add_dependency "activesupport", ">= 7.0"
spec.add_dependency "sshkit", "~> 1.21" spec.add_dependency "sshkit", "~> 1.21"
@@ -20,6 +19,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "zeitwerk", "~> 2.5" spec.add_dependency "zeitwerk", "~> 2.5"
spec.add_dependency "ed25519", "~> 1.2" spec.add_dependency "ed25519", "~> 1.2"
spec.add_dependency "bcrypt_pbkdf", "~> 1.0" spec.add_dependency "bcrypt_pbkdf", "~> 1.0"
spec.add_dependency "concurrent-ruby", "~> 1.2"
spec.add_development_dependency "debug" spec.add_development_dependency "debug"
spec.add_development_dependency "mocha" spec.add_development_dependency "mocha"

View File

@@ -1,10 +1,10 @@
module Mrsk module Kamal
end end
require "active_support" require "active_support"
require "zeitwerk" require "zeitwerk"
loader = Zeitwerk::Loader.for_gem loader = Zeitwerk::Loader.for_gem
loader.ignore("#{__dir__}/mrsk/sshkit_with_ext.rb") loader.ignore("#{__dir__}/kamal/sshkit_with_ext.rb")
loader.setup loader.setup
loader.eager_load # We need all commands loaded. loader.eager_load # We need all commands loaded.

View File

@@ -1,7 +1,7 @@
module Mrsk::Cli module Kamal::Cli
class LockError < StandardError; end class LockError < StandardError; end
class HookError < StandardError; end class HookError < StandardError; end
end end
# SSHKit uses instance eval, so we need a global const for ergonomics # SSHKit uses instance eval, so we need a global const for ergonomics
MRSK = Mrsk::Commander.new KAMAL = Kamal::Commander.new

View File

@@ -1,17 +1,17 @@
class Mrsk::Cli::Accessory < Mrsk::Cli::Base class Kamal::Cli::Accessory < Kamal::Cli::Base
desc "boot [NAME]", "Boot new accessory service on host (use NAME=all to boot all accessories)" desc "boot [NAME]", "Boot new accessory service on host (use NAME=all to boot all accessories)"
def boot(name, login: true) def boot(name, login: true)
mutating do mutating do
if name == "all" if name == "all"
MRSK.accessory_names.each { |accessory_name| boot(accessory_name) } KAMAL.accessory_names.each { |accessory_name| boot(accessory_name) }
else else
with_accessory(name) do |accessory| with_accessory(name) do |accessory|
directories(name) directories(name)
upload(name) upload(name)
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.registry.login if login execute *KAMAL.registry.login if login
execute *MRSK.auditor.record("Booted #{name} accessory"), verbosity: :debug execute *KAMAL.auditor.record("Booted #{name} accessory"), verbosity: :debug
execute *accessory.run execute *accessory.run
end end
end end
@@ -54,7 +54,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
mutating do mutating do
with_accessory(name) do |accessory| with_accessory(name) do |accessory|
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.registry.login execute *KAMAL.registry.login
end end
stop(name) stop(name)
@@ -69,7 +69,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
mutating do mutating do
with_accessory(name) do |accessory| with_accessory(name) do |accessory|
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.auditor.record("Started #{name} accessory"), verbosity: :debug execute *KAMAL.auditor.record("Started #{name} accessory"), verbosity: :debug
execute *accessory.start execute *accessory.start
end end
end end
@@ -81,7 +81,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
mutating do mutating do
with_accessory(name) do |accessory| with_accessory(name) do |accessory|
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.auditor.record("Stopped #{name} accessory"), verbosity: :debug execute *KAMAL.auditor.record("Stopped #{name} accessory"), verbosity: :debug
execute *accessory.stop, raise_on_non_zero_exit: false execute *accessory.stop, raise_on_non_zero_exit: false
end end
end end
@@ -101,7 +101,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
desc "details [NAME]", "Show details about accessory on host (use NAME=all to show all accessories)" desc "details [NAME]", "Show details about accessory on host (use NAME=all to show all accessories)"
def details(name) def details(name)
if name == "all" if name == "all"
MRSK.accessory_names.each { |accessory_name| details(accessory_name) } KAMAL.accessory_names.each { |accessory_name| details(accessory_name) }
else else
with_accessory(name) do |accessory| with_accessory(name) do |accessory|
on(accessory.hosts) { puts capture_with_info(*accessory.info) } on(accessory.hosts) { puts capture_with_info(*accessory.info) }
@@ -126,14 +126,14 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
when options[:reuse] when options[:reuse]
say "Launching command from existing container...", :magenta say "Launching command from existing container...", :magenta
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
capture_with_info(*accessory.execute_in_existing_container(cmd)) capture_with_info(*accessory.execute_in_existing_container(cmd))
end end
else else
say "Launching command from new container...", :magenta say "Launching command from new container...", :magenta
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{name} accessory"), verbosity: :debug
capture_with_info(*accessory.execute_in_new_container(cmd)) capture_with_info(*accessory.execute_in_new_container(cmd))
end end
end end
@@ -171,7 +171,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
def remove(name) def remove(name)
mutating do mutating do
if name == "all" if name == "all"
MRSK.accessory_names.each { |accessory_name| remove(accessory_name) } KAMAL.accessory_names.each { |accessory_name| remove(accessory_name) }
else else
if options[:confirmed] || ask("This will remove all containers, images and data directories for #{name}. Are you sure?", limited_to: %w( y N ), default: "N") == "y" if options[:confirmed] || ask("This will remove all containers, images and data directories for #{name}. Are you sure?", limited_to: %w( y N ), default: "N") == "y"
with_accessory(name) do with_accessory(name) do
@@ -190,7 +190,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
mutating do mutating do
with_accessory(name) do |accessory| with_accessory(name) do |accessory|
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.auditor.record("Remove #{name} accessory container"), verbosity: :debug execute *KAMAL.auditor.record("Remove #{name} accessory container"), verbosity: :debug
execute *accessory.remove_container execute *accessory.remove_container
end end
end end
@@ -202,7 +202,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
mutating do mutating do
with_accessory(name) do |accessory| with_accessory(name) do |accessory|
on(accessory.hosts) do on(accessory.hosts) do
execute *MRSK.auditor.record("Removed #{name} accessory image"), verbosity: :debug execute *KAMAL.auditor.record("Removed #{name} accessory image"), verbosity: :debug
execute *accessory.remove_image execute *accessory.remove_image
end end
end end
@@ -222,7 +222,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
private private
def with_accessory(name) def with_accessory(name)
if accessory = MRSK.accessory(name) if accessory = KAMAL.accessory(name)
yield accessory yield accessory
else else
error_on_missing_accessory(name) error_on_missing_accessory(name)
@@ -230,7 +230,7 @@ class Mrsk::Cli::Accessory < Mrsk::Cli::Base
end end
def error_on_missing_accessory(name) def error_on_missing_accessory(name)
options = MRSK.accessory_names.presence options = KAMAL.accessory_names.presence
error \ error \
"No accessory by the name of '#{name}'" + "No accessory by the name of '#{name}'" +

View File

@@ -1,23 +1,23 @@
class Mrsk::Cli::App < Mrsk::Cli::Base class Kamal::Cli::App < Kamal::Cli::Base
desc "boot", "Boot app on servers (or reboot app if already running)" desc "boot", "Boot app on servers (or reboot app if already running)"
def boot def boot
mutating do mutating do
hold_lock_on_error do hold_lock_on_error do
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(version_or_latest) do |version| using_version(version_or_latest) do |version|
say "Start container with version #{version} using a #{MRSK.config.readiness_delay}s readiness delay (or reboot if already running)...", :magenta say "Start container with version #{version} using a #{KAMAL.config.readiness_delay}s readiness delay (or reboot if already running)...", :magenta
on(MRSK.hosts) do on(KAMAL.hosts) do
execute *MRSK.auditor.record("Tagging #{MRSK.config.absolute_image} as the latest image"), verbosity: :debug execute *KAMAL.auditor.record("Tagging #{KAMAL.config.absolute_image} as the latest image"), verbosity: :debug
execute *MRSK.app.tag_current_as_latest execute *KAMAL.app.tag_current_as_latest
end end
on(MRSK.hosts, **MRSK.boot_strategy) do |host| on(KAMAL.hosts, **KAMAL.boot_strategy) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
app = MRSK.app(role: role) app = KAMAL.app(role: role)
auditor = MRSK.auditor(role: role) auditor = KAMAL.auditor(role: role)
if capture_with_info(*app.container_id_for_version(version, only_running: true), raise_on_non_zero_exit: false).present? if capture_with_info(*app.container_id_for_version(version, only_running: true), raise_on_non_zero_exit: false).present?
tmp_version = "#{version}_replaced_#{SecureRandom.hex(8)}" tmp_version = "#{version}_replaced_#{SecureRandom.hex(8)}"
@@ -31,7 +31,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
old_version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip old_version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
execute *app.start_or_run(hostname: "#{host}-#{SecureRandom.hex(6)}") execute *app.start_or_run(hostname: "#{host}-#{SecureRandom.hex(6)}")
Mrsk::Utils::HealthcheckPoller.wait_for_healthy(pause_after_ready: true) { capture_with_info(*app.status(version: version)) } Kamal::Utils::HealthcheckPoller.wait_for_healthy(pause_after_ready: true) { capture_with_info(*app.status(version: version)) }
execute *app.stop(version: old_version), raise_on_non_zero_exit: false if old_version.present? execute *app.stop(version: old_version), raise_on_non_zero_exit: false if old_version.present?
end end
@@ -44,12 +44,12 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
desc "start", "Start existing app container on servers" desc "start", "Start existing app container on servers"
def start def start
mutating do mutating do
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
execute *MRSK.auditor.record("Started app version #{MRSK.config.version}"), verbosity: :debug execute *KAMAL.auditor.record("Started app version #{KAMAL.config.version}"), verbosity: :debug
execute *MRSK.app(role: role).start, raise_on_non_zero_exit: false execute *KAMAL.app(role: role).start, raise_on_non_zero_exit: false
end end
end end
end end
@@ -58,12 +58,12 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
desc "stop", "Stop app container on servers" desc "stop", "Stop app container on servers"
def stop def stop
mutating do mutating do
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
execute *MRSK.auditor.record("Stopped app", role: role), verbosity: :debug execute *KAMAL.auditor.record("Stopped app", role: role), verbosity: :debug
execute *MRSK.app(role: role).stop, raise_on_non_zero_exit: false execute *KAMAL.app(role: role).stop, raise_on_non_zero_exit: false
end end
end end
end end
@@ -72,11 +72,11 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
# FIXME: Drop in favor of just containers? # FIXME: Drop in favor of just containers?
desc "details", "Show details about app containers" desc "details", "Show details about app containers"
def details def details
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
puts_by_host host, capture_with_info(*MRSK.app(role: role).info) puts_by_host host, capture_with_info(*KAMAL.app(role: role).info)
end end
end end
end end
@@ -89,15 +89,15 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
when options[:interactive] && options[:reuse] when options[:interactive] && options[:reuse]
say "Get current version of running container...", :magenta unless options[:version] say "Get current version of running container...", :magenta unless options[:version]
using_version(options[:version] || current_running_version) do |version| using_version(options[:version] || current_running_version) do |version|
say "Launching interactive command with version #{version} via SSH from existing container on #{MRSK.primary_host}...", :magenta say "Launching interactive command with version #{version} via SSH from existing container on #{KAMAL.primary_host}...", :magenta
run_locally { exec MRSK.app(role: "web").execute_in_existing_container_over_ssh(cmd, host: MRSK.primary_host) } run_locally { exec KAMAL.app(role: "web").execute_in_existing_container_over_ssh(cmd, host: KAMAL.primary_host) }
end end
when options[:interactive] when options[:interactive]
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(version_or_latest) do |version| using_version(version_or_latest) do |version|
say "Launching interactive command with version #{version} via SSH from new container on #{MRSK.primary_host}...", :magenta say "Launching interactive command with version #{version} via SSH from new container on #{KAMAL.primary_host}...", :magenta
run_locally { exec MRSK.app.execute_in_new_container_over_ssh(cmd, host: MRSK.primary_host) } run_locally { exec KAMAL.app(role: KAMAL.roles_on(KAMAL.primary_host).first).execute_in_new_container_over_ssh(cmd, host: KAMAL.primary_host) }
end end
when options[:reuse] when options[:reuse]
@@ -105,12 +105,12 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
using_version(options[:version] || current_running_version) do |version| using_version(options[:version] || current_running_version) do |version|
say "Launching command with version #{version} from existing container...", :magenta say "Launching command with version #{version} from existing container...", :magenta
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
execute *MRSK.auditor.record("Executed cmd '#{cmd}' on app version #{version}", role: role), verbosity: :debug execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on app version #{version}", role: role), verbosity: :debug
puts_by_host host, capture_with_info(*MRSK.app(role: role).execute_in_existing_container(cmd)) puts_by_host host, capture_with_info(*KAMAL.app(role: role).execute_in_existing_container(cmd))
end end
end end
end end
@@ -119,9 +119,9 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
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(version_or_latest) do |version| using_version(version_or_latest) do |version|
say "Launching command with version #{version} from new container...", :magenta say "Launching command with version #{version} from new container...", :magenta
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
execute *MRSK.auditor.record("Executed cmd '#{cmd}' on app version #{version}"), verbosity: :debug execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on app version #{version}"), verbosity: :debug
puts_by_host host, capture_with_info(*MRSK.app.execute_in_new_container(cmd)) puts_by_host host, capture_with_info(*KAMAL.app.execute_in_new_container(cmd))
end end
end end
end end
@@ -129,7 +129,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
desc "containers", "Show app containers on servers" desc "containers", "Show app containers on servers"
def containers def containers
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.list_containers) } on(KAMAL.hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.app.list_containers) }
end end
desc "stale_containers", "Detect app stale containers" desc "stale_containers", "Detect app stale containers"
@@ -140,16 +140,16 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
cli = self cli = self
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
cli.send(:stale_versions, host: host, role: role).each do |version| cli.send(:stale_versions, host: host, role: role).each do |version|
if stop if stop
puts_by_host host, "Stopping stale container for role #{role} with version #{version}" puts_by_host host, "Stopping stale container for role #{role} with version #{version}"
execute *MRSK.app(role: role).stop(version: version), raise_on_non_zero_exit: false execute *KAMAL.app(role: role).stop(version: version), raise_on_non_zero_exit: false
else else
puts_by_host host, "Detected stale container for role #{role} with version #{version} (use `mrsk app stale_containers --stop` to stop)" puts_by_host host, "Detected stale container for role #{role} with version #{version} (use `kamal app stale_containers --stop` to stop)"
end end
end end
end end
@@ -159,7 +159,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
desc "images", "Show app images on servers" desc "images", "Show app images on servers"
def images def images
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.list_images) } on(KAMAL.hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.app.list_images) }
end end
desc "logs", "Show log lines from app on servers (use --help to show options)" desc "logs", "Show log lines from app on servers (use --help to show options)"
@@ -174,24 +174,24 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
if options[:follow] if options[:follow]
run_locally do run_locally do
info "Following logs on #{MRSK.primary_host}..." info "Following logs on #{KAMAL.primary_host}..."
MRSK.specific_roles ||= ["web"] KAMAL.specific_roles ||= ["web"]
role = MRSK.roles_on(MRSK.primary_host).first role = KAMAL.roles_on(KAMAL.primary_host).first
info MRSK.app(role: role).follow_logs(host: MRSK.primary_host, grep: grep) info KAMAL.app(role: role).follow_logs(host: KAMAL.primary_host, grep: grep)
exec MRSK.app(role: role).follow_logs(host: MRSK.primary_host, grep: grep) exec KAMAL.app(role: role).follow_logs(host: KAMAL.primary_host, grep: grep)
end end
else else
since = options[:since] since = options[:since]
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
begin begin
puts_by_host host, capture_with_info(*MRSK.app(role: role).logs(since: since, lines: lines, grep: grep)) puts_by_host host, capture_with_info(*KAMAL.app(role: role).logs(since: since, lines: lines, grep: grep))
rescue SSHKit::Command::Failed rescue SSHKit::Command::Failed
puts_by_host host, "Nothing found" puts_by_host host, "Nothing found"
end end
@@ -212,12 +212,12 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
desc "remove_container [VERSION]", "Remove app container with given version from servers", hide: true desc "remove_container [VERSION]", "Remove app container with given version from servers", hide: true
def remove_container(version) def remove_container(version)
mutating do mutating do
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
execute *MRSK.auditor.record("Removed app container with version #{version}", role: role), verbosity: :debug execute *KAMAL.auditor.record("Removed app container with version #{version}", role: role), verbosity: :debug
execute *MRSK.app(role: role).remove_container(version: version) execute *KAMAL.app(role: role).remove_container(version: version)
end end
end end
end end
@@ -226,12 +226,12 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
desc "remove_containers", "Remove all app containers from servers", hide: true desc "remove_containers", "Remove all app containers from servers", hide: true
def remove_containers def remove_containers
mutating do mutating do
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
roles = MRSK.roles_on(host) roles = KAMAL.roles_on(host)
roles.each do |role| roles.each do |role|
execute *MRSK.auditor.record("Removed all app containers", role: role), verbosity: :debug execute *KAMAL.auditor.record("Removed all app containers", role: role), verbosity: :debug
execute *MRSK.app(role: role).remove_containers execute *KAMAL.app(role: role).remove_containers
end end
end end
end end
@@ -240,36 +240,42 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
desc "remove_images", "Remove all app images from servers", hide: true desc "remove_images", "Remove all app images from servers", hide: true
def remove_images def remove_images
mutating do mutating do
on(MRSK.hosts) do on(KAMAL.hosts) do
execute *MRSK.auditor.record("Removed all app images"), verbosity: :debug execute *KAMAL.auditor.record("Removed all app images"), verbosity: :debug
execute *MRSK.app.remove_images execute *KAMAL.app.remove_images
end end
end end
end end
desc "version", "Show app version currently running on servers" desc "version", "Show app version currently running on servers"
def version def version
on(MRSK.hosts) { |host| puts_by_host host, capture_with_info(*MRSK.app.current_running_version).strip } on(KAMAL.hosts) do |host|
role = KAMAL.roles_on(host).first
puts_by_host host, capture_with_info(*KAMAL.app(role: role).current_running_version).strip
end
end end
private private
def using_version(new_version) def using_version(new_version)
if new_version if new_version
begin begin
old_version = MRSK.config.version old_version = KAMAL.config.version
MRSK.config.version = new_version KAMAL.config.version = new_version
yield new_version yield new_version
ensure ensure
MRSK.config.version = old_version KAMAL.config.version = old_version
end end
else else
yield MRSK.config.version yield KAMAL.config.version
end end
end end
def current_running_version(host: MRSK.primary_host) def current_running_version(host: KAMAL.primary_host)
version = nil version = nil
on(host) { version = capture_with_info(*MRSK.app.current_running_version).strip } on(host) do
role = KAMAL.roles_on(host).first
version = capture_with_info(*KAMAL.app(role: role).current_running_version).strip
end
version.presence version.presence
end end
@@ -277,7 +283,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
versions = nil versions = nil
on(host) do on(host) do
versions = \ versions = \
capture_with_info(*MRSK.app(role: role).list_versions, raise_on_non_zero_exit: false) capture_with_info(*KAMAL.app(role: role).list_versions, raise_on_non_zero_exit: false)
.split("\n") .split("\n")
.drop(1) .drop(1)
end end

View File

@@ -1,8 +1,8 @@
require "thor" require "thor"
require "dotenv" require "dotenv"
require "mrsk/sshkit_with_ext" require "kamal/sshkit_with_ext"
module Mrsk::Cli module Kamal::Cli
class Base < Thor class Base < Thor
include SSHKit::DSL include SSHKit::DSL
@@ -42,7 +42,7 @@ module Mrsk::Cli
end end
def initialize_commander(options) def initialize_commander(options)
MRSK.tap do |commander| KAMAL.tap do |commander|
if options[:verbose] if options[:verbose]
ENV["VERBOSE"] = "1" # For backtraces via cli/start ENV["VERBOSE"] = "1" # For backtraces via cli/start
commander.verbosity = :debug commander.verbosity = :debug
@@ -73,9 +73,9 @@ module Mrsk::Cli
end end
def mutating def mutating
return yield if MRSK.holding_lock? return yield if KAMAL.holding_lock?
MRSK.config.ensure_env_available KAMAL.config.ensure_env_available
run_hook "pre-connect" run_hook "pre-connect"
@@ -84,7 +84,7 @@ module Mrsk::Cli
begin begin
yield yield
rescue rescue
if MRSK.hold_lock_on_error? if KAMAL.hold_lock_on_error?
error " \e[31mDeploy lock was not released\e[0m" error " \e[31mDeploy lock was not released\e[0m"
else else
release_lock release_lock
@@ -99,24 +99,24 @@ module Mrsk::Cli
def acquire_lock def acquire_lock
raise_if_locked do raise_if_locked do
say "Acquiring the deploy lock...", :magenta say "Acquiring the deploy lock...", :magenta
on(MRSK.primary_host) { execute *MRSK.lock.acquire("Automatic deploy lock", MRSK.config.version), verbosity: :debug } on(KAMAL.primary_host) { execute *KAMAL.lock.acquire("Automatic deploy lock", KAMAL.config.version), verbosity: :debug }
end end
MRSK.holding_lock = true KAMAL.holding_lock = true
end end
def release_lock def release_lock
say "Releasing the deploy lock...", :magenta say "Releasing the deploy lock...", :magenta
on(MRSK.primary_host) { execute *MRSK.lock.release, verbosity: :debug } on(KAMAL.primary_host) { execute *KAMAL.lock.release, verbosity: :debug }
MRSK.holding_lock = false KAMAL.holding_lock = false
end end
def raise_if_locked def raise_if_locked
yield yield
rescue SSHKit::Runner::ExecuteError => e rescue SSHKit::Runner::ExecuteError => e
if e.message =~ /cannot create directory/ if e.message =~ /cannot create directory/
on(MRSK.primary_host) { puts capture_with_debug(*MRSK.lock.status) } on(KAMAL.primary_host) { puts capture_with_debug(*KAMAL.lock.status) }
raise LockError, "Deploy lock found" raise LockError, "Deploy lock found"
else else
raise e raise e
@@ -124,22 +124,22 @@ module Mrsk::Cli
end end
def hold_lock_on_error def hold_lock_on_error
if MRSK.hold_lock_on_error? if KAMAL.hold_lock_on_error?
yield yield
else else
MRSK.hold_lock_on_error = true KAMAL.hold_lock_on_error = true
yield yield
MRSK.hold_lock_on_error = false KAMAL.hold_lock_on_error = false
end end
end end
def run_hook(hook, **extra_details) def run_hook(hook, **extra_details)
if !options[:skip_hooks] && MRSK.hook.hook_exists?(hook) if !options[:skip_hooks] && KAMAL.hook.hook_exists?(hook)
details = { hosts: MRSK.hosts.join(","), command: command, subcommand: subcommand } details = { hosts: KAMAL.hosts.join(","), command: command, subcommand: subcommand }
say "Running the #{hook} hook...", :magenta say "Running the #{hook} hook...", :magenta
run_locally do run_locally do
MRSK.with_verbosity(:debug) { execute *MRSK.hook.run(hook, **details, **extra_details) } KAMAL.with_verbosity(:debug) { execute *KAMAL.hook.run(hook, **details, **extra_details) }
rescue SSHKit::Command::Failed rescue SSHKit::Command::Failed
raise HookError.new("Hook `#{hook}` failed") raise HookError.new("Hook `#{hook}` failed")
end end
@@ -147,20 +147,20 @@ module Mrsk::Cli
end end
def command def command
@mrsk_command ||= begin @kamal_command ||= begin
invocation_class, invocation_commands = *first_invocation invocation_class, invocation_commands = *first_invocation
if invocation_class == Mrsk::Cli::Main if invocation_class == Kamal::Cli::Main
invocation_commands[0] invocation_commands[0]
else else
Mrsk::Cli::Main.subcommand_classes.find { |command, clazz| clazz == invocation_class }[0] Kamal::Cli::Main.subcommand_classes.find { |command, clazz| clazz == invocation_class }[0]
end end
end end
end end
def subcommand def subcommand
@mrsk_subcommand ||= begin @kamal_subcommand ||= begin
invocation_class, invocation_commands = *first_invocation invocation_class, invocation_commands = *first_invocation
invocation_commands[0] if invocation_class != Mrsk::Cli::Main invocation_commands[0] if invocation_class != Kamal::Cli::Main
end end
end end

View File

@@ -1,4 +1,4 @@
class Mrsk::Cli::Build < Mrsk::Cli::Base class Kamal::Cli::Build < Kamal::Cli::Base
class BuildError < StandardError; end class BuildError < StandardError; end
desc "deliver", "Build app and push app image to registry then pull image on servers" desc "deliver", "Build app and push app image to registry then pull image on servers"
@@ -17,15 +17,21 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
verify_local_dependencies verify_local_dependencies
run_hook "pre-build" run_hook "pre-build"
if (uncommitted_changes = Kamal::Utils.uncommitted_changes).present?
say "The following paths have uncommitted changes:\n #{uncommitted_changes}", :yellow
end
run_locally do run_locally do
begin begin
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push } KAMAL.with_verbosity(:debug) do
execute *KAMAL.builder.push
end
rescue SSHKit::Command::Failed => e rescue SSHKit::Command::Failed => e
if e.message =~ /(no builder)|(no such file or directory)/ if e.message =~ /(no builder)|(no such file or directory)/
error "Missing compatible builder, so creating a new one first" error "Missing compatible builder, so creating a new one first"
if cli.create if cli.create
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push } KAMAL.with_verbosity(:debug) { execute *KAMAL.builder.push }
end end
else else
raise raise
@@ -38,10 +44,10 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
desc "pull", "Pull app image from registry onto servers" desc "pull", "Pull app image from registry onto servers"
def pull def pull
mutating do mutating do
on(MRSK.hosts) do on(KAMAL.hosts) do
execute *MRSK.auditor.record("Pulled image with version #{MRSK.config.version}"), verbosity: :debug execute *KAMAL.auditor.record("Pulled image with version #{KAMAL.config.version}"), verbosity: :debug
execute *MRSK.builder.clean, raise_on_non_zero_exit: false execute *KAMAL.builder.clean, raise_on_non_zero_exit: false
execute *MRSK.builder.pull execute *KAMAL.builder.pull
end end
end end
end end
@@ -51,8 +57,8 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
mutating do mutating do
run_locally do run_locally do
begin begin
debug "Using builder: #{MRSK.builder.name}" debug "Using builder: #{KAMAL.builder.name}"
execute *MRSK.builder.create execute *KAMAL.builder.create
rescue SSHKit::Command::Failed => e rescue SSHKit::Command::Failed => e
if e.message =~ /stderr=(.*)/ if e.message =~ /stderr=(.*)/
error "Couldn't create remote builder: #{$1}" error "Couldn't create remote builder: #{$1}"
@@ -69,8 +75,8 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
def remove def remove
mutating do mutating do
run_locally do run_locally do
debug "Using builder: #{MRSK.builder.name}" debug "Using builder: #{KAMAL.builder.name}"
execute *MRSK.builder.remove execute *KAMAL.builder.remove
end end
end end
end end
@@ -78,8 +84,8 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
desc "details", "Show build setup" desc "details", "Show build setup"
def details def details
run_locally do run_locally do
puts "Builder: #{MRSK.builder.name}" puts "Builder: #{KAMAL.builder.name}"
puts capture(*MRSK.builder.info) puts capture(*KAMAL.builder.info)
end end
end end
@@ -87,7 +93,7 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
def verify_local_dependencies def verify_local_dependencies
run_locally do run_locally do
begin begin
execute *MRSK.builder.ensure_local_dependencies_installed execute *KAMAL.builder.ensure_local_dependencies_installed
rescue SSHKit::Command::Failed => e rescue SSHKit::Command::Failed => e
build_error = e.message =~ /command not found/ ? build_error = e.message =~ /command not found/ ?
"Docker is not installed locally" : "Docker is not installed locally" :

View File

@@ -0,0 +1,20 @@
class Kamal::Cli::Healthcheck < Kamal::Cli::Base
default_command :perform
desc "perform", "Health check current app version"
def perform
on(KAMAL.primary_host) do
begin
execute *KAMAL.healthcheck.run
Kamal::Utils::HealthcheckPoller.wait_for_healthy { capture_with_info(*KAMAL.healthcheck.status) }
rescue Kamal::Utils::HealthcheckPoller::HealthcheckError => e
error capture_with_info(*KAMAL.healthcheck.logs)
error capture_with_pretty_json(*KAMAL.healthcheck.container_health_log)
raise
ensure
execute *KAMAL.healthcheck.stop, raise_on_non_zero_exit: false
execute *KAMAL.healthcheck.remove, raise_on_non_zero_exit: false
end
end
end
end

View File

@@ -1,8 +1,8 @@
class Mrsk::Cli::Lock < Mrsk::Cli::Base class Kamal::Cli::Lock < Kamal::Cli::Base
desc "status", "Report lock status" desc "status", "Report lock status"
def status def status
handle_missing_lock do handle_missing_lock do
on(MRSK.primary_host) { puts capture_with_debug(*MRSK.lock.status) } on(KAMAL.primary_host) { puts capture_with_debug(*KAMAL.lock.status) }
end end
end end
@@ -11,7 +11,7 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
def acquire def acquire
message = options[:message] message = options[:message]
raise_if_locked do raise_if_locked do
on(MRSK.primary_host) { execute *MRSK.lock.acquire(message, MRSK.config.version), verbosity: :debug } on(KAMAL.primary_host) { execute *KAMAL.lock.acquire(message, KAMAL.config.version), verbosity: :debug }
say "Acquired the deploy lock" say "Acquired the deploy lock"
end end
end end
@@ -19,7 +19,7 @@ class Mrsk::Cli::Lock < Mrsk::Cli::Base
desc "release", "Release the deploy lock" desc "release", "Release the deploy lock"
def release def release
handle_missing_lock do handle_missing_lock do
on(MRSK.primary_host) { execute *MRSK.lock.release, verbosity: :debug } on(KAMAL.primary_host) { execute *KAMAL.lock.release, verbosity: :debug }
say "Released the deploy lock" say "Released the deploy lock"
end end
end end

View File

@@ -1,10 +1,10 @@
class Mrsk::Cli::Main < Mrsk::Cli::Base class Kamal::Cli::Main < Kamal::Cli::Base
desc "setup", "Setup all accessories and deploy app to servers" desc "setup", "Setup all accessories and deploy app to servers"
def setup def setup
print_runtime do print_runtime do
mutating do mutating do
invoke "mrsk:cli:server:bootstrap" invoke "kamal:cli:server:bootstrap"
invoke "mrsk:cli:accessory:boot", [ "all" ] invoke "kamal:cli:accessory:boot", [ "all" ]
deploy deploy
end end
end end
@@ -18,31 +18,31 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
invoke_options = deploy_options invoke_options = deploy_options
say "Log into image registry...", :magenta say "Log into image registry...", :magenta
invoke "mrsk:cli:registry:login", [], invoke_options invoke "kamal:cli:registry:login", [], invoke_options
if options[:skip_push] if options[:skip_push]
say "Pull app image...", :magenta say "Pull app image...", :magenta
invoke "mrsk:cli:build:pull", [], invoke_options invoke "kamal:cli:build:pull", [], invoke_options
else else
say "Build and push app image...", :magenta say "Build and push app image...", :magenta
invoke "mrsk:cli:build:deliver", [], invoke_options invoke "kamal:cli:build:deliver", [], invoke_options
end end
run_hook "pre-deploy" run_hook "pre-deploy"
say "Ensure Traefik is running...", :magenta say "Ensure Traefik is running...", :magenta
invoke "mrsk:cli:traefik:boot", [], invoke_options invoke "kamal:cli:traefik:boot", [], invoke_options
say "Ensure app can pass healthcheck...", :magenta say "Ensure app can pass healthcheck...", :magenta
invoke "mrsk:cli:healthcheck:perform", [], invoke_options invoke "kamal:cli:healthcheck:perform", [], invoke_options
say "Detect stale containers...", :magenta say "Detect stale containers...", :magenta
invoke "mrsk:cli:app:stale_containers", [], invoke_options invoke "kamal:cli:app:stale_containers", [], invoke_options
invoke "mrsk:cli:app:boot", [], invoke_options invoke "kamal:cli:app:boot", [], invoke_options
say "Prune old containers and images...", :magenta say "Prune old containers and images...", :magenta
invoke "mrsk:cli:prune:all", [], invoke_options invoke "kamal:cli:prune:all", [], invoke_options
end end
end end
@@ -58,21 +58,21 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
if options[:skip_push] if options[:skip_push]
say "Pull app image...", :magenta say "Pull app image...", :magenta
invoke "mrsk:cli:build:pull", [], invoke_options invoke "kamal:cli:build:pull", [], invoke_options
else else
say "Build and push app image...", :magenta say "Build and push app image...", :magenta
invoke "mrsk:cli:build:deliver", [], invoke_options invoke "kamal:cli:build:deliver", [], invoke_options
end end
run_hook "pre-deploy" run_hook "pre-deploy"
say "Ensure app can pass healthcheck...", :magenta say "Ensure app can pass healthcheck...", :magenta
invoke "mrsk:cli:healthcheck:perform", [], invoke_options invoke "kamal:cli:healthcheck:perform", [], invoke_options
say "Detect stale containers...", :magenta say "Detect stale containers...", :magenta
invoke "mrsk:cli:app:stale_containers", [], invoke_options invoke "kamal:cli:app:stale_containers", [], invoke_options
invoke "mrsk:cli:app:boot", [], invoke_options invoke "kamal:cli:app:boot", [], invoke_options
end end
end end
@@ -86,16 +86,16 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
mutating do mutating do
invoke_options = deploy_options invoke_options = deploy_options
MRSK.config.version = version KAMAL.config.version = version
old_version = nil old_version = nil
if container_available?(version) if container_available?(version)
run_hook "pre-deploy" run_hook "pre-deploy"
invoke "mrsk:cli:app:boot", [], invoke_options.merge(version: version) invoke "kamal:cli:app:boot", [], invoke_options.merge(version: version)
rolled_back = true rolled_back = true
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 'kamal app containers' for available versions)", :red
end end
end end
end end
@@ -105,27 +105,27 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
desc "details", "Show details about all containers" desc "details", "Show details about all containers"
def details def details
invoke "mrsk:cli:traefik:details" invoke "kamal:cli:traefik:details"
invoke "mrsk:cli:app:details" invoke "kamal:cli:app:details"
invoke "mrsk:cli:accessory:details", [ "all" ] invoke "kamal:cli:accessory:details", [ "all" ]
end end
desc "audit", "Show audit log from servers" desc "audit", "Show audit log from servers"
def audit def audit
on(MRSK.hosts) do |host| on(KAMAL.hosts) do |host|
puts_by_host host, capture_with_info(*MRSK.auditor.reveal) puts_by_host host, capture_with_info(*KAMAL.auditor.reveal)
end end
end end
desc "config", "Show combined config (including secrets!)" desc "config", "Show combined config (including secrets!)"
def config def config
run_locally do run_locally do
puts Mrsk::Utils.redacted(MRSK.config.to_h).to_yaml puts Kamal::Utils.redacted(KAMAL.config.to_h).to_yaml
end end
end end
desc "init", "Create config stub in config/deploy.yml and env stub in .env" 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" option :bundle, type: :boolean, default: false, desc: "Add Kamal to the Gemfile and create a bin/kamal binstub"
def init def init
require "fileutils" require "fileutils"
@@ -142,24 +142,24 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
puts "Created .env file" puts "Created .env file"
end end
unless (hooks_dir = Pathname.new(File.expand_path(".mrsk/hooks"))).exist? unless (hooks_dir = Pathname.new(File.expand_path(".kamal/hooks"))).exist?
hooks_dir.mkpath hooks_dir.mkpath
Pathname.new(File.expand_path("templates/sample_hooks", __dir__)).each_child do |sample_hook| Pathname.new(File.expand_path("templates/sample_hooks", __dir__)).each_child do |sample_hook|
FileUtils.cp sample_hook, hooks_dir, preserve: true FileUtils.cp sample_hook, hooks_dir, preserve: true
end end
puts "Created sample hooks in .mrsk/hooks" puts "Created sample hooks in .kamal/hooks"
end end
if options[:bundle] if options[:bundle]
if (binstub = Pathname.new(File.expand_path("bin/mrsk"))).exist? if (binstub = Pathname.new(File.expand_path("bin/kamal"))).exist?
puts "Binstub already exists in bin/mrsk (remove first to create a new one)" puts "Binstub already exists in bin/kamal (remove first to create a new one)"
else else
puts "Adding MRSK to Gemfile and bundle..." puts "Adding Kamal to Gemfile and bundle..."
run_locally do run_locally do
execute :bundle, :add, :mrsk execute :bundle, :add, :kamal
execute :bundle, :binstubs, :mrsk execute :bundle, :binstubs, :kamal
end end
puts "Created binstub file in bin/mrsk" puts "Created binstub file in bin/kamal"
end end
end end
end end
@@ -182,52 +182,52 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
def remove def remove
mutating do mutating do
if options[:confirmed] || ask("This will remove all containers and images. Are you sure?", 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 "kamal:cli:traefik:remove", [], options.without(:confirmed)
invoke "mrsk:cli:app:remove", [], options.without(:confirmed) invoke "kamal:cli:app:remove", [], options.without(:confirmed)
invoke "mrsk:cli:accessory:remove", [ "all" ], options invoke "kamal:cli:accessory:remove", [ "all" ], options
invoke "mrsk:cli:registry:logout", [], options.without(:confirmed) invoke "kamal:cli:registry:logout", [], options.without(:confirmed)
end end
end end
end end
desc "version", "Show MRSK version" desc "version", "Show Kamal version"
def version def version
puts Mrsk::VERSION puts Kamal::VERSION
end end
desc "accessory", "Manage accessories (db/redis/search)" desc "accessory", "Manage accessories (db/redis/search)"
subcommand "accessory", Mrsk::Cli::Accessory subcommand "accessory", Kamal::Cli::Accessory
desc "app", "Manage application" desc "app", "Manage application"
subcommand "app", Mrsk::Cli::App subcommand "app", Kamal::Cli::App
desc "build", "Build application image" desc "build", "Build application image"
subcommand "build", Mrsk::Cli::Build subcommand "build", Kamal::Cli::Build
desc "healthcheck", "Healthcheck application" desc "healthcheck", "Healthcheck application"
subcommand "healthcheck", Mrsk::Cli::Healthcheck subcommand "healthcheck", Kamal::Cli::Healthcheck
desc "lock", "Manage the deploy lock" desc "lock", "Manage the deploy lock"
subcommand "lock", Mrsk::Cli::Lock subcommand "lock", Kamal::Cli::Lock
desc "prune", "Prune old application images and containers" desc "prune", "Prune old application images and containers"
subcommand "prune", Mrsk::Cli::Prune subcommand "prune", Kamal::Cli::Prune
desc "registry", "Login and -out of the image registry" desc "registry", "Login and -out of the image registry"
subcommand "registry", Mrsk::Cli::Registry subcommand "registry", Kamal::Cli::Registry
desc "server", "Bootstrap servers with curl and Docker" desc "server", "Bootstrap servers with curl and Docker"
subcommand "server", Mrsk::Cli::Server subcommand "server", Kamal::Cli::Server
desc "traefik", "Manage Traefik load balancer" desc "traefik", "Manage Traefik load balancer"
subcommand "traefik", Mrsk::Cli::Traefik subcommand "traefik", Kamal::Cli::Traefik
private private
def container_available?(version) def container_available?(version)
begin begin
on(MRSK.hosts) do on(KAMAL.hosts) do
MRSK.roles_on(host).each do |role| KAMAL.roles_on(host).each do |role|
container_id = capture_with_info(*MRSK.app(role: role).container_id_for_version(version)) container_id = capture_with_info(*KAMAL.app(role: role).container_id_for_version(version))
raise "Container not found" unless container_id.present? raise "Container not found" unless container_id.present?
end end
end end
@@ -244,6 +244,6 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
end end
def deploy_options def deploy_options
{ "version" => MRSK.config.version }.merge(options.without("skip_push")) { "version" => KAMAL.config.version }.merge(options.without("skip_push"))
end end
end end

30
lib/kamal/cli/prune.rb Normal file
View File

@@ -0,0 +1,30 @@
class Kamal::Cli::Prune < Kamal::Cli::Base
desc "all", "Prune unused images and stopped containers"
def all
mutating do
containers
images
end
end
desc "images", "Prune dangling images"
def images
mutating do
on(KAMAL.hosts) do
execute *KAMAL.auditor.record("Pruned images"), verbosity: :debug
execute *KAMAL.prune.dangling_images
execute *KAMAL.prune.tagged_images
end
end
end
desc "containers", "Prune all stopped containers, except the last 5"
def containers
mutating do
on(KAMAL.hosts) do
execute *KAMAL.auditor.record("Pruned containers"), verbosity: :debug
execute *KAMAL.prune.containers
end
end
end
end

View File

@@ -1,8 +1,8 @@
class Mrsk::Cli::Registry < Mrsk::Cli::Base class Kamal::Cli::Registry < Kamal::Cli::Base
desc "login", "Log in to registry locally and remotely" desc "login", "Log in to registry locally and remotely"
def login def login
run_locally { execute *MRSK.registry.login } run_locally { execute *KAMAL.registry.login }
on(MRSK.hosts) { execute *MRSK.registry.login } on(KAMAL.hosts) { execute *KAMAL.registry.login }
# FIXME: This rescue needed? # FIXME: This rescue needed?
rescue ArgumentError => e rescue ArgumentError => e
puts e.message puts e.message
@@ -10,7 +10,7 @@ class Mrsk::Cli::Registry < Mrsk::Cli::Base
desc "logout", "Log out of registry remotely" desc "logout", "Log out of registry remotely"
def logout def logout
on(MRSK.hosts) { execute *MRSK.registry.logout } on(KAMAL.hosts) { execute *KAMAL.registry.logout }
# FIXME: This rescue needed? # FIXME: This rescue needed?
rescue ArgumentError => e rescue ArgumentError => e
puts e.message puts e.message

View File

@@ -1,13 +1,13 @@
class Mrsk::Cli::Server < Mrsk::Cli::Base class Kamal::Cli::Server < Kamal::Cli::Base
desc "bootstrap", "Set up Docker to run MRSK apps" desc "bootstrap", "Set up Docker to run Kamal apps"
def bootstrap def bootstrap
missing = [] missing = []
on(MRSK.hosts | MRSK.accessory_hosts) do |host| on(KAMAL.hosts | KAMAL.accessory_hosts) do |host|
unless execute(*MRSK.docker.installed?, raise_on_non_zero_exit: false) unless execute(*KAMAL.docker.installed?, raise_on_non_zero_exit: false)
if execute(*MRSK.docker.superuser?, raise_on_non_zero_exit: false) if execute(*KAMAL.docker.superuser?, raise_on_non_zero_exit: false)
info "Missing Docker on #{host}. Installing…" info "Missing Docker on #{host}. Installing…"
execute *MRSK.docker.install execute *KAMAL.docker.install
else else
missing << host missing << host
end end

View File

@@ -16,7 +16,7 @@ registry:
# Always use an access token rather than real password when possible. # Always use an access token rather than real password when possible.
password: password:
- MRSK_REGISTRY_PASSWORD - KAMAL_REGISTRY_PASSWORD
# Inject ENV variables into containers (secrets come from .env). # Inject ENV variables into containers (secrets come from .env).
# env: # env:

View File

@@ -0,0 +1,14 @@
#!/bin/sh
# A sample post-deploy hook
#
# These environment variables are available:
# KAMAL_RECORDED_AT
# KAMAL_PERFORMER
# KAMAL_VERSION
# KAMAL_HOSTS
# KAMAL_ROLE (if set)
# KAMAL_DESTINATION (if set)
# KAMAL_RUNTIME
echo "$KAMAL_PERFORMER deployed $KAMAL_VERSION to $KAMAL_DESTINATION in $KAMAL_RUNTIME seconds"

View File

@@ -9,12 +9,12 @@
# 4. The version we are deploying matches the remote # 4. The version we are deploying matches the remote
# #
# These environment variables are available: # These environment variables are available:
# MRSK_RECORDED_AT # KAMAL_RECORDED_AT
# MRSK_PERFORMER # KAMAL_PERFORMER
# MRSK_VERSION # KAMAL_VERSION
# MRSK_HOSTS # KAMAL_HOSTS
# MRSK_ROLE (if set) # KAMAL_ROLE (if set)
# MRSK_DESTINATION (if set) # KAMAL_DESTINATION (if set)
if [ -n "$(git status --porcelain)" ]; then if [ -n "$(git status --porcelain)" ]; then
echo "Git checkout is not clean, aborting..." >&2 echo "Git checkout is not clean, aborting..." >&2
@@ -43,8 +43,8 @@ if [ -z "$remote_head" ]; then
exit 1 exit 1
fi fi
if [ "$MRSK_VERSION" != "$remote_head" ]; then if [ "$KAMAL_VERSION" != "$remote_head" ]; then
echo "Version ($MRSK_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2 echo "Version ($KAMAL_VERSION) does not match remote HEAD ($remote_head), aborting..." >&2
exit 1 exit 1
fi fi

View File

@@ -5,15 +5,15 @@
# Warms DNS before connecting to hosts in parallel # Warms DNS before connecting to hosts in parallel
# #
# These environment variables are available: # These environment variables are available:
# MRSK_RECORDED_AT # KAMAL_RECORDED_AT
# MRSK_PERFORMER # KAMAL_PERFORMER
# MRSK_VERSION # KAMAL_VERSION
# MRSK_HOSTS # KAMAL_HOSTS
# MRSK_ROLE (if set) # KAMAL_ROLE (if set)
# MRSK_DESTINATION (if set) # KAMAL_DESTINATION (if set)
# MRSK_RUNTIME # KAMAL_RUNTIME
hosts = ENV["MRSK_HOSTS"].split(",") hosts = ENV["KAMAL_HOSTS"].split(",")
results = nil results = nil
max = 3 max = 3

View File

@@ -7,17 +7,17 @@
# Fails unless the combined status is "success" # Fails unless the combined status is "success"
# #
# These environment variables are available: # These environment variables are available:
# MRSK_RECORDED_AT # KAMAL_RECORDED_AT
# MRSK_PERFORMER # KAMAL_PERFORMER
# MRSK_VERSION # KAMAL_VERSION
# MRSK_HOSTS # KAMAL_HOSTS
# MRSK_COMMAND # KAMAL_COMMAND
# MRSK_SUBCOMMAND # KAMAL_SUBCOMMAND
# MRSK_ROLE (if set) # KAMAL_ROLE (if set)
# MRSK_DESTINATION (if set) # KAMAL_DESTINATION (if set)
# Only check the build status for production deployments # Only check the build status for production deployments
if ENV["MRSK_COMMAND"] == "rollback" || ENV["MRSK_DESTINATION"] != "production" if ENV["KAMAL_COMMAND"] == "rollback" || ENV["KAMAL_DESTINATION"] != "production"
exit 0 exit 0
end end

View File

@@ -0,0 +1,2 @@
KAMAL_REGISTRY_PASSWORD=change-this
RAILS_MASTER_KEY=another-env

View File

@@ -1,10 +1,10 @@
class Mrsk::Cli::Traefik < Mrsk::Cli::Base class Kamal::Cli::Traefik < Kamal::Cli::Base
desc "boot", "Boot Traefik on servers" desc "boot", "Boot Traefik on servers"
def boot def boot
mutating do mutating do
on(MRSK.traefik_hosts) do on(KAMAL.traefik_hosts) do
execute *MRSK.registry.login execute *KAMAL.registry.login
execute *MRSK.traefik.run, raise_on_non_zero_exit: false execute *KAMAL.traefik.start_or_run
end end
end end
end end
@@ -13,12 +13,12 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel" option :rolling, type: :boolean, default: false, desc: "Reboot traefik on hosts in sequence, rather than in parallel"
def reboot def reboot
mutating do mutating do
on(MRSK.traefik_hosts, in: options[:rolling] ? :sequence : :parallel) do on(KAMAL.traefik_hosts, in: options[:rolling] ? :sequence : :parallel) do
execute *MRSK.auditor.record("Rebooted traefik"), verbosity: :debug execute *KAMAL.auditor.record("Rebooted traefik"), verbosity: :debug
execute *MRSK.registry.login execute *KAMAL.registry.login
execute *MRSK.traefik.stop, raise_on_non_zero_exit: false execute *KAMAL.traefik.stop
execute *MRSK.traefik.remove_container execute *KAMAL.traefik.remove_container
execute *MRSK.traefik.run, raise_on_non_zero_exit: false execute *KAMAL.traefik.run
end end
end end
end end
@@ -26,9 +26,9 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "start", "Start existing Traefik container on servers" desc "start", "Start existing Traefik container on servers"
def start def start
mutating do mutating do
on(MRSK.traefik_hosts) do on(KAMAL.traefik_hosts) do
execute *MRSK.auditor.record("Started traefik"), verbosity: :debug execute *KAMAL.auditor.record("Started traefik"), verbosity: :debug
execute *MRSK.traefik.start, raise_on_non_zero_exit: false execute *KAMAL.traefik.start
end end
end end
end end
@@ -36,9 +36,9 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "stop", "Stop existing Traefik container on servers" desc "stop", "Stop existing Traefik container on servers"
def stop def stop
mutating do mutating do
on(MRSK.traefik_hosts) do on(KAMAL.traefik_hosts) do
execute *MRSK.auditor.record("Stopped traefik"), verbosity: :debug execute *KAMAL.auditor.record("Stopped traefik"), verbosity: :debug
execute *MRSK.traefik.stop, raise_on_non_zero_exit: false execute *KAMAL.traefik.stop
end end
end end
end end
@@ -53,7 +53,7 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "details", "Show details about Traefik container from servers" desc "details", "Show details about Traefik container from servers"
def details def details
on(MRSK.traefik_hosts) { |host| puts_by_host host, capture_with_info(*MRSK.traefik.info), type: "Traefik" } on(KAMAL.traefik_hosts) { |host| puts_by_host host, capture_with_info(*KAMAL.traefik.info), type: "Traefik" }
end end
desc "logs", "Show log lines from Traefik on servers" desc "logs", "Show log lines from Traefik on servers"
@@ -66,16 +66,16 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
if options[:follow] if options[:follow]
run_locally do run_locally do
info "Following logs on #{MRSK.primary_host}..." info "Following logs on #{KAMAL.primary_host}..."
info MRSK.traefik.follow_logs(host: MRSK.primary_host, grep: grep) info KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep)
exec MRSK.traefik.follow_logs(host: MRSK.primary_host, grep: grep) exec KAMAL.traefik.follow_logs(host: KAMAL.primary_host, grep: grep)
end end
else else
since = options[:since] since = options[:since]
lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set lines = options[:lines].presence || ((since || grep) ? nil : 100) # Default to 100 lines if since or grep isn't set
on(MRSK.traefik_hosts) do |host| on(KAMAL.traefik_hosts) do |host|
puts_by_host host, capture(*MRSK.traefik.logs(since: since, lines: lines, grep: grep)), type: "Traefik" puts_by_host host, capture(*KAMAL.traefik.logs(since: since, lines: lines, grep: grep)), type: "Traefik"
end end
end end
end end
@@ -92,9 +92,9 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "remove_container", "Remove Traefik container from servers", hide: true desc "remove_container", "Remove Traefik container from servers", hide: true
def remove_container def remove_container
mutating do mutating do
on(MRSK.traefik_hosts) do on(KAMAL.traefik_hosts) do
execute *MRSK.auditor.record("Removed traefik container"), verbosity: :debug execute *KAMAL.auditor.record("Removed traefik container"), verbosity: :debug
execute *MRSK.traefik.remove_container execute *KAMAL.traefik.remove_container
end end
end end
end end
@@ -102,9 +102,9 @@ class Mrsk::Cli::Traefik < Mrsk::Cli::Base
desc "remove_image", "Remove Traefik image from servers", hide: true desc "remove_image", "Remove Traefik image from servers", hide: true
def remove_image def remove_image
mutating do mutating do
on(MRSK.traefik_hosts) do on(KAMAL.traefik_hosts) do
execute *MRSK.auditor.record("Removed traefik image"), verbosity: :debug execute *KAMAL.auditor.record("Removed traefik image"), verbosity: :debug
execute *MRSK.traefik.remove_image execute *KAMAL.traefik.remove_image
end end
end end
end end

View File

@@ -1,7 +1,7 @@
require "active_support/core_ext/enumerable" require "active_support/core_ext/enumerable"
require "active_support/core_ext/module/delegation" require "active_support/core_ext/module/delegation"
class Mrsk::Commander class Kamal::Commander
attr_accessor :verbosity, :holding_lock, :hold_lock_on_error attr_accessor :verbosity, :holding_lock, :hold_lock_on_error
def initialize def initialize
@@ -11,7 +11,7 @@ class Mrsk::Commander
end end
def config def config
@config ||= Mrsk::Configuration.create_from(**@config_kwargs).tap do |config| @config ||= Kamal::Configuration.create_from(**@config_kwargs).tap do |config|
@config_kwargs = nil @config_kwargs = nil
configure_sshkit_with(config) configure_sshkit_with(config)
end end
@@ -77,47 +77,47 @@ class Mrsk::Commander
def app(role: nil) def app(role: nil)
Mrsk::Commands::App.new(config, role: role) Kamal::Commands::App.new(config, role: role)
end end
def accessory(name) def accessory(name)
Mrsk::Commands::Accessory.new(config, name: name) Kamal::Commands::Accessory.new(config, name: name)
end end
def auditor(**details) def auditor(**details)
Mrsk::Commands::Auditor.new(config, **details) Kamal::Commands::Auditor.new(config, **details)
end end
def builder def builder
@builder ||= Mrsk::Commands::Builder.new(config) @builder ||= Kamal::Commands::Builder.new(config)
end end
def docker def docker
@docker ||= Mrsk::Commands::Docker.new(config) @docker ||= Kamal::Commands::Docker.new(config)
end end
def healthcheck def healthcheck
@healthcheck ||= Mrsk::Commands::Healthcheck.new(config) @healthcheck ||= Kamal::Commands::Healthcheck.new(config)
end end
def hook def hook
@hook ||= Mrsk::Commands::Hook.new(config) @hook ||= Kamal::Commands::Hook.new(config)
end end
def lock def lock
@lock ||= Mrsk::Commands::Lock.new(config) @lock ||= Kamal::Commands::Lock.new(config)
end end
def prune def prune
@prune ||= Mrsk::Commands::Prune.new(config) @prune ||= Kamal::Commands::Prune.new(config)
end end
def registry def registry
@registry ||= Mrsk::Commands::Registry.new(config) @registry ||= Kamal::Commands::Registry.new(config)
end end
def traefik def traefik
@traefik ||= Mrsk::Commands::Traefik.new(config) @traefik ||= Kamal::Commands::Traefik.new(config)
end end
def with_verbosity(level) def with_verbosity(level)
@@ -143,7 +143,11 @@ class Mrsk::Commander
private private
# Lazy setup of SSHKit # Lazy setup of SSHKit
def configure_sshkit_with(config) def configure_sshkit_with(config)
SSHKit::Backend::Netssh.configure { |ssh| ssh.ssh_options = config.ssh_options } SSHKit::Backend::Netssh.pool.idle_timeout = config.sshkit.pool_idle_timeout
SSHKit::Backend::Netssh.configure do |sshkit|
sshkit.max_concurrent_starts = config.sshkit.max_concurrent_starts
sshkit.ssh_options = config.ssh.options
end
SSHKit.config.command_map[:docker] = "docker" # No need to use /usr/bin/env, just clogs up the logs SSHKit.config.command_map[:docker] = "docker" # No need to use /usr/bin/env, just clogs up the logs
SSHKit.config.output_verbosity = verbosity SSHKit.config.output_verbosity = verbosity
end end

2
lib/kamal/commands.rb Normal file
View File

@@ -0,0 +1,2 @@
module Kamal::Commands
end

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Accessory < Mrsk::Commands::Base class Kamal::Commands::Accessory < Kamal::Commands::Base
attr_reader :accessory_config attr_reader :accessory_config
delegate :service_name, :image, :hosts, :port, :files, :directories, :cmd, delegate :service_name, :image, :hosts, :port, :files, :directories, :cmd,
:publish_args, :env_args, :volume_args, :label_args, :option_args, to: :accessory_config :publish_args, :env_args, :volume_args, :label_args, :option_args, to: :accessory_config

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::App < Mrsk::Commands::Base class Kamal::Commands::App < Kamal::Commands::Base
ACTIVE_DOCKER_STATUSES = [ :running, :restarting ] ACTIVE_DOCKER_STATUSES = [ :running, :restarting ]
attr_reader :role attr_reader :role
@@ -20,7 +20,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
"--restart unless-stopped", "--restart unless-stopped",
"--name", container_name, "--name", container_name,
*(["--hostname", hostname] if hostname), *(["--hostname", hostname] if hostname),
"-e", "MRSK_CONTAINER_NAME=\"#{container_name}\"", "-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
*role.env_args, *role.env_args,
*role.health_check_args, *role.health_check_args,
*config.logging_args, *config.logging_args,
@@ -76,11 +76,14 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
end end
def execute_in_new_container(*command, interactive: false) def execute_in_new_container(*command, interactive: false)
role = config.role(self.role)
docker :run, docker :run,
("-it" if interactive), ("-it" if interactive),
"--rm", "--rm",
*config.env_args, *config.env_args,
*config.volume_args, *config.volume_args,
*role&.option_args,
config.absolute_image, config.absolute_image,
*command *command
end end
@@ -109,8 +112,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
def list_versions(*docker_args, statuses: nil) def list_versions(*docker_args, statuses: nil)
pipe \ pipe \
docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'), docker(:ps, *filter_args(statuses: statuses), *docker_args, "--format", '"{{.Names}}"'),
%(grep -oE "\\-[^-]+$"), # Extract SHA from "service-role-dest-SHA" %(while read line; do echo ${line##{service_role_dest}-}; done) # Extract SHA from "service-role-dest-SHA"
%(cut -c 2-)
end end
def list_containers def list_containers
@@ -157,6 +159,10 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
argumentize "--filter", filters(statuses: statuses) argumentize "--filter", filters(statuses: statuses)
end end
def service_role_dest
[config.service, role, config.destination].compact.join("-")
end
def filters(statuses: nil) def filters(statuses: nil)
[ "label=service=#{config.service}" ].tap do |filters| [ "label=service=#{config.service}" ].tap do |filters|
filters << "label=destination=#{config.destination}" if config.destination filters << "label=destination=#{config.destination}" if config.destination

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Auditor < Mrsk::Commands::Base class Kamal::Commands::Auditor < Kamal::Commands::Base
attr_reader :details attr_reader :details
def initialize(config, **details) def initialize(config, **details)
@@ -19,7 +19,7 @@ class Mrsk::Commands::Auditor < Mrsk::Commands::Base
private private
def audit_log_file def audit_log_file
[ "mrsk", config.service, config.destination, "audit.log" ].compact.join("-") [ "kamal", config.service, config.destination, "audit.log" ].compact.join("-")
end end
def audit_tags(**details) def audit_tags(**details)

View File

@@ -1,6 +1,6 @@
module Mrsk::Commands module Kamal::Commands
class Base class Base
delegate :sensitive, :argumentize, to: Mrsk::Utils delegate :sensitive, :argumentize, to: Kamal::Utils
DOCKER_HEALTH_STATUS_FORMAT = "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'" DOCKER_HEALTH_STATUS_FORMAT = "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'"
DOCKER_HEALTH_LOG_FORMAT = "'{{json .State.Health}}'" DOCKER_HEALTH_LOG_FORMAT = "'{{json .State.Health}}'"
@@ -13,12 +13,12 @@ module Mrsk::Commands
def run_over_ssh(*command, host:) def run_over_ssh(*command, host:)
"ssh".tap do |cmd| "ssh".tap do |cmd|
if config.ssh_proxy && config.ssh_proxy.is_a?(Net::SSH::Proxy::Jump) if config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Jump)
cmd << " -J #{config.ssh_proxy.jump_proxies}" cmd << " -J #{config.ssh.proxy.jump_proxies}"
elsif config.ssh_proxy && config.ssh_proxy.is_a?(Net::SSH::Proxy::Command) elsif config.ssh.proxy && config.ssh.proxy.is_a?(Net::SSH::Proxy::Command)
cmd << " -o ProxyCommand='#{config.ssh_proxy.command_line_template}'" cmd << " -o ProxyCommand='#{config.ssh.proxy.command_line_template}'"
end end
cmd << " -t #{config.ssh_user}@#{host} '#{command.join(" ")}'" cmd << " -t #{config.ssh.user}@#{host} '#{command.join(" ")}'"
end end
end end
@@ -59,7 +59,7 @@ module Mrsk::Commands
end end
def tags(**details) def tags(**details)
Mrsk::Tags.from_config(config, **details) Kamal::Tags.from_config(config, **details)
end end
end end
end end

View File

@@ -1,8 +1,10 @@
class Mrsk::Commands::Builder < Mrsk::Commands::Base require "active_support/core_ext/string/filters"
class Kamal::Commands::Builder < Kamal::Commands::Base
delegate :create, :remove, :push, :clean, :pull, :info, to: :target delegate :create, :remove, :push, :clean, :pull, :info, to: :target
def name def name
target.class.to_s.remove("Mrsk::Commands::Builder::").underscore.inquiry target.class.to_s.remove("Kamal::Commands::Builder::").underscore.inquiry
end end
def target def target
@@ -21,23 +23,23 @@ class Mrsk::Commands::Builder < Mrsk::Commands::Base
end end
def native def native
@native ||= Mrsk::Commands::Builder::Native.new(config) @native ||= Kamal::Commands::Builder::Native.new(config)
end end
def native_cached def native_cached
@native ||= Mrsk::Commands::Builder::Native::Cached.new(config) @native ||= Kamal::Commands::Builder::Native::Cached.new(config)
end end
def native_remote def native_remote
@native ||= Mrsk::Commands::Builder::Native::Remote.new(config) @native ||= Kamal::Commands::Builder::Native::Remote.new(config)
end end
def multiarch def multiarch
@multiarch ||= Mrsk::Commands::Builder::Multiarch.new(config) @multiarch ||= Kamal::Commands::Builder::Multiarch.new(config)
end end
def multiarch_remote def multiarch_remote
@multiarch_remote ||= Mrsk::Commands::Builder::Multiarch::Remote.new(config) @multiarch_remote ||= Kamal::Commands::Builder::Multiarch::Remote.new(config)
end end

View File

@@ -1,8 +1,8 @@
class Mrsk::Commands::Builder::Base < Mrsk::Commands::Base class Kamal::Commands::Builder::Base < Kamal::Commands::Base
class BuilderError < StandardError; end class BuilderError < StandardError; end
delegate :argumentize, to: Mrsk::Utils delegate :argumentize, to: Kamal::Utils
delegate :args, :secrets, :dockerfile, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, to: :builder_config delegate :args, :secrets, :dockerfile, :local_arch, :local_host, :remote_arch, :remote_host, :cache_from, :cache_to, to: :builder_config
def clean def clean

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Builder::Multiarch < Mrsk::Commands::Builder::Base class Kamal::Commands::Builder::Multiarch < Kamal::Commands::Builder::Base
def create def create
docker :buildx, :create, "--use", "--name", builder_name docker :buildx, :create, "--use", "--name", builder_name
end end
@@ -24,6 +24,6 @@ class Mrsk::Commands::Builder::Multiarch < Mrsk::Commands::Builder::Base
private private
def builder_name def builder_name
"mrsk-#{config.service}-multiarch" "kamal-#{config.service}-multiarch"
end end
end end

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Builder::Multiarch::Remote < Mrsk::Commands::Builder::Multiarch class Kamal::Commands::Builder::Multiarch::Remote < Kamal::Commands::Builder::Multiarch
def create def create
combine \ combine \
create_contexts, create_contexts,

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Builder::Native < Mrsk::Commands::Builder::Base class Kamal::Commands::Builder::Native < Kamal::Commands::Builder::Base
def create def create
# No-op on native without cache # No-op on native without cache
end end

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Builder::Native::Cached < Mrsk::Commands::Builder::Native class Kamal::Commands::Builder::Native::Cached < Kamal::Commands::Builder::Native
def create def create
docker :buildx, :create, "--use", "--driver=docker-container" docker :buildx, :create, "--use", "--driver=docker-container"
end end

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Builder::Native::Remote < Mrsk::Commands::Builder::Native class Kamal::Commands::Builder::Native::Remote < Kamal::Commands::Builder::Native
def create def create
chain \ chain \
create_context, create_context,
@@ -29,7 +29,7 @@ class Mrsk::Commands::Builder::Native::Remote < Mrsk::Commands::Builder::Native
private private
def builder_name def builder_name
"mrsk-#{config.service}-native-remote" "kamal-#{config.service}-native-remote"
end end
def builder_name_with_arch def builder_name_with_arch

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Docker < Mrsk::Commands::Base class Kamal::Commands::Docker < Kamal::Commands::Base
# Install Docker using the https://github.com/docker/docker-install convenience script. # Install Docker using the https://github.com/docker/docker-install convenience script.
def install def install
pipe [ :curl, "-fsSL", "https://get.docker.com" ], :sh pipe [ :curl, "-fsSL", "https://get.docker.com" ], :sh

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Healthcheck < Mrsk::Commands::Base class Kamal::Commands::Healthcheck < Kamal::Commands::Base
EXPOSED_PORT = 3999 EXPOSED_PORT = 3999
def run def run
@@ -9,7 +9,7 @@ class Mrsk::Commands::Healthcheck < Mrsk::Commands::Base
"--name", container_name_with_version, "--name", container_name_with_version,
"--publish", "#{EXPOSED_PORT}:#{config.healthcheck["port"]}", "--publish", "#{EXPOSED_PORT}:#{config.healthcheck["port"]}",
"--label", "service=#{container_name}", "--label", "service=#{container_name}",
"-e", "MRSK_CONTAINER_NAME=\"#{container_name}\"", "-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
*web.env_args, *web.env_args,
*web.health_check_args, *web.health_check_args,
*config.volume_args, *config.volume_args,

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Hook < Mrsk::Commands::Base class Kamal::Commands::Hook < Kamal::Commands::Base
def run(hook, **details) def run(hook, **details)
[ hook_file(hook), env: tags(**details).env ] [ hook_file(hook), env: tags(**details).env ]
end end

View File

@@ -1,7 +1,7 @@
require "active_support/duration" require "active_support/duration"
require "time" require "time"
class Mrsk::Commands::Lock < Mrsk::Commands::Base class Kamal::Commands::Lock < Kamal::Commands::Base
def acquire(message, version) def acquire(message, version)
combine \ combine \
[:mkdir, lock_dir], [:mkdir, lock_dir],
@@ -40,7 +40,7 @@ class Mrsk::Commands::Lock < Mrsk::Commands::Base
end end
def lock_dir def lock_dir
"mrsk_lock-#{config.service}" "kamal_lock-#{config.service}"
end end
def lock_details_file def lock_details_file

View File

@@ -1,7 +1,7 @@
require "active_support/duration" require "active_support/duration"
require "active_support/core_ext/numeric/time" require "active_support/core_ext/numeric/time"
class Mrsk::Commands::Prune < Mrsk::Commands::Base class Kamal::Commands::Prune < Kamal::Commands::Base
def dangling_images def dangling_images
docker :image, :prune, "--force", "--filter", "label=service=#{config.service}", "--filter", "dangling=true" docker :image, :prune, "--force", "--filter", "label=service=#{config.service}", "--filter", "dangling=true"
end end

View File

@@ -1,4 +1,4 @@
class Mrsk::Commands::Registry < Mrsk::Commands::Base class Kamal::Commands::Registry < Kamal::Commands::Base
delegate :registry, to: :config delegate :registry, to: :config
def login def login

View File

@@ -1,5 +1,5 @@
class Mrsk::Commands::Traefik < Mrsk::Commands::Base class Kamal::Commands::Traefik < Kamal::Commands::Base
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Kamal::Utils
DEFAULT_IMAGE = "traefik:v2.9" DEFAULT_IMAGE = "traefik:v2.9"
CONTAINER_PORT = 80 CONTAINER_PORT = 80
@@ -11,7 +11,7 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
docker :run, "--name traefik", docker :run, "--name traefik",
"--detach", "--detach",
"--restart", "unless-stopped", "--restart", "unless-stopped",
"--publish", port, *publish_args,
"--volume", "/var/run/docker.sock:/var/run/docker.sock", "--volume", "/var/run/docker.sock:/var/run/docker.sock",
*env_args, *env_args,
*config.logging_args, *config.logging_args,
@@ -30,6 +30,10 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
docker :container, :stop, "traefik" docker :container, :stop, "traefik"
end end
def start_or_run
combine start, run, by: "||"
end
def info def info
docker :ps, "--filter", "name=^traefik$" docker :ps, "--filter", "name=^traefik$"
end end
@@ -60,6 +64,10 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
end end
private private
def publish_args
argumentize "--publish", port unless config.traefik["publish"] == false
end
def label_args def label_args
argumentize "--label", labels argumentize "--label", labels
end end

View File

@@ -5,9 +5,9 @@ require "pathname"
require "erb" require "erb"
require "net/ssh/proxy/jump" require "net/ssh/proxy/jump"
class Mrsk::Configuration class Kamal::Configuration
delegate :service, :image, :servers, :env, :labels, :registry, :stop_wait_time, :hooks_path, to: :raw_config, allow_nil: true delegate :service, :image, :servers, :env, :labels, :registry, :stop_wait_time, :hooks_path, to: :raw_config, allow_nil: true
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Kamal::Utils
attr_accessor :destination attr_accessor :destination
attr_accessor :raw_config attr_accessor :raw_config
@@ -54,7 +54,7 @@ class Mrsk::Configuration
end end
def abbreviated_version def abbreviated_version
Mrsk::Utils.abbreviate_version(version) Kamal::Utils.abbreviate_version(version)
end end
@@ -67,7 +67,7 @@ class Mrsk::Configuration
end end
def accessories def accessories
@accessories ||= raw_config.accessories&.keys&.collect { |name| Mrsk::Configuration::Accessory.new(name, config: self) } || [] @accessories ||= raw_config.accessories&.keys&.collect { |name| Kamal::Configuration::Accessory.new(name, config: self) } || []
end end
def accessory(name) def accessory(name)
@@ -88,7 +88,7 @@ class Mrsk::Configuration
end end
def boot def boot
Mrsk::Configuration::Boot.new(config: self) Kamal::Configuration::Boot.new(config: self)
end end
@@ -135,25 +135,12 @@ class Mrsk::Configuration
end end
def ssh_user def ssh
if raw_config.ssh.present? Kamal::Configuration::Ssh.new(config: self)
raw_config.ssh["user"] || "root"
else
"root"
end
end end
def ssh_proxy def sshkit
if raw_config.ssh.present? && raw_config.ssh["proxy"] Kamal::Configuration::Sshkit.new(config: self)
Net::SSH::Proxy::Jump.new \
raw_config.ssh["proxy"].include?("@") ? raw_config.ssh["proxy"] : "root@#{raw_config.ssh["proxy"]}"
elsif raw_config.ssh.present? && raw_config.ssh["proxy_command"]
Net::SSH::Proxy::Command.new(raw_config.ssh["proxy_command"])
end
end
def ssh_options
{ user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ] }.compact
end end
@@ -170,7 +157,7 @@ class Mrsk::Configuration
end end
def valid? def valid?
ensure_required_keys_present && ensure_valid_mrsk_version ensure_required_keys_present && ensure_valid_kamal_version
end end
@@ -185,7 +172,8 @@ class Mrsk::Configuration
service_with_version: service_with_version, service_with_version: service_with_version,
env_args: env_args, env_args: env_args,
volume_args: volume_args, volume_args: volume_args,
ssh_options: ssh_options, ssh_options: ssh.to_h,
sshkit: sshkit.to_h,
builder: builder.to_h, builder: builder.to_h,
accessories: raw_config.accessories, accessories: raw_config.accessories,
logging: logging_args, logging: logging_args,
@@ -198,11 +186,11 @@ class Mrsk::Configuration
end end
def hooks_path def hooks_path
raw_config.hooks_path || ".mrsk/hooks" raw_config.hooks_path || ".kamal/hooks"
end end
def builder def builder
Mrsk::Configuration::Builder.new(config: self) Kamal::Configuration::Builder.new(config: self)
end end
# Will raise KeyError if any secret ENVs are missing # Will raise KeyError if any secret ENVs are missing
@@ -237,9 +225,9 @@ class Mrsk::Configuration
true true
end end
def ensure_valid_mrsk_version def ensure_valid_kamal_version
if minimum_version && Gem::Version.new(minimum_version) > Gem::Version.new(Mrsk::VERSION) if minimum_version && Gem::Version.new(minimum_version) > Gem::Version.new(Kamal::VERSION)
raise ArgumentError, "Current version is #{Mrsk::VERSION}, minimum required is #{minimum_version}" raise ArgumentError, "Current version is #{Kamal::VERSION}, minimum required is #{minimum_version}"
end end
true true
@@ -253,7 +241,7 @@ class Mrsk::Configuration
def git_version def git_version
@git_version ||= @git_version ||=
if system("git rev-parse") if system("git rev-parse")
uncommitted_suffix = `git status --porcelain`.strip.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : "" uncommitted_suffix = Kamal::Utils.uncommitted_changes.present? ? "_uncommitted_#{SecureRandom.hex(8)}" : ""
"#{`git rev-parse HEAD`.strip}#{uncommitted_suffix}" "#{`git rev-parse HEAD`.strip}#{uncommitted_suffix}"
else else

View File

@@ -1,5 +1,5 @@
class Mrsk::Configuration::Accessory class Kamal::Configuration::Accessory
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Kamal::Utils
attr_accessor :name, :specifics attr_accessor :name, :specifics

View File

@@ -1,4 +1,4 @@
class Mrsk::Configuration::Boot class Kamal::Configuration::Boot
def initialize(config:) def initialize(config:)
@options = config.raw_config.boot || {} @options = config.raw_config.boot || {}
@host_count = config.all_hosts.count @host_count = config.all_hosts.count

View File

@@ -1,4 +1,4 @@
class Mrsk::Configuration::Builder class Kamal::Configuration::Builder
def initialize(config:) def initialize(config:)
@options = config.raw_config.builder || {} @options = config.raw_config.builder || {}
@image = config.image @image = config.image
@@ -83,10 +83,6 @@ class Mrsk::Configuration::Builder
private private
def valid? def valid?
if @options["local"] && !@options["remote"]
raise ArgumentError, "You must specify both local and remote builder config for remote multiarch builds"
end
if @options["cache"] && @options["cache"]["type"] if @options["cache"] && @options["cache"]["type"]
raise ArgumentError, "Invalid cache type: #{@options["cache"]["type"]}" unless ["gha", "registry"].include?(@options["cache"]["type"]) raise ArgumentError, "Invalid cache type: #{@options["cache"]["type"]}" unless ["gha", "registry"].include?(@options["cache"]["type"])
end end
@@ -96,12 +92,16 @@ class Mrsk::Configuration::Builder
@options["cache"]&.fetch("image", nil) || "#{@image}-build-cache" @options["cache"]&.fetch("image", nil) || "#{@image}-build-cache"
end end
def cache_image_ref
[ @server, cache_image ].compact.join("/")
end
def cache_from_config_for_gha def cache_from_config_for_gha
"type=gha" "type=gha"
end end
def cache_from_config_for_registry def cache_from_config_for_registry
[ "type=registry", "ref=#{@server}/#{cache_image}" ].compact.join(",") [ "type=registry", "ref=#{cache_image_ref}" ].compact.join(",")
end end
def cache_to_config_for_gha def cache_to_config_for_gha
@@ -109,6 +109,6 @@ class Mrsk::Configuration::Builder
end end
def cache_to_config_for_registry def cache_to_config_for_registry
[ "type=registry", @options["cache"]&.fetch("options", nil), "ref=#{@server}/#{cache_image}" ].compact.join(",") [ "type=registry", @options["cache"]&.fetch("options", nil), "ref=#{cache_image_ref}" ].compact.join(",")
end end
end end

View File

@@ -1,5 +1,5 @@
class Mrsk::Configuration::Role class Kamal::Configuration::Role
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Kamal::Utils
attr_accessor :name attr_accessor :name

View File

@@ -0,0 +1,38 @@
class Kamal::Configuration::Ssh
LOGGER = ::Logger.new(STDERR)
def initialize(config:)
@config = config.raw_config.ssh || {}
end
def user
config.fetch("user", "root")
end
def proxy
if (proxy = config["proxy"])
Net::SSH::Proxy::Jump.new(proxy.include?("@") ? proxy : "root@#{proxy}")
elsif (proxy_command = config["proxy_command"])
Net::SSH::Proxy::Command.new(proxy_command)
end
end
def options
{ user: user, proxy: proxy, auth_methods: [ "publickey" ], logger: logger, keepalive: true, keepalive_interval: 30 }.compact
end
def to_h
options.except(:logger).merge(log_level: log_level)
end
private
attr_accessor :config
def logger
LOGGER.tap { |logger| logger.level = log_level }
end
def log_level
config.fetch("log_level", :fatal)
end
end

View File

@@ -0,0 +1,20 @@
class Kamal::Configuration::Sshkit
def initialize(config:)
@options = config.raw_config.sshkit || {}
end
def max_concurrent_starts
options.fetch("max_concurrent_starts", 30)
end
def pool_idle_timeout
options.fetch("pool_idle_timeout", 900)
end
def to_h
options
end
private
attr_accessor :options
end

View File

@@ -54,3 +54,51 @@ class SSHKit::Backend::Abstract
end end
prepend CommandEnvMerge prepend CommandEnvMerge
end end
class SSHKit::Backend::Netssh::Configuration
attr_accessor :max_concurrent_starts
end
class SSHKit::Backend::Netssh
module LimitConcurrentStartsClass
attr_reader :start_semaphore
def configure(&block)
super &block
# Create this here to avoid lazy creation by multiple threads
if config.max_concurrent_starts
@start_semaphore = Concurrent::Semaphore.new(config.max_concurrent_starts)
end
end
end
class << self
prepend LimitConcurrentStartsClass
end
module LimitConcurrentStartsInstance
private
def with_ssh(&block)
host.ssh_options = self.class.config.ssh_options.merge(host.ssh_options || {})
self.class.pool.with(
method(:start_with_concurrency_limit),
String(host.hostname),
host.username,
host.netssh_options,
&block
)
end
def start_with_concurrency_limit(*args)
if self.class.start_semaphore
self.class.start_semaphore.acquire do
Net::SSH.start(*args)
end
else
Net::SSH.start(*args)
end
end
end
prepend LimitConcurrentStartsInstance
end

View File

@@ -1,6 +1,6 @@
require "time" require "time"
class Mrsk::Tags class Kamal::Tags
attr_reader :config, :tags attr_reader :config, :tags
class << self class << self
@@ -26,7 +26,7 @@ class Mrsk::Tags
end end
def env def env
tags.transform_keys { |detail| "MRSK_#{detail.upcase}" } tags.transform_keys { |detail| "KAMAL_#{detail.upcase}" }
end end
def to_s def to_s

View File

@@ -1,4 +1,4 @@
module Mrsk::Utils module Kamal::Utils
extend self extend self
DOLLAR_SIGN_WITHOUT_SHELL_EXPANSION_REGEX = /\$(?!{[^\}]*\})/ DOLLAR_SIGN_WITHOUT_SHELL_EXPANSION_REGEX = /\$(?!{[^\}]*\})/
@@ -46,7 +46,7 @@ module Mrsk::Utils
# Pass `redaction:` to change the default `"[REDACTED]"` redaction, e.g. # Pass `redaction:` to change the default `"[REDACTED]"` redaction, e.g.
# `sensitive "#{arg}=#{secret}", redaction: "#{arg}=xxxx" # `sensitive "#{arg}=#{secret}", redaction: "#{arg}=xxxx"
def sensitive(...) def sensitive(...)
Mrsk::Utils::Sensitive.new(...) Kamal::Utils::Sensitive.new(...)
end end
def redacted(value) def redacted(value)
@@ -93,4 +93,8 @@ module Mrsk::Utils
end end
end end
end end
def uncommitted_changes
`git status --porcelain`.strip
end
end end

View File

@@ -1,4 +1,4 @@
class Mrsk::Utils::HealthcheckPoller class Kamal::Utils::HealthcheckPoller
TRAEFIK_HEALTHY_DELAY = 2 TRAEFIK_HEALTHY_DELAY = 2
class HealthcheckError < StandardError; end class HealthcheckError < StandardError; end
@@ -6,14 +6,14 @@ class Mrsk::Utils::HealthcheckPoller
class << self class << self
def wait_for_healthy(pause_after_ready: false, &block) def wait_for_healthy(pause_after_ready: false, &block)
attempt = 1 attempt = 1
max_attempts = MRSK.config.healthcheck["max_attempts"] max_attempts = KAMAL.config.healthcheck["max_attempts"]
begin begin
case status = block.call case status = block.call
when "healthy" when "healthy"
sleep TRAEFIK_HEALTHY_DELAY if pause_after_ready sleep TRAEFIK_HEALTHY_DELAY if pause_after_ready
when "running" # No health check configured when "running" # No health check configured
sleep MRSK.config.readiness_delay if pause_after_ready sleep KAMAL.config.readiness_delay if pause_after_ready
else else
raise HealthcheckError, "container not ready (#{status})" raise HealthcheckError, "container not ready (#{status})"
end end

View File

@@ -1,6 +1,6 @@
require "active_support/core_ext/module/delegation" require "active_support/core_ext/module/delegation"
class Mrsk::Utils::Sensitive class Kamal::Utils::Sensitive
# So SSHKit knows to redact these values. # So SSHKit knows to redact these values.
include SSHKit::Redaction include SSHKit::Redaction

3
lib/kamal/version.rb Normal file
View File

@@ -0,0 +1,3 @@
module Kamal
VERSION = "0.16.1"
end

View File

@@ -1,20 +0,0 @@
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
default_command :perform
desc "perform", "Health check current app version"
def perform
on(MRSK.primary_host) do
begin
execute *MRSK.healthcheck.run
Mrsk::Utils::HealthcheckPoller.wait_for_healthy { capture_with_info(*MRSK.healthcheck.status) }
rescue Mrsk::Utils::HealthcheckPoller::HealthcheckError => e
error capture_with_info(*MRSK.healthcheck.logs)
error capture_with_pretty_json(*MRSK.healthcheck.container_health_log)
raise
ensure
execute *MRSK.healthcheck.stop, raise_on_non_zero_exit: false
execute *MRSK.healthcheck.remove, raise_on_non_zero_exit: false
end
end
end
end

View File

@@ -1,30 +0,0 @@
class Mrsk::Cli::Prune < Mrsk::Cli::Base
desc "all", "Prune unused images and stopped containers"
def all
mutating do
containers
images
end
end
desc "images", "Prune dangling images"
def images
mutating do
on(MRSK.hosts) do
execute *MRSK.auditor.record("Pruned images"), verbosity: :debug
execute *MRSK.prune.dangling_images
execute *MRSK.prune.tagged_images
end
end
end
desc "containers", "Prune all stopped containers, except the last 5"
def containers
mutating do
on(MRSK.hosts) do
execute *MRSK.auditor.record("Pruned containers"), verbosity: :debug
execute *MRSK.prune.containers
end
end
end
end

View File

@@ -1,14 +0,0 @@
#!/bin/sh
# A sample post-deploy hook
#
# These environment variables are available:
# MRSK_RECORDED_AT
# MRSK_PERFORMER
# MRSK_VERSION
# MRSK_HOSTS
# MRSK_ROLE (if set)
# MRSK_DESTINATION (if set)
# MRSK_RUNTIME
echo "$MRSK_PERFORMER deployed $MRSK_VERSION to $MRSK_DESTINATION in $MRSK_RUNTIME seconds"

View File

@@ -1,2 +0,0 @@
MRSK_REGISTRY_PASSWORD=change-this
RAILS_MASTER_KEY=another-env

View File

@@ -1,2 +0,0 @@
module Mrsk::Commands
end

View File

@@ -1,3 +0,0 @@
module Mrsk
VERSION = "0.15.1"
end

View File

@@ -2,8 +2,8 @@ require_relative "cli_test_case"
class CliAccessoryTest < CliTestCase class CliAccessoryTest < CliTestCase
test "boot" do test "boot" do
Mrsk::Cli::Accessory.any_instance.expects(:directories).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:directories).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:upload).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:upload).with("mysql")
run_command("boot", "mysql").tap do |output| run_command("boot", "mysql").tap do |output|
assert_match /docker login.*on 1.1.1.3/, output assert_match /docker login.*on 1.1.1.3/, output
@@ -12,10 +12,10 @@ class CliAccessoryTest < CliTestCase
end end
test "boot all" do test "boot all" do
Mrsk::Cli::Accessory.any_instance.expects(:directories).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:directories).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:upload).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:upload).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:directories).with("redis") Kamal::Cli::Accessory.any_instance.expects(:directories).with("redis")
Mrsk::Cli::Accessory.any_instance.expects(:upload).with("redis") Kamal::Cli::Accessory.any_instance.expects(:upload).with("redis")
run_command("boot", "all").tap do |output| run_command("boot", "all").tap do |output|
assert_match /docker login.*on 1.1.1.3/, output assert_match /docker login.*on 1.1.1.3/, output
@@ -40,10 +40,10 @@ class CliAccessoryTest < CliTestCase
end end
test "reboot" do test "reboot" do
Mrsk::Commands::Registry.any_instance.expects(:login) Kamal::Commands::Registry.any_instance.expects(:login)
Mrsk::Cli::Accessory.any_instance.expects(:stop).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:remove_container).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:boot).with("mysql", login: false) Kamal::Cli::Accessory.any_instance.expects(:boot).with("mysql", login: false)
run_command("reboot", "mysql") run_command("reboot", "mysql")
end end
@@ -57,8 +57,8 @@ class CliAccessoryTest < CliTestCase
end end
test "restart" do test "restart" do
Mrsk::Cli::Accessory.any_instance.expects(:stop).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:start).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:start).with("mysql")
run_command("restart", "mysql") run_command("restart", "mysql")
end end
@@ -103,23 +103,23 @@ class CliAccessoryTest < CliTestCase
end end
test "remove with confirmation" do test "remove with confirmation" do
Mrsk::Cli::Accessory.any_instance.expects(:stop).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:remove_container).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:remove_image).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:remove_service_directory).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("mysql")
run_command("remove", "mysql", "-y") run_command("remove", "mysql", "-y")
end end
test "remove all with confirmation" do test "remove all with confirmation" do
Mrsk::Cli::Accessory.any_instance.expects(:stop).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:stop).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:remove_container).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:remove_image).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:remove_service_directory).with("mysql") Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("mysql")
Mrsk::Cli::Accessory.any_instance.expects(:stop).with("redis") Kamal::Cli::Accessory.any_instance.expects(:stop).with("redis")
Mrsk::Cli::Accessory.any_instance.expects(:remove_container).with("redis") Kamal::Cli::Accessory.any_instance.expects(:remove_container).with("redis")
Mrsk::Cli::Accessory.any_instance.expects(:remove_image).with("redis") Kamal::Cli::Accessory.any_instance.expects(:remove_image).with("redis")
Mrsk::Cli::Accessory.any_instance.expects(:remove_service_directory).with("redis") Kamal::Cli::Accessory.any_instance.expects(:remove_service_directory).with("redis")
run_command("remove", "all", "-y") run_command("remove", "all", "-y")
end end
@@ -138,6 +138,6 @@ class CliAccessoryTest < CliTestCase
private private
def run_command(*command) def run_command(*command)
stdouted { Mrsk::Cli::Accessory.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } stdouted { Kamal::Cli::Accessory.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
end end
end end

View File

@@ -11,7 +11,7 @@ class CliAppTest < CliTestCase
end end
test "boot will rename if same version is already running" do test "boot will rename if same version is already running" do
run_command("details") # Preheat MRSK const run_command("details") # Preheat Kamal const
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :container, :ls, "--filter", "name=^app-web-latest$", "--quiet", raise_on_non_zero_exit: false) .with(:docker, :container, :ls, "--filter", "name=^app-web-latest$", "--quiet", raise_on_non_zero_exit: false)
@@ -22,7 +22,7 @@ class CliAppTest < CliTestCase
.returns("running") # health check .returns("running") # health check
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "grep -oE \"\\-[^-]+$\"", "|", "cut -c 2-", raise_on_non_zero_exit: false) .with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
.returns("123") # old version .returns("123") # old version
run_command("boot").tap do |output| run_command("boot").tap do |output|
@@ -36,11 +36,11 @@ class CliAppTest < CliTestCase
end end
test "boot uses group strategy when specified" do test "boot uses group strategy when specified" do
Mrsk::Cli::App.any_instance.stubs(:on).with("1.1.1.1").twice # acquire & release lock Kamal::Cli::App.any_instance.stubs(:on).with("1.1.1.1").twice # acquire & release lock
Mrsk::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container Kamal::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container
# Strategy is used when booting the containers # Strategy is used when booting the containers
Mrsk::Cli::App.any_instance.expects(:on).with([ "1.1.1.1" ], in: :groups, limit: 3, wait: 2).with_block_given Kamal::Cli::App.any_instance.expects(:on).with([ "1.1.1.1" ], in: :groups, limit: 3, wait: 2).with_block_given
run_command("boot", config: :with_boot_strategy) run_command("boot", config: :with_boot_strategy)
end end
@@ -48,13 +48,13 @@ class CliAppTest < CliTestCase
test "boot errors leave lock in place" do test "boot errors leave lock in place" do
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999" } invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999" }
Mrsk::Cli::App.any_instance.expects(:using_version).raises(RuntimeError) Kamal::Cli::App.any_instance.expects(:using_version).raises(RuntimeError)
assert !MRSK.holding_lock? assert !KAMAL.holding_lock?
assert_raises(RuntimeError) do assert_raises(RuntimeError) do
stderred { run_command("boot") } stderred { run_command("boot") }
end end
assert MRSK.holding_lock? assert KAMAL.holding_lock?
end end
test "start" do test "start" do
@@ -71,7 +71,7 @@ class CliAppTest < CliTestCase
test "stale_containers" do test "stale_containers" do
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--format", "\"{{.Names}}\"", "|", "grep -oE \"\\-[^-]+$\"", "|", "cut -c 2-", raise_on_non_zero_exit: false) .with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
.returns("12345678\n87654321") .returns("12345678\n87654321")
run_command("stale_containers").tap do |output| run_command("stale_containers").tap do |output|
@@ -81,7 +81,7 @@ class CliAppTest < CliTestCase
test "stop stale_containers" do test "stop stale_containers" do
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--format", "\"{{.Names}}\"", "|", "grep -oE \"\\-[^-]+$\"", "|", "cut -c 2-", raise_on_non_zero_exit: false) .with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
.returns("12345678\n87654321") .returns("12345678\n87654321")
run_command("stale_containers", "--stop").tap do |output| run_command("stale_containers", "--stop").tap do |output|
@@ -130,7 +130,7 @@ class CliAppTest < CliTestCase
test "exec with reuse" do test "exec with reuse" do
run_command("exec", "--reuse", "ruby -v").tap do |output| run_command("exec", "--reuse", "ruby -v").tap do |output|
assert_match "docker ps --filter label=service=app --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | grep -oE \"\\-[^-]+$\" | cut -c 2-", output # Get current version assert_match "docker ps --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | while read line; do echo ${line#app-web-}; done", output # Get current version
assert_match "docker exec app-web-999 ruby -v", output assert_match "docker exec app-web-999 ruby -v", output
end end
end end
@@ -163,20 +163,20 @@ class CliAppTest < CliTestCase
test "version" do test "version" do
run_command("version").tap do |output| run_command("version").tap do |output|
assert_match "docker ps --filter label=service=app --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | grep -oE \"\\-[^-]+$\" | cut -c 2-", output assert_match "docker ps --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | while read line; do echo ${line#app-web-}; done", output
end end
end end
test "version through main" do test "version through main" do
stdouted { Mrsk::Cli::Main.start(["app", "version", "-c", "test/fixtures/deploy_with_accessories.yml", "--hosts", "1.1.1.1"]) }.tap do |output| stdouted { Kamal::Cli::Main.start(["app", "version", "-c", "test/fixtures/deploy_with_accessories.yml", "--hosts", "1.1.1.1"]) }.tap do |output|
assert_match "docker ps --filter label=service=app --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | grep -oE \"\\-[^-]+$\" | cut -c 2-", output assert_match "docker ps --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | while read line; do echo ${line#app-web-}; done", output
end end
end end
private private
def run_command(*command, config: :with_accessories) def run_command(*command, config: :with_accessories)
stdouted { Mrsk::Cli::App.start([*command, "-c", "test/fixtures/deploy_#{config}.yml", "--hosts", "1.1.1.1"]) } stdouted { Kamal::Cli::App.start([*command, "-c", "test/fixtures/deploy_#{config}.yml", "--hosts", "1.1.1.1"]) }
end end
def stub_running def stub_running

View File

@@ -2,20 +2,20 @@ require_relative "cli_test_case"
class CliBuildTest < CliTestCase class CliBuildTest < CliTestCase
test "deliver" do test "deliver" do
Mrsk::Cli::Build.any_instance.expects(:push) Kamal::Cli::Build.any_instance.expects(:push)
Mrsk::Cli::Build.any_instance.expects(:pull) Kamal::Cli::Build.any_instance.expects(:pull)
run_command("deliver") run_command("deliver")
end end
test "push" do test "push" do
Mrsk::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true) Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
hook_variables = { version: 999, service_version: "app@999", hosts: "1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4", command: "build", subcommand: "push" } hook_variables = { version: 999, service_version: "app@999", hosts: "1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4", command: "build", subcommand: "push" }
run_command("push").tap do |output| run_command("push").tap do |output|
assert_hook_ran "pre-build", output, **hook_variables assert_hook_ran "pre-build", output, **hook_variables
assert_match /docker --version && docker buildx version/, output assert_match /docker --version && docker buildx version/, output
assert_match /docker buildx build --push --platform linux\/amd64,linux\/arm64 --builder mrsk-app-multiarch -t dhh\/app:999 -t dhh\/app:latest --label service="app" --file Dockerfile \. as .*@localhost/, output assert_match /docker buildx build --push --platform linux\/amd64,linux\/arm64 --builder kamal-app-multiarch -t dhh\/app:999 -t dhh\/app:latest --label service="app" --file Dockerfile \. as .*@localhost/, output
end end
end end
@@ -41,14 +41,14 @@ class CliBuildTest < CliTestCase
.with(:docker, "--version", "&&", :docker, :buildx, "version") .with(:docker, "--version", "&&", :docker, :buildx, "version")
.raises(SSHKit::Command::Failed.new("no buildx")) .raises(SSHKit::Command::Failed.new("no buildx"))
Mrsk::Commands::Builder.any_instance.stubs(:native_and_local?).returns(false) Kamal::Commands::Builder.any_instance.stubs(:native_and_local?).returns(false)
assert_raises(Mrsk::Cli::Build::BuildError) { run_command("push") } assert_raises(Kamal::Cli::Build::BuildError) { run_command("push") }
end end
test "push pre-build hook failure" do test "push pre-build hook failure" do
fail_hook("pre-build") fail_hook("pre-build")
assert_raises(Mrsk::Cli::HookError) { run_command("push") } assert_raises(Kamal::Cli::HookError) { run_command("push") }
assert @executions.none? { |args| args[0..2] == [:docker, :buildx, :build] } assert @executions.none? { |args| args[0..2] == [:docker, :buildx, :build] }
end end
@@ -62,7 +62,7 @@ class CliBuildTest < CliTestCase
test "create" do test "create" do
run_command("create").tap do |output| run_command("create").tap do |output|
assert_match /docker buildx create --use --name mrsk-app-multiarch/, output assert_match /docker buildx create --use --name kamal-app-multiarch/, output
end end
end end
@@ -79,7 +79,7 @@ class CliBuildTest < CliTestCase
test "remove" do test "remove" do
run_command("remove").tap do |output| run_command("remove").tap do |output|
assert_match /docker buildx rm mrsk-app-multiarch/, output assert_match /docker buildx rm kamal-app-multiarch/, output
end end
end end
@@ -96,7 +96,7 @@ class CliBuildTest < CliTestCase
private private
def run_command(*command) def run_command(*command)
stdouted { Mrsk::Cli::Build.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } stdouted { Kamal::Cli::Build.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
end end
def stub_dependency_checks def stub_dependency_checks

View File

@@ -5,8 +5,8 @@ class CliTestCase < ActiveSupport::TestCase
ENV["VERSION"] = "999" ENV["VERSION"] = "999"
ENV["RAILS_MASTER_KEY"] = "123" ENV["RAILS_MASTER_KEY"] = "123"
ENV["MYSQL_ROOT_PASSWORD"] = "secret123" ENV["MYSQL_ROOT_PASSWORD"] = "secret123"
Object.send(:remove_const, :MRSK) Object.send(:remove_const, :KAMAL)
Object.const_set(:MRSK, Mrsk::Commander.new) Object.const_set(:KAMAL, Kamal::Commander.new)
end end
teardown do teardown do
@@ -18,20 +18,20 @@ class CliTestCase < ActiveSupport::TestCase
private private
def fail_hook(hook) def fail_hook(hook)
@executions = [] @executions = []
Mrsk::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true) Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |*args| @executions << args; args != [".mrsk/hooks/#{hook}"] } .with { |*args| @executions << args; args != [".kamal/hooks/#{hook}"] }
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |*args| args.first == ".mrsk/hooks/#{hook}" } .with { |*args| args.first == ".kamal/hooks/#{hook}" }
.raises(SSHKit::Command::Failed.new("failed")) .raises(SSHKit::Command::Failed.new("failed"))
end end
def stub_locking def stub_locking
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |arg1, arg2| arg1 == :mkdir && arg2 == "mrsk_lock-app" } .with { |arg1, arg2| arg1 == :mkdir && arg2 == "kamal_lock-app" }
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |arg1, arg2| arg1 == :rm && arg2 == "mrsk_lock-app/details" } .with { |arg1, arg2| arg1 == :rm && arg2 == "kamal_lock-app/details" }
end end
def assert_hook_ran(hook, output, version:, service_version:, hosts:, command:, subcommand: nil, runtime: nil) def assert_hook_ran(hook, output, version:, service_version:, hosts:, command:, subcommand: nil, runtime: nil)
@@ -39,17 +39,17 @@ class CliTestCase < ActiveSupport::TestCase
assert_match "Running the #{hook} hook...\n", output assert_match "Running the #{hook} hook...\n", output
expected = %r{Running\s/usr/bin/env\s\.mrsk/hooks/#{hook}\sas\s#{performer}@localhost\n\s expected = %r{Running\s/usr/bin/env\s\.kamal/hooks/#{hook}\sas\s#{performer}@localhost\n\s
DEBUG\s\[[0-9a-f]*\]\sCommand:\s\(\sexport\s DEBUG\s\[[0-9a-f]*\]\sCommand:\s\(\sexport\s
MRSK_RECORDED_AT=\"\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ\"\s KAMAL_RECORDED_AT=\"\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\dZ\"\s
MRSK_PERFORMER=\"#{performer}\"\s KAMAL_PERFORMER=\"#{performer}\"\s
MRSK_VERSION=\"#{version}\"\s KAMAL_VERSION=\"#{version}\"\s
MRSK_SERVICE_VERSION=\"#{service_version}\"\s KAMAL_SERVICE_VERSION=\"#{service_version}\"\s
MRSK_HOSTS=\"#{hosts}\"\s KAMAL_HOSTS=\"#{hosts}\"\s
MRSK_COMMAND=\"#{command}\"\s KAMAL_COMMAND=\"#{command}\"\s
#{"MRSK_SUBCOMMAND=\\\"#{subcommand}\\\"\\s" if subcommand} #{"KAMAL_SUBCOMMAND=\\\"#{subcommand}\\\"\\s" if subcommand}
#{"MRSK_RUNTIME=\\\"#{runtime}\\\"\\s" if runtime} #{"KAMAL_RUNTIME=\\\"#{runtime}\\\"\\s" if runtime}
;\s/usr/bin/env\s\.mrsk/hooks/#{hook} }x ;\s/usr/bin/env\s\.kamal/hooks/#{hook} }x
assert_match expected, output assert_match expected, output
end end

View File

@@ -5,12 +5,12 @@ class CliHealthcheckTest < 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::Utils::HealthcheckPoller.stubs(:sleep) # No sleeping when retrying Kamal::Utils::HealthcheckPoller.stubs(:sleep) # No sleeping when retrying
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with(:docker, :container, :ls, "--all", "--filter", "name=^healthcheck-app-999$", "--quiet", "|", :xargs, :docker, :stop, raise_on_non_zero_exit: false) .with(:docker, :container, :ls, "--all", "--filter", "name=^healthcheck-app-999$", "--quiet", "|", :xargs, :docker, :stop, raise_on_non_zero_exit: false)
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with(:docker, :run, "--detach", "--name", "healthcheck-app-999", "--publish", "3999:3000", "--label", "service=healthcheck-app", "-e", "MRSK_CONTAINER_NAME=\"healthcheck-app\"", "--health-cmd", "\"curl -f http://localhost:3000/up || exit 1\"", "--health-interval", "\"1s\"", "dhh/app:999") .with(:docker, :run, "--detach", "--name", "healthcheck-app-999", "--publish", "3999:3000", "--label", "service=healthcheck-app", "-e", "KAMAL_CONTAINER_NAME=\"healthcheck-app\"", "--health-cmd", "\"curl -f http://localhost:3000/up || exit 1\"", "--health-interval", "\"1s\"", "dhh/app:999")
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with(:docker, :container, :ls, "--all", "--filter", "name=^healthcheck-app-999$", "--quiet", "|", :xargs, :docker, :container, :rm, raise_on_non_zero_exit: false) .with(:docker, :container, :ls, "--all", "--filter", "name=^healthcheck-app-999$", "--quiet", "|", :xargs, :docker, :container, :rm, raise_on_non_zero_exit: false)
@@ -34,12 +34,12 @@ class CliHealthcheckTest < 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::Utils::HealthcheckPoller.stubs(:sleep) # No sleeping when retrying Kamal::Utils::HealthcheckPoller.stubs(:sleep) # No sleeping when retrying
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with(:docker, :container, :ls, "--all", "--filter", "name=^healthcheck-app-999$", "--quiet", "|", :xargs, :docker, :stop, raise_on_non_zero_exit: false) .with(:docker, :container, :ls, "--all", "--filter", "name=^healthcheck-app-999$", "--quiet", "|", :xargs, :docker, :stop, raise_on_non_zero_exit: false)
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with(:docker, :run, "--detach", "--name", "healthcheck-app-999", "--publish", "3999:3000", "--label", "service=healthcheck-app", "-e", "MRSK_CONTAINER_NAME=\"healthcheck-app\"", "--health-cmd", "\"curl -f http://localhost:3000/up || exit 1\"", "--health-interval", "\"1s\"", "dhh/app:999") .with(:docker, :run, "--detach", "--name", "healthcheck-app-999", "--publish", "3999:3000", "--label", "service=healthcheck-app", "-e", "KAMAL_CONTAINER_NAME=\"healthcheck-app\"", "--health-cmd", "\"curl -f http://localhost:3000/up || exit 1\"", "--health-interval", "\"1s\"", "dhh/app:999")
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with(:docker, :container, :ls, "--all", "--filter", "name=^healthcheck-app-999$", "--quiet", "|", :xargs, :docker, :container, :rm, raise_on_non_zero_exit: false) .with(:docker, :container, :ls, "--all", "--filter", "name=^healthcheck-app-999$", "--quiet", "|", :xargs, :docker, :container, :rm, raise_on_non_zero_exit: false)
@@ -66,6 +66,6 @@ class CliHealthcheckTest < CliTestCase
private private
def run_command(*command) def run_command(*command)
stdouted { Mrsk::Cli::Healthcheck.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } stdouted { Kamal::Cli::Healthcheck.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
end end
end end

View File

@@ -15,6 +15,6 @@ class CliLockTest < CliTestCase
private private
def run_command(*command) def run_command(*command)
stdouted { Mrsk::Cli::Lock.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } stdouted { Kamal::Cli::Lock.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
end end
end end

View File

@@ -2,9 +2,9 @@ require_relative "cli_test_case"
class CliMainTest < CliTestCase class CliMainTest < CliTestCase
test "setup" do test "setup" do
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:server:bootstrap") Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:server:bootstrap")
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:accessory:boot", [ "all" ]) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:boot", [ "all" ])
Mrsk::Cli::Main.any_instance.expects(:deploy) Kamal::Cli::Main.any_instance.expects(:deploy)
run_command("setup") run_command("setup")
end end
@@ -12,15 +12,15 @@ class CliMainTest < CliTestCase
test "deploy" do test "deploy" do
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false } invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false }
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:registry:login", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:build:deliver", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:traefik:boot", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:healthcheck:perform", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:stale_containers", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:boot", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:prune:all", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
Mrsk::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true) Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
hook_variables = { version: 999, service_version: "app@999", hosts: "1.1.1.1,1.1.1.2", command: "deploy" } hook_variables = { version: 999, service_version: "app@999", hosts: "1.1.1.1,1.1.1.2", command: "deploy" }
run_command("deploy").tap do |output| run_command("deploy").tap do |output|
@@ -39,13 +39,13 @@ class CliMainTest < CliTestCase
test "deploy with skip_push" do test "deploy with skip_push" do
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false } invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false }
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:registry:login", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:build:pull", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:pull", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:traefik:boot", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:healthcheck:perform", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:stale_containers", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:boot", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:prune:all", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
run_command("deploy", "--skip_push").tap do |output| run_command("deploy", "--skip_push").tap do |output|
assert_match /Acquiring the deploy lock/, output assert_match /Acquiring the deploy lock/, output
@@ -63,13 +63,13 @@ class CliMainTest < CliTestCase
Thread.report_on_exception = false Thread.report_on_exception = false
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |*arg| arg[0..1] == [:mkdir, 'mrsk_lock-app'] } .with { |*arg| arg[0..1] == [:mkdir, 'kamal_lock-app'] }
.raises(RuntimeError, "mkdir: cannot create directory mrsk_lock-app: File exists") .raises(RuntimeError, "mkdir: cannot create directory kamal_lock-app: File exists")
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_debug) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_debug)
.with(:stat, 'mrsk_lock-app', ">", "/dev/null", "&&", :cat, "mrsk_lock-app/details", "|", :base64, "-d") .with(:stat, 'kamal_lock-app', ">", "/dev/null", "&&", :cat, "kamal_lock-app/details", "|", :base64, "-d")
assert_raises(Mrsk::Cli::LockError) do assert_raises(Kamal::Cli::LockError) do
run_command("deploy") run_command("deploy")
end end
end end
@@ -78,7 +78,7 @@ class CliMainTest < CliTestCase
Thread.report_on_exception = false Thread.report_on_exception = false
SSHKit::Backend::Abstract.any_instance.stubs(:execute) SSHKit::Backend::Abstract.any_instance.stubs(:execute)
.with { |*arg| arg[0..1] == [:mkdir, 'mrsk_lock-app'] } .with { |*arg| arg[0..1] == [:mkdir, 'kamal_lock-app'] }
.raises(SocketError, "getaddrinfo: nodename nor servname provided, or not known") .raises(SocketError, "getaddrinfo: nodename nor servname provided, or not known")
assert_raises(SSHKit::Runner::ExecuteError) do assert_raises(SSHKit::Runner::ExecuteError) do
@@ -89,27 +89,27 @@ class CliMainTest < CliTestCase
test "deploy errors during outside section leave remove lock" do test "deploy errors during outside section leave remove lock" do
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false } invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false }
Mrsk::Cli::Main.any_instance.expects(:invoke) Kamal::Cli::Main.any_instance.expects(:invoke)
.with("mrsk:cli:registry:login", [], invoke_options) .with("kamal:cli:registry:login", [], invoke_options)
.raises(RuntimeError) .raises(RuntimeError)
assert !MRSK.holding_lock? assert !KAMAL.holding_lock?
assert_raises(RuntimeError) do assert_raises(RuntimeError) do
stderred { run_command("deploy") } stderred { run_command("deploy") }
end end
assert !MRSK.holding_lock? assert !KAMAL.holding_lock?
end end
test "deploy with skipped hooks" do test "deploy with skipped hooks" do
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => true } invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => true }
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:registry:login", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:registry:login", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:build:deliver", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:traefik:boot", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:boot", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:healthcheck:perform", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:stale_containers", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:boot", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:prune:all", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:prune:all", [], invoke_options)
run_command("deploy", "--skip_hooks") do run_command("deploy", "--skip_hooks") do
refute_match /Running the post-deploy hook.../, output refute_match /Running the post-deploy hook.../, output
@@ -125,12 +125,12 @@ class CliMainTest < CliTestCase
test "redeploy" do test "redeploy" do
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false } invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false }
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:build:deliver", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:deliver", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:healthcheck:perform", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:stale_containers", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:boot", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
Mrsk::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true) Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
hook_variables = { version: 999, service_version: "app@999", hosts: "1.1.1.1,1.1.1.2", command: "redeploy" } hook_variables = { version: 999, service_version: "app@999", hosts: "1.1.1.1,1.1.1.2", command: "redeploy" }
@@ -147,10 +147,10 @@ class CliMainTest < CliTestCase
test "redeploy with skip_push" do test "redeploy with skip_push" do
invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false } invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false }
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:build:pull", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:build:pull", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:healthcheck:perform", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:healthcheck:perform", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:stale_containers", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:stale_containers", [], invoke_options)
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:boot", [], invoke_options) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:boot", [], invoke_options)
run_command("redeploy", "--skip_push").tap do |output| run_command("redeploy", "--skip_push").tap do |output|
assert_match /Pull app image/, output assert_match /Pull app image/, output
@@ -161,7 +161,7 @@ class CliMainTest < CliTestCase
test "rollback bad version" do test "rollback bad version" do
Thread.report_on_exception = false Thread.report_on_exception = false
run_command("details") # Preheat MRSK const run_command("details") # Preheat Kamal const
run_command("rollback", "nonsense").tap do |output| run_command("rollback", "nonsense").tap do |output|
assert_match /docker container ls --all --filter name=\^app-web-nonsense\$ --quiet/, output assert_match /docker container ls --all --filter name=\^app-web-nonsense\$ --quiet/, output
@@ -178,14 +178,14 @@ class CliMainTest < CliTestCase
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-#{role}-123$", "--quiet") .with(:docker, :container, :ls, "--all", "--filter", "name=^app-#{role}-123$", "--quiet")
.returns("version-to-rollback\n").at_least_once .returns("version-to-rollback\n").at_least_once
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=#{role}", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "grep -oE \"\\-[^-]+$\"", "|", "cut -c 2-", raise_on_non_zero_exit: false) .with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=#{role}", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-#{role}-}; done", raise_on_non_zero_exit: false)
.returns("version-to-rollback\n").at_least_once .returns("version-to-rollback\n").at_least_once
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-#{role}-123$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'") .with(:docker, :container, :ls, "--all", "--filter", "name=^app-#{role}-123$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
.returns("running").at_least_once # health check .returns("running").at_least_once # health check
end end
Mrsk::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true) Kamal::Commands::Hook.any_instance.stubs(:hook_exists?).returns(true)
hook_variables = { version: 123, service_version: "app@123", hosts: "1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4", command: "rollback" } hook_variables = { version: 123, service_version: "app@123", hosts: "1.1.1.1,1.1.1.2,1.1.1.3,1.1.1.4", command: "rollback" }
run_command("rollback", "123", config_file: "deploy_with_accessories").tap do |output| run_command("rollback", "123", config_file: "deploy_with_accessories").tap do |output|
@@ -199,15 +199,15 @@ class CliMainTest < CliTestCase
end end
test "rollback without old version" do test "rollback without old version" do
Mrsk::Cli::Main.any_instance.stubs(:container_available?).returns(true) Kamal::Cli::Main.any_instance.stubs(:container_available?).returns(true)
Mrsk::Utils::HealthcheckPoller.stubs(:sleep) Kamal::Utils::HealthcheckPoller.stubs(:sleep)
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :container, :ls, "--filter", "name=^app-web-123$", "--quiet", raise_on_non_zero_exit: false) .with(:docker, :container, :ls, "--filter", "name=^app-web-123$", "--quiet", raise_on_non_zero_exit: false)
.returns("").at_least_once .returns("").at_least_once
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "grep -oE \"\\-[^-]+$\"", "|", "cut -c 2-", raise_on_non_zero_exit: false) .with(:docker, :ps, "--filter", "label=service=app", "--filter", "label=role=web", "--filter", "status=running", "--filter", "status=restarting", "--latest", "--format", "\"{{.Names}}\"", "|", "while read line; do echo ${line#app-web-}; done", raise_on_non_zero_exit: false)
.returns("").at_least_once .returns("").at_least_once
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info) SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info)
.with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-123$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'") .with(:docker, :container, :ls, "--all", "--filter", "name=^app-web-123$", "--quiet", "|", :xargs, :docker, :inspect, "--format", "'{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}'")
@@ -221,16 +221,16 @@ class CliMainTest < CliTestCase
end end
test "details" do test "details" do
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:traefik:details") Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:traefik:details")
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:app:details") Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:app:details")
Mrsk::Cli::Main.any_instance.expects(:invoke).with("mrsk:cli:accessory:details", [ "all" ]) Kamal::Cli::Main.any_instance.expects(:invoke).with("kamal:cli:accessory:details", [ "all" ])
run_command("details") run_command("details")
end end
test "audit" do test "audit" do
run_command("audit").tap do |output| run_command("audit").tap do |output|
assert_match /tail -n 50 mrsk-app-audit.log on 1.1.1.1/, output assert_match /tail -n 50 kamal-app-audit.log on 1.1.1.1/, output
assert_match /App Host: 1.1.1.1/, output assert_match /App Host: 1.1.1.1/, output
end end
end end
@@ -305,10 +305,10 @@ class CliMainTest < CliTestCase
run_command("init", "--bundle").tap do |output| run_command("init", "--bundle").tap do |output|
assert_match /Created configuration file in config\/deploy.yml/, output assert_match /Created configuration file in config\/deploy.yml/, output
assert_match /Created \.env file/, output assert_match /Created \.env file/, output
assert_match /Adding MRSK to Gemfile and bundle/, output assert_match /Adding Kamal to Gemfile and bundle/, output
assert_match /bundle add mrsk/, output assert_match /bundle add kamal/, output
assert_match /bundle binstubs mrsk/, output assert_match /bundle binstubs kamal/, output
assert_match /Created binstub file in bin\/mrsk/, output assert_match /Created binstub file in bin\/kamal/, output
end end
end end
@@ -321,7 +321,7 @@ class CliMainTest < CliTestCase
run_command("init", "--bundle").tap do |output| run_command("init", "--bundle").tap do |output|
assert_match /Config file already exists in config\/deploy.yml \(remove first to create a new one\)/, output assert_match /Config file already exists in config\/deploy.yml \(remove first to create a new one\)/, output
assert_match /Binstub already exists in bin\/mrsk \(remove first to create a new one\)/, output assert_match /Binstub already exists in bin\/kamal \(remove first to create a new one\)/, output
end end
end end
@@ -364,12 +364,12 @@ class CliMainTest < CliTestCase
end end
test "version" do test "version" do
version = stdouted { Mrsk::Cli::Main.new.version } version = stdouted { Kamal::Cli::Main.new.version }
assert_equal Mrsk::VERSION, version assert_equal Kamal::VERSION, version
end end
private private
def run_command(*command, config_file: "deploy_simple") def run_command(*command, config_file: "deploy_simple")
stdouted { Mrsk::Cli::Main.start([*command, "-c", "test/fixtures/#{config_file}.yml"]) } stdouted { Kamal::Cli::Main.start([*command, "-c", "test/fixtures/#{config_file}.yml"]) }
end end
end end

View File

@@ -2,8 +2,8 @@ require_relative "cli_test_case"
class CliPruneTest < CliTestCase class CliPruneTest < CliTestCase
test "all" do test "all" do
Mrsk::Cli::Prune.any_instance.expects(:containers) Kamal::Cli::Prune.any_instance.expects(:containers)
Mrsk::Cli::Prune.any_instance.expects(:images) Kamal::Cli::Prune.any_instance.expects(:images)
run_command("all") run_command("all")
end end
@@ -23,6 +23,6 @@ class CliPruneTest < CliTestCase
private private
def run_command(*command) def run_command(*command)
stdouted { Mrsk::Cli::Prune.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } stdouted { Kamal::Cli::Prune.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
end end
end end

View File

@@ -16,6 +16,6 @@ class CliRegistryTest < CliTestCase
private private
def run_command(*command) def run_command(*command)
stdouted { Mrsk::Cli::Registry.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } stdouted { Kamal::Cli::Registry.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
end end
end end

View File

@@ -30,6 +30,6 @@ class CliServerTest < CliTestCase
private private
def run_command(*command) def run_command(*command)
stdouted { Mrsk::Cli::Server.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } stdouted { Kamal::Cli::Server.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
end end
end end

View File

@@ -4,17 +4,17 @@ class CliTraefikTest < CliTestCase
test "boot" do test "boot" do
run_command("boot").tap do |output| run_command("boot").tap do |output|
assert_match "docker login", output assert_match "docker login", output
assert_match "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Mrsk::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"", output assert_match "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Kamal::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"", output
end end
end end
test "reboot" do test "reboot" do
Mrsk::Commands::Registry.any_instance.expects(:login).twice Kamal::Commands::Registry.any_instance.expects(:login).twice
run_command("reboot").tap do |output| run_command("reboot").tap do |output|
assert_match "docker container stop traefik", output assert_match "docker container stop traefik", output
assert_match "docker container prune --force --filter label=org.opencontainers.image.title=Traefik", output assert_match "docker container prune --force --filter label=org.opencontainers.image.title=Traefik", output
assert_match "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Mrsk::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"", output assert_match "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Kamal::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"", output
end end
end end
@@ -37,8 +37,8 @@ class CliTraefikTest < CliTestCase
end end
test "restart" do test "restart" do
Mrsk::Cli::Traefik.any_instance.expects(:stop) Kamal::Cli::Traefik.any_instance.expects(:stop)
Mrsk::Cli::Traefik.any_instance.expects(:start) Kamal::Cli::Traefik.any_instance.expects(:start)
run_command("restart") run_command("restart")
end end
@@ -68,9 +68,9 @@ class CliTraefikTest < CliTestCase
end end
test "remove" do test "remove" do
Mrsk::Cli::Traefik.any_instance.expects(:stop) Kamal::Cli::Traefik.any_instance.expects(:stop)
Mrsk::Cli::Traefik.any_instance.expects(:remove_container) Kamal::Cli::Traefik.any_instance.expects(:remove_container)
Mrsk::Cli::Traefik.any_instance.expects(:remove_image) Kamal::Cli::Traefik.any_instance.expects(:remove_image)
run_command("remove") run_command("remove")
end end
@@ -89,6 +89,6 @@ class CliTraefikTest < CliTestCase
private private
def run_command(*command) def run_command(*command)
stdouted { Mrsk::Cli::Traefik.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } stdouted { Kamal::Cli::Traefik.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) }
end end
end end

View File

@@ -6,74 +6,74 @@ class CommanderTest < ActiveSupport::TestCase
end end
test "lazy configuration" do test "lazy configuration" do
assert_equal Mrsk::Configuration, @mrsk.config.class assert_equal Kamal::Configuration, @kamal.config.class
end end
test "overwriting hosts" do test "overwriting hosts" do
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @mrsk.hosts assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @kamal.hosts
@mrsk.specific_hosts = [ "1.1.1.1", "1.1.1.2" ] @kamal.specific_hosts = [ "1.1.1.1", "1.1.1.2" ]
assert_equal [ "1.1.1.1", "1.1.1.2" ], @mrsk.hosts assert_equal [ "1.1.1.1", "1.1.1.2" ], @kamal.hosts
end end
test "filtering hosts by filtering roles" do test "filtering hosts by filtering roles" do
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @mrsk.hosts assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @kamal.hosts
@mrsk.specific_roles = [ "web" ] @kamal.specific_roles = [ "web" ]
assert_equal [ "1.1.1.1", "1.1.1.2" ], @mrsk.hosts assert_equal [ "1.1.1.1", "1.1.1.2" ], @kamal.hosts
end end
test "filtering roles" do test "filtering roles" do
assert_equal [ "web", "workers" ], @mrsk.roles.map(&:name) assert_equal [ "web", "workers" ], @kamal.roles.map(&:name)
@mrsk.specific_roles = [ "workers" ] @kamal.specific_roles = [ "workers" ]
assert_equal [ "workers" ], @mrsk.roles.map(&:name) assert_equal [ "workers" ], @kamal.roles.map(&:name)
end end
test "filtering roles by filtering hosts" do test "filtering roles by filtering hosts" do
assert_equal [ "web", "workers" ], @mrsk.roles.map(&:name) assert_equal [ "web", "workers" ], @kamal.roles.map(&:name)
@mrsk.specific_hosts = [ "1.1.1.3" ] @kamal.specific_hosts = [ "1.1.1.3" ]
assert_equal [ "workers" ], @mrsk.roles.map(&:name) assert_equal [ "workers" ], @kamal.roles.map(&:name)
end end
test "overwriting hosts with primary" do test "overwriting hosts with primary" do
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @mrsk.hosts assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4" ], @kamal.hosts
@mrsk.specific_primary! @kamal.specific_primary!
assert_equal [ "1.1.1.1" ], @mrsk.hosts assert_equal [ "1.1.1.1" ], @kamal.hosts
end end
test "primary_host with specific hosts via role" do test "primary_host with specific hosts via role" do
@mrsk.specific_roles = "workers" @kamal.specific_roles = "workers"
assert_equal "1.1.1.3", @mrsk.primary_host assert_equal "1.1.1.3", @kamal.primary_host
end end
test "roles_on" do test "roles_on" do
assert_equal [ "web" ], @mrsk.roles_on("1.1.1.1") assert_equal [ "web" ], @kamal.roles_on("1.1.1.1")
assert_equal [ "workers" ], @mrsk.roles_on("1.1.1.3") assert_equal [ "workers" ], @kamal.roles_on("1.1.1.3")
end end
test "default group strategy" do test "default group strategy" do
assert_empty @mrsk.boot_strategy assert_empty @kamal.boot_strategy
end end
test "specific limit group strategy" do test "specific limit group strategy" do
configure_with(:deploy_with_boot_strategy) configure_with(:deploy_with_boot_strategy)
assert_equal({ in: :groups, limit: 3, wait: 2 }, @mrsk.boot_strategy) assert_equal({ in: :groups, limit: 3, wait: 2 }, @kamal.boot_strategy)
end end
test "percentage-based group strategy" do test "percentage-based group strategy" do
configure_with(:deploy_with_percentage_boot_strategy) configure_with(:deploy_with_percentage_boot_strategy)
assert_equal({ in: :groups, limit: 1, wait: 2 }, @mrsk.boot_strategy) assert_equal({ in: :groups, limit: 1, wait: 2 }, @kamal.boot_strategy)
end end
private private
def configure_with(variant) def configure_with(variant)
@mrsk = Mrsk::Commander.new.tap do |mrsk| @kamal = Kamal::Commander.new.tap do |kamal|
mrsk.configure config_file: Pathname.new(File.expand_path("fixtures/#{variant}.yml", __dir__)) kamal.configure config_file: Pathname.new(File.expand_path("fixtures/#{variant}.yml", __dir__))
end end
end end
end end

View File

@@ -146,6 +146,6 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
private private
def new_command(accessory) def new_command(accessory)
Mrsk::Commands::Accessory.new(Mrsk::Configuration.new(@config), name: accessory) Kamal::Commands::Accessory.new(Kamal::Configuration.new(@config), name: accessory)
end end
end end

View File

@@ -13,13 +13,13 @@ class CommandsAppTest < ActiveSupport::TestCase
test "run" do test "run" do
assert_equal \ assert_equal \
"docker run --detach --restart unless-stopped --name app-web-999 -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.run.join(" ") new_command.run.join(" ")
end end
test "run with hostname" do test "run with hostname" do
assert_equal \ assert_equal \
"docker run --detach --restart unless-stopped --name app-web-999 --hostname myhost -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker run --detach --restart unless-stopped --name app-web-999 --hostname myhost -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.run(hostname: "myhost").join(" ") new_command.run(hostname: "myhost").join(" ")
end end
@@ -27,7 +27,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 --name app-web-999 -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --volume /local/path:/container/path --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --volume /local/path:/container/path --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -35,7 +35,7 @@ class CommandsAppTest < ActiveSupport::TestCase
@config[:healthcheck] = { "path" => "/healthz" } @config[:healthcheck] = { "path" => "/healthz" }
assert_equal \ assert_equal \
"docker run --detach --restart unless-stopped --name app-web-999 -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/healthz || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/healthz || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -43,7 +43,7 @@ class CommandsAppTest < ActiveSupport::TestCase
@config[:healthcheck] = { "cmd" => "/bin/up" } @config[:healthcheck] = { "cmd" => "/bin/up" }
assert_equal \ assert_equal \
"docker run --detach --restart unless-stopped --name app-web-999 -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"/bin/up\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"/bin/up\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -51,14 +51,14 @@ class CommandsAppTest < ActiveSupport::TestCase
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "healthcheck" => { "cmd" => "/bin/healthy" } } } @config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "healthcheck" => { "cmd" => "/bin/healthy" } } }
assert_equal \ assert_equal \
"docker run --detach --restart unless-stopped --name app-web-999 -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"/bin/healthy\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"/bin/healthy\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.run.join(" ") new_command.run.join(" ")
end end
test "run with custom options" do test "run with custom options" do
@config[:servers] = { "web" => [ "1.1.1.1" ], "jobs" => { "hosts" => [ "1.1.1.2" ], "cmd" => "bin/jobs", "options" => { "mount" => "somewhere", "cap-add" => true } } } @config[:servers] = { "web" => [ "1.1.1.1" ], "jobs" => { "hosts" => [ "1.1.1.2" ], "cmd" => "bin/jobs", "options" => { "mount" => "somewhere", "cap-add" => true } } }
assert_equal \ assert_equal \
"docker run --detach --restart unless-stopped --name app-jobs-999 -e MRSK_CONTAINER_NAME=\"app-jobs-999\" -e RAILS_MASTER_KEY=\"456\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"jobs\" --mount \"somewhere\" --cap-add dhh/app:999 bin/jobs", "docker run --detach --restart unless-stopped --name app-jobs-999 -e KAMAL_CONTAINER_NAME=\"app-jobs-999\" -e RAILS_MASTER_KEY=\"456\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"jobs\" --mount \"somewhere\" --cap-add dhh/app:999 bin/jobs",
new_command(role: "jobs").run.join(" ") new_command(role: "jobs").run.join(" ")
end end
@@ -66,7 +66,7 @@ class CommandsAppTest < ActiveSupport::TestCase
@config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } } @config[:logging] = { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => "3" } }
assert_equal \ assert_equal \
"docker run --detach --restart unless-stopped --name app-web-999 -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-driver \"local\" --log-opt max-size=\"100m\" --log-opt max-file=\"3\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -85,13 +85,13 @@ class CommandsAppTest < ActiveSupport::TestCase
test "start_or_run" do test "start_or_run" do
assert_equal \ assert_equal \
"docker start app-web-999 || docker run --detach --restart unless-stopped --name app-web-999 -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker start app-web-999 || docker run --detach --restart unless-stopped --name app-web-999 -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.start_or_run.join(" ") new_command.start_or_run.join(" ")
end end
test "start_or_run with hostname" do test "start_or_run with hostname" do
assert_equal \ assert_equal \
"docker start app-web-999 || docker run --detach --restart unless-stopped --name app-web-999 --hostname myhost -e MRSK_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999", "docker start app-web-999 || docker run --detach --restart unless-stopped --name app-web-999 --hostname myhost -e KAMAL_CONTAINER_NAME=\"app-web-999\" -e RAILS_MASTER_KEY=\"456\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --log-opt max-size=\"10m\" --label service=\"app\" --label role=\"web\" --label traefik.http.services.app-web.loadbalancer.server.scheme=\"http\" --label traefik.http.routers.app-web.rule=\"PathPrefix(\\`/\\`)\" --label traefik.http.middlewares.app-web-retry.retry.attempts=\"5\" --label traefik.http.middlewares.app-web-retry.retry.initialinterval=\"500ms\" --label traefik.http.routers.app-web.middlewares=\"app-web-retry@docker\" dhh/app:999",
new_command.start_or_run(hostname: "myhost").join(" ") new_command.start_or_run(hostname: "myhost").join(" ")
end end
@@ -171,6 +171,13 @@ class CommandsAppTest < ActiveSupport::TestCase
new_command.execute_in_new_container("bin/rails", "db:setup").join(" ") new_command.execute_in_new_container("bin/rails", "db:setup").join(" ")
end end
test "execute in new container with custom options" do
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere", "cap-add" => true } } }
assert_equal \
"docker run --rm -e RAILS_MASTER_KEY=\"456\" --mount \"somewhere\" --cap-add dhh/app:999 bin/rails db:setup",
new_command.execute_in_new_container("bin/rails", "db:setup").join(" ")
end
test "execute in existing container" do test "execute in existing container" do
assert_equal \ assert_equal \
"docker exec app-web-999 bin/rails db:setup", "docker exec app-web-999 bin/rails db:setup",
@@ -182,6 +189,12 @@ class CommandsAppTest < ActiveSupport::TestCase
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1") new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
end end
test "execute in new container with custom options over ssh" do
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere", "cap-add" => true } } }
assert_match %r|docker run -it --rm -e RAILS_MASTER_KEY=\"456\" --mount \"somewhere\" --cap-add dhh/app:999 bin/rails c|,
new_command.execute_in_new_container_over_ssh("bin/rails", "c", host: "app-1")
end
test "execute in existing container over ssh" do test "execute in existing container over ssh" do
assert_match %r|docker exec -it app-web-999 bin/rails c|, assert_match %r|docker exec -it app-web-999 bin/rails c|,
new_command.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1") new_command.execute_in_existing_container_over_ssh("bin/rails", "c", host: "app-1")
@@ -237,17 +250,17 @@ class CommandsAppTest < ActiveSupport::TestCase
test "current_running_version" do test "current_running_version" do
assert_equal \ assert_equal \
"docker ps --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | grep -oE \"\\-[^-]+$\" | cut -c 2-", "docker ps --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | while read line; do echo ${line#app-web-}; done",
new_command.current_running_version.join(" ") new_command.current_running_version.join(" ")
end end
test "list_versions" do test "list_versions" do
assert_equal \ assert_equal \
"docker ps --filter label=service=app --filter label=role=web --format \"{{.Names}}\" | grep -oE \"\\-[^-]+$\" | cut -c 2-", "docker ps --filter label=service=app --filter label=role=web --format \"{{.Names}}\" | while read line; do echo ${line#app-web-}; done",
new_command.list_versions.join(" ") new_command.list_versions.join(" ")
assert_equal \ assert_equal \
"docker ps --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | grep -oE \"\\-[^-]+$\" | cut -c 2-", "docker ps --filter label=service=app --filter label=role=web --filter status=running --filter status=restarting --latest --format \"{{.Names}}\" | while read line; do echo ${line#app-web-}; done",
new_command.list_versions("--latest", statuses: [ :running, :restarting ]).join(" ") new_command.list_versions("--latest", statuses: [ :running, :restarting ]).join(" ")
end end
@@ -323,6 +336,6 @@ class CommandsAppTest < ActiveSupport::TestCase
private private
def new_command(role: "web") def new_command(role: "web")
Mrsk::Commands::App.new(Mrsk::Configuration.new(@config, destination: @destination, version: "999"), role: role) Kamal::Commands::App.new(Kamal::Configuration.new(@config, destination: @destination, version: "999"), role: role)
end end
end end

View File

@@ -21,7 +21,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
:echo, :echo,
"[#{@recorded_at}] [#{@performer}]", "[#{@recorded_at}] [#{@performer}]",
"app removed container", "app removed container",
">>", "mrsk-app-audit.log" ">>", "kamal-app-audit.log"
], @auditor.record("app removed container") ], @auditor.record("app removed container")
end end
@@ -31,7 +31,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
:echo, :echo,
"[#{@recorded_at}] [#{@performer}] [staging]", "[#{@recorded_at}] [#{@performer}] [staging]",
"app removed container", "app removed container",
">>", "mrsk-app-staging-audit.log" ">>", "kamal-app-staging-audit.log"
], auditor.record("app removed container") ], auditor.record("app removed container")
end end
end end
@@ -42,7 +42,7 @@ class CommandsAuditorTest < ActiveSupport::TestCase
:echo, :echo,
"[#{@recorded_at}] [#{@performer}] [web]", "[#{@recorded_at}] [#{@performer}] [web]",
"app removed container", "app removed container",
">>", "mrsk-app-audit.log" ">>", "kamal-app-audit.log"
], auditor.record("app removed container") ], auditor.record("app removed container")
end end
end end
@@ -52,13 +52,13 @@ class CommandsAuditorTest < ActiveSupport::TestCase
:echo, :echo,
"[#{@recorded_at}] [#{@performer}] [value]", "[#{@recorded_at}] [#{@performer}] [value]",
"app removed container", "app removed container",
">>", "mrsk-app-audit.log" ">>", "kamal-app-audit.log"
], @auditor.record("app removed container", detail: "value") ], @auditor.record("app removed container", detail: "value")
end end
private private
def new_command(destination: nil, **details) def new_command(destination: nil, **details)
Mrsk::Commands::Auditor.new(Mrsk::Configuration.new(@config, destination: destination, version: "123"), **details) Kamal::Commands::Auditor.new(Kamal::Configuration.new(@config, destination: destination, version: "123"), **details)
end end
end end

View File

@@ -9,7 +9,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
builder = new_builder_command(builder: { "cache" => { "type" => "gha" }}) builder = new_builder_command(builder: { "cache" => { "type" => "gha" }})
assert_equal "multiarch", builder.name assert_equal "multiarch", builder.name
assert_equal \ assert_equal \
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", "docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -33,7 +33,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
builder = new_builder_command(builder: { "local" => { }, "remote" => { }, "cache" => { "type" => "gha" } }) builder = new_builder_command(builder: { "local" => { }, "remote" => { }, "cache" => { "type" => "gha" } })
assert_equal "multiarch/remote", builder.name assert_equal "multiarch/remote", builder.name
assert_equal \ assert_equal \
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", "docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -41,7 +41,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } }) builder = new_builder_command(builder: { "remote" => { "arch" => "amd64" }, "cache" => { "type" => "gha" } })
assert_equal "native/remote", builder.name assert_equal "native/remote", builder.name
assert_equal \ assert_equal \
"docker buildx build --push --platform linux/amd64 --builder mrsk-app-native-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .", "docker buildx build --push --platform linux/amd64 --builder kamal-app-native-remote -t dhh/app:123 -t dhh/app:latest --cache-to type=gha --cache-from type=gha --label service=\"app\" --file Dockerfile .",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -70,7 +70,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
test "missing dockerfile" do test "missing dockerfile" do
Pathname.any_instance.expects(:exist?).returns(false).once Pathname.any_instance.expects(:exist?).returns(false).once
builder = new_builder_command(builder: { "dockerfile" => "Dockerfile.xyz" }) builder = new_builder_command(builder: { "dockerfile" => "Dockerfile.xyz" })
assert_raises(Mrsk::Commands::Builder::Base::BuilderError) do assert_raises(Kamal::Commands::Builder::Base::BuilderError) do
builder.target.build_options.join(" ") builder.target.build_options.join(" ")
end end
end end
@@ -78,7 +78,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
test "build context" do test "build context" do
builder = new_builder_command(builder: { "context" => ".." }) builder = new_builder_command(builder: { "context" => ".." })
assert_equal \ assert_equal \
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ..", "docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --file Dockerfile ..",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -92,7 +92,7 @@ class CommandsBuilderTest < ActiveSupport::TestCase
test "multiarch push with build args" do test "multiarch push with build args" do
builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } }) builder = new_builder_command(builder: { "args" => { "a" => 1, "b" => 2 } })
assert_equal \ assert_equal \
"docker buildx build --push --platform linux/amd64,linux/arm64 --builder mrsk-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" --file Dockerfile .", "docker buildx build --push --platform linux/amd64,linux/arm64 --builder kamal-app-multiarch -t dhh/app:123 -t dhh/app:latest --label service=\"app\" --build-arg a=\"1\" --build-arg b=\"2\" --file Dockerfile .",
builder.push.join(" ") builder.push.join(" ")
end end
@@ -105,6 +105,6 @@ class CommandsBuilderTest < ActiveSupport::TestCase
private private
def new_builder_command(additional_config = {}) def new_builder_command(additional_config = {})
Mrsk::Commands::Builder.new(Mrsk::Configuration.new(@config.merge(additional_config), version: "123")) Kamal::Commands::Builder.new(Kamal::Configuration.new(@config.merge(additional_config), version: "123"))
end end
end end

View File

@@ -5,7 +5,7 @@ class CommandsDockerTest < ActiveSupport::TestCase
@config = { @config = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ] service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, servers: [ "1.1.1.1" ]
} }
@docker = Mrsk::Commands::Docker.new(Mrsk::Configuration.new(@config)) @docker = Kamal::Commands::Docker.new(Kamal::Configuration.new(@config))
end end
test "install" do test "install" do

View File

@@ -10,7 +10,7 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase
test "run" do test "run" do
assert_equal \ assert_equal \
"docker run --detach --name healthcheck-app-123 --publish 3999:3000 --label service=healthcheck-app -e MRSK_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" dhh/app:123", "docker run --detach --name healthcheck-app-123 --publish 3999:3000 --label service=healthcheck-app -e KAMAL_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" dhh/app:123",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -18,7 +18,7 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase
@config[:healthcheck] = { "port" => 3001 } @config[:healthcheck] = { "port" => 3001 }
assert_equal \ assert_equal \
"docker run --detach --name healthcheck-app-123 --publish 3999:3001 --label service=healthcheck-app -e MRSK_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"curl -f http://localhost:3001/up || exit 1\" --health-interval \"1s\" dhh/app:123", "docker run --detach --name healthcheck-app-123 --publish 3999:3001 --label service=healthcheck-app -e KAMAL_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"curl -f http://localhost:3001/up || exit 1\" --health-interval \"1s\" dhh/app:123",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -26,7 +26,7 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase
@destination = "staging" @destination = "staging"
assert_equal \ assert_equal \
"docker run --detach --name healthcheck-app-staging-123 --publish 3999:3000 --label service=healthcheck-app-staging -e MRSK_CONTAINER_NAME=\"healthcheck-app-staging\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" dhh/app:123", "docker run --detach --name healthcheck-app-staging-123 --publish 3999:3000 --label service=healthcheck-app-staging -e KAMAL_CONTAINER_NAME=\"healthcheck-app-staging\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" dhh/app:123",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -34,14 +34,14 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase
@config[:healthcheck] = { "cmd" => "/bin/up" } @config[:healthcheck] = { "cmd" => "/bin/up" }
assert_equal \ assert_equal \
"docker run --detach --name healthcheck-app-123 --publish 3999:3000 --label service=healthcheck-app -e MRSK_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"/bin/up\" --health-interval \"1s\" dhh/app:123", "docker run --detach --name healthcheck-app-123 --publish 3999:3000 --label service=healthcheck-app -e KAMAL_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"/bin/up\" --health-interval \"1s\" dhh/app:123",
new_command.run.join(" ") new_command.run.join(" ")
end end
test "run with custom options" do test "run with custom options" do
@config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere" } } } @config[:servers] = { "web" => { "hosts" => [ "1.1.1.1" ], "options" => { "mount" => "somewhere" } } }
assert_equal \ assert_equal \
"docker run --detach --name healthcheck-app-123 --publish 3999:3000 --label service=healthcheck-app -e MRSK_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --mount \"somewhere\" dhh/app:123", "docker run --detach --name healthcheck-app-123 --publish 3999:3000 --label service=healthcheck-app -e KAMAL_CONTAINER_NAME=\"healthcheck-app\" --health-cmd \"curl -f http://localhost:3000/up || exit 1\" --health-interval \"1s\" --mount \"somewhere\" dhh/app:123",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -101,6 +101,6 @@ class CommandsHealthcheckTest < ActiveSupport::TestCase
private private
def new_command def new_command
Mrsk::Commands::Healthcheck.new(Mrsk::Configuration.new(@config, destination: @destination, version: "123")) Kamal::Commands::Healthcheck.new(Kamal::Configuration.new(@config, destination: @destination, version: "123"))
end end
end end

View File

@@ -17,12 +17,12 @@ class CommandsHookTest < ActiveSupport::TestCase
test "run" do test "run" do
assert_equal [ assert_equal [
".mrsk/hooks/foo", ".kamal/hooks/foo",
{ env: { { env: {
"MRSK_RECORDED_AT" => @recorded_at, "KAMAL_RECORDED_AT" => @recorded_at,
"MRSK_PERFORMER" => @performer, "KAMAL_PERFORMER" => @performer,
"MRSK_VERSION" => "123", "KAMAL_VERSION" => "123",
"MRSK_SERVICE_VERSION" => "app@123" } } "KAMAL_SERVICE_VERSION" => "app@123" } }
], new_command.run("foo") ], new_command.run("foo")
end end
@@ -30,15 +30,15 @@ class CommandsHookTest < ActiveSupport::TestCase
assert_equal [ assert_equal [
"custom/hooks/path/foo", "custom/hooks/path/foo",
{ env: { { env: {
"MRSK_RECORDED_AT" => @recorded_at, "KAMAL_RECORDED_AT" => @recorded_at,
"MRSK_PERFORMER" => @performer, "KAMAL_PERFORMER" => @performer,
"MRSK_VERSION" => "123", "KAMAL_VERSION" => "123",
"MRSK_SERVICE_VERSION" => "app@123" } } "KAMAL_SERVICE_VERSION" => "app@123" } }
], new_command(hooks_path: "custom/hooks/path").run("foo") ], new_command(hooks_path: "custom/hooks/path").run("foo")
end end
private private
def new_command(**extra_config) def new_command(**extra_config)
Mrsk::Commands::Hook.new(Mrsk::Configuration.new(@config.merge(**extra_config), version: "123")) Kamal::Commands::Hook.new(Kamal::Configuration.new(@config.merge(**extra_config), version: "123"))
end end
end end

View File

@@ -10,24 +10,24 @@ class CommandsLockTest < ActiveSupport::TestCase
test "status" do test "status" do
assert_equal \ assert_equal \
"stat mrsk_lock-app > /dev/null && cat mrsk_lock-app/details | base64 -d", "stat kamal_lock-app > /dev/null && cat kamal_lock-app/details | base64 -d",
new_command.status.join(" ") new_command.status.join(" ")
end end
test "acquire" do test "acquire" do
assert_match \ assert_match \
/mkdir mrsk_lock-app && echo ".*" > mrsk_lock-app\/details/m, /mkdir kamal_lock-app && echo ".*" > kamal_lock-app\/details/m,
new_command.acquire("Hello", "123").join(" ") new_command.acquire("Hello", "123").join(" ")
end end
test "release" do test "release" do
assert_match \ assert_match \
"rm mrsk_lock-app/details && rm -r mrsk_lock-app", "rm kamal_lock-app/details && rm -r kamal_lock-app",
new_command.release.join(" ") new_command.release.join(" ")
end end
private private
def new_command def new_command
Mrsk::Commands::Lock.new(Mrsk::Configuration.new(@config, version: "123")) Kamal::Commands::Lock.new(Kamal::Configuration.new(@config, version: "123"))
end end
end end

View File

@@ -28,6 +28,6 @@ class CommandsPruneTest < ActiveSupport::TestCase
private private
def new_command def new_command
Mrsk::Commands::Prune.new(Mrsk::Configuration.new(@config, version: "123")) Kamal::Commands::Prune.new(Kamal::Configuration.new(@config, version: "123"))
end end
end end

View File

@@ -10,7 +10,7 @@ class CommandsRegistryTest < ActiveSupport::TestCase
}, },
servers: [ "1.1.1.1" ] servers: [ "1.1.1.1" ]
} }
@registry = Mrsk::Commands::Registry.new Mrsk::Configuration.new(@config) @registry = Kamal::Commands::Registry.new Kamal::Configuration.new(@config)
end end
test "registry login" do test "registry login" do
@@ -20,25 +20,25 @@ class CommandsRegistryTest < ActiveSupport::TestCase
end end
test "registry login with ENV password" do test "registry login with ENV password" do
ENV["MRSK_REGISTRY_PASSWORD"] = "more-secret" ENV["KAMAL_REGISTRY_PASSWORD"] = "more-secret"
@config[:registry]["password"] = [ "MRSK_REGISTRY_PASSWORD" ] @config[:registry]["password"] = [ "KAMAL_REGISTRY_PASSWORD" ]
assert_equal \ assert_equal \
"docker login hub.docker.com -u dhh -p more-secret", "docker login hub.docker.com -u dhh -p more-secret",
@registry.login.join(" ") @registry.login.join(" ")
ensure ensure
ENV.delete("MRSK_REGISTRY_PASSWORD") ENV.delete("KAMAL_REGISTRY_PASSWORD")
end end
test "registry login with ENV username" do test "registry login with ENV username" do
ENV["MRSK_REGISTRY_USERNAME"] = "also-secret" ENV["KAMAL_REGISTRY_USERNAME"] = "also-secret"
@config[:registry]["username"] = [ "MRSK_REGISTRY_USERNAME" ] @config[:registry]["username"] = [ "KAMAL_REGISTRY_USERNAME" ]
assert_equal \ assert_equal \
"docker login hub.docker.com -u also-secret -p secret", "docker login hub.docker.com -u also-secret -p secret",
@registry.login.join(" ") @registry.login.join(" ")
ensure ensure
ENV.delete("MRSK_REGISTRY_USERNAME") ENV.delete("KAMAL_REGISTRY_USERNAME")
end end
test "registry logout" do test "registry logout" do

View File

@@ -25,6 +25,11 @@ class CommandsTraefikTest < ActiveSupport::TestCase
assert_equal \ assert_equal \
"docker run --name traefik --detach --restart unless-stopped --publish 8080:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"", "docker run --name traefik --detach --restart unless-stopped --publish 8080:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
new_command.run.join(" ") new_command.run.join(" ")
@config[:traefik]["publish"] = false
assert_equal \
"docker run --name traefik --detach --restart unless-stopped --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{@image} --providers.docker --log.level=\"DEBUG\" --accesslog.format=\"json\" --api.insecure --metrics.prometheus.buckets=\"0.1,0.3,1.2,5.0\"",
new_command.run.join(" ")
end end
test "run with ports configured" do test "run with ports configured" do
@@ -86,7 +91,7 @@ class CommandsTraefikTest < ActiveSupport::TestCase
@config.delete(:traefik) @config.delete(:traefik)
assert_equal \ assert_equal \
"docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Mrsk::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"", "docker run --name traefik --detach --restart unless-stopped --publish 80:80 --volume /var/run/docker.sock:/var/run/docker.sock --log-opt max-size=\"10m\" #{Kamal::Commands::Traefik::DEFAULT_IMAGE} --providers.docker --log.level=\"DEBUG\"",
new_command.run.join(" ") new_command.run.join(" ")
end end
@@ -174,6 +179,6 @@ class CommandsTraefikTest < ActiveSupport::TestCase
private private
def new_command def new_command
Mrsk::Commands::Traefik.new(Mrsk::Configuration.new(@config, version: "123")) Kamal::Commands::Traefik.new(Kamal::Configuration.new(@config, version: "123"))
end end
end end

View File

@@ -66,7 +66,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
} }
} }
@config = Mrsk::Configuration.new(@deploy) @config = Kamal::Configuration.new(@deploy)
end end
test "service name" do test "service name" do
@@ -87,7 +87,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
test "missing host" do test "missing host" do
@deploy[:accessories]["mysql"]["host"] = nil @deploy[:accessories]["mysql"]["host"] = nil
@config = Mrsk::Configuration.new(@deploy) @config = Kamal::Configuration.new(@deploy)
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
@config.accessory(:mysql).hosts @config.accessory(:mysql).hosts
@@ -97,7 +97,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
test "setting host, hosts and roles" do test "setting host, hosts and roles" do
@deploy[:accessories]["mysql"]["hosts"] = true @deploy[:accessories]["mysql"]["hosts"] = true
@deploy[:accessories]["mysql"]["roles"] = true @deploy[:accessories]["mysql"]["roles"] = true
@config = Mrsk::Configuration.new(@deploy) @config = Kamal::Configuration.new(@deploy)
exception = assert_raises(ArgumentError) do exception = assert_raises(ArgumentError) do
@config.accessory(:mysql).hosts @config.accessory(:mysql).hosts
@@ -114,8 +114,8 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
ENV["MYSQL_ROOT_PASSWORD"] = "secret123" ENV["MYSQL_ROOT_PASSWORD"] = "secret123"
@config.accessory(:mysql).env_args.tap do |env_args| @config.accessory(:mysql).env_args.tap do |env_args|
assert_equal ["-e", "MYSQL_ROOT_PASSWORD=\"secret123\"", "-e", "MYSQL_ROOT_HOST=\"%\""], Mrsk::Utils.unredacted(env_args) assert_equal ["-e", "MYSQL_ROOT_PASSWORD=\"secret123\"", "-e", "MYSQL_ROOT_HOST=\"%\""], Kamal::Utils.unredacted(env_args)
assert_equal ["-e", "MYSQL_ROOT_PASSWORD=[REDACTED]", "-e", "MYSQL_ROOT_HOST=\"%\""], Mrsk::Utils.redacted(env_args) assert_equal ["-e", "MYSQL_ROOT_PASSWORD=[REDACTED]", "-e", "MYSQL_ROOT_HOST=\"%\""], Kamal::Utils.redacted(env_args)
end end
ensure ensure
ENV["MYSQL_ROOT_PASSWORD"] = nil ENV["MYSQL_ROOT_PASSWORD"] = nil
@@ -132,7 +132,7 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
test "dynamic file expansion" do test "dynamic file expansion" do
@deploy[:accessories]["mysql"]["files"] << "test/fixtures/files/structure.sql.erb:/docker-entrypoint-initdb.d/structure.sql" @deploy[:accessories]["mysql"]["files"] << "test/fixtures/files/structure.sql.erb:/docker-entrypoint-initdb.d/structure.sql"
@config = Mrsk::Configuration.new(@deploy) @config = Kamal::Configuration.new(@deploy)
assert_match "This was dynamically expanded", @config.accessory(:mysql).files.keys[2].read assert_match "This was dynamically expanded", @config.accessory(:mysql).files.keys[2].read
assert_match "%", @config.accessory(:mysql).files.keys[2].read assert_match "%", @config.accessory(:mysql).files.keys[2].read

View File

@@ -7,7 +7,7 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
servers: [ "1.1.1.1" ] servers: [ "1.1.1.1" ]
} }
@config = Mrsk::Configuration.new(@deploy) @config = Kamal::Configuration.new(@deploy)
@deploy_with_builder_option = { @deploy_with_builder_option = {
service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" }, service: "app", image: "dhh/app", registry: { "username" => "dhh", "password" => "secret" },
@@ -15,7 +15,7 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
builder: {} builder: {}
} }
@config_with_builder_option = Mrsk::Configuration.new(@deploy_with_builder_option) @config_with_builder_option = Kamal::Configuration.new(@deploy_with_builder_option)
end end
test "multiarch?" do test "multiarch?" do
@@ -44,14 +44,6 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
assert_nil @config.builder.remote_host assert_nil @config.builder.remote_host
end end
test "remote config is missing when local is specified" do
@deploy_with_builder_option[:builder] = { "local" => { "arch" => "arm64", "host" => "unix:///Users/<%= `whoami`.strip %>/.docker/run/docker.sock" } }
assert_raises(ArgumentError) do
@config_with_builder_option.builder
end
end
test "setting both local and remote configs" do test "setting both local and remote configs" do
@deploy_with_builder_option[:builder] = { @deploy_with_builder_option[:builder] = {
"local" => { "arch" => "arm64", "host" => "unix:///Users/<%= `whoami`.strip %>/.docker/run/docker.sock" }, "local" => { "arch" => "arm64", "host" => "unix:///Users/<%= `whoami`.strip %>/.docker/run/docker.sock" },
@@ -98,15 +90,23 @@ class ConfigurationBuilderTest < ActiveSupport::TestCase
test "setting registry cache" do test "setting registry cache" do
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } } @deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } }
assert_equal "type=registry,ref=/dhh/app-build-cache", @config_with_builder_option.builder.cache_from assert_equal "type=registry,ref=dhh/app-build-cache", @config_with_builder_option.builder.cache_from
assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=/dhh/app-build-cache", @config_with_builder_option.builder.cache_to assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=dhh/app-build-cache", @config_with_builder_option.builder.cache_to
end
test "setting registry cache when using a custom registry" do
@config_with_builder_option.registry["server"] = "registry.example.com"
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "options" => "mode=max,image-manifest=true,oci-mediatypes=true" } }
assert_equal "type=registry,ref=registry.example.com/dhh/app-build-cache", @config_with_builder_option.builder.cache_from
assert_equal "type=registry,mode=max,image-manifest=true,oci-mediatypes=true,ref=registry.example.com/dhh/app-build-cache", @config_with_builder_option.builder.cache_to
end end
test "setting registry cache with image" do test "setting registry cache with image" do
@deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "image" => "mrsk", "options" => "mode=max" } } @deploy_with_builder_option[:builder] = { "cache" => { "type" => "registry", "image" => "kamal", "options" => "mode=max" } }
assert_equal "type=registry,ref=/mrsk", @config_with_builder_option.builder.cache_from assert_equal "type=registry,ref=kamal", @config_with_builder_option.builder.cache_from
assert_equal "type=registry,mode=max,ref=/mrsk", @config_with_builder_option.builder.cache_to assert_equal "type=registry,mode=max,ref=kamal", @config_with_builder_option.builder.cache_to
end end
test "args" do test "args" do

View File

@@ -8,7 +8,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
env: { "REDIS_URL" => "redis://x/y" } env: { "REDIS_URL" => "redis://x/y" }
} }
@config = Mrsk::Configuration.new(@deploy) @config = Kamal::Configuration.new(@deploy)
@deploy_with_roles = @deploy.dup.merge({ @deploy_with_roles = @deploy.dup.merge({
servers: { servers: {
@@ -24,7 +24,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
} }
}) })
@config_with_roles = Mrsk::Configuration.new(@deploy_with_roles) @config_with_roles = Kamal::Configuration.new(@deploy_with_roles)
end end
test "hosts" do test "hosts" do
@@ -62,7 +62,7 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
end end
test "default traefik label on non-web role" do test "default traefik label on non-web role" do
config = Mrsk::Configuration.new(@deploy_with_roles.tap { |c| config = Kamal::Configuration.new(@deploy_with_roles.tap { |c|
c[:servers]["beta"] = { "traefik" => "true", "hosts" => [ "1.1.1.5" ] } c[:servers]["beta"] = { "traefik" => "true", "hosts" => [ "1.1.1.5" ] }
}) })
@@ -98,8 +98,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
ENV["DB_PASSWORD"] = "secret&\"123" ENV["DB_PASSWORD"] = "secret&\"123"
@config_with_roles.role(:workers).env_args.tap do |env_args| @config_with_roles.role(:workers).env_args.tap do |env_args|
assert_equal ["-e", "REDIS_PASSWORD=\"secret456\"", "-e", "DB_PASSWORD=\"secret&\\\"123\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Mrsk::Utils.unredacted(env_args) assert_equal ["-e", "REDIS_PASSWORD=\"secret456\"", "-e", "DB_PASSWORD=\"secret&\\\"123\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Kamal::Utils.unredacted(env_args)
assert_equal ["-e", "REDIS_PASSWORD=[REDACTED]", "-e", "DB_PASSWORD=[REDACTED]", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Mrsk::Utils.redacted(env_args) assert_equal ["-e", "REDIS_PASSWORD=[REDACTED]", "-e", "DB_PASSWORD=[REDACTED]", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Kamal::Utils.redacted(env_args)
end end
ensure ensure
ENV["REDIS_PASSWORD"] = nil ENV["REDIS_PASSWORD"] = nil
@@ -120,8 +120,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
ENV["DB_PASSWORD"] = "secret123" ENV["DB_PASSWORD"] = "secret123"
@config_with_roles.role(:workers).env_args.tap do |env_args| @config_with_roles.role(:workers).env_args.tap do |env_args|
assert_equal ["-e", "DB_PASSWORD=\"secret123\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Mrsk::Utils.unredacted(env_args) assert_equal ["-e", "DB_PASSWORD=\"secret123\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Kamal::Utils.unredacted(env_args)
assert_equal ["-e", "DB_PASSWORD=[REDACTED]", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Mrsk::Utils.redacted(env_args) assert_equal ["-e", "DB_PASSWORD=[REDACTED]", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Kamal::Utils.redacted(env_args)
end end
ensure ensure
ENV["DB_PASSWORD"] = nil ENV["DB_PASSWORD"] = nil
@@ -140,8 +140,8 @@ class ConfigurationRoleTest < ActiveSupport::TestCase
ENV["REDIS_PASSWORD"] = "secret456" ENV["REDIS_PASSWORD"] = "secret456"
@config_with_roles.role(:workers).env_args.tap do |env_args| @config_with_roles.role(:workers).env_args.tap do |env_args|
assert_equal ["-e", "REDIS_PASSWORD=\"secret456\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Mrsk::Utils.unredacted(env_args) assert_equal ["-e", "REDIS_PASSWORD=\"secret456\"", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Kamal::Utils.unredacted(env_args)
assert_equal ["-e", "REDIS_PASSWORD=[REDACTED]", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Mrsk::Utils.redacted(env_args) assert_equal ["-e", "REDIS_PASSWORD=[REDACTED]", "-e", "REDIS_URL=\"redis://a/b\"", "-e", "WEB_CONCURRENCY=\"4\""], Kamal::Utils.redacted(env_args)
end end
ensure ensure
ENV["REDIS_PASSWORD"] = nil ENV["REDIS_PASSWORD"] = nil

View File

@@ -0,0 +1,36 @@
require "test_helper"
class ConfigurationSshTest < ActiveSupport::TestCase
setup do
@deploy = {
service: "app", image: "dhh/app",
registry: { "username" => "dhh", "password" => "secret" },
env: { "REDIS_URL" => "redis://x/y" },
servers: [ "1.1.1.1", "1.1.1.2" ],
volumes: ["/local/path:/container/path"]
}
@config = Kamal::Configuration.new(@deploy)
end
test "ssh options" do
assert_equal "root", @config.ssh.options[:user]
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "user" => "app" }) })
assert_equal "app", config.ssh.options[:user]
assert_equal 4, config.ssh.options[:logger].level
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "log_level" => "debug" }) })
assert_equal 0, config.ssh.options[:logger].level
end
test "ssh options with proxy host" do
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) })
assert_equal "root@1.2.3.4", config.ssh.options[:proxy].jump_proxies
end
test "ssh options with proxy host and user" do
config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "app@1.2.3.4" }) })
assert_equal "app@1.2.3.4", config.ssh.options[:proxy].jump_proxies
end
end

View File

@@ -0,0 +1,27 @@
require "test_helper"
class ConfigurationSshkitTest < ActiveSupport::TestCase
setup do
@deploy = {
service: "app", image: "dhh/app",
registry: { "username" => "dhh", "password" => "secret" },
env: { "REDIS_URL" => "redis://x/y" },
servers: [ "1.1.1.1", "1.1.1.2" ],
volumes: ["/local/path:/container/path"]
}
@config = Kamal::Configuration.new(@deploy)
end
test "sshkit max concurrent starts" do
assert_equal 30, @config.sshkit.max_concurrent_starts
@config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "max_concurrent_starts" => 50 }) })
assert_equal 50, @config.sshkit.max_concurrent_starts
end
test "sshkit pool idle timeout" do
assert_equal 900, @config.sshkit.pool_idle_timeout
@config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(sshkit: { "pool_idle_timeout" => 600 }) })
assert_equal 600, @config.sshkit.pool_idle_timeout
end
end

View File

@@ -13,12 +13,12 @@ class ConfigurationTest < ActiveSupport::TestCase
volumes: ["/local/path:/container/path"] volumes: ["/local/path:/container/path"]
} }
@config = Mrsk::Configuration.new(@deploy) @config = Kamal::Configuration.new(@deploy)
@deploy_with_roles = @deploy.dup.merge({ @deploy_with_roles = @deploy.dup.merge({
servers: { "web" => [ "1.1.1.1", "1.1.1.2" ], "workers" => { "hosts" => [ "1.1.1.1", "1.1.1.3" ] } } }) servers: { "web" => [ "1.1.1.1", "1.1.1.2" ], "workers" => { "hosts" => [ "1.1.1.1", "1.1.1.3" ] } } })
@config_with_roles = Mrsk::Configuration.new(@deploy_with_roles) @config_with_roles = Kamal::Configuration.new(@deploy_with_roles)
end end
teardown do teardown do
@@ -29,7 +29,7 @@ class ConfigurationTest < ActiveSupport::TestCase
%i[ service image registry ].each do |key| %i[ service image registry ].each do |key|
test "#{key} config required" do test "#{key} config required" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
Mrsk::Configuration.new @deploy.tap { _1.delete key } Kamal::Configuration.new @deploy.tap { _1.delete key }
end end
end end
end end
@@ -37,7 +37,7 @@ class ConfigurationTest < ActiveSupport::TestCase
%w[ username password ].each do |key| %w[ username password ].each do |key|
test "registry #{key} required" do test "registry #{key} required" do
assert_raise(ArgumentError) do assert_raise(ArgumentError) do
Mrsk::Configuration.new @deploy.tap { _1[:registry].delete key } Kamal::Configuration.new @deploy.tap { _1[:registry].delete key }
end end
end end
end end
@@ -67,7 +67,7 @@ class ConfigurationTest < ActiveSupport::TestCase
assert_equal [ "1.1.1.1", "1.1.1.2" ], @config_with_roles.traefik_hosts assert_equal [ "1.1.1.1", "1.1.1.2" ], @config_with_roles.traefik_hosts
@deploy_with_roles[:servers]["workers"]["traefik"] = true @deploy_with_roles[:servers]["workers"]["traefik"] = true
config = Mrsk::Configuration.new(@deploy_with_roles) config = Kamal::Configuration.new(@deploy_with_roles)
assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], config.traefik_hosts assert_equal [ "1.1.1.1", "1.1.1.2", "1.1.1.3" ], config.traefik_hosts
end end
@@ -84,7 +84,7 @@ class ConfigurationTest < ActiveSupport::TestCase
ENV.delete("VERSION") ENV.delete("VERSION")
@config.expects(:`).with("git rev-parse HEAD").returns("git-version") @config.expects(:`).with("git rev-parse HEAD").returns("git-version")
@config.expects(:`).with("git status --porcelain").returns("") Kamal::Utils.expects(:uncommitted_changes).returns("")
assert_equal "git-version", @config.version assert_equal "git-version", @config.version
end end
@@ -92,7 +92,7 @@ class ConfigurationTest < ActiveSupport::TestCase
ENV.delete("VERSION") ENV.delete("VERSION")
@config.expects(:`).with("git rev-parse HEAD").returns("git-version") @config.expects(:`).with("git rev-parse HEAD").returns("git-version")
@config.expects(:`).with("git status --porcelain").returns("M file\n") Kamal::Utils.expects(:uncommitted_changes).returns("M file\n")
assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, @config.version assert_match /^git-version_uncommitted_[0-9a-f]{16}$/, @config.version
end end
@@ -109,14 +109,14 @@ class ConfigurationTest < ActiveSupport::TestCase
test "repository" do test "repository" do
assert_equal "dhh/app", @config.repository assert_equal "dhh/app", @config.repository
config = Mrsk::Configuration.new(@deploy.tap { |c| c[:registry].merge!({ "server" => "ghcr.io" }) }) config = Kamal::Configuration.new(@deploy.tap { |c| c[:registry].merge!({ "server" => "ghcr.io" }) })
assert_equal "ghcr.io/dhh/app", config.repository assert_equal "ghcr.io/dhh/app", config.repository
end end
test "absolute image" do test "absolute image" do
assert_equal "dhh/app:missing", @config.absolute_image assert_equal "dhh/app:missing", @config.absolute_image
config = Mrsk::Configuration.new(@deploy.tap { |c| c[:registry].merge!({ "server" => "ghcr.io" }) }) config = Kamal::Configuration.new(@deploy.tap { |c| c[:registry].merge!({ "server" => "ghcr.io" }) })
assert_equal "ghcr.io/dhh/app:missing", config.absolute_image assert_equal "ghcr.io/dhh/app:missing", config.absolute_image
end end
@@ -131,18 +131,18 @@ class ConfigurationTest < ActiveSupport::TestCase
test "env args with clear and secrets" do test "env args with clear and secrets" do
ENV["PASSWORD"] = "secret123" ENV["PASSWORD"] = "secret123"
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!({ config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!({
env: { "clear" => { "PORT" => "3000" }, "secret" => [ "PASSWORD" ] } env: { "clear" => { "PORT" => "3000" }, "secret" => [ "PASSWORD" ] }
}) }) }) })
assert_equal [ "-e", "PASSWORD=\"secret123\"", "-e", "PORT=\"3000\"" ], Mrsk::Utils.unredacted(config.env_args) assert_equal [ "-e", "PASSWORD=\"secret123\"", "-e", "PORT=\"3000\"" ], Kamal::Utils.unredacted(config.env_args)
assert_equal [ "-e", "PASSWORD=[REDACTED]", "-e", "PORT=\"3000\"" ], Mrsk::Utils.redacted(config.env_args) assert_equal [ "-e", "PASSWORD=[REDACTED]", "-e", "PORT=\"3000\"" ], Kamal::Utils.redacted(config.env_args)
ensure ensure
ENV["PASSWORD"] = nil ENV["PASSWORD"] = nil
end end
test "env args with only clear" do test "env args with only clear" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!({ config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!({
env: { "clear" => { "PORT" => "3000" } } env: { "clear" => { "PORT" => "3000" } }
}) }) }) })
@@ -152,19 +152,19 @@ class ConfigurationTest < ActiveSupport::TestCase
test "env args with only secrets" do test "env args with only secrets" do
ENV["PASSWORD"] = "secret123" ENV["PASSWORD"] = "secret123"
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!({ config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!({
env: { "secret" => [ "PASSWORD" ] } env: { "secret" => [ "PASSWORD" ] }
}) }) }) })
assert_equal [ "-e", "PASSWORD=\"secret123\"" ], Mrsk::Utils.unredacted(config.env_args) assert_equal [ "-e", "PASSWORD=\"secret123\"" ], Kamal::Utils.unredacted(config.env_args)
assert_equal [ "-e", "PASSWORD=[REDACTED]" ], Mrsk::Utils.redacted(config.env_args) assert_equal [ "-e", "PASSWORD=[REDACTED]" ], Kamal::Utils.redacted(config.env_args)
ensure ensure
ENV["PASSWORD"] = nil ENV["PASSWORD"] = nil
end end
test "env args with missing secret" do test "env args with missing secret" do
assert_raises(KeyError) do assert_raises(KeyError) do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!({ config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!({
env: { "secret" => [ "PASSWORD" ] } env: { "secret" => [ "PASSWORD" ] }
}) }).ensure_env_available }) }).ensure_env_available
end end
@@ -178,52 +178,35 @@ class ConfigurationTest < ActiveSupport::TestCase
test "hosts required for all roles" do test "hosts required for all roles" do
# Empty server list for implied web role # Empty server list for implied web role
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Mrsk::Configuration.new @deploy.merge(servers: []) Kamal::Configuration.new @deploy.merge(servers: [])
end end
# Empty server list # Empty server list
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Mrsk::Configuration.new @deploy.merge(servers: { "web" => [] }) Kamal::Configuration.new @deploy.merge(servers: { "web" => [] })
end end
# Missing hosts key # Missing hosts key
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Mrsk::Configuration.new @deploy.merge(servers: { "web" => {} }) Kamal::Configuration.new @deploy.merge(servers: { "web" => {} })
end end
# Empty hosts list # Empty hosts list
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Mrsk::Configuration.new @deploy.merge(servers: { "web" => { "hosts" => [] } }) Kamal::Configuration.new @deploy.merge(servers: { "web" => { "hosts" => [] } })
end end
# Nil hosts # Nil hosts
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Mrsk::Configuration.new @deploy.merge(servers: { "web" => { "hosts" => nil } }) Kamal::Configuration.new @deploy.merge(servers: { "web" => { "hosts" => nil } })
end end
# One role with hosts, one without # One role with hosts, one without
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Mrsk::Configuration.new @deploy.merge(servers: { "web" => %w[ web ], "workers" => { "hosts" => %w[ ] } }) Kamal::Configuration.new @deploy.merge(servers: { "web" => %w[ web ], "workers" => { "hosts" => %w[ ] } })
end end
end end
test "ssh options" do
assert_equal "root", @config.ssh_options[:user]
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "user" => "app" }) })
assert_equal "app", @config.ssh_options[:user]
end
test "ssh options with proxy host" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "1.2.3.4" }) })
assert_equal "root@1.2.3.4", @config.ssh_options[:proxy].jump_proxies
end
test "ssh options with proxy host and user" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(ssh: { "proxy" => "app@1.2.3.4" }) })
assert_equal "app@1.2.3.4", @config.ssh_options[:proxy].jump_proxies
end
test "volume_args" do test "volume_args" do
assert_equal ["--volume", "/local/path:/container/path"], @config.volume_args assert_equal ["--volume", "/local/path:/container/path"], @config.volume_args
end end
@@ -233,27 +216,27 @@ class ConfigurationTest < ActiveSupport::TestCase
end end
test "logging args with configured options" do test "logging args with configured options" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(logging: { "options" => { "max-size" => "100m", "max-file" => 5 } }) }) config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(logging: { "options" => { "max-size" => "100m", "max-file" => 5 } }) })
assert_equal ["--log-opt", "max-size=\"100m\"", "--log-opt", "max-file=\"5\""], @config.logging_args assert_equal ["--log-opt", "max-size=\"100m\"", "--log-opt", "max-file=\"5\""], @config.logging_args
end end
test "logging args with configured driver and options" do test "logging args with configured driver and options" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(logging: { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => 5 } }) }) config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(logging: { "driver" => "local", "options" => { "max-size" => "100m", "max-file" => 5 } }) })
assert_equal ["--log-driver", "\"local\"", "--log-opt", "max-size=\"100m\"", "--log-opt", "max-file=\"5\""], @config.logging_args assert_equal ["--log-driver", "\"local\"", "--log-opt", "max-size=\"100m\"", "--log-opt", "max-file=\"5\""], @config.logging_args
end end
test "erb evaluation of yml config" do test "erb evaluation of yml config" do
config = Mrsk::Configuration.create_from config_file: Pathname.new(File.expand_path("fixtures/deploy.erb.yml", __dir__)) config = Kamal::Configuration.create_from config_file: Pathname.new(File.expand_path("fixtures/deploy.erb.yml", __dir__))
assert_equal "my-user", config.registry["username"] assert_equal "my-user", config.registry["username"]
end end
test "destination yml config merge" do test "destination yml config merge" do
dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__)) dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__))
config = Mrsk::Configuration.create_from config_file: dest_config_file, destination: "world" config = Kamal::Configuration.create_from config_file: dest_config_file, destination: "world"
assert_equal "1.1.1.1", config.all_hosts.first assert_equal "1.1.1.1", config.all_hosts.first
config = Mrsk::Configuration.create_from config_file: dest_config_file, destination: "mars" config = Kamal::Configuration.create_from config_file: dest_config_file, destination: "mars"
assert_equal "1.1.1.3", config.all_hosts.first assert_equal "1.1.1.3", config.all_hosts.first
end end
@@ -261,27 +244,43 @@ class ConfigurationTest < ActiveSupport::TestCase
dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__)) dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__))
assert_raises(RuntimeError) do assert_raises(RuntimeError) do
config = Mrsk::Configuration.create_from config_file: dest_config_file, destination: "missing" config = Kamal::Configuration.create_from config_file: dest_config_file, destination: "missing"
end end
end end
test "to_h" do test "to_h" do
assert_equal({ :roles=>["web"], :hosts=>["1.1.1.1", "1.1.1.2"], :primary_host=>"1.1.1.1", :version=>"missing", :repository=>"dhh/app", :absolute_image=>"dhh/app:missing", :service_with_version=>"app-missing", :env_args=>["-e", "REDIS_URL=\"redis://x/y\""], :ssh_options=>{:user=>"root", :auth_methods=>["publickey"]}, :volume_args=>["--volume", "/local/path:/container/path"], :builder=>{}, :logging=>["--log-opt", "max-size=\"10m\""], :healthcheck=>{"path"=>"/up", "port"=>3000, "max_attempts" => 7 }}, @config.to_h) expected_config = \
{ :roles=>["web"],
:hosts=>["1.1.1.1", "1.1.1.2"],
:primary_host=>"1.1.1.1",
:version=>"missing",
:repository=>"dhh/app",
:absolute_image=>"dhh/app:missing",
:service_with_version=>"app-missing",
:env_args=>["-e", "REDIS_URL=\"redis://x/y\""],
:ssh_options=>{ :user=>"root", :auth_methods=>["publickey"], log_level: :fatal, keepalive: true, keepalive_interval: 30 },
:sshkit=>{},
:volume_args=>["--volume", "/local/path:/container/path"],
:builder=>{},
:logging=>["--log-opt", "max-size=\"10m\""],
:healthcheck=>{ "path"=>"/up", "port"=>3000, "max_attempts" => 7 }}
assert_equal expected_config, @config.to_h
end end
test "min version is lower" do test "min version is lower" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: "0.0.1") }) config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: "0.0.1") })
assert_equal "0.0.1", config.minimum_version assert_equal "0.0.1", config.minimum_version
end end
test "min version is equal" do test "min version is equal" do
config = Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: Mrsk::VERSION) }) config = Kamal::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: Kamal::VERSION) })
assert_equal Mrsk::VERSION, config.minimum_version assert_equal Kamal::VERSION, config.minimum_version
end end
test "min version is higher" do test "min version is higher" do
assert_raises(ArgumentError) do assert_raises(ArgumentError) do
Mrsk::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: "10000.0.0") }) Kamal::Configuration.new(@deploy.tap { |c| c.merge!(minimum_version: "10000.0.0") })
end end
end end
end end

View File

@@ -2,22 +2,22 @@ require_relative "integration_test"
class AccessoryTest < IntegrationTest class AccessoryTest < IntegrationTest
test "boot, stop, start, restart, logs, remove" do test "boot, stop, start, restart, logs, remove" do
mrsk :accessory, :boot, :busybox kamal :accessory, :boot, :busybox
assert_accessory_running :busybox assert_accessory_running :busybox
mrsk :accessory, :stop, :busybox kamal :accessory, :stop, :busybox
assert_accessory_not_running :busybox assert_accessory_not_running :busybox
mrsk :accessory, :start, :busybox kamal :accessory, :start, :busybox
assert_accessory_running :busybox assert_accessory_running :busybox
mrsk :accessory, :restart, :busybox kamal :accessory, :restart, :busybox
assert_accessory_running :busybox assert_accessory_running :busybox
logs = mrsk :accessory, :logs, :busybox, capture: true logs = kamal :accessory, :logs, :busybox, capture: true
assert_match /Starting busybox.../, logs assert_match /Starting busybox.../, logs
mrsk :accessory, :remove, :busybox, "-y" kamal :accessory, :remove, :busybox, "-y"
assert_accessory_not_running :busybox assert_accessory_not_running :busybox
end end
@@ -31,6 +31,6 @@ class AccessoryTest < IntegrationTest
end end
def accessory_details(name) def accessory_details(name)
mrsk :accessory, :details, name, capture: true kamal :accessory, :details, name, capture: true
end end
end end

View File

@@ -2,52 +2,52 @@ require_relative "integration_test"
class AppTest < IntegrationTest class AppTest < IntegrationTest
test "stop, start, boot, logs, images, containers, exec, remove" do test "stop, start, boot, logs, images, containers, exec, remove" do
mrsk :deploy kamal :deploy
assert_app_is_up assert_app_is_up
mrsk :app, :stop kamal :app, :stop
# traefik is up and returns 404s when it can't match a route # traefik is up and returns 404s when it can't match a route
assert_app_not_found assert_app_not_found
mrsk :app, :start kamal :app, :start
# mrsk app start does not wait # kamal app start does not wait
wait_for_app_to_be_up wait_for_app_to_be_up
mrsk :app, :boot kamal :app, :boot
wait_for_app_to_be_up wait_for_app_to_be_up
logs = mrsk :app, :logs, capture: true logs = kamal :app, :logs, capture: true
assert_match /App Host: vm1/, logs assert_match /App Host: vm1/, logs
assert_match /App Host: vm2/, logs assert_match /App Host: vm2/, logs
assert_match /GET \/ HTTP\/1.1/, logs assert_match /GET \/ HTTP\/1.1/, logs
images = mrsk :app, :images, capture: true images = kamal :app, :images, capture: true
assert_match /App Host: vm1/, images assert_match /App Host: vm1/, images
assert_match /App Host: vm2/, images assert_match /App Host: vm2/, images
assert_match /registry:4443\/app\s+#{latest_app_version}/, images assert_match /registry:4443\/app\s+#{latest_app_version}/, images
assert_match /registry:4443\/app\s+latest/, images assert_match /registry:4443\/app\s+latest/, images
containers = mrsk :app, :containers, capture: true containers = kamal :app, :containers, capture: true
assert_match /App Host: vm1/, containers assert_match /App Host: vm1/, containers
assert_match /App Host: vm2/, containers assert_match /App Host: vm2/, containers
assert_match /registry:4443\/app:#{latest_app_version}/, containers assert_match /registry:4443\/app:#{latest_app_version}/, containers
assert_match /registry:4443\/app:latest/, containers assert_match /registry:4443\/app:latest/, containers
exec_output = mrsk :app, :exec, :ps, capture: true exec_output = kamal :app, :exec, :ps, capture: true
assert_match /App Host: vm1/, exec_output assert_match /App Host: vm1/, exec_output
assert_match /App Host: vm2/, exec_output assert_match /App Host: vm2/, exec_output
assert_match /1 root 0:\d\d ps/, exec_output assert_match /1 root 0:\d\d ps/, exec_output
exec_output = mrsk :app, :exec, "--reuse", :ps, capture: true exec_output = kamal :app, :exec, "--reuse", :ps, capture: true
assert_match /App Host: vm1/, exec_output assert_match /App Host: vm1/, exec_output
assert_match /App Host: vm2/, exec_output assert_match /App Host: vm2/, exec_output
assert_match /1 root 0:\d\d nginx/, exec_output assert_match /1 root 0:\d\d nginx/, exec_output
mrsk :app, :remove kamal :app, :remove
# traefik is up and returns 404s when it can't match a route # traefik is up and returns 404s when it can't match a route
assert_app_not_found assert_app_not_found

View File

@@ -1,5 +1,5 @@
version: "3.7" version: "3.7"
name: "mrsk-test" name: "kamal-test"
volumes: volumes:
shared: shared:
@@ -20,7 +20,7 @@ services:
environment: environment:
- TEST_ID=${TEST_ID} - TEST_ID=${TEST_ID}
volumes: volumes:
- ../..:/mrsk - ../..:/kamal
- shared:/shared - shared:/shared
- registry:/registry - registry:/registry
- deployer_bundle:/usr/local/bundle/ - deployer_bundle:/usr/local/bundle/

Some files were not shown because too many files have changed in this diff Show More