Skip to content

Commit ef864c3

Browse files
committed
base template implementation
1 parent 954834f commit ef864c3

File tree

9 files changed

+234
-0
lines changed

9 files changed

+234
-0
lines changed

.github/actions/setup/action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Build
2+
description: Setup and Build Containers locally
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Network Initialization
8+
shell: bash
9+
run: bash networks.sh
10+
- name: Build
11+
shell: bash
12+
run: docker compose build;

.github/workflows/dry-run.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Dry Run
2+
3+
on:
4+
# Runs on pushes targeting the default branch
5+
push:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ./.github/actions/setup

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssl

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[![Dry Run](https://github.com/dgma/ngix-ssl/actions/workflows/dry-run.yml/badge.svg)](https://github.com/dgma/ngix-ssl/actions/workflows/dry-run.yml)
2+
3+
# TEMPLATE_NGINX_SSL
4+
5+
Template for simple nginx-le based container for service requests routing.
6+
7+
Bonus: custom github actions for easy CI\CD rollout.
8+
9+
## Installation
10+
11+
- Install Docker & Docker Compose
12+
- Run ```sh docker compose up```
13+
14+
## Configuration
15+
16+
1. Fork it
17+
2. Identify your routes (domain -> service)
18+
3. Configure `ect/service.conf` according to your needs. Check `examples` folder for inspiration.
19+
4. Configure docker-compose.yaml (environment, ports)
20+
5. Optional: update `networks.sh` if you need more than one network.

docker-compose.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
version: '3.7'
2+
3+
x-logging: &loggingConf
4+
logging:
5+
driver: "json-file"
6+
options:
7+
max-file: "5"
8+
max-size: "100m"
9+
10+
services:
11+
nginx-router:
12+
hostname: nginx-router
13+
image: umputun/nginx-le:latest
14+
<<: *loggingConf
15+
restart: always
16+
volumes:
17+
- ./etc/ssl:/etc/nginx/ssl
18+
- ./etc/service.conf:/etc/nginx/service.conf
19+
ports:
20+
- "80:80"
21+
- "443:443"
22+
23+
environment:
24+
# timezone
25+
- TZ=GMT
26+
# use letsencrypt for ssl
27+
- LETSENCRYPT=true
28+
# email for ssl
29+
- LE_EMAIL=dogmaprotocol@gmail.com
30+
# letsencrypt domains
31+
- LE_FQDN=dgma.dev,dev.dgma.dev
32+
networks:
33+
pub-shared-net:
34+
35+
networks:
36+
pub-shared-net:
37+
name: pub-shared-net
38+
external: true

etc/service.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
server {
2+
server_name dgma.dev;
3+
4+
# list all publically available ports for domain
5+
listen 80;
6+
listen 443;
7+
8+
root /var/www/app;
9+
10+
autoindex on;
11+
12+
ssl on;
13+
ssl_certificate SSL_CERT;
14+
ssl_certificate_key SSL_KEY;
15+
ssl_trusted_certificate SSL_CHAIN_CERT;
16+
17+
location / {
18+
try_files $uri $uri/ =404;
19+
}
20+
}

examples/containers.routing.conf

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# The following mapping block declares a relationship between the
2+
# public port the nginx-le container listens on and the service name for your service containers.
3+
# 1. Service containers shoudl be at the same network (pub-shared-net) as nginx-le container
4+
# You can modify/add more networks in docker-compose files.
5+
# 2. Nginx-le container must be initialized after service container initialization and shared network creation.
6+
7+
map $server_port $stg_pass_route {
8+
# port => container name:port
9+
"443" "web:8080";
10+
11+
default "localhost:$server_port";
12+
}
13+
14+
server {
15+
server_name you-domain.com;
16+
17+
# must specify docker DNS as a resolver when use variables for proxy_pass
18+
resolver 127.0.0.11 ipv6=off;
19+
20+
# list all publically available ports for domain
21+
listen 80;
22+
listen 443;
23+
24+
ssl on;
25+
ssl_certificate SSL_CERT;
26+
ssl_certificate_key SSL_KEY;
27+
ssl_trusted_certificate SSL_CHAIN_CERT;
28+
29+
client_max_body_size 2M;
30+
31+
location / {
32+
proxy_set_header Host $http_host;
33+
proxy_set_header X-Real-IP $remote_addr;
34+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
35+
proxy_set_header X-Forwarded-Proto $scheme;
36+
37+
# use the mapped hostname and port for a proxy target
38+
proxy_pass "http://$stg_pass_route";
39+
}
40+
}
41+
42+
map $server_port $dev_pass_route {
43+
# port => name label:port
44+
"443" "web:8081";
45+
46+
default "localhost:$server_port";
47+
}
48+
49+
server {
50+
server_name sub.you-domain.com;
51+
52+
# must specify docker DNS as a resolver when use variables for proxy_pass
53+
resolver 127.0.0.11 ipv6=off;
54+
55+
# list all publically available ports for domain
56+
listen 80;
57+
listen 443;
58+
59+
ssl on;
60+
ssl_certificate SSL_CERT;
61+
ssl_certificate_key SSL_KEY;
62+
ssl_trusted_certificate SSL_CHAIN_CERT;
63+
64+
client_max_body_size 2M;
65+
66+
location / {
67+
proxy_set_header Host $http_host;
68+
proxy_set_header X-Real-IP $remote_addr;
69+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
70+
proxy_set_header X-Forwarded-Proto $scheme;
71+
72+
# use the mapped hostname and port for a proxy target
73+
proxy_pass "http://$dev_pass_route";
74+
}
75+
}

examples/static.routing.conf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
server {
2+
server_name you-domain.com;
3+
4+
# list all publically available ports for domain
5+
listen 80;
6+
listen 443;
7+
8+
root /var/www/app;
9+
10+
autoindex on;
11+
12+
ssl on;
13+
ssl_certificate SSL_CERT;
14+
ssl_certificate_key SSL_KEY;
15+
ssl_trusted_certificate SSL_CHAIN_CERT;
16+
17+
location / {
18+
try_files $uri $uri/ =404;
19+
}
20+
}
21+
22+
server {
23+
server_name sub.you-domain.com;
24+
25+
# list all publically available ports for domain
26+
listen 80;
27+
listen 443;
28+
29+
root /var/www/app-dev;
30+
31+
autoindex on;
32+
33+
ssl on;
34+
ssl_certificate SSL_CERT;
35+
ssl_certificate_key SSL_KEY;
36+
ssl_trusted_certificate SSL_CHAIN_CERT;
37+
38+
location / {
39+
try_files $uri $uri/ =404;
40+
}
41+
}

networks.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Initializes all shared networks for nginx-le and other service containers
4+
5+
networks=("pub-shared-net")
6+
7+
init_ntw () {
8+
docker network inspect $1 >/dev/null 2>&1 || \
9+
echo "create network $1" && \
10+
docker network create --driver bridge $1
11+
}
12+
13+
for ntw in ${networks[@]}; do
14+
init_ntw $ntw
15+
done

0 commit comments

Comments
 (0)