Skip to content

Commit

Permalink
Fix issues with newer vesions of Unit
Browse files Browse the repository at this point in the history
  • Loading branch information
xZero707 committed Apr 15, 2024
1 parent 293c8d8 commit 87af839
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
19 changes: 12 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ RUN set -eux \
################################################
# Root FS builder / docker overlay - Stage #3 #
################################################
FROM scratch AS rootfs
FROM alpine:3.19 AS rootfs

COPY --from=nginx-unit-builder ["/opt/unit/", "/opt/unit/"]
COPY --from=ghcr.io/n0rthernl1ghts/s6-rootfs:2.2 ["/", "/"]
COPY --from=ghcr.io/n0rthernl1ghts/s6-rootfs:2.2 ["/", "/rootfs-build"]

# Rootfs
COPY ["./rootfs", "/"]
COPY ["./rootfs", "/rootfs-build"]

# Prepare unit
COPY --chmod=0775 ["./src/setup-unit.sh", "/tmp/setup-unit.sh"]

RUN set -eux \
&& apk add --update --no-cache bash rsync \
&& /tmp/setup-unit.sh



Expand All @@ -57,11 +64,9 @@ ARG PHP_ALPINE_VERSION
FROM --platform=${TARGETPLATFORM} php:${PHP_VERSION}-zts-alpine${PHP_ALPINE_VERSION}

RUN set -eux \
&& apk add --update --no-cache pcre-dev socat \
&& ln -sf /opt/unit/sbin/unitd /sbin/unitd \
&& mkdir /var/lib/unit/state/certs -p
&& apk add --update --no-cache pcre-dev socat

COPY --from=rootfs ["/", "/"]
COPY --from=rootfs ["/rootfs-build/", "/"]


ARG UNIT_VERSION
Expand Down
8 changes: 7 additions & 1 deletion rootfs/etc/services.d/unitd/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#!/usr/bin/env sh

exec /opt/unit/sbin/unitd --no-daemon --tmp "/tmp" --state "/var/lib/unit/state" --modules "/opt/unit/modules" --control "unix:${UNIT_SOCKET}"
# This is for legacy support for versions prior to 1.30.0
if [ -d "/opt/unit" ] && [ -x "/opt/unit/sbin/unitd" ]; then
exec "/opt/unit/sbin/unitd" --no-daemon --tmp "/tmp" --state "/var/lib/unit/state" --modules "/opt/unit/modules" --control "unix:${UNIT_SOCKET}"
exit
fi

exec "/usr/local/sbin/unitd" --no-daemon --control "unix:${UNIT_SOCKET}"
28 changes: 28 additions & 0 deletions src/setup-unit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -eux

main() {
local unitOpt="/opt/unit/"

mkdir /rootfs-build/var/lib/unit/state/certs -p

if [ -d "${unitOpt}/usr/" ]; then
rsync -ah --progress "${unitOpt}/usr" /rootfs-build/
rm -rf "${unitOpt}"
return
fi

if [ -f "${unitOpt}/sbin/unitd" ]; then
mkdir -p /rootfs-build/sbin /rootfs/opt
mv "${unitOpt}" "/rootfs-build/opt/"
ln -sf "${unitOpt}/sbin/unitd" /rootfs-build/sbin/unitd
return
fi

echo "Error: Nginx Unit not found in ${unitOpt}" >&2
ls -al "${unitOpt}"
return 1
}

main "${@}"

0 comments on commit 87af839

Please sign in to comment.