1
0
Fork 0

Compare commits

...

41 Commits
main ... master

Author SHA1 Message Date
colin fa877872f3 Update Dockerfile
ci/woodpecker/push/woodpecker Pipeline was successful Details
2023-12-12 17:04:36 +00:00
colin 8d0b77a98a Update .woodpecker.yml
ci/woodpecker/push/woodpecker Pipeline failed Details
2023-12-12 17:02:21 +00:00
colin d88eb9c29d Update stack.yml 2023-12-12 16:59:33 +00:00
colin 03b390b415 Update docker-compose.yml 2023-12-12 16:56:40 +00:00
colin 72bdbc4f33 Delete tests/nginx-proxy.nixc.us.test.ts 2023-12-12 16:56:06 +00:00
colin 5ea048a78a Update README.md 2023-12-12 16:54:13 +00:00
colin 9972656e5f Added Healthcheck 2023-12-12 16:51:27 +00:00
colin f534f34cac adding healthcheck 2023-12-12 16:50:47 +00:00
colin da028e4e49 Update Dockerfile 2023-12-12 16:48:21 +00:00
colin 1a463ab46f Update nginx.conf.template 2023-12-12 16:46:18 +00:00
colin 6ed0ffa4d8 Update Dockerfile 2023-12-12 16:42:33 +00:00
colin b49d6e8364 updating entrypoint for udp/tcp/both/allowedip's 2023-12-12 16:40:09 +00:00
colin eb0fac3b5a Update .woodpecker.yml 2023-11-21 19:07:22 +00:00
colin 76da77346e Update .woodpecker.yml 2023-11-21 19:06:34 +00:00
colin aea8f34af2 Add tests/nginx-proxy.nixc.us.test.ts 2023-11-21 19:05:54 +00:00
colin 4ba9f6c7d5 Update stack.yml 2023-11-21 18:58:23 +00:00
colin 033b5bdb19 Update nginx.conf 2023-11-21 18:11:27 +00:00
colin 81705866f8 Update nginx.conf 2023-11-21 18:05:25 +00:00
colin 0d1d52f400 Update nginx.conf 2023-11-21 17:54:44 +00:00
colin a373f322b5 Trying something dumb 2023-11-21 17:49:29 +00:00
colin b3489c8dea Update nginx.conf 2023-11-21 17:44:04 +00:00
colin 1580bd9c95 Update .woodpecker.yml 2023-11-21 17:32:55 +00:00
colin 7d1f0da36d Update .woodpecker.yml 2023-11-21 17:32:44 +00:00
colin cdcd9a68b0 Update .woodpecker.yml 2023-11-21 17:31:38 +00:00
colin ae5a5b1a21 Add .woodpecker.yml 2023-11-21 17:30:07 +00:00
colin 364dd72343 Update docker-entrypoint.sh 2023-11-21 17:26:19 +00:00
colin 4009ca3d4d Update Dockerfile 2023-11-21 17:25:42 +00:00
colin 20234e08ae Update nginx.conf 2023-11-21 17:25:03 +00:00
colin c1247366a6 Update stack.yml 2023-11-21 17:24:47 +00:00
colin 9455a06b6b Update docker-compose.yml 2023-11-21 17:20:48 +00:00
colin 3402dd6674 Update nginx.conf 2023-11-21 17:19:43 +00:00
colin 860e1456e3 Update nginx.conf 2023-11-21 17:13:54 +00:00
root 53783f238e Stream editing working tracking not 2023-10-02 16:16:07 +00:00
root 9fc16fda7e fixup 2023-09-25 13:36:33 -04:00
root bf114b273b fixup 2023-09-25 13:31:48 -04:00
root 5f2bc789c4 fixup 2023-09-25 13:30:40 -04:00
root f40a8697bc fixup 2023-09-25 13:21:09 -04:00
root 4edc4ccd85 fixup 2023-09-25 13:13:04 -04:00
root fa29897d55 fixup 2023-09-25 13:08:21 -04:00
Dowerent a2a4ef19ee adding template stackfile 2023-09-25 17:02:41 +00:00
Dowerent 0ef41ee169 Add README.md 2023-09-25 16:55:27 +00:00
8 changed files with 175 additions and 39 deletions

39
.woodpecker.yml Normal file
View File

@ -0,0 +1,39 @@
# woodpecker.yml
labels:
hostname: "macmini7"
clone:
git:
image: woodpeckerci/plugin-git
settings:
partial: false
depth: 1
steps:
build-push:
name: build-push
when:
- path:
include: [ 'stack.yml','.woodpecker.yml', 'Dockerfile', 'docker-entrypoint.sh', 'nginx.conf.template', 'README.md' ]
image: woodpeckerci/plugin-docker-buildx
secrets: [REGISTRY_USER, REGISTRY_PASSWORD]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
commands:
- echo "$${REGISTRY_PASSWORD}" | docker login -u "$${REGISTRY_USER}" --password-stdin git.nixc.us
- echo compose up build
- docker compose build
- echo compose push
- docker compose push
- echo docker compose rm -f
- docker compose rm -f
deploy-config:
name: deploy-config
when:
- path:
include: [ 'stack.yml','.woodpecker.yml', 'Dockerfile', 'docker-entrypoint.sh', 'nginx.conf.template', 'README.md' ]
image: woodpeckerci/plugin-docker-buildx
secrets: [REGISTRY_USER, REGISTRY_PASSWORD]
volumes:
- /var/run/docker.sock:/var/run/docker.sock
commands:
- echo "$${REGISTRY_PASSWORD}" | docker login -u "$${REGISTRY_USER}" --password-stdin git.nixc.us
- docker stack deploy --with-registry-auth -c ./stack.yml lan-to-nginx

View File

@ -1,7 +1,26 @@
# Start from the official Nginx image # Use the official NGINX image as a parent image
FROM nginx:alpine FROM nginx:alpine
# Copy our custom Nginx configuration # Set environment variables with default values
COPY nginx.conf /etc/nginx/nginx.conf ENV BACKEND_HOST=git_git
ENV BACKEND_TCP_PORT=22
ENV BACKEND_UDP_PORT=22
# Set the default value of ALLOWED_IPS to cover typical Docker network ranges
# set this value to 0.0.0.0 in the Stack definition for allow all.
ENV ALLOWED_IPS="10.0.0.0/8 172.16.0.0/12 192.168.0.0/16"
# Copy the script and configuration template into the container
COPY docker-entrypoint.sh /docker-entrypoint.sh
COPY nginx.conf.template /etc/nginx/nginx.conf.template
# Make the script executable
RUN chmod +x /docker-entrypoint.sh
# HEALTHCHECK instruction using curl to check the health of the NGINX server
# Install curl, then set up the health check
RUN apk add --no-cache curl
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD curl -f http://localhost:8080/healthz || exit 1
# Use the script as the entrypoint
ENTRYPOINT ["/docker-entrypoint.sh"]

51
README.md Normal file
View File

@ -0,0 +1,51 @@
### host-port-ingress-proxy
1. **Docker Container Setup**:
- The Docker container is based on the official NGINX Alpine image.
- Several environment variables are defined in the Dockerfile to configure the NGINX reverse proxy. These include `BACKEND_HOST`, `BACKEND_TCP_PORT`, `BACKEND_UDP_PORT`, and `ALLOWED_IPS`.
- The Dockerfile also installs `curl` for health checking purposes and includes a custom entrypoint script.
2. **NGINX Configuration**:
- A template for the NGINX configuration (`nginx.conf.template`) is used. This template is processed by the entrypoint script (`entrypoint.sh`) to replace placeholders with the actual environment variable values.
- The NGINX configuration sets up NGINX as a reverse proxy to forward TCP and UDP traffic to the configured backend host and ports. It also includes IP-based access control.
- Additionally, NGINX listens on a separate HTTP port (8080) with a specific location (`/healthz`) that always returns a `200 OK` response. This endpoint is used for health checks.
3. **Health Checking**:
- The Dockerfile defines a `HEALTHCHECK` instruction that uses `curl` to periodically check the health of the NGINX server by accessing the `/healthz` endpoint.
- If the health check fails (does not return `200 OK`), Docker marks the container as unhealthy.
4. **Running the Container**:
- When the container is run, the environment variables can be set to define the backend host, ports, and allowed IPs.
- Docker's health check mechanism monitors the container's health status by checking the `/healthz` endpoint.
### Mermaid Diagram
Here's a Mermaid diagram that visualizes the flow:
```mermaid
graph LR
subgraph Docker Container
NGINX[NGINX Reverse Proxy]
ENTRYPOINT[Entrypoint Script]
CONFIG[nginx.conf.template]
HEALTHCHECK[Health Check]
ENTRYPOINT -->|Processes| CONFIG
CONFIG -->|Configures| NGINX
NGINX -->|TCP/UDP Proxy| BACKEND[Backend Service]
NGINX -->|HTTP Health Check| HEALTHCHECK
HEALTHCHECK -->|curl /healthz| NGINX
end
USER[User] -->|TCP/UDP Request| NGINX
NGINX -->|Responds| USER
DOCKER[Docker Daemon] -->|Periodic Check| HEALTHCHECK
style NGINX fill:#f96,stroke:#333,stroke-width:2px
style BACKEND fill:#ff9,stroke:#333,stroke-width:2px
style USER fill:#9f6,stroke:#333,stroke-width:2px
style HEALTHCHECK fill:#6f9,stroke:#333,stroke-width:2px
style DOCKER fill:#f69,stroke:#333,stroke-width:2px
```
This diagram represents the flow of requests through the NGINX reverse proxy and how the health check mechanism works within the Docker container. The `NGINX Reverse Proxy` handles both TCP/UDP requests and health check requests, forwarding the former to the `Backend Service` and responding directly to the latter. The `Docker Daemon` periodically triggers the health check to ensure the NGINX server is functioning correctly.

View File

@ -1,14 +1,8 @@
version: '3.9' version: '3.9'
services: services:
nginx-proxy: host-port-ingress-proxy:
build: build:
context: . context: .
dockerfile: Dockerfile dockerfile: Dockerfile
image: codeberg.org/Iridium-net/lan-to-nginx:latest image: git.nixc.us/colin/host-port-ingress-proxy:latest
environment:
- BACKEND_ADDRESS=192.168.8.1 # Replace with your backend address
- BACKEND_PORT=80 # Replace with your backend port
ports:
- "80:80" # Map port 80 from the host to port 80 in the container

7
docker-entrypoint.sh Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
# Substitute environment variables in the NGINX config template
envsubst < /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf
# Start NGINX
exec nginx -g 'daemon off;'

View File

@ -1,28 +0,0 @@
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load environment variables
env BACKEND_ADDRESS;
env BACKEND_PORT;
server {
listen 80;
location / {
# Use the environment variables for the proxy pass
proxy_pass http://$BACKEND_ADDRESS:$BACKEND_PORT;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}

31
nginx.conf.template Normal file
View File

@ -0,0 +1,31 @@
events {}
http {
server {
listen 8080; # Listen on a separate port for health checks
location /healthz {
# Just return a 200 OK for any request to /healthz
return 200 'healthy\n';
add_header Content-Type text/plain;
}
}
}
stream {
# TCP proxy configuration
server {
listen ${BACKEND_TCP_PORT};
allow ${ALLOWED_IPS}; # Apply IP restrictions based on the ALLOWED_IPS variable
deny all;
proxy_pass ${BACKEND_HOST}:${BACKEND_TCP_PORT};
}
# UDP proxy configuration
server {
listen ${BACKEND_UDP_PORT} udp;
allow ${ALLOWED_IPS}; # Apply IP restrictions
deny all;
proxy_pass ${BACKEND_HOST}:${BACKEND_UDP_PORT};
}
}

23
stack.yml Normal file
View File

@ -0,0 +1,23 @@
version: "3.9"
networks:
traefik:
external: true
services:
nginx:
image: git.nixc.us/colin/host-port-ingress-proxy:latest
ports:
- target: 22
published: 2221
protocol: udp
mode: host
environment:
- BACKEND_HOST=git_git
- BACKEND_UDP_PORT=22
- BACKEND_TCP_PORT=22
- ALLOWED_IPS=0.0.0.0
networks:
- traefik
deploy:
replicas: 1