Adds a simple integration test to ensure that `mrsk deploy` works. Everything required is spun up with docker compose: - shared: a container that contains an ssh key and a self signed cert to be shared between the images - deployer: the image we will deploy from - registry: a docker registry - two vm images to deploy into - load_balancer: an nginx load balancer to use between our images The other images are in privileged mode so that we can run docker-in-docker. We need to run docker inside the images - mapping in the docker socket doesn't work because both VMs would share the host daemon. The docker registry requires a self signed cert as you cannot use basic auth over HTTP except on localhost. It runs on port 4443 rather than 443 because docker refused to accept that "registry" is a docker host and tries to push images to docker.io/registry. "registry:4443" works fine. The shared container contains the ssh keys for the deployer and vms, and the self signed cert for the registry. When the shared container boots, it copies them into a shared volume. The other deployer and vm images are built with soft links from the shared volume to the require locations. Their boot scripts wait for the files to be copied in before continuing. The root mrsk folder is mapped into the deployer container. On boot it builds the gem and installs it. Right now there's just a single test. We confirm that the load balancer is returning a 502, run `mrsk deploy` and then confirm it returns 200.
43 lines
769 B
Ruby
43 lines
769 B
Ruby
require "net/http"
|
|
|
|
class DeployTest < ActiveSupport::TestCase
|
|
|
|
setup do
|
|
docker_compose "up --build --force-recreate -d"
|
|
sleep 5
|
|
end
|
|
|
|
teardown do
|
|
docker_compose "down -v"
|
|
end
|
|
|
|
test "deploy" do
|
|
assert_app_is_down
|
|
|
|
mrsk :deploy
|
|
|
|
assert_app_is_up
|
|
end
|
|
|
|
private
|
|
def docker_compose(*commands)
|
|
system("cd test/integration && docker compose #{commands.join(" ")}")
|
|
end
|
|
|
|
def mrsk(*commands)
|
|
docker_compose("exec deployer mrsk #{commands.join(" ")}")
|
|
end
|
|
|
|
def assert_app_is_down
|
|
assert_equal "502", app_response.code
|
|
end
|
|
|
|
def assert_app_is_up
|
|
assert_equal "200", app_response.code
|
|
end
|
|
|
|
def app_response
|
|
Net::HTTP.get_response(URI.parse("http://localhost:12345"))
|
|
end
|
|
end
|