diff --git a/.github/workflows/coolify-release.yml b/.github/workflows/coolify-release.yml index 9f83302ee9..70bb5d6af5 100644 --- a/.github/workflows/coolify-release.yml +++ b/.github/workflows/coolify-release.yml @@ -30,7 +30,8 @@ jobs: version: ${{ steps.version.outputs.version }} steps: - name: Reject releases outside the production branch - if: ${{ github.ref_name != 'main' }} + # tmp: allow the 4.4.7 security release from fix/v4.4.7 + if: ${{ github.ref_name != 'main' && !startsWith(github.ref_name, 'fix/v') }} run: | echo "Stable releases must run from main, not ${{ github.ref_name }}." exit 1 diff --git a/.github/workflows/tmp-coolify-hotfix-release.yml b/.github/workflows/tmp-coolify-hotfix-release.yml new file mode 100644 index 0000000000..2ef14b3597 --- /dev/null +++ b/.github/workflows/tmp-coolify-hotfix-release.yml @@ -0,0 +1,159 @@ +# Temporary: releases the 4.0 to 4.3 security fixes from the v4.0.x to v4.3.x branches without moving latest. +# Delete this workflow once 4.5 ships. +name: TMP Release Coolify Hotfix +run-name: tmp ${{ inputs.branch }} + +on: + workflow_dispatch: + inputs: + branch: + description: Release line branch + required: true + type: choice + options: + - v4.3.x + - v4.2.x + - v4.1.x + - v4.0.x + +permissions: {} + +concurrency: + group: tmp-coolify-hotfix-release + cancel-in-progress: false + +env: + GITHUB_REGISTRY: ghcr.io + DOCKER_REGISTRY: docker.io + IMAGE_NAME: coollabsio/coolify + +jobs: + validate: + runs-on: ubuntu-24.04 + permissions: + contents: read + outputs: + sha: ${{ steps.version.outputs.sha }} + version: ${{ steps.version.outputs.version }} + steps: + - uses: actions/checkout@v5 + with: + ref: ${{ inputs.branch }} + persist-credentials: false + + - name: Resolve version + id: version + env: + BRANCH: ${{ inputs.branch }} + GH_TOKEN: ${{ github.token }} + run: | + VERSION=$(docker run --rm -v "$(pwd):/app" -w /app php:8.2-alpine3.16 php bootstrap/getVersion.php) + if [[ "${VERSION}" != "${BRANCH:1:3}."* || ! "${VERSION}" =~ ^4\.[0-3]\.[0-9]+$ ]]; then + echo "Version ${VERSION} does not belong to ${BRANCH}." + exit 1 + fi + if gh release view "v${VERSION}" --repo "${GITHUB_REPOSITORY}" > /dev/null 2>&1; then + echo "Release v${VERSION} already exists." + exit 1 + fi + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" + echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" + + build: + needs: validate + permissions: + contents: read + packages: write + strategy: + matrix: + include: + - arch: amd64 + platform: linux/amd64 + runner: ubuntu-24.04 + - arch: aarch64 + platform: linux/aarch64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v5 + with: + ref: ${{ needs.validate.outputs.sha }} + persist-credentials: false + + - name: Login to ${{ env.GITHUB_REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.GITHUB_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to ${{ env.DOCKER_REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push image (${{ matrix.arch }}) + uses: docker/build-push-action@v6 + with: + context: . + file: docker/production/Dockerfile + platforms: ${{ matrix.platform }} + push: true + build-args: | + COOLIFY_VERSION=${{ needs.validate.outputs.version }} + labels: | + org.opencontainers.image.revision=${{ needs.validate.outputs.sha }} + tags: | + ${{ env.GITHUB_REGISTRY }}/${{ env.IMAGE_NAME }}:release-${{ needs.validate.outputs.version }}-${{ needs.validate.outputs.sha }}-${{ matrix.arch }} + ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:release-${{ needs.validate.outputs.version }}-${{ needs.validate.outputs.sha }}-${{ matrix.arch }} + + publish: + needs: [validate, build] + runs-on: ubuntu-24.04 + permissions: + contents: write + packages: write + steps: + - uses: docker/setup-buildx-action@v3 + + - name: Login to ${{ env.GITHUB_REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.GITHUB_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to ${{ env.DOCKER_REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Publish the version tag + env: + VERSION: ${{ needs.validate.outputs.version }} + SHA: ${{ needs.validate.outputs.sha }} + run: | + for REGISTRY in "${GITHUB_REGISTRY}" "${DOCKER_REGISTRY}"; do + IMAGE="${REGISTRY}/${IMAGE_NAME}" + docker buildx imagetools create \ + "${IMAGE}:release-${VERSION}-${SHA}-amd64" \ + "${IMAGE}:release-${VERSION}-${SHA}-aarch64" \ + --tag "${IMAGE}:${VERSION}" + done + + - name: Publish the GitHub release + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ needs.validate.outputs.version }} + SHA: ${{ needs.validate.outputs.sha }} + run: | + gh release create "v${VERSION}" \ + --repo "${GITHUB_REPOSITORY}" \ + --target "${SHA}" \ + --title "v${VERSION}" \ + --latest=false \ + --notes "Security fix release for Coolify ${VERSION%.*}. Apply it with: curl -fsSL https://cdn.coollabs.io/coolify/patch.sh | sudo bash" diff --git a/.github/workflows/tmp-php-base-image.yml b/.github/workflows/tmp-php-base-image.yml new file mode 100644 index 0000000000..f8c1839e33 --- /dev/null +++ b/.github/workflows/tmp-php-base-image.yml @@ -0,0 +1,134 @@ +# Temporary: builds PHP from the signed php.net release and rebuilds serversideup/php v4.5.1 on it for the 4.x security fixes. +# Delete this workflow and docker/tmp-php once 4.5 ships on serversideup/php v5. +name: TMP Build Patched PHP Base +run-name: tmp php ${{ inputs.php_version }} + +on: + workflow_dispatch: + inputs: + php_version: + description: Patched PHP 8.4 release, for example 8.4.27 + required: true + type: string + php_sha256: + description: SHA256 of php-.tar.xz from https://www.php.net/downloads.php + required: true + type: string + +permissions: + contents: read + packages: write + +concurrency: + group: tmp-php-base-image + cancel-in-progress: false + +env: + GITHUB_REGISTRY: ghcr.io + PHP_IMAGE: ghcr.io/coollabsio/php + BASE_IMAGE: ghcr.io/coollabsio/serversideup-php + # serversideup/docker-php v4.5.1 + SERVERSIDEUP_CONTEXT: https://github.com/serversideup/docker-php.git#92b16c9ee63bde4f75cdcc7ebe96aee36a896f88 + +jobs: + build: + strategy: + matrix: + include: + - arch: amd64 + platform: linux/amd64 + runner: ubuntu-24.04 + - arch: aarch64 + platform: linux/aarch64 + runner: ubuntu-24.04-arm + runs-on: ${{ matrix.runner }} + steps: + - name: Validate inputs + env: + PHP_VERSION: ${{ inputs.php_version }} + PHP_SHA256: ${{ inputs.php_sha256 }} + run: | + if [[ ! "${PHP_VERSION}" =~ ^8\.4\.[0-9]+$ ]]; then + echo "Unsupported PHP version: ${PHP_VERSION}" + exit 1 + fi + if [[ ! "${PHP_SHA256}" =~ ^[0-9a-f]{64}$ ]]; then + echo "Invalid SHA256: ${PHP_SHA256}" + exit 1 + fi + + - uses: actions/checkout@v5 + with: + persist-credentials: false + + - name: Login to ${{ env.GITHUB_REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.GITHUB_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build PHP from the signed release (${{ matrix.arch }}) + uses: docker/build-push-action@v6 + with: + context: docker/tmp-php + platforms: ${{ matrix.platform }} + push: true + build-args: | + PHP_VERSION=${{ inputs.php_version }} + PHP_SHA256=${{ inputs.php_sha256 }} + tags: ${{ env.PHP_IMAGE }}:${{ inputs.php_version }}-fpm-alpine3.24-${{ matrix.arch }} + + - name: Rebuild serversideup/php v4.5.1 on it (${{ matrix.arch }}) + uses: docker/build-push-action@v6 + with: + context: ${{ env.SERVERSIDEUP_CONTEXT }} + file: src/variations/fpm-nginx/Dockerfile + platforms: ${{ matrix.platform }} + push: true + build-args: | + BASE_IMAGE=${{ env.PHP_IMAGE }}:${{ inputs.php_version }}-fpm-alpine3.24-${{ matrix.arch }} + PHP_VERSION=8.4 + BASE_OS_VERSION=alpine3.24 + PHP_VARIATION=fpm-nginx + NGINX_VERSION=1.30.4-r1 + REPOSITORY_BUILD_VERSION=v4.5.1-php${{ inputs.php_version }} + tags: ${{ env.BASE_IMAGE }}:${{ inputs.php_version }}-fpm-nginx-alpine-v4.5.1-${{ matrix.arch }} + + - name: Check the PHP version (${{ matrix.arch }}) + env: + IMAGE: ${{ env.BASE_IMAGE }}:${{ inputs.php_version }}-fpm-nginx-alpine-v4.5.1-${{ matrix.arch }} + PHP_VERSION: ${{ inputs.php_version }} + run: | + BUILT_VERSION=$(docker run --rm --entrypoint php "${IMAGE}" -r 'echo PHP_VERSION;') + if [ "${BUILT_VERSION}" != "${PHP_VERSION}" ]; then + echo "The base image runs PHP ${BUILT_VERSION}, expected ${PHP_VERSION}." + exit 1 + fi + + publish: + needs: build + runs-on: ubuntu-24.04 + steps: + - uses: docker/setup-buildx-action@v3 + + - name: Login to ${{ env.GITHUB_REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.GITHUB_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish multi-arch images + env: + PHP_VERSION: ${{ inputs.php_version }} + run: | + docker buildx imagetools create \ + "${PHP_IMAGE}:${PHP_VERSION}-fpm-alpine3.24-amd64" \ + "${PHP_IMAGE}:${PHP_VERSION}-fpm-alpine3.24-aarch64" \ + --tag "${PHP_IMAGE}:${PHP_VERSION}-fpm-alpine3.24" + docker buildx imagetools create \ + "${BASE_IMAGE}:${PHP_VERSION}-fpm-nginx-alpine-v4.5.1-amd64" \ + "${BASE_IMAGE}:${PHP_VERSION}-fpm-nginx-alpine-v4.5.1-aarch64" \ + --tag "${BASE_IMAGE}:${PHP_VERSION}-fpm-nginx-alpine-v4.5.1" \ + --tag "${BASE_IMAGE}:8.4-fpm-nginx-alpine-v4.5.1-hotfix" diff --git a/app/Console/Commands/SyncCdn.php b/app/Console/Commands/SyncCdn.php index 3e7be78b4a..c447c5f726 100644 --- a/app/Console/Commands/SyncCdn.php +++ b/app/Console/Commands/SyncCdn.php @@ -312,6 +312,7 @@ class SyncCdn extends Command $install_script_location = "$parent_dir/scripts/install.sh"; $upgrade_script_location = "$parent_dir/scripts/upgrade.sh"; $upgrade_postgres_script_location = "$parent_dir/scripts/upgrade-postgres.sh"; + $patch_script_location = "$parent_dir/scripts/patch.sh"; $production_env_location = "$parent_dir/.env.production"; $service_template_location = "$parent_dir/templates/$service_template"; $versions_location = "$parent_dir/$versions"; @@ -346,6 +347,7 @@ class SyncCdn extends Command $install_script_location => 'json/coolify/install.sh', $upgrade_script_location => 'json/coolify/upgrade.sh', $upgrade_postgres_script_location => 'json/coolify/upgrade-postgres.sh', + $patch_script_location => 'json/coolify/patch.sh', $service_template_location => 'json/coolify/service-templates-latest.json', ]; } diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile index 5060ef6b13..3cea5815b9 100644 --- a/docker/production/Dockerfile +++ b/docker/production/Dockerfile @@ -2,12 +2,14 @@ # https://hub.docker.com/r/serversideup/php/tags?name=8.4-fpm-nginx-alpine ARG SERVERSIDEUP_PHP_VERSION=8.4-fpm-nginx-alpine-v5.0.0 # https://github.com/cloudflare/cloudflared/releases -ARG CLOUDFLARED_VERSION=2026.7.3 +ARG CLOUDFLARED_VERSION=2026.10.3 # https://www.postgresql.org/support/versioning/ # Note: We are using version 18 of the postgres client (while still using postgres 15 for the postgres server) as version 15 has been removed from Alpine 3.23+ https://pkgs.alpinelinux.org/packages?name=postgresql*-client&branch=v3.23&repo=&arch=x86_64&origin=&flagged=&maintainer= ARG POSTGRES_VERSION=18 # https://nginx.org/en/linux_packages.html ARG NGINX_VERSION=1.31.2-r1 +# https://nodejs.org/en/about/previous-releases +ARG NODE_VERSION=24.22.1 # https://pecl.php.net/package/uv ARG PHP_UV_VERSION=0.3.0 @@ -48,10 +50,15 @@ RUN --mount=type=cache,target=/tmp/cache \ USER www-data +# Temporary: the node:24.22.1 multi-arch manifest is not published yet, pull the per-arch image instead +FROM amd64/node:${NODE_VERSION}-alpine3.24 AS nodejs-amd64 +FROM arm64v8/node:${NODE_VERSION}-alpine3.24 AS nodejs-arm64 +FROM nodejs-${TARGETARCH} AS nodejs + # ================================================================= # Stage 2: Frontend assets compilation # ================================================================= -FROM node:24-alpine AS static-assets +FROM nodejs AS static-assets WORKDIR /app COPY package*.json vite.config.js postcss.config.cjs ./ @@ -73,7 +80,10 @@ FROM serversideup/php:${SERVERSIDEUP_PHP_VERSION} AS terminal-dependencies USER root RUN apk upgrade && \ - apk add --no-cache nodejs npm make g++ python3 + apk add --no-cache make g++ python3 +COPY --from=nodejs /usr/local/bin/node /usr/local/bin/node +COPY --from=nodejs /usr/local/lib/node_modules/npm /usr/local/lib/node_modules/npm +RUN ln -s ../lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm COPY docker/coolify-terminal/package*.json /terminal/ RUN --mount=type=cache,target=/root/.npm \ npm ci --prefix /terminal && \ @@ -129,7 +139,7 @@ RUN --mount=type=cache,target=/var/cache/apk \ apk upgrade && \ apk add --no-cache \ postgresql${POSTGRES_VERSION}-client \ - nodejs \ + libstdc++ \ openssh-client \ git \ git-lfs \ @@ -193,6 +203,7 @@ COPY --chown=www-data:www-data versions.json ./versions.json RUN composer dump-autoload # Install terminal WebSocket server dependencies +COPY --from=nodejs /usr/local/bin/node /usr/local/bin/node COPY --from=terminal-dependencies --chown=www-data:www-data /terminal /terminal # Configure Nginx and S6 overlay diff --git a/docker/tmp-php/Dockerfile b/docker/tmp-php/Dockerfile new file mode 100644 index 0000000000..0be8e996dd --- /dev/null +++ b/docker/tmp-php/Dockerfile @@ -0,0 +1,275 @@ +# Temporary copy of docker-library/php 8.4/alpine3.24/fpm (9dac3d0), only the PHP release and its SHA256 are build arguments +# +# NOTE: THIS DOCKERFILE IS GENERATED VIA "apply-templates.sh" +# +# PLEASE DO NOT EDIT IT DIRECTLY. +# + +FROM alpine:3.24 + +# dependencies required for running "phpize" +# these get automatically installed and removed by "docker-php-ext-*" (unless they're already installed) +ENV PHPIZE_DEPS \ + autoconf \ + dpkg-dev dpkg \ + file \ + g++ \ + gcc \ + libc-dev \ + make \ + pkgconf \ + re2c + +# persistent / runtime deps +RUN apk add --no-cache \ + ca-certificates \ + curl \ + openssl \ + tar \ + xz + +# ensure www-data user exists +RUN set -eux; \ + adduser -u 82 -D -S -G www-data www-data +# 82 is the standard uid/gid for "www-data" in Alpine +# https://git.alpinelinux.org/aports/tree/main/apache2/apache2.pre-install?h=3.14-stable +# https://git.alpinelinux.org/aports/tree/main/lighttpd/lighttpd.pre-install?h=3.14-stable +# https://git.alpinelinux.org/aports/tree/main/nginx/nginx.pre-install?h=3.14-stable + +ENV PHP_INI_DIR /usr/local/etc/php +RUN set -eux; \ + mkdir -p "$PHP_INI_DIR/conf.d"; \ +# allow running as an arbitrary user (https://github.com/docker-library/php/issues/743) + [ ! -d /var/www/html ]; \ + mkdir -p /var/www/html; \ + chown www-data:www-data /var/www/html; \ + chmod 1777 /var/www/html + +# Apply stack smash protection to functions using local buffers and alloca() +# Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64) +# Enable optimization (-O2) +# Enable linker optimization (this sorts the hash buckets to improve cache locality, and is non-default) +# https://github.com/docker-library/php/issues/272 +# -D_LARGEFILE_SOURCE and -D_FILE_OFFSET_BITS=64 (https://www.php.net/manual/en/intro.filesystem.php) +ENV PHP_CFLAGS="-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" +ENV PHP_CPPFLAGS="$PHP_CFLAGS" +ENV PHP_LDFLAGS="-Wl,-O1 -pie" + +ENV GPG_KEYS AFD8691FDAEDF03BDF6E460563F15A9B715376CA 9D7F99A0CB8F05C8A6958D6256A97AF7600A39A6 0616E93D95AF471243E26761770426E17EBBB3DD + +ARG PHP_VERSION +ARG PHP_SHA256 +ENV PHP_VERSION ${PHP_VERSION} +ENV PHP_URL="https://www.php.net/distributions/php-${PHP_VERSION}.tar.xz" PHP_ASC_URL="https://www.php.net/distributions/php-${PHP_VERSION}.tar.xz.asc" +ENV PHP_SHA256=${PHP_SHA256} + +RUN set -eux; \ + \ + apk add --no-cache --virtual .fetch-deps gnupg; \ + \ + mkdir -p /usr/src; \ + cd /usr/src; \ + \ + curl -fsSL -o php.tar.xz "$PHP_URL"; \ + \ + if [ -n "$PHP_SHA256" ]; then \ + echo "$PHP_SHA256 *php.tar.xz" | sha256sum -c -; \ + fi; \ + \ + curl -fsSL -o php.tar.xz.asc "$PHP_ASC_URL"; \ + export GNUPGHOME="$(mktemp -d)"; \ + for key in $GPG_KEYS; do \ + gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key"; \ + done; \ + gpg --batch --verify php.tar.xz.asc php.tar.xz; \ + gpgconf --kill all; \ + rm -rf "$GNUPGHOME"; \ + \ + apk del --no-network .fetch-deps + +COPY docker-php-source /usr/local/bin/ + +RUN set -eux; \ + apk add --no-cache --virtual .build-deps \ + $PHPIZE_DEPS \ + argon2-dev \ + coreutils \ + curl-dev \ + gnu-libiconv-dev \ + libsodium-dev \ + libxml2-dev \ + linux-headers \ + oniguruma-dev \ + openssl-dev \ + readline-dev \ + sqlite-dev \ + ; \ + \ +# make sure musl's iconv doesn't get used (https://www.php.net/manual/en/intro.iconv.php) + rm -vf /usr/include/iconv.h; \ + \ + export \ + CFLAGS="$PHP_CFLAGS" \ + CPPFLAGS="$PHP_CPPFLAGS" \ + LDFLAGS="$PHP_LDFLAGS" \ +# https://github.com/php/php-src/blob/d6299206dd828382753453befd1b915491b741c6/configure.ac#L1496-L1511 + PHP_BUILD_PROVIDER='https://github.com/docker-library/php' \ + PHP_UNAME='Linux - Docker' \ + ; \ + docker-php-source extract; \ + cd /usr/src/php; \ + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"; \ + case "$gnuArch" in \ + 'i686-linux-'*) \ + # php zend jit assumes SSE registers, xmm0-7, are available (and "Pentium4"/SSE2 is a reasonable baseline) + # https://github.com/php/php-src/pull/22832 + # so, allow it and use SSE/SSE2 floating-point unit instead of the legacy stack + export \ + CFLAGS="$CFLAGS -msse2 -mfpmath=sse" \ + CPPFLAGS="$CPPFLAGS -msse2 -mfpmath=sse" \ + ; \ + ;; \ + esac; \ + test "$PHP_INI_DIR" != "${PHP_INI_DIR%/php}"; \ + ./configure \ + --build="$gnuArch" \ + --sysconfdir="${PHP_INI_DIR%/php}" \ + --with-config-file-path="$PHP_INI_DIR" \ + --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \ + \ +# make sure invalid --configure-flags are fatal errors instead of just warnings + --enable-option-checking=fatal \ + \ +# https://github.com/docker-library/php/issues/439 + --with-mhash \ + \ +# https://github.com/docker-library/php/issues/822 + --with-pic \ + \ +# --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195) + --enable-mbstring \ +# --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself) + --enable-mysqlnd \ +# https://wiki.php.net/rfc/argon2_password_hash + --with-password-argon2 \ +# https://wiki.php.net/rfc/libsodium + --with-sodium=shared \ +# always build against system sqlite3 (https://github.com/php/php-src/commit/6083a387a81dbbd66d6316a3a12a63f06d5f7109) + --with-pdo-sqlite=/usr \ + --with-sqlite3=/usr \ + \ + --with-curl \ + --with-iconv=/usr \ + --with-openssl \ + --with-readline \ + --with-zlib \ + \ +# https://github.com/bwoebi/phpdbg-docs/issues/1#issuecomment-163872806 ("phpdbg is primarily a CLI debugger, and is not suitable for debugging an fpm stack.") + --disable-phpdbg \ + \ +# in PHP 7.4+, the pecl/pear installers are officially deprecated (requiring an explicit "--with-pear") + --with-pear \ + \ + \ + --disable-cgi \ + \ + --enable-fpm \ + --with-fpm-user=www-data \ + --with-fpm-group=www-data \ + ; \ + make -j "$(nproc)"; \ + find -type f -name '*.a' -delete; \ + make install; \ + find \ + /usr/local \ + -type f \ + -perm '/0111' \ + -exec sh -euxc ' \ + strip --strip-all "$@" || : \ + ' -- '{}' + \ + ; \ + make clean; \ + \ +# https://github.com/docker-library/php/issues/692 (copy default example "php.ini" files somewhere easily discoverable) + cp -v php.ini-* "$PHP_INI_DIR/"; \ + \ + cd /; \ + docker-php-source delete; \ + \ + runDeps="$( \ + scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \ + | tr ',' '\n' \ + | sort -u \ + | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ + )"; \ + apk add --no-cache $runDeps; \ + \ + apk del --no-network .build-deps; \ + \ +# update pecl channel definitions https://github.com/docker-library/php/issues/443 + pecl update-channels; \ + rm -rf /tmp/pear ~/.pearrc; \ + \ +# smoke test + php --version + +COPY docker-php-ext-* docker-php-entrypoint /usr/local/bin/ + +# enable OPcache by default (https://wiki.php.net/rfc/make_opcache_required) +RUN docker-php-ext-enable opcache + +# sodium was built as a shared module (so that it can be replaced later if so desired), so let's enable it too (https://github.com/docker-library/php/issues/598) +RUN docker-php-ext-enable sodium + +ENTRYPOINT ["docker-php-entrypoint"] +WORKDIR /var/www/html + +RUN set -eux; \ + cd "${PHP_INI_DIR%/php}"; \ + \ + cp -v php-fpm.conf.default php-fpm.conf; \ + cp -v php-fpm.d/www.conf.default php-fpm.d/www.conf; \ + \ + # comment out localhost-only listen address + grep -E '^listen = 127.0.0.1:9000' php-fpm.d/www.conf; \ + sed -ri 's/^(listen = 127.0.0.1:9000)/;\1/' php-fpm.d/www.conf; \ + grep -E '^;listen = 127.0.0.1:9000' php-fpm.d/www.conf; \ + \ + { \ + echo '[global]'; \ + echo 'error_log = /proc/self/fd/2'; \ + echo; echo '; https://github.com/docker-library/php/pull/725#issuecomment-443540114'; echo 'log_limit = 8192'; \ + echo; \ + echo '[www]'; \ + echo '; php-fpm closes STDOUT on startup, so sending logs to /proc/self/fd/1 does not work.'; \ + echo '; https://bugs.php.net/bug.php?id=73886'; \ + echo 'access.log = /proc/self/fd/2'; \ + echo; \ + echo 'clear_env = no'; \ + echo; \ + echo '; Ensure worker stdout and stderr are sent to the main error log.'; \ + echo 'catch_workers_output = yes'; \ + echo 'decorate_workers_output = no'; \ + echo; \ + echo '; default listen address for easy override in later php-fpm.d/*.conf files'; \ + echo 'listen = 9000'; \ + } | tee php-fpm.d/docker.conf; \ + { \ + echo '[global]'; \ + echo 'daemonize = no'; \ + echo; \ + echo '; the [www] ini section below is for backwards compatibility and will be removed in 8.6+'; \ + echo '[www]'; \ + } | tee php-fpm.d/zz-docker.conf; \ + mkdir -p "$PHP_INI_DIR/conf.d"; \ + { \ + echo '; https://github.com/docker-library/php/issues/878#issuecomment-938595965'; \ + echo 'fastcgi.logging = Off'; \ + } > "$PHP_INI_DIR/conf.d/docker-fpm.ini" + +# Override stop signal to stop process gracefully +# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163 +STOPSIGNAL SIGQUIT + +EXPOSE 9000 +CMD ["php-fpm"] diff --git a/docker/tmp-php/docker-php-entrypoint b/docker/tmp-php/docker-php-entrypoint new file mode 100755 index 0000000000..86343d8038 --- /dev/null +++ b/docker/tmp-php/docker-php-entrypoint @@ -0,0 +1,9 @@ +#!/bin/sh +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- php-fpm "$@" +fi + +exec "$@" diff --git a/docker/tmp-php/docker-php-ext-configure b/docker/tmp-php/docker-php-ext-configure new file mode 100755 index 0000000000..34fc1337d5 --- /dev/null +++ b/docker/tmp-php/docker-php-ext-configure @@ -0,0 +1,69 @@ +#!/bin/sh +set -e + +# prefer user supplied CFLAGS, but default to our PHP_CFLAGS +: ${CFLAGS:=$PHP_CFLAGS} +: ${CPPFLAGS:=$PHP_CPPFLAGS} +: ${LDFLAGS:=$PHP_LDFLAGS} +export CFLAGS CPPFLAGS LDFLAGS + +srcExists= +if [ -d /usr/src/php ]; then + srcExists=1 +fi +docker-php-source extract +if [ -z "$srcExists" ]; then + touch /usr/src/php/.docker-delete-me +fi + +cd /usr/src/php/ext + +usage() { + echo "usage: $0 ext-name [configure flags]" + echo " ie: $0 gd --with-jpeg-dir=/usr/local/something" + echo + echo 'Possible values for ext-name:' + find . \ + -mindepth 2 \ + -maxdepth 2 \ + -type f \ + -name 'config.m4' \ + | xargs -n1 dirname \ + | xargs -n1 basename \ + | sort \ + | xargs + echo + echo 'Some of the above modules are already compiled into PHP; please check' + echo 'the output of "php -i" to see which modules are already loaded.' +} + +ext="$1" +if [ -z "$ext" ] || [ ! -d "$ext" ]; then + usage >&2 + exit 1 +fi +shift + +pm='unknown' +if [ -e /lib/apk/db/installed ]; then + pm='apk' +fi + +if [ "$pm" = 'apk' ]; then + if \ + [ -n "$PHPIZE_DEPS" ] \ + && ! apk info --installed .phpize-deps > /dev/null \ + && ! apk info --installed .phpize-deps-configure > /dev/null \ + ; then + apk add --no-cache --virtual .phpize-deps-configure $PHPIZE_DEPS + fi +fi + +if command -v dpkg-architecture > /dev/null; then + gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" + set -- --build="$gnuArch" "$@" +fi + +cd "$ext" +phpize +./configure --enable-option-checking=fatal "$@" diff --git a/docker/tmp-php/docker-php-ext-enable b/docker/tmp-php/docker-php-ext-enable new file mode 100755 index 0000000000..41d20bbe3f --- /dev/null +++ b/docker/tmp-php/docker-php-ext-enable @@ -0,0 +1,121 @@ +#!/bin/sh +set -e + +extDir="$(php -d 'display_errors=stderr' -r 'echo ini_get("extension_dir");')" +cd "$extDir" + +usage() { + echo "usage: $0 [options] module-name [module-name ...]" + echo " ie: $0 gd mysqli" + echo " $0 pdo pdo_mysql" + echo " $0 --ini-name 0-apc.ini apcu apc" + echo + echo 'Possible values for module-name:' + find -maxdepth 1 \ + -type f \ + -name '*.so' \ + -exec basename '{}' ';' \ + | sort \ + | xargs + echo + echo 'Some of the above modules are already compiled into PHP; please check' + echo 'the output of "php -i" to see which modules are already loaded.' +} + +opts="$(getopt -o 'h?' --long 'help,ini-name:' -- "$@" || { usage >&2 && false; })" +eval set -- "$opts" + +iniName= +while true; do + flag="$1" + shift + case "$flag" in + --help|-h|'-?') usage && exit 0 ;; + --ini-name) iniName="$1" && shift ;; + --) break ;; + *) + { + echo "error: unknown flag: $flag" + usage + } >&2 + exit 1 + ;; + esac +done + +modules= +for module; do + if [ -z "$module" ]; then + continue + fi + if ! [ -f "$module" ] && ! [ -f "$module.so" ]; then + echo >&2 "error: '$module' does not exist" + echo >&2 + usage >&2 + exit 1 + fi + modules="$modules $module" +done + +if [ -z "$modules" ]; then + usage >&2 + exit 1 +fi + +pm='unknown' +if [ -e /lib/apk/db/installed ]; then + pm='apk' +fi + +apkDel= +if [ "$pm" = 'apk' ]; then + if \ + [ -n "$PHPIZE_DEPS" ] \ + && ! apk info --installed .phpize-deps > /dev/null \ + && ! apk info --installed .phpize-deps-configure > /dev/null \ + ; then + apk add --no-cache --virtual '.docker-php-ext-enable-deps' binutils + apkDel='.docker-php-ext-enable-deps' + fi +fi + +for module in $modules; do + moduleFile="$module" + if [ -f "$module.so" ] && ! [ -f "$module" ]; then + moduleFile="$module.so" + fi + if readelf --wide --syms "$moduleFile" | grep -q ' zend_extension_entry$'; then + # https://wiki.php.net/internals/extensions#loading_zend_extensions + line="zend_extension=$module" + else + line="extension=$module" + fi + + ext="$(basename "$module")" + ext="${ext%.*}" + if php -d 'display_errors=stderr' -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then + # this isn't perfect, but it's better than nothing + # (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache') + echo >&2 + echo >&2 "warning: $ext ($module) is already loaded!" + echo >&2 + continue + fi + + case "$iniName" in + /*) + # allow an absolute path + ini="$iniName" + ;; + *) + ini="$PHP_INI_DIR/conf.d/${iniName:-"docker-php-ext-$ext.ini"}" + ;; + esac + if ! grep -qFx -e "$line" -e "$line.so" "$ini" 2>/dev/null; then + echo "$line" >> "$ini" + fi +done + +if [ "$pm" = 'apk' ] && [ -n "$apkDel" ]; then + apk del --no-network $apkDel +fi diff --git a/docker/tmp-php/docker-php-ext-install b/docker/tmp-php/docker-php-ext-install new file mode 100755 index 0000000000..fbf44849c0 --- /dev/null +++ b/docker/tmp-php/docker-php-ext-install @@ -0,0 +1,143 @@ +#!/bin/sh +set -e + +# prefer user supplied CFLAGS, but default to our PHP_CFLAGS +: ${CFLAGS:=$PHP_CFLAGS} +: ${CPPFLAGS:=$PHP_CPPFLAGS} +: ${LDFLAGS:=$PHP_LDFLAGS} +export CFLAGS CPPFLAGS LDFLAGS + +srcExists= +if [ -d /usr/src/php ]; then + srcExists=1 +fi +docker-php-source extract +if [ -z "$srcExists" ]; then + touch /usr/src/php/.docker-delete-me +fi + +cd /usr/src/php/ext + +usage() { + echo "usage: $0 [-jN] [--ini-name file.ini] ext-name [ext-name ...]" + echo " ie: $0 gd mysqli" + echo " $0 pdo pdo_mysql" + echo " $0 -j5 gd mbstring mysqli pdo pdo_mysql shmop" + echo + echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure' + echo + echo 'Possible values for ext-name:' + find . \ + -mindepth 2 \ + -maxdepth 2 \ + -type f \ + -name 'config.m4' \ + | xargs -n1 dirname \ + | xargs -n1 basename \ + | sort \ + | xargs + echo + echo 'Some of the above modules are already compiled into PHP; please check' + echo 'the output of "php -i" to see which modules are already loaded.' +} + +opts="$(getopt -o 'h?j:' --long 'help,ini-name:,jobs:' -- "$@" || { usage >&2 && false; })" +eval set -- "$opts" + +j=1 +iniName= +while true; do + flag="$1" + shift + case "$flag" in + --help|-h|'-?') usage && exit 0 ;; + --ini-name) iniName="$1" && shift ;; + --jobs|-j) j="$1" && shift ;; + --) break ;; + *) + { + echo "error: unknown flag: $flag" + usage + } >&2 + exit 1 + ;; + esac +done + +exts= +for ext; do + if [ -z "$ext" ]; then + continue + fi + if [ ! -d "$ext" ]; then + echo >&2 "error: $PWD/$ext does not exist" + echo >&2 + usage >&2 + exit 1 + fi + exts="$exts $ext" +done + +if [ -z "$exts" ]; then + usage >&2 + exit 1 +fi + +pm='unknown' +if [ -e /lib/apk/db/installed ]; then + pm='apk' +fi + +apkDel= +if [ "$pm" = 'apk' ]; then + if [ -n "$PHPIZE_DEPS" ]; then + if apk info --installed .phpize-deps-configure > /dev/null; then + apkDel='.phpize-deps-configure' + elif ! apk info --installed .phpize-deps > /dev/null; then + apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS + apkDel='.phpize-deps' + fi + fi +fi + +popDir="$PWD" +for ext in $exts; do + cd "$ext" + + [ -e Makefile ] || docker-php-ext-configure "$ext" + + make -j"$j" + + if ! php -n -d 'display_errors=stderr' -r 'exit(ZEND_DEBUG_BUILD ? 0 : 1);' > /dev/null; then + # only "strip" modules if we aren't using a debug build of PHP + # (none of our builds are debug builds, but PHP might be recompiled with "--enable-debug" configure option) + # https://github.com/docker-library/php/issues/1268 + + find modules \ + -maxdepth 1 \ + -name '*.so' \ + -exec sh -euxc ' \ + strip --strip-all "$@" || : + ' -- '{}' + + fi + + make -j"$j" install + + find modules \ + -maxdepth 1 \ + -name '*.so' \ + -exec basename '{}' '.so' ';' \ + | xargs -r docker-php-ext-enable ${iniName:+--ini-name "$iniName"} + + make -j"$j" clean + + cd "$popDir" +done + +if [ "$pm" = 'apk' ] && [ -n "$apkDel" ]; then + apk del --no-network $apkDel +fi + +if [ -e /usr/src/php/.docker-delete-me ]; then + docker-php-source delete +fi diff --git a/docker/tmp-php/docker-php-source b/docker/tmp-php/docker-php-source new file mode 100755 index 0000000000..9033d243de --- /dev/null +++ b/docker/tmp-php/docker-php-source @@ -0,0 +1,34 @@ +#!/bin/sh +set -e + +dir=/usr/src/php + +usage() { + echo "usage: $0 COMMAND" + echo + echo "Manage php source tarball lifecycle." + echo + echo "Commands:" + echo " extract extract php source tarball into directory $dir if not already done." + echo " delete delete extracted php source located into $dir if not already done." + echo +} + +case "$1" in + extract) + mkdir -p "$dir" + if [ ! -f "$dir/.docker-extracted" ]; then + tar -Jxf /usr/src/php.tar.xz -C "$dir" --strip-components=1 + touch "$dir/.docker-extracted" + fi + ;; + + delete) + rm -rf "$dir" + ;; + + *) + usage + exit 1 + ;; +esac diff --git a/other/nightly/versions.json b/other/nightly/versions.json index 17b6b3a81c..50f381b7b6 100644 --- a/other/nightly/versions.json +++ b/other/nightly/versions.json @@ -10,7 +10,7 @@ "version": "1.0.18" }, "sentinel": { - "version": "1.1.1" + "version": "1.1.2" }, "sentinel-host": { "version": "1.1.1", diff --git a/scripts/patch.sh b/scripts/patch.sh new file mode 100755 index 0000000000..94e757a1b7 --- /dev/null +++ b/scripts/patch.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash +# Patches Coolify 4.0 to 4.4 to the security fix release of its own line. +# Only the coolify container is recreated, the compose files and the other containers stay as they are. +# Usage: curl -fsSL https://cdn.coollabs.io/coolify/patch.sh | sudo bash +set -euo pipefail + +SOURCE_DIR=/data/coolify/source +ENV_FILE="$SOURCE_DIR/.env" +TIMESTAMP="$(date +%Y-%m-%d-%H-%M-%S)" +LOG_FILE="$SOURCE_DIR/patch-$TIMESTAMP.log" +BACKUP_FILE="$ENV_FILE-$TIMESTAMP" +PATCH_VERSIONS=(4.0.1 4.1.3 4.2.1 4.3.24 4.4.7) + +BOLD=$'\033[1m' GREEN=$'\033[32m' BLUE=$'\033[34m' RED=$'\033[31m' RESET=$'\033[0m' + +heading() { printf '\n %s%s%s\n' "$BOLD" "$*" "$RESET"; } +info() { printf ' %sℹ%s %s\n' "$BLUE" "$RESET" "$*"; } +ok() { printf ' %s✔%s %s\n' "$GREEN" "$RESET" "$*"; } +die() { + printf ' %s✖%s %s\n' "$RED" "$RESET" "$*" >&2 + exit 1 +} + +main() { + check_installation + read_version + select_patch_version + check_compose_files + heading "Patching Coolify $current_version to $patch_version" + pull_image + update_env_file + restart_coolify + wait_for_coolify +} + +check_installation() { + heading "Checking the installation" + [ "$EUID" = 0 ] || die "run this script as root, for example with sudo" + [ -f "$ENV_FILE" ] && [ -f "$SOURCE_DIR/docker-compose.prod.yml" ] || die "Coolify is not installed in $SOURCE_DIR" + docker compose version > /dev/null 2>&1 || die "the Docker Compose plugin is not installed" + compose=(docker compose --env-file "$ENV_FILE" -f "$SOURCE_DIR/docker-compose.yml" -f "$SOURCE_DIR/docker-compose.prod.yml") + if [ -f "$SOURCE_DIR/docker-compose.custom.yml" ]; then + compose+=(-f "$SOURCE_DIR/docker-compose.custom.yml") + fi + if [ -f "$SOURCE_DIR/docker-compose.postgres-upgrade.yml" ]; then + compose+=(-f "$SOURCE_DIR/docker-compose.postgres-upgrade.yml") + fi + ok "Coolify is installed in $SOURCE_DIR" +} + +read_version() { + current_version="$(docker exec -w /var/www/html coolify php bootstrap/getVersion.php 2> /dev/null)" || die "the coolify container is not running" + ok "Coolify $BOLD$current_version$RESET is running" +} + +select_patch_version() { + [[ "$current_version" =~ ^4\.([0-4])\.([0-9]+)$ ]] || die "Coolify $current_version has no security fix release, upgrade to the latest version from the dashboard instead" + patch_version="${PATCH_VERSIONS[${BASH_REMATCH[1]}]}" + if [ "${BASH_REMATCH[2]}" -ge "${patch_version##*.}" ]; then + ok "Coolify $current_version already includes the security fixes" + exit 0 + fi +} + +check_compose_files() { + local has_realtime=false needs_realtime=true + if grep -q 'coollabsio/coolify-realtime:' "$SOURCE_DIR/docker-compose.prod.yml"; then + has_realtime=true + fi + if [[ "$patch_version" == 4.4.* ]]; then + needs_realtime=false + fi + [ "$has_realtime" = "$needs_realtime" ] || die "the compose files in $SOURCE_DIR do not belong to Coolify $current_version, upgrade to the latest version from the dashboard instead" + ok "the compose files belong to Coolify $current_version" +} + +pull_image() { + LATEST_IMAGE="$patch_version" "${compose[@]}" pull coolify < /dev/null >> "$LOG_FILE" 2>&1 || die "could not pull Coolify $patch_version, nothing was changed (log: $LOG_FILE)" + ok "pulled Coolify $patch_version" +} + +update_env_file() { + local key updated + cp "$ENV_FILE" "$BACKUP_FILE" + for key in LATEST_IMAGE COOLIFY_VERSION; do + if grep -q "^$key=" "$ENV_FILE"; then + updated="$(sed "s|^$key=.*|$key=$patch_version|" "$ENV_FILE")" + printf '%s\n' "$updated" > "$ENV_FILE" + fi + done + ok "backed up .env to $BACKUP_FILE" +} + +restart_coolify() { + # Detached, because the Coolify 4.4 terminal runs inside the coolify container and closes when it stops + LATEST_IMAGE="$patch_version" nohup "${compose[@]}" up -d --no-deps coolify < /dev/null >> "$LOG_FILE" 2>&1 & + wait $! || die "could not restart the coolify container (log: $LOG_FILE)" + ok "restarted the coolify container" +} + +wait_for_coolify() { + local status + for _ in $(seq 60); do + status="$(docker inspect --format '{{.State.Health.Status}}' coolify 2> /dev/null || true)" + if [ "$status" = healthy ]; then + ok "Coolify $BOLD$patch_version$RESET is healthy and runs PHP $(docker exec coolify php -r 'echo PHP_VERSION;')" + return + fi + sleep 5 + done + info "roll back with: cp $BACKUP_FILE $ENV_FILE && LATEST_IMAGE=$current_version ${compose[*]} up -d --no-deps coolify" + die "Coolify $patch_version is not healthy after 5 minutes, check it with: docker logs coolify" +} + +main diff --git a/tests/Feature/SyncCdnTest.php b/tests/Feature/SyncCdnTest.php index 00bed238c7..52e0ea8945 100644 --- a/tests/Feature/SyncCdnTest.php +++ b/tests/Feature/SyncCdnTest.php @@ -97,6 +97,7 @@ SH); 'install.sh', 'upgrade.sh', 'upgrade-postgres.sh', + ...($environment === 'production' ? ['patch.sh'] : []), 'service-templates-latest.json', ]; $allTargets = array_map(fn (string $file) => "$targetDirectory/$file", $allBasenames); @@ -179,6 +180,7 @@ it('purges the CDN files from the Cloudflare cache', function (string $environme 'install.sh', 'upgrade.sh', 'upgrade-postgres.sh', + ...($environment === 'production' ? ['patch.sh'] : []), 'service-templates-latest.json', ]))->all()); })->with([ diff --git a/versions.json b/versions.json index 17b6b3a81c..50f381b7b6 100644 --- a/versions.json +++ b/versions.json @@ -10,7 +10,7 @@ "version": "1.0.18" }, "sentinel": { - "version": "1.1.1" + "version": "1.1.2" }, "sentinel-host": { "version": "1.1.1",