From 290c5c302bbaadc806686791fd00252e8ecd3f9c Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Tue, 2 May 2023 03:17:30 +0200 Subject: [PATCH] feat(haproxy): Add config --- haproxy/README.md | 32 +++++++++++++++++++ haproxy/build-context/Dockerfile | 14 ++++++++ haproxy/build-context/docker-data/.gitkeep | 0 haproxy/build-context/docker-data/haproxy.cfg | 0 haproxy/build-context/extras/.gitkeep | 0 haproxy/common-settings.yml | 11 +++++++ haproxy/docker-compose.override.yml | 9 ++++++ haproxy/docker-compose.yml | 25 +++++++++++++++ haproxy/env/fqdn_context.env.example | 6 ++++ 9 files changed, 97 insertions(+) create mode 100644 haproxy/README.md create mode 100644 haproxy/build-context/Dockerfile create mode 100644 haproxy/build-context/docker-data/.gitkeep create mode 100644 haproxy/build-context/docker-data/haproxy.cfg create mode 100644 haproxy/build-context/extras/.gitkeep create mode 100644 haproxy/common-settings.yml create mode 100644 haproxy/docker-compose.override.yml create mode 100644 haproxy/docker-compose.yml create mode 100644 haproxy/env/fqdn_context.env.example diff --git a/haproxy/README.md b/haproxy/README.md new file mode 100644 index 0000000..df7f1b9 --- /dev/null +++ b/haproxy/README.md @@ -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= +``` + +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. +``` diff --git a/haproxy/build-context/Dockerfile b/haproxy/build-context/Dockerfile new file mode 100644 index 0000000..67530b5 --- /dev/null +++ b/haproxy/build-context/Dockerfile @@ -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/* diff --git a/haproxy/build-context/docker-data/.gitkeep b/haproxy/build-context/docker-data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/haproxy/build-context/docker-data/haproxy.cfg b/haproxy/build-context/docker-data/haproxy.cfg new file mode 100644 index 0000000..e69de29 diff --git a/haproxy/build-context/extras/.gitkeep b/haproxy/build-context/extras/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/haproxy/common-settings.yml b/haproxy/common-settings.yml new file mode 100644 index 0000000..9fd26d7 --- /dev/null +++ b/haproxy/common-settings.yml @@ -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}" diff --git a/haproxy/docker-compose.override.yml b/haproxy/docker-compose.override.yml new file mode 100644 index 0000000..cce982b --- /dev/null +++ b/haproxy/docker-compose.override.yml @@ -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}" diff --git a/haproxy/docker-compose.yml b/haproxy/docker-compose.yml new file mode 100644 index 0000000..a5873fe --- /dev/null +++ b/haproxy/docker-compose.yml @@ -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} diff --git a/haproxy/env/fqdn_context.env.example b/haproxy/env/fqdn_context.env.example new file mode 100644 index 0000000..af2361c --- /dev/null +++ b/haproxy/env/fqdn_context.env.example @@ -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=