Start with HTTP, add HTTPS when certificates are available

What I’d like to achieve is to have HAProxy running in a docker container, proxying requests to website containers and to a container obtaining certificates. For apparent reasons I need to start with HTTP. Then when the certificates container obtains the certificate I want it to reload HAProxy, enabling HTTPS as a result.

I see that HAProxy has conditional blocks, but they can’t check for existence of files (.if exists(/path/to/certificate)). I can’t integrate a new value of an environment variable into a process. So it seems like the options are:

  • Enable HTTPS settings .if defined(HTTPS). I don’t like the idea of changing the way a container starts, so I guess I need some wrapper that sets HTTPS=1 if the certificate exists and starts HAProxy.
  • Generate the config from a template. The first approach looks simpler.

In both cases I need to restart the HAProxy container.

Any better ideas?

Actually generating the config is the only option, but it appears reload can’t make haproxy bind to another port (8080, 443).