Skip to content

Commit

Permalink
Updates to S6 overlay
Browse files Browse the repository at this point in the history
# Conflicts:
#	build/Dockerfile
#	fs/etc/s6-overlay/s6-rc.d/ingress-controller/run
#	pkg/haproxy/main.go
#	pkg/haproxy/process/s6-overlay.go
  • Loading branch information
PKizzle committed Dec 15, 2023
1 parent d421ee3 commit eab8eae
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 33 deletions.
37 changes: 21 additions & 16 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ FROM haproxytech/haproxy-alpine:2.8

ARG TARGETPLATFORM

ARG S6_OVERLAY_VERSION=2.2.0.3
ARG S6_OVERLAY_VERSION=3.1.6.2
ENV S6_OVERLAY_VERSION $S6_OVERLAY_VERSION
ENV S6_READ_ONLY_ROOT=1
ENV S6_USER=haproxy
ENV S6_GROUP=haproxy

COPY /fs /

Expand All @@ -52,25 +54,28 @@ RUN apk --no-cache add socat openssl util-linux htop tzdata curl libcap && \
chmod -R ug+rwx /usr/local/etc/haproxy /run /var && \
setcap 'cap_net_bind_service=+ep' /usr/local/sbin/haproxy && \
case "${TARGETPLATFORM}" in \
"linux/arm64") S6_ARCH=aarch64 ;; \
"linux/amd64") S6_ARCH=amd64 ;; \
"linux/arm/v6") S6_ARCH=arm ;; \
"linux/arm/v7") S6_ARCH=armhf ;; \
"linux/ppc64le") S6_ARCH=ppc64le ;; \
"linux/386") S6_ARCH=x86 ;; \
"linux/arm64") S6_ARCH=aarch64 ;; \
"linux/amd64") S6_ARCH=x86_64 ;; \
"linux/arm/v6") S6_ARCH=arm ;; \
"linux/arm/v7") S6_ARCH=armhf ;; \
"linux/ppc64") S6_ARCH=powerpc64 ;; \
"linux/ppc64le") S6_ARCH=powerpc64le ;; \
"linux/486") S6_ARCH=i486 ;; \
"linux/686") S6_ARCH=i686 ;; \
*) echo "ARG TARGETPLATFORM undeclared" >&2 && exit 1 ;; \
esac && \
curl -sS -L -o /tmp/s6-overlay-installer "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}-installer" && \
chmod +x /tmp/s6-overlay-installer && \
/tmp/s6-overlay-installer / && \
rm -f /tmp/s6-overlay-installer && \
mkdir /var/run/s6 && \
chown haproxy:haproxy /var/run/s6 && \
chmod ug+rwx /var/run/s6 && \
sed -i 's/ root / haproxy /g' /etc/s6/init/init-stage2-fixattrs.txt && \
chmod ugo+x /etc/services.d/*/run /etc/cont-init.d/* && \
curl -sS -L -o /tmp/s6-overlay-scripts.tar.xz "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz" && \
tar -C / -Jxpf /tmp/s6-overlay-scripts.tar.xz && \
curl -sS -L -o /tmp/s6-overlay-binaries.tar.xz "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.xz" && \
tar -C / -Jxpf /tmp/s6-overlay-binaries.tar.xz && \
rm -f /tmp/s6-overlay-scripts.tar.xz /tmp/s6-overlay-binaries.tar.xz && \
chown -R haproxy:haproxy /init /etc/s6-overlay && \
chmod u+x /etc/s6-overlay/scripts/* && \
chmod +s /init && \
rm -rf /var/lib/pebble

COPY --from=builder /src/fs/haproxy-ingress-controller .

VOLUME [ "/run" ]

ENTRYPOINT ["/start.sh"]
1 change: 1 addition & 0 deletions fs/etc/s6-overlay/s6-rc.d/aux-cfg/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions fs/etc/s6-overlay/s6-rc.d/aux-cfg/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/scripts/01-aux-cfg
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/with-contenv sh
#!/command/with-contenv sh

MEMLIMIT=$(free -m | awk '/Mem:/ {print int($2 * 2 / 3)}')

Expand Down
1 change: 1 addition & 0 deletions fs/etc/s6-overlay/s6-rc.d/haproxy/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions fs/etc/s6-overlay/s6-rc.d/ingress-controller/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/command/with-contenv sh

echo "Ingress Controller exited with code ${1}, taking down the S6 supervision tree"
exec /run/s6/basedir/bin/halt
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
#!/usr/bin/with-contenv sh

if [ ! -f /var/run/s6/services/.s6-svscan/SIGUSR1 ]; then
cat > /var/run/s6/services/.s6-svscan/SIGUSR1 <<EOF
#!/bin/sh
kill -SIGTERM 1
EOF
chmod +x /var/run/s6/services/.s6-svscan/SIGUSR1
fi
#!/command/with-contenv sh

MEMLIMIT=$(free -m | awk '/Mem:/ {print int($2 / 3)}')

Expand Down
1 change: 1 addition & 0 deletions fs/etc/s6-overlay/s6-rc.d/ingress-controller/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/with-contenv sh
#!/command/with-contenv sh

if [ ! -e /etc/haproxy/haproxy-aux.cfg ]; then
touch /etc/haproxy/haproxy-aux.cfg
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.4 // indirect
Expand Down
11 changes: 6 additions & 5 deletions pkg/haproxy/process/s6-overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ func (d *s6Control) Service(action string) error {

switch action {
case "start":
// no need to start it is up already (s6)
return nil
cmd = exec.Command("s6-svc", "-u", "/run/service/haproxy")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
case "stop":
// no need to stop it (s6)
return nil
case "reload":
cmd = exec.Command("s6-svc", "-2", "/var/run/s6/services/haproxy")
cmd = exec.Command("s6-svc", "-2", "/run/service/haproxy")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
case "restart":
// -t terminates and s6 will start it again
cmd = exec.Command("s6-svc", "-t", "/var/run/s6/services/haproxy")
cmd = exec.Command("s6-svc", "-r", "/run/service/haproxy")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
Expand Down

0 comments on commit eab8eae

Please sign in to comment.