Add an integration test for roles
Add an app with roles to the integration tests. We'll deploy two web containers and one worker. The worker just sleeps, so we are testing that the container has booted.
This commit is contained in:
@@ -62,3 +62,7 @@ services:
|
|||||||
context: docker/load_balancer
|
context: docker/load_balancer
|
||||||
ports:
|
ports:
|
||||||
- "12345:80"
|
- "12345:80"
|
||||||
|
depends_on:
|
||||||
|
- vm1
|
||||||
|
- vm2
|
||||||
|
- vm3
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ RUN apt-get update --fix-missing && apt-get install -y docker-ce docker-ce-cli c
|
|||||||
|
|
||||||
COPY *.sh .
|
COPY *.sh .
|
||||||
COPY app/ app/
|
COPY app/ app/
|
||||||
|
COPY app_with_roles/ app_with_roles/
|
||||||
|
|
||||||
RUN rm -rf /root/.ssh
|
RUN rm -rf /root/.ssh
|
||||||
RUN ln -s /shared/ssh /root/.ssh
|
RUN ln -s /shared/ssh /root/.ssh
|
||||||
@@ -26,6 +27,7 @@ RUN mkdir -p /etc/docker/certs.d/registry:4443 && ln -s /shared/certs/domain.crt
|
|||||||
RUN git config --global user.email "deployer@example.com"
|
RUN git config --global user.email "deployer@example.com"
|
||||||
RUN git config --global user.name "Deployer"
|
RUN git config --global user.name "Deployer"
|
||||||
RUN cd app && git init && echo ".env" >> .gitignore && git add . && git commit -am "Initial version"
|
RUN cd app && git init && echo ".env" >> .gitignore && git add . && git commit -am "Initial version"
|
||||||
|
RUN cd app_with_roles && git init && echo ".env" >> .gitignore && git add . && git commit -am "Initial version"
|
||||||
|
|
||||||
HEALTHCHECK --interval=1s CMD pgrep sleep
|
HEALTHCHECK --interval=1s CMD pgrep sleep
|
||||||
|
|
||||||
|
|||||||
1
test/integration/docker/deployer/app_with_roles/.env.erb
Normal file
1
test/integration/docker/deployer/app_with_roles/.env.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
SECRET_TOKEN=1234
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Docker set up!"
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/docker-setup
|
||||||
3
test/integration/docker/deployer/app_with_roles/.kamal/hooks/post-deploy
Executable file
3
test/integration/docker/deployer/app_with_roles/.kamal/hooks/post-deploy
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Deployed!"
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/post-deploy
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Rebooted Traefik on ${KAMAL_HOSTS}"
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/post-traefik-reboot
|
||||||
3
test/integration/docker/deployer/app_with_roles/.kamal/hooks/pre-build
Executable file
3
test/integration/docker/deployer/app_with_roles/.kamal/hooks/pre-build
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "About to build and push..."
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-build
|
||||||
8
test/integration/docker/deployer/app_with_roles/.kamal/hooks/pre-connect
Executable file
8
test/integration/docker/deployer/app_with_roles/.kamal/hooks/pre-connect
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
echo "About to lock..."
|
||||||
|
if [ "$KAMAL_HOSTS" != "vm1,vm2,vm3" ]; then
|
||||||
|
echo "Expected hosts to be 'vm1,vm2,vm3', got $KAMAL_HOSTS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-connect
|
||||||
3
test/integration/docker/deployer/app_with_roles/.kamal/hooks/pre-deploy
Executable file
3
test/integration/docker/deployer/app_with_roles/.kamal/hooks/pre-deploy
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Deployed!"
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-deploy
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
echo "Rebooting Traefik on ${KAMAL_HOSTS}..."
|
||||||
|
mkdir -p /tmp/${TEST_ID} && touch /tmp/${TEST_ID}/pre-traefik-reboot
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
FROM registry:4443/nginx:1-alpine-slim
|
||||||
|
|
||||||
|
COPY default.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
ARG COMMIT_SHA
|
||||||
|
RUN echo $COMMIT_SHA > /usr/share/nginx/html/version
|
||||||
|
RUN mkdir -p /usr/share/nginx/html/versions && echo "version" > /usr/share/nginx/html/versions/$COMMIT_SHA
|
||||||
|
RUN mkdir -p /usr/share/nginx/html/versions && echo "hidden" > /usr/share/nginx/html/versions/.hidden
|
||||||
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
service: app
|
||||||
|
image: app
|
||||||
|
servers:
|
||||||
|
web:
|
||||||
|
hosts:
|
||||||
|
- vm1
|
||||||
|
- vm2
|
||||||
|
workers:
|
||||||
|
hosts:
|
||||||
|
- vm3
|
||||||
|
cmd: sleep infinity
|
||||||
|
|
||||||
|
asset_path: /usr/share/nginx/html/versions
|
||||||
|
|
||||||
|
registry:
|
||||||
|
server: registry:4443
|
||||||
|
username: root
|
||||||
|
password: root
|
||||||
|
builder:
|
||||||
|
multiarch: false
|
||||||
|
args:
|
||||||
|
COMMIT_SHA: <%= `git rev-parse HEAD` %>
|
||||||
|
healthcheck:
|
||||||
|
cmd: wget -qO- http://localhost > /dev/null || exit 1
|
||||||
|
traefik:
|
||||||
|
args:
|
||||||
|
accesslog: true
|
||||||
|
accesslog.format: json
|
||||||
|
image: registry:4443/traefik:v2.10
|
||||||
|
accessories:
|
||||||
|
busybox:
|
||||||
|
service: custom-busybox
|
||||||
|
image: registry:4443/busybox:1.36.0
|
||||||
|
cmd: sh -c 'echo "Starting busybox..."; trap exit term; while true; do sleep 1; done'
|
||||||
|
roles:
|
||||||
|
- web
|
||||||
|
stop_wait_time: 1
|
||||||
17
test/integration/docker/deployer/app_with_roles/default.conf
Normal file
17
test/integration/docker/deployer/app_with_roles/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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,6 +42,22 @@ class MainTest < IntegrationTest
|
|||||||
assert_no_remote_env_file
|
assert_no_remote_env_file
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "app with roles" do
|
||||||
|
@app = "app_with_roles"
|
||||||
|
|
||||||
|
kamal :envify
|
||||||
|
|
||||||
|
version = latest_app_version
|
||||||
|
|
||||||
|
assert_app_is_down
|
||||||
|
|
||||||
|
kamal :deploy
|
||||||
|
|
||||||
|
assert_app_is_up version: version
|
||||||
|
assert_hooks_ran "pre-connect", "pre-build", "pre-deploy", "post-deploy"
|
||||||
|
assert_container_running host: :vm3, name: "app-workers-#{version}"
|
||||||
|
end
|
||||||
|
|
||||||
test "config" do
|
test "config" do
|
||||||
config = YAML.load(kamal(:config, capture: true))
|
config = YAML.load(kamal(:config, capture: true))
|
||||||
version = latest_app_version
|
version = latest_app_version
|
||||||
@@ -115,4 +131,8 @@ class MainTest < IntegrationTest
|
|||||||
assert vm1_image_ids.any?
|
assert vm1_image_ids.any?
|
||||||
assert vm1_container_ids.any?
|
assert vm1_container_ids.any?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_container_running(host:, name:)
|
||||||
|
assert docker_compose("exec #{host} docker ps --filter=name=#{name} -q", capture: true).strip.present?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user