Skip to content

Commit

Permalink
Upgraded to haproxy 2.7.6 and also fixed config monitoring bug and im…
Browse files Browse the repository at this point in the history
…proved healthcheck
  • Loading branch information
richturner committed Apr 27, 2023
1 parent 7c801a9 commit 9a84bf9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# HAProxy image with certbot for certificate generation and renewal
#
# -----------------------------------------------------------------------------------------------
FROM haproxy:2.7.0-alpine
FROM haproxy:2.7.6-alpine
MAINTAINER [email protected]

USER root
Expand Down Expand Up @@ -59,7 +59,7 @@ ADD cli.ini /root/.config/letsencrypt/
ADD entrypoint.sh /
RUN chmod +x /entrypoint.sh

HEALTHCHECK --interval=3s --timeout=3s --start-period=2s --retries=30 CMD curl --fail --silent http://127.0.0.1:80 || exit 1
HEALTHCHECK --interval=60s --timeout=3s --start-period=5s --retries=2 CMD curl --fail --silent http://127.0.0.1/docker-health || exit 1

RUN chown -R haproxy:haproxy /etc/haproxy

Expand Down
11 changes: 4 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,10 @@ monitor() {
log_info "Monitoring config file '$HAPROXY_CONFIG' and certs in '$CERT_DIR' for changes..."

# Wait if config or certificates were changed, block this execution
inotifywait -q -r --exclude '\.git/' -e modify,create,delete,move,move_self "$HAPROXY_CONFIG" "$CERT_DIR" |
while read events; do
log_info "Change detected..."
sleep 5
restart
done
monitor
inotifywait -q -r --exclude '\.git/' -e modify,create,delete,move,move_self "$HAPROXY_CONFIG" "$CERT_DIR"
log_info "Change detected..." &&
sleep 5 &&
restart
done
}

Expand Down
15 changes: 14 additions & 1 deletion haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@ defaults
resolvers docker_resolver
nameserver dns 127.0.0.11:53


frontend stats
bind *:8404
http-request use-service prometheus-exporter if { path /metrics }
stats enable
stats uri /stats
stats refresh 10s

frontend http
bind *:80

# Serve certificate validation challenges directly with Lua plugin
acl url_acme_http01 path_beg /.well-known/acme-challenge/
http-request use-service lua.acme-http01 if METH_GET url_acme_http01

# Static health endpoint for docker healthcheck (don't log it)
acl url_docker_health path /docker-health
http-request set-log-level silent if url_docker_health
http-request return status 200 if url_docker_health

# Optional: redirects for root requests with certain host names to service paths
acl is_root path -i /
acl is_redirect_1 hdr(host) -i "${PROXY_HOST_REDIRECT_1_NAME}"
Expand All @@ -61,7 +74,7 @@ frontend http
redirect code 302 location "https://${DOMAINNAME}${PROXY_HOST_REDIRECT_10_TARGET}" if is_root is_redirect_10

# Redirect all http requests to https
redirect scheme https if !url_acme_http01
redirect scheme https if !url_acme_http01 !url_docker_health

frontend https
bind *:443 ssl crt /etc/haproxy/certs crt "${CERT_DIR}" no-tls-tickets
Expand Down

0 comments on commit 9a84bf9

Please sign in to comment.