-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #981 from igor-alexandrov/proxy-accessories
Proxy for accessories
- Loading branch information
Showing
12 changed files
with
212 additions
and
3 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
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,16 @@ | ||
module Kamal::Commands::Accessory::Proxy | ||
delegate :proxy_container_name, to: :config | ||
|
||
def deploy(target:) | ||
proxy_exec :deploy, service_name, *proxy.deploy_command_args(target: target) | ||
end | ||
|
||
def remove | ||
proxy_exec :remove, service_name | ||
end | ||
|
||
private | ||
def proxy_exec(*command) | ||
docker :exec, proxy_container_name, "kamal-proxy", *command | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,3 +98,7 @@ accessories: | |
# Defaults to kamal: | ||
network: custom | ||
|
||
# Proxy | ||
# | ||
proxy: | ||
... |
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
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 |