Skip to content

Commit

Permalink
feat: add S6
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitjilka committed Dec 21, 2023
1 parent 3136de7 commit 2beabf3
Show file tree
Hide file tree
Showing 32 changed files with 65 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Build and Push Docker Image
on:
push:
branches:
- "7.4"
- "7.4-s6"

jobs:
build-and-push:
Expand Down
35 changes: 22 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM alpine:3.14
LABEL MAINTAINER "Rakshit Menpara <[email protected]>"

ARG S6_OVERLAY_VERSION="3.1.5.0"
ARG S6_OVERLAY_ARCH="x86_64"

ENV UID=100 \
GID=101 \
FPM_LOG_LEVEL=warning
ENV composer_hash 48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5
ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
Expand All @@ -26,15 +31,14 @@ RUN set -ex \
# Other dependencies
mariadb-client sudo \
# Miscellaneous packages
bash ca-certificates dialog git libjpeg libpng-dev openssh-client supervisor vim wget \
bash ca-certificates dialog git libjpeg libpng-dev openssh-client shadow vim wget \
# Nginx
nginx \
# Create directories
&& mkdir -p /etc/nginx \
&& mkdir -p /run/nginx \
&& mkdir -p /etc/nginx/sites-available \
&& mkdir -p /etc/nginx/sites-enabled \
&& mkdir -p /var/log/supervisor \
&& rm -Rf /var/www/* \
&& rm -Rf /etc/nginx/nginx.conf \
# Composer
Expand All @@ -47,13 +51,27 @@ RUN set -ex \

################## INSTALLATION ENDS ##################

# add s6 overlay
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz

# add s6 optional symlinks
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-noarch.tar.xz
ADD https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz /tmp
RUN tar -C / -Jxpf /tmp/s6-overlay-symlinks-arch.tar.xz

################## CONFIGURATION STARTS ##################

ADD rootfs /

RUN ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf && \
ln -s /etc/php7/php.ini /etc/php7/conf.d/php.ini && \
chown -R nginx:nginx /var/www && \
chmod 755 /etc/s6-overlay/s6-rc.d/*/run && \
chmod 755 /etc/s6-overlay/s6-rc.d/*/up && \
mkdir -p /var/www/storage/logs/ && \
touch /var/www/storage/logs/laravel.log /var/log/nginx/error.log /var/log/php7/error.log

Expand All @@ -63,13 +81,4 @@ EXPOSE 443 80

WORKDIR /var/www

ENTRYPOINT ["dockerize", \
"-template", "/etc/php7/php.ini:/etc/php7/php.ini", \
"-template", "/etc/php7/php-fpm.conf:/etc/php7/php-fpm.conf", \
"-template", "/etc/php7/php-fpm.d:/etc/php7/php-fpm.d", \
"-stdout", "/var/www/storage/logs/laravel.log", \
"-stdout", "/var/log/nginx/error.log", \
"-stdout", "/var/log/php7/error.log", \
"-poll"]

CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
ENTRYPOINT ["/init"]
Empty file.
7 changes: 7 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-nginx/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

# copy default config files if they don't exist
if [[ ! -f /etc/nginx/sites-enabled/default.conf ]]; then
cp /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf
fi
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-nginx/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-nginx/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-nginx/run
Empty file.
5 changes: 5 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-php7-fpm/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

# add environment variable into files
dockerize -template /etc/php7/php.ini:/etc/php7/php.ini -template /etc/php7/php-fpm.conf:/etc/php7/php-fpm.conf -template /etc/php7/php-fpm.d:/etc/php7/php-fpm.d
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-php7-fpm/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-php7-fpm/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-php7-fpm/run
Empty file.
8 changes: 8 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-usermod/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

UID=${UID:-911}
GID=${GID:-911}

echo "User Id $UID, Group id $GID"
usermod -u "$UID" nginx && groupmod -g "$GID" nginx
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-usermod/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/init-usermod/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-usermod/run
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-nginx/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

/usr/sbin/nginx -g "daemon off;"
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-nginx/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-php7-fpm/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

/usr/sbin/php-fpm7 --nodaemonize --fpm-config /etc/php7/php-fpm.conf
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-php7-fpm/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-stdout/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/with-contenv bash

dockerize -stdout /var/www/storage/logs/laravel.log -stdout /var/log/nginx/error.log -stdout /var/log/php7/error.log -poll
1 change: 1 addition & 0 deletions rootfs/etc/s6-overlay/s6-rc.d/svc-stdout/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
46 changes: 0 additions & 46 deletions rootfs/etc/supervisord.conf

This file was deleted.

4 changes: 4 additions & 0 deletions rootfs/etc/usermod/setuid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

echo "User Id $UID, Group id $GID"
usermod -u "$UID" nginx && groupmod -g "$GID" nginx

0 comments on commit 2beabf3

Please sign in to comment.