forked from basecamp/kamal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an integration test for proxied accessory using Busybox and netcat
- Loading branch information
1 parent
f367ca8
commit eee47d1
Showing
6 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/integration/docker/deployer/app_with_proxied_accessory/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
RUN echo "Up!" > /usr/share/nginx/html/up |
44 changes: 44 additions & 0 deletions
44
test/integration/docker/deployer/app_with_proxied_accessory/config/deploy.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
service: app_with_proxied_accessory | ||
image: app_with_proxied_accessory | ||
servers: | ||
- vm1 | ||
env: | ||
clear: | ||
CLEAR_TOKEN: 4321 | ||
CLEAR_TAG: "" | ||
HOST_TOKEN: "${HOST_TOKEN}" | ||
asset_path: /usr/share/nginx/html/versions | ||
proxy: | ||
host: 127.0.0.1 | ||
registry: | ||
server: registry:4443 | ||
username: root | ||
password: root | ||
builder: | ||
driver: docker | ||
arch: <%= Kamal::Utils.docker_arch %> | ||
args: | ||
COMMIT_SHA: <%= `git rev-parse HEAD` %> | ||
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 | ||
netcat: | ||
service: netcat | ||
image: registry:4443/busybox:1.36.0 | ||
cmd: > | ||
sh -c 'echo "Starting netcat..."; while true; do echo -e "HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nHello Ruby" | nc -l -p 80; done' | ||
roles: | ||
- web | ||
port: 12345:80 | ||
proxy: | ||
host: netcat | ||
ssl: false | ||
healthcheck: | ||
interval: 1 | ||
timeout: 1 | ||
path: "/" | ||
|
17 changes: 17 additions & 0 deletions
17
test/integration/docker/deployer/app_with_proxied_accessory/default.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require_relative "integration_test" | ||
|
||
class ProxiedAccessoryTest < IntegrationTest | ||
test "boot, stop, start, restart, logs, remove" do | ||
@app = "app_with_proxied_accessory" | ||
|
||
kamal :deploy | ||
|
||
kamal :accessory, :boot, :netcat | ||
assert_accessory_running :netcat | ||
assert_netcat_is_up | ||
|
||
kamal :accessory, :stop, :netcat | ||
assert_accessory_not_running :netcat | ||
assert_netcat_not_found | ||
|
||
kamal :accessory, :start, :netcat | ||
assert_accessory_running :netcat | ||
assert_netcat_is_up | ||
|
||
kamal :accessory, :restart, :netcat | ||
assert_accessory_running :netcat | ||
assert_netcat_is_up | ||
|
||
kamal :accessory, :remove, :netcat, "-y" | ||
assert_accessory_not_running :netcat | ||
assert_netcat_not_found | ||
end | ||
|
||
private | ||
def assert_accessory_running(name) | ||
assert_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name) | ||
end | ||
|
||
def assert_accessory_not_running(name) | ||
assert_no_match /registry:4443\/busybox:1.36.0 "sh -c 'echo \\"Start/, accessory_details(name) | ||
end | ||
|
||
def accessory_details(name) | ||
kamal :accessory, :details, name, capture: true | ||
end | ||
|
||
def assert_netcat_is_up | ||
response = netcat_response | ||
debug_response_code(response, "200") | ||
assert_equal "200", response.code | ||
end | ||
|
||
def assert_netcat_not_found | ||
response = netcat_response | ||
debug_response_code(response, "404") | ||
assert_equal "404", response.code | ||
end | ||
|
||
def netcat_response | ||
uri = URI.parse("http://127.0.0.1:12345/up") | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
request = Net::HTTP::Get.new(uri) | ||
request["Host"] = "netcat" | ||
|
||
http.request(request) | ||
end | ||
end |