Merge pull request #224 from basecamp/integration-tests
This commit is contained in:
42
test/integration/deploy_test.rb
Normal file
42
test/integration/deploy_test.rb
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
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
|
||||||
50
test/integration/docker-compose.yml
Normal file
50
test/integration/docker-compose.yml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
version: "3.7"
|
||||||
|
name: "mrsk-test"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
shared:
|
||||||
|
|
||||||
|
services:
|
||||||
|
shared:
|
||||||
|
build:
|
||||||
|
context: docker/shared
|
||||||
|
volumes:
|
||||||
|
- shared:/shared
|
||||||
|
|
||||||
|
deployer:
|
||||||
|
privileged: true
|
||||||
|
build:
|
||||||
|
context: docker/deployer
|
||||||
|
volumes:
|
||||||
|
- ../..:/mrsk
|
||||||
|
- shared:/shared
|
||||||
|
|
||||||
|
registry:
|
||||||
|
build:
|
||||||
|
context: docker/registry
|
||||||
|
environment:
|
||||||
|
- REGISTRY_HTTP_ADDR=0.0.0.0:4443
|
||||||
|
- REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt
|
||||||
|
- REGISTRY_HTTP_TLS_KEY=/certs/domain.key
|
||||||
|
volumes:
|
||||||
|
- shared:/shared
|
||||||
|
|
||||||
|
vm1:
|
||||||
|
privileged: true
|
||||||
|
build:
|
||||||
|
context: docker/vm
|
||||||
|
volumes:
|
||||||
|
- shared:/shared
|
||||||
|
|
||||||
|
vm2:
|
||||||
|
privileged: true
|
||||||
|
build:
|
||||||
|
context: docker/vm
|
||||||
|
volumes:
|
||||||
|
- shared:/shared
|
||||||
|
|
||||||
|
load_balancer:
|
||||||
|
build:
|
||||||
|
context: docker/load_balancer
|
||||||
|
ports:
|
||||||
|
- "12345:80"
|
||||||
27
test/integration/docker/deployer/Dockerfile
Normal file
27
test/integration/docker/deployer/Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
FROM ruby:3.2
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y ca-certificates openssh-client curl gnupg docker.io
|
||||||
|
|
||||||
|
RUN install -m 0755 -d /etc/apt/keyrings
|
||||||
|
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||||
|
RUN chmod a+r /etc/apt/keyrings/docker.gpg
|
||||||
|
RUN echo \
|
||||||
|
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
|
||||||
|
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
|
||||||
|
tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
||||||
|
|
||||||
|
COPY boot.sh .
|
||||||
|
COPY app/ .
|
||||||
|
|
||||||
|
RUN ln -s /shared/ssh /root/.ssh
|
||||||
|
RUN mkdir -p /etc/docker/certs.d/registry:4443 && ln -s /shared/certs/domain.crt /etc/docker/certs.d/registry:4443/ca.crt
|
||||||
|
|
||||||
|
RUN git config --global user.email "deployer@example.com"
|
||||||
|
RUN git config --global user.name "Deployer"
|
||||||
|
RUN git init && git add . && git commit -am "Initial version"
|
||||||
|
|
||||||
|
CMD ["./boot.sh"]
|
||||||
3
test/integration/docker/deployer/app/Dockerfile
Normal file
3
test/integration/docker/deployer/app/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
FROM nginx:1-alpine-slim
|
||||||
|
|
||||||
|
COPY default.conf /etc/nginx/conf.d/default.conf
|
||||||
14
test/integration/docker/deployer/app/config/deploy.yml
Normal file
14
test/integration/docker/deployer/app/config/deploy.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
service: app
|
||||||
|
image: app
|
||||||
|
servers:
|
||||||
|
- vm1
|
||||||
|
- vm2
|
||||||
|
registry:
|
||||||
|
server: registry:4443
|
||||||
|
username: root
|
||||||
|
password: root
|
||||||
|
builder:
|
||||||
|
multiarch: false
|
||||||
|
healthcheck:
|
||||||
|
path: /
|
||||||
|
port: 80
|
||||||
17
test/integration/docker/deployer/app/default.conf
Normal file
17
test/integration/docker/deployer/app/default.conf
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
index index.html index.htm;
|
||||||
|
}
|
||||||
|
|
||||||
|
# redirect server error pages to the static page /50x.html
|
||||||
|
#
|
||||||
|
error_page 500 502 503 504 /50x.html;
|
||||||
|
location = /50x.html {
|
||||||
|
root /usr/share/nginx/html;
|
||||||
|
}
|
||||||
|
}
|
||||||
9
test/integration/docker/deployer/boot.sh
Executable file
9
test/integration/docker/deployer/boot.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
cd /mrsk && gem build mrsk.gemspec -o /tmp/mrsk.gem && gem install /tmp/mrsk.gem
|
||||||
|
|
||||||
|
dockerd &
|
||||||
|
|
||||||
|
trap "pkill -f sleep" term
|
||||||
|
|
||||||
|
sleep infinity & wait
|
||||||
4
test/integration/docker/load_balancer/Dockerfile
Normal file
4
test/integration/docker/load_balancer/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FROM nginx:1-alpine-slim
|
||||||
|
|
||||||
|
COPY default.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
12
test/integration/docker/load_balancer/default.conf
Normal file
12
test/integration/docker/load_balancer/default.conf
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
upstream loadbalancer {
|
||||||
|
server vm1:80;
|
||||||
|
server vm2:80;
|
||||||
|
}
|
||||||
|
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://loadbalancer;
|
||||||
|
}
|
||||||
|
}
|
||||||
7
test/integration/docker/registry/Dockerfile
Normal file
7
test/integration/docker/registry/Dockerfile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
FROM registry
|
||||||
|
|
||||||
|
COPY boot.sh .
|
||||||
|
|
||||||
|
RUN ln -s /shared/certs /certs
|
||||||
|
|
||||||
|
ENTRYPOINT ["./boot.sh"]
|
||||||
7
test/integration/docker/registry/boot.sh
Executable file
7
test/integration/docker/registry/boot.sh
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
while [ ! -f /certs/domain.crt ]; do sleep 1; done
|
||||||
|
|
||||||
|
trap "pkill -f registry" term
|
||||||
|
|
||||||
|
/entrypoint.sh /etc/docker/registry/config.yml & wait
|
||||||
14
test/integration/docker/shared/Dockerfile
Normal file
14
test/integration/docker/shared/Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
FROM ubuntu:22.10
|
||||||
|
|
||||||
|
WORKDIR /work
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get -y install openssh-client openssl
|
||||||
|
|
||||||
|
RUN mkdir ssh && \
|
||||||
|
ssh-keygen -t rsa -f ssh/id_rsa -N ""
|
||||||
|
|
||||||
|
COPY registry-dns.conf .
|
||||||
|
|
||||||
|
RUN mkdir certs && openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key -x509 -days 365 -out certs/domain.crt -subj '/CN=registry' -extensions EXT -config registry-dns.conf
|
||||||
|
|
||||||
|
CMD ["bash", "-c", "cp -r * /shared"]
|
||||||
7
test/integration/docker/shared/registry-dns.conf
Normal file
7
test/integration/docker/shared/registry-dns.conf
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[dn]
|
||||||
|
CN=registry
|
||||||
|
[req]
|
||||||
|
distinguished_name = dn
|
||||||
|
[EXT]
|
||||||
|
subjectAltName=DNS:registry
|
||||||
|
keyUsage=digitalSignature
|
||||||
12
test/integration/docker/vm/Dockerfile
Normal file
12
test/integration/docker/vm/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM ubuntu:22.10
|
||||||
|
|
||||||
|
WORKDIR /work
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get -y install openssh-client openssh-server docker.io
|
||||||
|
|
||||||
|
RUN mkdir /root/.ssh && ln -s /shared/ssh/id_rsa.pub /root/.ssh/authorized_keys
|
||||||
|
RUN mkdir -p /etc/docker/certs.d/registry:4443 && ln -s /shared/certs/domain.crt /etc/docker/certs.d/registry:4443/ca.crt
|
||||||
|
|
||||||
|
COPY boot.sh .
|
||||||
|
|
||||||
|
CMD ["./boot.sh"]
|
||||||
11
test/integration/docker/vm/boot.sh
Executable file
11
test/integration/docker/vm/boot.sh
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
while [ ! -f /root/.ssh/authorized_keys ]; do echo "Waiting for ssh keys"; sleep 1; done
|
||||||
|
|
||||||
|
service ssh restart
|
||||||
|
|
||||||
|
dockerd &
|
||||||
|
|
||||||
|
trap "pkill -f sleep" term
|
||||||
|
|
||||||
|
sleep infinity & wait
|
||||||
Reference in New Issue
Block a user