Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #373: Run custom command in fpm images without running web server #413

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,43 +122,3 @@ example-project | 2023/12/05 19:52:38 [info] 67#67 OpenSSL 3.0.11 19 Sep 2023,
::

You can see our `👋 Hello, world!` is executing *after* the initialization of `10-init-unit.sh`.

## Additional Steps For FPM-Apache & FPM-NGINX (S6 Overlay based images)
If the image you're working with is using S6 Overlay (`fpm-nginx` and `fpm-apache`), you'll need to take additional steps to get your scripts to execute.

### Background
S6 Overlay uses a set of directories to execute scripts at different stages of the container's life cycle. You can read more about it in [S6 Overlay's documentation](https://github.com/just-containers/s6-overlay).

### Our Solution
Instead of reading through the complexities of S6 Overlay, we wrote a script called `docker-php-serversideup-s6-init` that will automatically configure your script located in `/etc/entrypoint.d` to execute correctly with S6 Overlay.

### `docker-php-serversideup-s6-init` Usage
The only thing you need to do is call `docker-php-serversideup-s6-init` after your script is copied. Here's an example:

::note
Depending on your usecase, you may want to set `S6_CMD_WAIT_FOR_SERVICES` to `1` in your environment variables. This will make sure your script doesn't execute until all the services are ready. Learn more about this in [S6 Overlay's documentation](https://github.com/just-containers/s6-overlay).
::

::code-panel
---
label: "Dockerfile"
---
```dockerfile
FROM serversideup/php:8.3-fpm-nginx

ENV S6_CMD_WAIT_FOR_SERVICES=1

COPY --chmod=755 ./entrypoint.d/ /etc/entrypoint.d/

# Change to root, so we can do root things
USER root

# As root, run the docker-php-serversideup-s6-init script
RUN docker-php-serversideup-s6-init

# Change back to the www-data user
USER www-data
```
::

The above `Dockerfile` will copy scripts from our `entrypoint.d` directory to `/etc/entrypoint.d/` and then run `docker-php-serversideup-s6-init`, which will then take any scripts in `/etc/entrypoint.d/` and configure them to execute correctly with S6 Overlay.
3 changes: 0 additions & 3 deletions docs/content/docs/7.reference/2.command-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ docker-php-serversideup-set-id www-data 1000:1000
```
::

## docker-php-serversideup-s6-init
This is a command used at build time to take scripts from "/etc/entrypoint.d" and move them to the S6 Overlay structure.

## docker-php-serversideup-s6-install
This is a command used at build time to install a specific version of S6 Overlay.

Expand Down
1 change: 0 additions & 1 deletion src/s6/etc/s6-overlay/s6-rc.d/php-fpm/dependencies
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
50-laravel-automations
57 changes: 0 additions & 57 deletions src/s6/usr/local/bin/docker-php-serversideup-s6-init

This file was deleted.

5 changes: 3 additions & 2 deletions src/variations/fpm-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ COPY --from=s6-build /usr/local/bin/php-fpm-healthcheck /usr/local/bin/php-fpm-h
# install pecl extensions, dependencies, and clean up
RUN docker-php-serversideup-dep-install-debian "${DEPENDENCY_PACKAGES_DEBIAN}" && \
docker-php-serversideup-install-php-ext-installer && \
docker-php-serversideup-s6-init && \
\
# Ensure /var/www/ has the correct permissions
chown -R www-data:www-data /var/www && \
Expand Down Expand Up @@ -150,12 +149,14 @@ USER www-data

EXPOSE 8080 8443

ENTRYPOINT ["docker-php-serversideup-entrypoint"]

# Set stop signal to SIGQUIT for a graceful shutdown instead of S6's preferred SIGTERM (https://github.com/just-containers/s6-overlay/issues/586)
STOPSIGNAL SIGQUIT

WORKDIR ${APP_BASE_DIR}

ENTRYPOINT ["/init"]
CMD ["/init"]

HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
CMD [ "sh", "-c", "curl --insecure --silent --location --show-error --fail http://localhost:8080$HEALTHCHECK_PATH || exit 1" ]
5 changes: 3 additions & 2 deletions src/variations/fpm-nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ COPY --from=nginx-repo-config /etc/apt/preferences.d/99nginx /etc/apt/preference
RUN docker-php-serversideup-dep-install-alpine "${DEPENDENCY_PACKAGES_ALPINE}" && \
docker-php-serversideup-dep-install-debian "${DEPENDENCY_PACKAGES_DEBIAN}" && \
docker-php-serversideup-install-php-ext-installer && \
docker-php-serversideup-s6-init && \
\
# Ensure /var/www/ has the correct permissions
chown -R www-data:www-data /var/www && \
Expand Down Expand Up @@ -179,12 +178,14 @@ USER www-data

EXPOSE 8080 8443

ENTRYPOINT ["docker-php-serversideup-entrypoint"]

# Set stop signal to SIGQUIT for a graceful shutdown instead of S6's preferred SIGTERM (https://github.com/just-containers/s6-overlay/issues/586)
STOPSIGNAL SIGQUIT

WORKDIR ${APP_BASE_DIR}

ENTRYPOINT ["/init"]
CMD ["/init"]

HEALTHCHECK --interval=5s --timeout=3s --retries=3 \
CMD [ "sh", "-c", "curl --insecure --silent --location --show-error --fail http://localhost:8080$HEALTHCHECK_PATH || exit 1" ]