Skip to content

Commit 2095c21

Browse files
authored
Fix exit on error during migrations, CI updates, and improve notices and messages (#490)
* Force do not exit on error for the try loop on migrations. Fixes #489 * Update notice for custom commands * Removed Alpine from 7.4.33 because Alpine 3.16 reached EOL (#426 (comment)) * Removed Alpine from PHP 8.0 because Alpine 3.16 reached EOL (#426 (comment)) * Added PHP version and image version to container info start up * Switch to GitHub runners on Ubuntu 24.04 * Set GHA cache * Re-added alpine for 7.4 and 8.0 (#426 (comment)) * Converted to buildx and added platform support * Adjusted PRs to run automatically * Deprecated and removed linux/arm/v7 * Sign into docker registry only if we're pushing the image * Added docs to clarify why we don't use subshells (#481 (comment)) * Fixed link
1 parent f2250d8 commit 2095c21

File tree

12 files changed

+103
-21
lines changed

12 files changed

+103
-21
lines changed

.github/workflows/action_publish-images-prs.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: Docker Publish (PR Images)
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
pr_number:
7+
description: 'PR number to build (leave empty for manual branch build)'
8+
required: false
9+
type: string
510
pull_request:
611
types: [opened, synchronize, reopened]
712
paths:
@@ -12,11 +17,16 @@ on:
1217

1318
jobs:
1419
build-dev-images:
15-
if: ${{ github.event_name == 'pull_request' && ! github.event.pull_request.head.repo.fork }}
1620
uses: ./.github/workflows/service_docker-build-and-publish.yml
1721
with:
18-
registry-repositories: "docker.io/serversideup/php-dev" # Set to our development repository
19-
tag-prefix: "${{ github.event.pull_request.number }}"
22+
registry-repositories: "docker.io/serversideup/php-dev"
23+
# Use PR number from input if provided, otherwise use the PR event number
24+
tag-prefix: ${{ inputs.pr_number || github.event.pull_request.number }}
2025
release-type: testing
2126
authenticate_with_ghcr: false
22-
secrets: inherit
27+
push-to-registry: >-
28+
${{
29+
github.event_name == 'workflow_dispatch' ||
30+
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.owner.type == 'Organization')
31+
}}
32+
secrets: inherit

.github/workflows/scheduled-task_update-sponsors.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- cron: 30 15 * * 0-6
66
jobs:
77
deploy:
8-
runs-on: ubuntu-22.04
8+
runs-on: ubuntu-24.04
99
steps:
1010
- name: Checkout 🛎️
1111
uses: actions/checkout@v4

.github/workflows/service_docker-build-and-publish.yml

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ on:
2727
type: string
2828
default: 'testing'
2929
description: 'The type of release to create. Options: testing, latest'
30+
push-to-registry:
31+
type: boolean
32+
default: true
33+
description: 'Whether to push the images to the registry.'
3034

3135
jobs:
3236
setup-matrix:
33-
runs-on: ubuntu-22.04
37+
runs-on: ubuntu-24.04
3438
outputs:
3539
php-version-map-json: ${{ steps.get-php-versions.outputs.php-version-map-json }}
3640
steps:
@@ -68,10 +72,12 @@ jobs:
6872

6973
docker-publish:
7074
needs: setup-matrix
71-
runs-on:
72-
- runs-on
73-
- runner=4cpu-linux-x64
74-
- run-id=${{ github.run_id }}
75+
runs-on: ubuntu-24.04
76+
## Use AWS runners
77+
# runs-on:
78+
# - runs-on
79+
# - runner=4cpu-linux-x64
80+
# - run-id=${{ github.run_id }}
7581
strategy:
7682
matrix: ${{fromJson(needs.setup-matrix.outputs.php-version-map-json)}}
7783

@@ -93,13 +99,14 @@ jobs:
9399
##
94100
- name: Login to DockerHub
95101
uses: docker/login-action@v3
102+
if: ${{ inputs.push-to-registry }}
96103
with:
97104
username: ${{ secrets.DOCKER_HUB_USERNAME }}
98105
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
99106

100107
- name: Login to GitHub Container Registry
101108
uses: docker/login-action@v3
102-
if: ${{ inputs.authenticate_with_ghcr }}
109+
if: ${{ inputs.push-to-registry && inputs.authenticate_with_ghcr }}
103110
with:
104111
registry: ghcr.io
105112
username: ${{ github.actor }}
@@ -139,23 +146,24 @@ jobs:
139146
echo "REPOSITORY_BUILD_VERSION=git-${SHORT_SHA}-${{ github.run_id }}" >> $GITHUB_ENV
140147
fi
141148
142-
- name: Build and push
149+
- name: Build images
143150
uses: docker/build-push-action@v6
144151
with:
145152
file: src/variations/${{ matrix.php_variation }}/Dockerfile
146-
cache-from: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }}
147-
cache-to: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }},mode=max
153+
cache-from: type=gha
154+
cache-to: type=gha
155+
## Run-on cache
156+
# cache-from: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }}
157+
# cache-to: type=s3,blobs_prefix=cache/${{ github.repository }}/,manifests_prefix=cache/${{ github.repository }}/,region=${{ env.RUNS_ON_AWS_REGION }},bucket=${{ env.RUNS_ON_S3_BUCKET_CACHE }},mode=max
148158
build-args: |
149159
BASE_OS_VERSION=${{ matrix.base_os }}
150160
PHP_VERSION=${{ matrix.patch_version }}
151161
PHP_VARIATION=${{ matrix.php_variation }}
152162
REPOSITORY_BUILD_VERSION=${{ env.REPOSITORY_BUILD_VERSION }}
153-
154163
platforms: |
155164
linux/amd64
156-
linux/arm/v7
157165
linux/arm64/v8
158166
pull: true
159-
push: true
167+
push: ${{ inputs.push-to-registry }}
160168
tags: ${{ env.DOCKER_TAGS }}
161169
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=Supercharge your PHP experience with Docker images that are based off the official PHP images but are optimized to be run in production environments for Laravel and WordPress and more

docs/content/docs/5.customizing-the-image/3.adding-your-own-start-up-scripts.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Your script should:
1818
- Located in the `/etc/entrypoint.d` directory
1919
- Have the file extension ending in `.sh`
2020
::
21+
2122
We recommend writing your script in `/bin/sh` for the best compatibility between Alpine and Debian. If you choose to use `/bin/bash`, your script will only be able to run on Debian-based images.
2223

2324
## Choose your execution order
@@ -27,6 +28,15 @@ Since [we provide default entrypoint scripts](/docs/getting-started/default-conf
2728
If you want to disable our entrypoint scripts, you can set `DISABLE_DEFAULT_CONFIG` to `true` in your environment variables.
2829
::
2930

31+
## Long running services
32+
::note
33+
Don't use entrypoint scripts for long-running services. You want your services to be monitored and restarted if they crash.
34+
::
35+
36+
Anything in the `/etc/entrypoint.d` directory are scripts that are intended to run quickly and then move on. If you run a service as an entrypoint script, that service may crash and not be restarted.
37+
38+
Instead, learn about [using S6 overlay](/docs/guide/using-s6-overlay) so your services can be properly initialized and monitored. See the [S6 Overylay project](https://github.com/just-containers/s6-overlay) for more details on how to write your own S6 service.
39+
3040
## Example: Create a custom entrypoint script
3141
In this example, let's create a `99-my-script.sh` so it executes after all the other default scripts.
3242

@@ -95,6 +105,11 @@ services:
95105
96106
In the above file, we're building our image using the `Dockerfile` in the current directory. We're also mounting our current directory to `/var/www/html` in the container.
97107

108+
## Don't use `exit 0` in your script
109+
If you use `exit 0` in your script, it will stop the execution of the rest of the entrypoint scripts. We recommend using `return 0` instead. [See this discussion](https://github.com/serversideup/docker-php/issues/481#issuecomment-2463082306) for more details on why.
110+
111+
Long story short, we don't use subshells to execute your scripts, so `exit 0` will not work as expected. We do this because we want to ensure your script has access to the environment variables that are set in the entrypoint scripts.
112+
98113
## Running our example
99114
When we run `docker compose up`, we should see the following output:
100115

@@ -121,4 +136,4 @@ example-project | 2023/12/05 19:52:38 [info] 67#67 OpenSSL 3.0.11 19 Sep 2023,
121136
```
122137
::
123138

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

scripts/dev.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ PHP_BUILD_PREFIX=""
2626
DOCKER_REPOSITORY="${DOCKER_REPOSITORY:-"serversideup/php"}"
2727
DOCKER_ADDITIONAL_BUILD_ARGS=()
2828
CUSTOM_REGISTRY=""
29+
PLATFORM=""
2930

3031
# UI Colors
3132
function ui_set_yellow {
@@ -68,11 +69,34 @@ check_vars() {
6869
return 0
6970
}
7071

72+
detect_platform() {
73+
local arch=$(uname -m)
74+
case $arch in
75+
x86_64)
76+
echo "linux/amd64"
77+
;;
78+
arm64|aarch64)
79+
echo "linux/arm64/v8"
80+
;;
81+
*)
82+
echo "Unsupported architecture: $arch" >&2
83+
exit 1
84+
;;
85+
esac
86+
}
87+
7188
build_docker_image() {
7289
build_tag="${DOCKER_REPOSITORY}:${PHP_BUILD_PREFIX}${PHP_BUILD_VERSION}-${PHP_BUILD_VARIATION}-${PHP_BUILD_BASE_OS}"
7390
echo_color_message yellow "🐳 Building Docker Image: $build_tag"
74-
docker build \
75-
${DOCKER_ADDITIONAL_BUILD_ARGS[@]} \
91+
92+
# Set default platform if not specified
93+
if [ -z "$PLATFORM" ]; then
94+
PLATFORM=$(detect_platform)
95+
fi
96+
97+
docker buildx build \
98+
"${DOCKER_ADDITIONAL_BUILD_ARGS[@]}" \
99+
--platform "$PLATFORM" \
76100
--build-arg PHP_VARIATION="$PHP_BUILD_VARIATION" \
77101
--build-arg PHP_VERSION="$PHP_BUILD_VERSION" \
78102
--build-arg BASE_OS_VERSION="$PHP_BUILD_BASE_OS" \
@@ -105,6 +129,7 @@ help_menu() {
105129
echo " --os <os> Set the base OS (e.g., bullseye, bookworm, alpine)"
106130
echo " --prefix <prefix> Set the prefix for the Docker image (e.g., beta)"
107131
echo " --registry <registry> Set a custom registry (e.g., localhost:5000)"
132+
echo " --platform <platform> Set the platform (default: detected from system architecture)"
108133
echo " --* Any additional options will be passed to the docker buildx command"
109134
echo
110135
echo "Environment Variables:"
@@ -136,6 +161,10 @@ while [[ $# -gt 0 ]]; do
136161
CUSTOM_REGISTRY="$2"
137162
shift 2
138163
;;
164+
--platform)
165+
PLATFORM="$2"
166+
shift 2
167+
;;
139168
--*)
140169
# If there's a next argument and it starts with '--', treat the current argument as standalone.
141170
# Otherwise, pair the current argument with the next.

src/common/etc/entrypoint.d/0-container-info.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Docker user: $(whoami)
4040
Docker uid: $(id -u)
4141
Docker gid: $(id -g)
4242
OPcache: $PHP_OPCACHE_MESSAGE
43+
PHP Version: $(php -r 'echo phpversion();')
44+
Image Version: $(cat /etc/serversideup-php-version)
4345
"
4446

4547
if [ "$PHP_OPCACHE_STATUS" = "0" ]; then

src/common/etc/entrypoint.d/50-laravel-automations.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ if [ "$DISABLE_DEFAULT_CONFIG" = "false" ]; then
5151
echo "🚀 Clearing Laravel cache before attempting migrations..."
5252
php "$APP_BASE_DIR/artisan" config:clear
5353

54+
# Do not exit on error for this loop
55+
set +e
56+
echo "⚡️ Attempting database connection..."
5457
while [ $count -lt "$timeout" ]; do
5558
test_db_connection > /dev/null 2>&1
5659
status=$?
@@ -64,6 +67,9 @@ if [ "$DISABLE_DEFAULT_CONFIG" = "false" ]; then
6467
fi
6568
done
6669

70+
# Re-enable exit on error
71+
set -e
72+
6773
if [ $count -eq "$timeout" ]; then
6874
echo "Database connection failed after multiple attempts."
6975
return 1

src/s6/etc/entrypoint.d/10-init-webserver-config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ script_name="init-webserver-config"
99

1010
# Check if S6 is initialized
1111
if [ "$S6_INITIALIZED" != "true" ]; then
12-
echo "ℹ️ [NOTICE]: S6 is not initialized. Skipping web server configuration and running custom command."
12+
echo "ℹ️ [NOTICE]: Running custom command instead of web server configuration: '$*'"
1313
return 0
1414
fi
1515

src/variations/cli/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ RUN docker-php-serversideup-dep-install-alpine "${DEPENDENCY_PACKAGES_ALPINE}" &
5959
chown -R www-data:www-data /var/www && \
6060
chmod -R 755 /var/www && \
6161
\
62+
# Set the image version
63+
echo "${REPOSITORY_BUILD_VERSION}" > /etc/serversideup-php-version && \
64+
\
6265
# Make composer cache directory
6366
mkdir -p "${COMPOSER_HOME}" && \
6467
chown -R www-data:www-data "${COMPOSER_HOME}" && \

src/variations/fpm-apache/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ RUN docker-php-serversideup-dep-install-debian "${DEPENDENCY_PACKAGES_DEBIAN}"
104104
chown -R www-data:www-data /var/www && \
105105
chmod -R 755 /var/www && \
106106
\
107+
# Set the image version
108+
echo "${REPOSITORY_BUILD_VERSION}" > /etc/serversideup-php-version && \
109+
\
107110
# Make composer cache directory
108111
mkdir -p "${COMPOSER_HOME}" && \
109112
chown -R www-data:www-data "${COMPOSER_HOME}" && \

0 commit comments

Comments
 (0)