Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
25f02a3
add docker compose file and nginx template
strazto Dec 15, 2020
aaa1300
adjust docker compose port binding
strazto Dec 15, 2020
dc82455
add example pre/post hooks
strazto Dec 15, 2020
3713b41
Add example config
strazto Dec 15, 2020
e88c37b
ignore actual yaml
strazto Dec 15, 2020
894d5c4
mark hooks executable
strazto Dec 15, 2020
d1ad196
update paths for hooks
strazto Dec 15, 2020
a38c353
ignore nginx.conf
strazto Dec 15, 2020
ecd39d3
Move load_module directive up in conf
strazto Dec 15, 2020
8194417
Add dockerfile for nginx (hopefuly can install stream module)
strazto Dec 15, 2020
2792d0f
Build nginx container
strazto Dec 15, 2020
232c77f
Fix noninteractive install
strazto Dec 15, 2020
805984b
target lib not lib64 for stream module
strazto Dec 15, 2020
f9f4a2a
ignore nginx logs
strazto Dec 15, 2020
be76b1c
fix port config
strazto Dec 15, 2020
017e87e
install correct module for image
strazto Dec 15, 2020
a7149de
enable override compose
strazto Dec 15, 2020
1384017
forward 8080 to localhost for proxy
strazto Dec 15, 2020
60d4fc8
nginx via docker isn't playing nicely
strazto Dec 15, 2020
800ee68
work on making nginx work
strazto Dec 15, 2020
ad517b2
fix events & module load in nginx
strazto Dec 16, 2020
257109f
change to json logging
strazto Dec 16, 2020
2f92ca5
pass to localhost instead of docker-compose hostname (as no longer ru…
strazto Dec 16, 2020
fe366f0
Revert "pass to localhost instead of docker-compose hostname (as no l…
strazto Dec 17, 2020
ac10050
Revert "nginx via docker isn't playing nicely"
strazto Dec 17, 2020
c963d76
upgrade docker compose version, use explicit file binding for nginx.conf
strazto Dec 17, 2020
e3ce304
comment out module load for container version
strazto Dec 17, 2020
ad72499
use intermediate image to eval nginx.conf.tmpl at build time
strazto Dec 17, 2020
4260039
allow specifying template data as build time arg
strazto Dec 17, 2020
a8a96b0
update compose & override to match new dockerfile
strazto Dec 17, 2020
d16c748
fix typo in template filename in dockerfile
strazto Dec 17, 2020
1ce3a34
log info about templatefile during build
strazto Dec 17, 2020
a3eba11
coloured logging at buildtime
strazto Dec 17, 2020
2169318
enable ssl keepalive etc
strazto Dec 17, 2020
4c74b0c
add install script for certbot hooks
strazto Dec 17, 2020
3154287
fix typo in pre hook
strazto Dec 17, 2020
2066f90
if ssl section is empty in template data, bind to localhost
strazto Dec 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
all-proxy
all-proxy
/docker-compose.override.yml

9 changes: 9 additions & 0 deletions docker-compose.override.tmpl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3.7'
services:
nginx:
build:
args:
nginx_template_data: nginx.yaml
tty-proxy:
environment:
- URL=tty.example.com
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3.7'
services:
nginx:
build:
context: ./nginx/
image: webserver
container_name: webserver
volumes:
# - type: bind
# source: ./nginx/nginx.conf
# target: /etc/nginx/nginx.conf
- ./nginx/log/:/var/log/nginx/
- /etc/letsencrypt/:/etc/letsencrypt/
ports:
- 80:80
- 443:443
- 3456:3456
tty-proxy:
container_name: tty-proxy
build: ./
ports:
- 8080:8080
5 changes: 5 additions & 0 deletions nginx/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
nginx.yaml
nginx.conf

/log/**

19 changes: 19 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ruby as template
ARG nginx_template_data=nginx.example.yaml

RUN echo "\e[31m---" \
&& echo "template_file: ${nginx_template_data} #############" \
&& echo "---\e[0m"

ADD "./nginx.tmpl.conf" ${nginx_template_data} "/build/"
RUN gem install mustache \
&& cd /build \
&& cat ${nginx_template_data} \
&& mustache ${nginx_template_data} nginx.tmpl.conf > nginx.conf


FROM nginx:latest
#RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -y libnginx-mod-stream
COPY --from=template /build/nginx.conf /etc/nginx/nginx.conf


23 changes: 23 additions & 0 deletions nginx/install_certbot_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

hook_dir=/etc/letsencrypt/renewal-hooks

project_root="$(git rev-parse --show-toplevel)"
shebang="#!/bin/sh"


sudo cat << EOF > "$hook_dir/pre/tty-proxy.sh"
$shebang

docker-compose -f "$project_root/docker-compose.yml" down
EOF

sudo cat << EOF > "$hook_dir/post/tty-proxy.sh"
$shebang

docker-compose -f "$project_root/docker-compose.yml" up -d
EOF

sudo chmod 755 "$hook_dir/pre/tty-proxy.sh"
sudo chmod 755 "$hook_dir/post/tty-proxy.sh"

4 changes: 4 additions & 0 deletions nginx/nginx.example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
your_subdomain: tty.example.com
ssl:
chain: /etc/letsencrypt/live/tty.example.com/fullchain.pem
key: /etc/letsencrypt/live/tty.example.com/privkey.pem
121 changes: 121 additions & 0 deletions nginx/nginx.tmpl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Define a yaml with:
# ---
# your_subdomain: https://whatever.whatever.whatever
# ssl:
# chain: path_to_your_chain
# key: path_to_your_key
#
# ---

# Module is loaded by default on container
# load_module modules/ngx_stream_module.so;

events {
worker_connections 1024; ## Default: 1024
}
# You may have to install the stream module separately


stream {
upstream backend {
server tty-proxy:3456;
}
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_port":"$remote_port",'
'"hostname": "$hostname",'
'"status": "$status",'
'"bytes_sent":"$bytes_sent",'
'"bytes_received":"$bytes_received",'
'"connection":"$connection"'
'}';
# https://nginx.org/en/docs/stream/ngx_stream_core_module.html#server
# the tty-server tcp connection ssl proxy
server {
# If ssl is given
{{#ssl}}
listen 3456 ssl so_keepalive=30m::10;
# proxy_ssl off means terminate ssl here which is good.
proxy_ssl off;
ssl_certificate {{ssl.chain}};
ssl_certificate_key {{ssl.key}};
{{/ssl}}

# If ssl is empty or missing
{{^ssl}}
listen 127.0.0.1:3456;
{{/ssl}}

proxy_pass backend;
access_log /var/log/nginx/stream.log json_combined;
}
}

http {
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent"'
'}';

# if ssl is given
{{#ssl}}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
listen 80;
server_name {{your_subdomain}};
return 301 https://{{your_subdomain}}$request_uri;
}

server {
listen 443 ssl;
server_name {{your_subdomain}};

ssl_certificate {{ssl.chain}};
ssl_certificate_key {{ssl.key}};

access_log /var/log/nginx/data-access.log json_combined;

location / {
proxy_pass http://tty-proxy:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://tty-proxy $scheme://$http_host/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_read_timeout 20d;
proxy_buffering off;
}
}

{{/ssl}}

# if ssl is not given
{{^ssl}}
server {
listen 127.0.0.1:80;

server_name {{your_subdomain}};
location / {
proxy_pass http://tty-proxy:8080;
}
}
{{/ssl}}

}
4 changes: 4 additions & 0 deletions nginx/tty-proxy_post_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

docker-compose -f /home/ubuntu/projects/tty-proxy/docker-compose.yml up -d

4 changes: 4 additions & 0 deletions nginx/tty-proxy_pre_hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

docker-compose -f home/ubuntu/tty-proxy/docker-compose.yml down