Compare commits
13 Commits
71f7129851
...
a950dc2d90
Author | SHA1 | Date | |
---|---|---|---|
a950dc2d90 | |||
9cdf8f83c8 | |||
9aef21657c | |||
cd46b3eb52 | |||
01c5241d8f | |||
bdd97be8dd | |||
f2b383ee19 | |||
93c3dcbb6d | |||
ada5c6b876 | |||
18222d510a | |||
a5558aa494 | |||
38cce0f3c2 | |||
3982de3550 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -21,3 +21,9 @@
|
|||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
# Ignore Private config
|
||||||
|
config/private
|
||||||
|
|
||||||
|
# Ignore templated config
|
||||||
|
haproxy/config/haproxy.cfg
|
||||||
|
haproxy/haproxy-compose.yaml
|
2
backend/BACKEND.md
Normal file
2
backend/BACKEND.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Backend
|
||||||
|
The backend is the API which serves every content under the web root /api
|
0
config/private
Normal file
0
config/private
Normal file
19
config/public
Normal file
19
config/public
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Database Config
|
||||||
|
## Database Port
|
||||||
|
DB_PORT="3306"
|
||||||
|
## Database User
|
||||||
|
DB_USER="dbuser"
|
||||||
|
## Database Port
|
||||||
|
DB_PORT="testdb"
|
||||||
|
## Database name
|
||||||
|
DB_NAME="testdb"
|
||||||
|
|
||||||
|
# Port Mapping
|
||||||
|
## Frontend Port will be used by frontend container to expose itself
|
||||||
|
FRONTEND_PORT="30381"
|
||||||
|
## Backend Port will be used by bachend container to expose itself
|
||||||
|
BACKEND_PORT="30382"
|
||||||
|
## Haproxy Port will be used by haproxy container to expose webserver & backends based on uri
|
||||||
|
HAPROXY_PORT="80"
|
||||||
|
## Haproxy Stats Port will display haproxy stats interface
|
||||||
|
HAPROXY_STATS_PORT="81"
|
2
frontend/FRONTEND.md
Normal file
2
frontend/FRONTEND.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Frontend
|
||||||
|
The Frontend is the visual part of this project
|
5
haproxy/HAPROXY.md
Normal file
5
haproxy/HAPROXY.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# HAPROXY
|
||||||
|
The Haproxy is used to route the requests to the diffrent backends & location
|
||||||
|
--> Only for local deployment
|
||||||
|
--> On kubernetes you can use an ingress for this
|
||||||
|
|
29
haproxy/config/haproxy.cfg.b2
Normal file
29
haproxy/config/haproxy.cfg.b2
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
global
|
||||||
|
log stdout format raw local0 info
|
||||||
|
|
||||||
|
defaults
|
||||||
|
mode http
|
||||||
|
timeout client 10s
|
||||||
|
timeout connect 5s
|
||||||
|
timeout server 10s
|
||||||
|
timeout http-request 10s
|
||||||
|
log global
|
||||||
|
|
||||||
|
frontend stats
|
||||||
|
bind *:HAPROXY_STATS_PORT
|
||||||
|
stats enable
|
||||||
|
stats uri /
|
||||||
|
stats refresh 10s
|
||||||
|
|
||||||
|
frontend web
|
||||||
|
bind :HAPROXY_PORT
|
||||||
|
default_backend webui
|
||||||
|
|
||||||
|
acl uri_api path_beg /api
|
||||||
|
use_backend api if uri_api
|
||||||
|
|
||||||
|
backend webui
|
||||||
|
server webui H_LOCAL_IP:FRONTEND_PORT check
|
||||||
|
|
||||||
|
backend api
|
||||||
|
server api H_LOCAL_IP:BACKEND_PORT check
|
12
haproxy/haproxy-compose.yaml.b2
Normal file
12
haproxy/haproxy-compose.yaml.b2
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
version: "3"
|
||||||
|
services:
|
||||||
|
haproxy:
|
||||||
|
image: haproxy:alpine
|
||||||
|
ports:
|
||||||
|
- "HAPROXY_PORT:HAPROXY_PORT"
|
||||||
|
- "HAPROXY_STATS_PORT:HAPROXY_STATS_PORT"
|
||||||
|
volumes:
|
||||||
|
- ./config/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
|
||||||
|
networks:
|
||||||
|
proxy:
|
||||||
|
external: true
|
38
haproxy/reconfigure-haproxy.sh
Executable file
38
haproxy/reconfigure-haproxy.sh
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
|
||||||
|
# Funcitons
|
||||||
|
## Load config from file
|
||||||
|
function loadconfig {
|
||||||
|
source config/public
|
||||||
|
source config/private
|
||||||
|
}
|
||||||
|
## Load variables from host
|
||||||
|
function hostconfig {
|
||||||
|
H_LOCAL_IP=$(hostname -i | cut -d ' ' -f 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
function copytemplates {
|
||||||
|
cp ./haproxy/config/haproxy.cfg.b2 ./haproxy/config/haproxy.cfg
|
||||||
|
cp ./haproxy/haproxy-compose.yaml.b2 ./haproxy/haproxy-compose.yaml
|
||||||
|
}
|
||||||
|
|
||||||
|
## Bajia Tempalting (Bash & Jinja)
|
||||||
|
function b2templating {
|
||||||
|
### HAPROXY config
|
||||||
|
sed -i "s/H_LOCAL_IP/$H_LOCAL_IP/g" ./haproxy/config/haproxy.cfg
|
||||||
|
sed -i "s/FRONTEND_PORT/$FRONTEND_PORT/g" ./haproxy/config/haproxy.cfg
|
||||||
|
sed -i "s/BACKEND_PORT/$BACKEND_PORT/g" ./haproxy/config/haproxy.cfg
|
||||||
|
sed -i "s/HAPROXY_STATS_PORT/$HAPROXY_STATS_PORT/g" ./haproxy/config/haproxy.cfg
|
||||||
|
sed -i "s/HAPROXY_PORT/$HAPROXY_PORT/g" ./haproxy/config/haproxy.cfg
|
||||||
|
### Docker Compose
|
||||||
|
sed -i "s/HAPROXY_PORT/$HAPROXY_PORT/g" ./haproxy/haproxy-compose.yaml
|
||||||
|
sed -i "s/HAPROXY_STATS_PORT/$HAPROXY_STATS_PORT/g" ./haproxy/haproxy-compose.yaml
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main Script
|
||||||
|
loadconfig
|
||||||
|
hostconfig
|
||||||
|
copytemplates
|
||||||
|
b2templating
|
62
makefile
Normal file
62
makefile
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
all: database backend frontend
|
||||||
|
|
||||||
|
# Database
|
||||||
|
database: database-stop database-clean databgase-start database-init
|
||||||
|
|
||||||
|
database-stop:
|
||||||
|
|
||||||
|
database-start:
|
||||||
|
|
||||||
|
database-restart: database-stop database-start
|
||||||
|
|
||||||
|
database-clean:
|
||||||
|
|
||||||
|
database-init:
|
||||||
|
|
||||||
|
# Backend
|
||||||
|
backend:
|
||||||
|
|
||||||
|
backend-restart:
|
||||||
|
|
||||||
|
backend-rebuild:
|
||||||
|
|
||||||
|
backend-image-push:
|
||||||
|
|
||||||
|
# Frontend
|
||||||
|
|
||||||
|
frontend:
|
||||||
|
|
||||||
|
frontend-stop:
|
||||||
|
|
||||||
|
frontend-start:
|
||||||
|
|
||||||
|
frontend-restart: frontend-stop frontend-start
|
||||||
|
|
||||||
|
frontend-clean:
|
||||||
|
|
||||||
|
frontend-rebuild:
|
||||||
|
|
||||||
|
frontend-image-push:
|
||||||
|
|
||||||
|
# Haproxy - Only used for local
|
||||||
|
|
||||||
|
haproxy: reconfigure-haproxy haproxy-restart
|
||||||
|
|
||||||
|
haproxy-stop:
|
||||||
|
docker-compose -f haproxy/haproxy-compose.yaml down
|
||||||
|
haproxy-start:
|
||||||
|
docker-compose -f haproxy/haproxy-compose.yaml up -d
|
||||||
|
haproxy-restart: haproxy-stop haproxy-start
|
||||||
|
|
||||||
|
# Config Templating - Only used for local
|
||||||
|
|
||||||
|
reconfigure: reconfigure-database reconfigure-backend reconfigure-frontend
|
||||||
|
|
||||||
|
reconfigure-database:
|
||||||
|
|
||||||
|
reconfigure-backend:
|
||||||
|
|
||||||
|
reconfigure-frontend:
|
||||||
|
|
||||||
|
reconfigure-haproxy:
|
||||||
|
./haproxy/reconfigure-haproxy.sh
|
Loading…
Reference in New Issue
Block a user