diff --git a/README.md b/README.md index dd18174..a145dee 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +--- +sidebar_key: docker-easy-haproxy +tags: [docker, devops] +--- + # EasyHAProxy [![Sponsor](https://img.shields.io/badge/Sponsor-%23ea4aaa?logo=githubsponsors&logoColor=white&labelColor=0d1117)](https://github.com/sponsors/byjg) diff --git a/docs/reference/container-labels.md b/docs/reference/container-labels.md index 7bc02c8..1405bff 100644 --- a/docs/reference/container-labels.md +++ b/docs/reference/container-labels.md @@ -153,16 +153,17 @@ docker run \ When using Kubernetes, configure EasyHAProxy behavior with these annotations on your Ingress resources. Annotations apply to **all hosts** in the ingress configuration. -| Annotation | Description | Default | Example | -|-------------------------------------|--------------------------------------------------------------------------------------|------------|-----------------------------| -| kubernetes.io/ingress.class | (deprecated) Activate EasyHAProxy. Use `spec.ingressClassName` instead. | *optional* | easyhaproxy-ingress | -| easyhaproxy.redirect_ssl | (optional) Boolean. Force redirect all endpoints to HTTPS. | false | true or false | -| easyhaproxy.certbot | (optional) Boolean. Request certbot certificates for the ingress domains. | false | true or false | -| easyhaproxy.redirect | (optional) JSON. Key pair with a domain and its destination. | *empty* | \{"domain":"redirect_url"} | -| easyhaproxy.mode | (optional) Set the HTTP mode for that connection. | http | http or tcp | -| easyhaproxy.listen_port | (optional) Override the HTTP listen port created for that ingress. | 80 | 8081 | -| easyhaproxy.plugins | (optional) Comma-separated list of plugins to enable for this ingress. | *empty* | cloudflare,deny_pages | -| easyhaproxy.plugin.`{name}`.`{key}` | (optional) Plugin-specific configuration (see [Using Plugins](../guides/plugins.md)) | *varies* | See plugin docs | +| Annotation | Description | Default | Example | +|-------------------------------------|------------------------------------------------------------------------------------------------|------------|----------------------------| +| kubernetes.io/ingress.class | (deprecated) Activate EasyHAProxy. Use `spec.ingressClassName` instead. | *optional* | easyhaproxy-ingress | +| easyhaproxy.redirect_ssl | (optional) Boolean. Force redirect all endpoints to HTTPS. | false | true or false | +| easyhaproxy.certbot | (optional) Boolean. Request certbot certificates for the ingress domains. | false | true or false | +| easyhaproxy.redirect | (optional) JSON. Key pair with a domain and its destination. | *empty* | \{"domain":"redirect_url"} | +| easyhaproxy.mode | (optional) Set the HTTP mode for that connection. | http | http or tcp | +| easyhaproxy.proto | (optional) Backend server protocol. Automatically set to `fcgi` when using the fastcgi plugin. | *empty* | fcgi, h2 | +| easyhaproxy.listen_port | (optional) Override the HTTP listen port created for that ingress. | 80 | 8081 | +| easyhaproxy.plugins | (optional) Comma-separated list of plugins to enable for this ingress. | *empty* | cloudflare,deny_pages | +| easyhaproxy.plugin.`{name}`.`{key}` | (optional) Plugin-specific configuration (see [Using Plugins](../guides/plugins.md)) | *varies* | See plugin docs | For annotation usage examples, see the [Kubernetes getting started guide](../getting-started/kubernetes.md). diff --git a/docs/reference/plugins/fastcgi.md b/docs/reference/plugins/fastcgi.md index 943f059..f606a3f 100644 --- a/docs/reference/plugins/fastcgi.md +++ b/docs/reference/plugins/fastcgi.md @@ -67,6 +67,8 @@ services: ### Kubernetes Annotations +The `proto: fcgi` backend protocol is set automatically when using this plugin — no need to add `easyhaproxy.proto` manually. + ```yaml apiVersion: networking.k8s.io/v1 kind: Ingress @@ -75,12 +77,15 @@ metadata: easyhaproxy.plugins: "fastcgi" easyhaproxy.plugin.fastcgi.document_root: "/var/www/html" easyhaproxy.plugin.fastcgi.index_file: "index.php" + easyhaproxy.plugin.fastcgi.script_filename: "/var/www/html/index.php" spec: + ingressClassName: easyhaproxy rules: - host: phpapp.example.com http: paths: - path: / + pathType: ImplementationSpecific backend: service: name: php-fpm diff --git a/src/easymapping/config_generator.py b/src/easymapping/config_generator.py index 845bca1..d6abe68 100644 --- a/src/easymapping/config_generator.py +++ b/src/easymapping/config_generator.py @@ -260,6 +260,11 @@ class HaproxyConfigGenerator: # Extract all plugin configs in a single loop plugin_configs_for_host = [] for result in domain_results: + # Allow plugins to override host-level config (e.g. proto) + if result.modified_easymapping: + for key, value in result.modified_easymapping.items(): + easymapping[port]["hosts"][hostname][key] = value + # HAProxy config snippets for this domain if result.haproxy_config: plugin_configs_for_host.append(result.haproxy_config) diff --git a/src/functions/haproxy.py b/src/functions/haproxy.py index 09423fc..c7c3fa7 100644 --- a/src/functions/haproxy.py +++ b/src/functions/haproxy.py @@ -4,7 +4,7 @@ import shutil import subprocess import sys import time -from multiprocessing import Process +import multiprocessing from typing import Final import psutil @@ -31,7 +31,7 @@ class DaemonizeHAProxy: logger_haproxy.fatal(f"Failed to start HAProxy ({action}). Exiting.") sys.exit(1) - self.thread = Process(target=self.__start, args=()) + self.thread = multiprocessing.get_context('fork').Process(target=self.__start, args=()) self.thread.start() @staticmethod diff --git a/src/plugins/builtin/fastcgi.py b/src/plugins/builtin/fastcgi.py index a63a5a1..7078900 100644 --- a/src/plugins/builtin/fastcgi.py +++ b/src/plugins/builtin/fastcgi.py @@ -148,7 +148,7 @@ class FastcgiPlugin(PluginInterface): return PluginResult( haproxy_config=backend_config, # use-fcgi-app directive for the backend - modified_easymapping=None, + modified_easymapping={"proto": "fcgi"}, metadata=metadata, global_configs=[fcgi_app_definition] # For top-level injection ) diff --git a/src/processor/kubernetes.py b/src/processor/kubernetes.py index 9416633..f7490c8 100644 --- a/src/processor/kubernetes.py +++ b/src/processor/kubernetes.py @@ -269,6 +269,7 @@ class Kubernetes(ProcessorInterface): redirect_ssl = self._check_annotation(annotations, "easyhaproxy.redirect_ssl") redirect = self._check_annotation(annotations, "easyhaproxy.redirect") mode = self._check_annotation(annotations, "easyhaproxy.mode") + proto = self._check_annotation(annotations, "easyhaproxy.proto") listen_port = self._check_annotation(annotations, "easyhaproxy.listen_port", 80) plugins = self._check_annotation(annotations, "easyhaproxy.plugins") @@ -432,6 +433,8 @@ class Kubernetes(ProcessorInterface): rule_data[f"{definition}.redirect"] = redirect if mode is not None: rule_data[f"{definition}.mode"] = mode + if proto is not None: + rule_data[f"{definition}.proto"] = proto rule_data[f"{definition}.balance"] = self._check_annotation(ingress.metadata.annotations, "easyhaproxy.balance", "roundrobin") # Add plugin configuration diff --git a/tests_e2e/docker/docker-compose-php-fpm.yml b/tests_e2e/docker/docker-compose-php-fpm.yml index 20edeb6..be087f7 100644 --- a/tests_e2e/docker/docker-compose-php-fpm.yml +++ b/tests_e2e/docker/docker-compose-php-fpm.yml @@ -77,9 +77,9 @@ services: easyhaproxy.http.port: 80 # PHP-FPM listens on port 9000 easyhaproxy.http.localport: 9000 - easyhaproxy.http.proto: fcgi # Enable FastCGI plugin for PHP environment configuration + # Note: proto fcgi is set automatically by the fastcgi plugin easyhaproxy.http.plugins: fastcgi # FastCGI plugin configuration