feat(haproxy): Add config

This commit is contained in:
hygienic-books 2023-05-02 03:17:30 +02:00
parent a62dcd794c
commit 290c5c302b
9 changed files with 97 additions and 0 deletions

32
haproxy/README.md Normal file
View File

@ -0,0 +1,32 @@
# Docker Compose
## Environment
Prepare an environment file following the example in [env/fqdn_context.env.example](env/fqdn_context.env.example):
```
CONTEXT=foodstuffs_hongkong
DOCKER_SUBNET=172.24.23.0/24
HAPROXY_VERSION=latest
```
Var `${DOCKER_SUBNET}` is optional and defaults to `${DOCKER_SUBNET-172.24.23.0/24}`. Treat `CONTEXT` as a team name, purpose or scope. If the same Docker application can run multiple times and serve different tenants then `CONTEXT` is what distinguishes one instance from the other. Here `foodstuffs_hongkong` indicates for example a Hong Kong-based foodstuffs team of some sort.
## Vars
Define Docker Compose variables, use the `COMPOSE_ENV_FILE` defined above in [Environment](#environment):
```
export COMPOSE_DIR='/opt/containers' # Or wherever this repo is checked out
export COMPOSE_FILE="${COMPOSE_DIR}"'/docker-compose.yml'
export COMPOSE_ENV_FILE=<add accordingly>
```
Run like so:
```
docker compose --file "${COMPOSE_FILE}" --env-file "${COMPOSE_ENV_FILE}" up --detach
```
Log entries will just be something along the lines of:
```
haproxy-CONTEXT | [NOTICE] (1) : New worker (8) forked
haproxy-CONTEXT | [NOTICE] (1) : Loading success.
```

View File

@ -0,0 +1,14 @@
# For the remainder of this Dockerfile EXAMPLE_ARG_FOR_DOCKERFILE will be
# available with a value of 'must_be_available_in_dockerfile', check out the env
# file at 'env/fully.qualified.domain.name.example' for reference.
# ARG EXAMPLE_ARG_FOR_DOCKERFILE
# Another env var, this one's needed in the example build step below:
# ARG HAPROXY_VERSION
# Example
# FROM "haproxy:${HAPROXY_VERSION}"
# RUN apt-get update && \
# apt-get -y install \
# somepackage-6.q16-6-extra && \
# rm -rf /var/lib/apt/lists/*

View File

View File

@ -0,0 +1,11 @@
services:
common-settings:
environment:
TZ: "${TIMEZONE:-Etc/UTC}"
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "10"
compress: "true"
restart: "${RESTARTPOLICY:-unless-stopped}"

View File

@ -0,0 +1,9 @@
services:
haproxy-build:
image: "haproxy:${HAPROXY_VERSION}"
profiles: ["build"]
build:
context: "build-context/haproxy"
dockerfile: Dockerfile
args:
HAPROXY_VERSION: "${HAPROXY_VERSION}"

View File

@ -0,0 +1,25 @@
services:
haproxy:
image: "haproxy:${HAPROXY_VERSION}"
container_name: "haproxy-${CONTEXT}"
networks:
haproxy-default:
extends:
file: common-settings.yml
service: common-settings
ports:
- 80:80
- 443:443
volumes:
- /opt/docker-data/haproxy-${CONTEXT}/config/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg
networks:
haproxy-default:
name: haproxy-${CONTEXT}
driver: bridge
driver_opts:
com.docker.network.enable_ipv6: "false"
ipam:
driver: default
config:
- subnet: ${DOCKER_SUBNET-172.24.23.0/24}

6
haproxy/env/fqdn_context.env.example vendored Normal file
View File

@ -0,0 +1,6 @@
# This file is maintained by remco and populated with data from HashiCorp
# Vault. Changes not done in Vault will be reverted when file gets rendered.
CONTEXT=
DOCKER_SUBNET=
HAPROXY_VERSION=