Haproxy configuration
This commit is contained in:
		@@ -9,6 +9,11 @@ DB_PORT="testdb"
 | 
			
		||||
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="80"
 | 
			
		||||
## 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"
 | 
			
		||||
@@ -1,26 +0,0 @@
 | 
			
		||||
global
 | 
			
		||||
  stats socket /var/run/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
 | 
			
		||||
  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 *:8404
 | 
			
		||||
  stats enable
 | 
			
		||||
  stats uri /
 | 
			
		||||
  stats refresh 10s
 | 
			
		||||
 | 
			
		||||
frontend myfrontend
 | 
			
		||||
  bind :80
 | 
			
		||||
  default_backend webservers
 | 
			
		||||
 | 
			
		||||
backend webservers
 | 
			
		||||
  server s1 web1:8080 check
 | 
			
		||||
  server s2 web2:8080 check
 | 
			
		||||
  server s3 web3:8080 check
 | 
			
		||||
							
								
								
									
										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
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
version: 3
 | 
			
		||||
services:
 | 
			
		||||
  haproxy:
 | 
			
		||||
    image: haproxy:alpine
 | 
			
		||||
    ports:
 | 
			
		||||
    - "80:80"
 | 
			
		||||
    voluems:
 | 
			
		||||
    - ./config/haproxy.cfg:/usr/local/etc/haproxy:ro
 | 
			
		||||
							
								
								
									
										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
 | 
			
		||||
@@ -3,12 +3,36 @@
 | 
			
		||||
# 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
 | 
			
		||||
 | 
			
		||||
echo $BACKEND_PORT
 | 
			
		||||
hostconfig
 | 
			
		||||
copytemplates
 | 
			
		||||
b2templating
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								makefile
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								makefile
									
									
									
									
									
								
							@@ -40,12 +40,12 @@ frontend-image-push:
 | 
			
		||||
 | 
			
		||||
# Haproxy - Only used for local
 | 
			
		||||
 | 
			
		||||
haproxy:
 | 
			
		||||
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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user