* Give the foreign key a backing index before dropping the unique social_accounts.workspace_id carries a foreign key, and the composite unique index is the only one covering it, as its leftmost prefix. MySQL refuses to drop the sole index backing a foreign key (SQLSTATE[HY000] 1553), so both rehearsal suites failed in beforeEach and never ran a single assertion on MySQL. Add a plain index on workspace_id first; PostgreSQL has no such requirement and simply carries it. This unmasks one assertion underneath that had never executed: the automation graph comparison at DuplicateIdentityMigrationTest.php:419 depended on JSON object key order, which MySQL normalises on storage. (cherry picked from commit 98a494bd2205e873321a18232f63b358ae259fdf) * Compare JSON payloads without depending on key order MySQL normalises JSON object keys (length, then lexicographic) on storage, so an identity comparison against a literal asserts how the driver chose to lay the object out rather than what it contains. PostgreSQL preserves insertion order, which is why these passed there. toEqual compares associative arrays recursively without regard to key order. Applied to every assertion in this class, including the few that pass today only because their keys already happen to match MySQL's ordering. (cherry picked from commit 3124023c548d6c2b8b52126afc6fc5f38d461ea6) * Match logged SQL without depending on identifier quoting Four DB::listen predicates matched 'select * from "post_platforms"'. PostgreSQL quotes identifiers with double quotes and MySQL with backticks, so on MySQL the predicates never matched, the simulated mid-run pause never fired, and the race these tests exist to cover went unexercised while the tests still reported failures elsewhere. Compare against the unquoted form via a small helper. (cherry picked from commit 67a81df5de155e80227df748b34cd8b3cfd744f9) * Cast raw boolean reads in tests so they pass on MySQL Three assertions read oauth_refresh_tokens.revoked through the query builder rather than Eloquent, so no cast applies and the driver's native representation leaks into the test: a real boolean on PostgreSQL, 1 on MySQL. Cast explicitly at the call site. (cherry picked from commit 2911c5c48cf65d24a34a41e667335c40005839a7) * Use a scheduling date inside MySQL's TIMESTAMP range MySQL TIMESTAMP columns end at 2038-01-19, so the 2099 sentinel these tests used is rejected outright with SQLSTATE[22007]. 2037-12-31 still reads as a far-future schedule and works on both engines. (cherry picked from commit bde33eb239cdbd3a5567d4c21e1d85302913cdd7) * Remove the duplicate-identity migration scenario test The suite rebuilt a pre-migration schema by dropping the unique index in beforeEach and re-running the migration by hand, exercising a database state the application never runs in. * Fix the MySQL rollback path and run CI on both engines The migration's down() dropped a unique whose leftmost prefix is an FK column, which MySQL refuses when nothing else backs the constraint (SQLSTATE 1553). It now creates a standalone index first, so migrate:rollback works on MySQL and stays a no-op change for PostgreSQL. up() is untouched: every database already migrated keeps its schema. The rehearsal test calls that down() instead of hand-rolling the drop, so it exercises the real rollback rather than an imitation of it. Matches logged SQL through the connection's query grammar rather than stripping quote characters, and adds a MySQL leg to the backend CI job. * Use a readiness check both database images can run mysql:8.4 installs mysql-community-server-minimal, which ships neither mysqladmin nor the mysql client, so a mysqladmin health command never succeeds and the service never reports healthy. Both images run their init phase without networking, so an open port is the point either engine starts accepting connections - one check covers both, and the per-engine matrix key goes away. * Use each engine's own readiness tool pg_isready and mysqladmin ping are what the respective images ship for this, and the mysql image's entrypoint invokes mysqladmin itself, so it is present. Keeps 20 retries, which MySQL needs to finish initialising. * State the two-engine ceiling as a rule, not a test detail The 2038 TIMESTAMP limit binds anything written to the column, not just the sentinel dates in fixtures, and the same reasoning generalises: what the app supports is the intersection of both engines. * Let the release image connect to MySQL The published image installed only pdo_pgsql, so DB_CONNECTION=mysql failed with "could not find driver" before any query ran - the app supports MySQL but the image people actually deploy could not reach it. mysql-client mirrors the postgresql-client already present, for artisan db and dumps. * Keep "backend" a single required status check Matrixing the job split its check in two, so the "backend" context the branch protection requires was never reported and every PR sat waiting on it. The matrix is now "tests" and a small "backend" job gates on it, which keeps the required check stable however many engines the matrix grows to - and leaves the open PRs mergeable without a rebase. --------- Co-authored-by: Paulo Castellano <paulo@castellanos.llc>
214 lines
7.8 KiB
Docker
214 lines
7.8 KiB
Docker
# syntax=docker/dockerfile:1.7
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# TryPost Dockerfile — multi-stage with `dev` and `production` targets.
|
|
#
|
|
# docker build --target dev -t trypost:dev -f docker/Dockerfile .
|
|
# docker build --target production -t trypost:prod -f docker/Dockerfile .
|
|
# ----------------------------------------------------------------------------
|
|
|
|
ARG PHP_VERSION=8.4
|
|
ARG NODE_VERSION=22
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Stage 1: system-base — PHP-FPM + system packages + extensions
|
|
# ----------------------------------------------------------------------------
|
|
FROM php:${PHP_VERSION}-fpm-alpine AS system-base
|
|
|
|
RUN apk add --no-cache \
|
|
nginx \
|
|
supervisor \
|
|
bash \
|
|
curl \
|
|
git \
|
|
unzip \
|
|
shadow \
|
|
tzdata \
|
|
postgresql-client \
|
|
postgresql-dev \
|
|
mysql-client \
|
|
libpng-dev \
|
|
libjpeg-turbo-dev \
|
|
freetype-dev \
|
|
libwebp-dev \
|
|
libavif-dev \
|
|
libzip-dev \
|
|
oniguruma-dev \
|
|
icu-dev \
|
|
linux-headers \
|
|
$PHPIZE_DEPS \
|
|
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp --with-avif \
|
|
&& docker-php-ext-install -j"$(nproc)" \
|
|
pdo_pgsql \
|
|
pgsql \
|
|
pdo_mysql \
|
|
gd \
|
|
zip \
|
|
opcache \
|
|
bcmath \
|
|
exif \
|
|
pcntl \
|
|
intl \
|
|
sockets \
|
|
&& pecl install redis \
|
|
&& docker-php-ext-enable redis \
|
|
&& apk del $PHPIZE_DEPS \
|
|
&& rm -rf /tmp/* /var/cache/apk/*
|
|
|
|
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
|
|
|
|
WORKDIR /var/www/html
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Stage 2: composer-deps — full PHP deps (incl. dev) for tooling/asset build
|
|
# ----------------------------------------------------------------------------
|
|
FROM system-base AS composer-deps
|
|
|
|
COPY composer.json composer.lock ./
|
|
RUN composer install \
|
|
--no-scripts \
|
|
--no-autoloader \
|
|
--prefer-dist \
|
|
--no-interaction
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Stage 3: composer-deps-prod — production deps only (no dev tooling)
|
|
# ----------------------------------------------------------------------------
|
|
FROM system-base AS composer-deps-prod
|
|
|
|
COPY composer.json composer.lock ./
|
|
RUN composer install \
|
|
--no-dev \
|
|
--no-scripts \
|
|
--no-autoloader \
|
|
--prefer-dist \
|
|
--no-interaction
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Stage 4: asset-build — wayfinder TS gen + Vite + Inertia SSR build
|
|
#
|
|
# PHP and Node together in one stage because @laravel/vite-plugin-wayfinder
|
|
# invokes `php artisan wayfinder:generate` during vite build — splitting
|
|
# the stages would mean the vite phase has no PHP available.
|
|
#
|
|
# Vite inlines VITE_* values into the JS bundle at build time. Pass them
|
|
# as build args (--build-arg VITE_REVERB_APP_KEY=...) so the bundle reaches
|
|
# the browser with the correct Reverb/PostHog config. Runtime env vars on
|
|
# the container have no effect on the already-compiled bundle.
|
|
# ----------------------------------------------------------------------------
|
|
FROM composer-deps AS asset-build
|
|
|
|
# Node 22 for Vite + npm scripts.
|
|
RUN apk add --no-cache nodejs npm
|
|
|
|
ARG VITE_APP_NAME=TryPost
|
|
ARG VITE_REVERB_APP_KEY=
|
|
ARG VITE_REVERB_HOST=localhost
|
|
ARG VITE_REVERB_PORT=8080
|
|
ARG VITE_REVERB_SCHEME=http
|
|
ARG VITE_POSTHOG_ENABLED=false
|
|
ARG VITE_POSTHOG_API_KEY=
|
|
ARG VITE_POSTHOG_HOST=https://us.i.posthog.com
|
|
|
|
# Stub PHP envs so artisan can boot (overridden at runtime).
|
|
ENV APP_KEY=base64:c3R1Yi13YXlmaW5kZXItZ2VuLWtleS1mb3ItYnVpbGRpbmctYXNzZXRzMA== \
|
|
APP_ENV=production \
|
|
APP_DEBUG=false \
|
|
APP_URL=http://localhost \
|
|
VITE_APP_NAME=${VITE_APP_NAME} \
|
|
VITE_REVERB_APP_KEY=${VITE_REVERB_APP_KEY} \
|
|
VITE_REVERB_HOST=${VITE_REVERB_HOST} \
|
|
VITE_REVERB_PORT=${VITE_REVERB_PORT} \
|
|
VITE_REVERB_SCHEME=${VITE_REVERB_SCHEME} \
|
|
VITE_POSTHOG_ENABLED=${VITE_POSTHOG_ENABLED} \
|
|
VITE_POSTHOG_API_KEY=${VITE_POSTHOG_API_KEY} \
|
|
VITE_POSTHOG_HOST=${VITE_POSTHOG_HOST}
|
|
|
|
COPY --from=composer-deps /var/www/html/vendor ./vendor
|
|
COPY . .
|
|
|
|
# Ensure Laravel runtime dirs exist — .dockerignore strips their contents
|
|
# (correct: caches shouldn't bloat builds), but artisan boot needs the dirs.
|
|
RUN mkdir -p storage/framework/cache/data \
|
|
storage/framework/sessions \
|
|
storage/framework/views \
|
|
storage/logs \
|
|
bootstrap/cache
|
|
|
|
RUN composer dump-autoload --no-scripts --optimize \
|
|
&& php artisan wayfinder:generate --with-form \
|
|
&& npm ci --no-audit --no-fund \
|
|
&& npm run build \
|
|
&& npm run build:ssr
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Stage 6: dev — local development image (bind-mount the source at runtime)
|
|
# ----------------------------------------------------------------------------
|
|
FROM system-base AS dev
|
|
|
|
ARG UID=1000
|
|
ARG GID=1000
|
|
|
|
# Node + npm for in-container Vite, npm scripts, ad-hoc tooling.
|
|
RUN apk add --no-cache nodejs npm
|
|
|
|
# Create non-root app user matching host UID/GID for clean bind-mount writes.
|
|
RUN groupmod -g "${GID}" www-data 2>/dev/null || groupadd -g "${GID}" app \
|
|
&& (id -u app >/dev/null 2>&1 || useradd -u "${UID}" -g "${GID}" -d /home/app -m -s /bin/bash app) \
|
|
&& chown -R "${UID}:${GID}" /var/www/html
|
|
|
|
COPY docker/nginx.conf /etc/nginx/http.d/default.conf
|
|
COPY docker/php.dev.ini /usr/local/etc/php/conf.d/99-trypost.ini
|
|
COPY docker/supervisord.dev.conf /etc/supervisor/conf.d/supervisord.conf
|
|
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
COPY docker/.env.docker.example /var/www/html/.env.docker.example
|
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
|
|
|
ENV TRYPOST_TARGET=dev
|
|
|
|
EXPOSE 80 5173 8080
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=5 \
|
|
CMD curl -fsS http://127.0.0.1/up || exit 1
|
|
|
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# Stage 7: production — self-contained image for self-hosters
|
|
# ----------------------------------------------------------------------------
|
|
FROM system-base AS production
|
|
|
|
# php-fpm runs as www-data (Alpine default pool config) — that's the user
|
|
# storage and bootstrap/cache must be owned by, so Laravel can write logs,
|
|
# session files, view cache, etc.
|
|
|
|
COPY docker/nginx.conf /etc/nginx/http.d/default.conf
|
|
COPY docker/php.prod.ini /usr/local/etc/php/conf.d/99-trypost.ini
|
|
COPY docker/supervisord.prod.conf /etc/supervisor/conf.d/supervisord.conf
|
|
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
|
|
|
# Application source + generated wayfinder TS + built assets — all from
|
|
# asset-build (the merged stage that ran php artisan wayfinder:generate,
|
|
# npm run build, and npm run build:ssr).
|
|
COPY --from=asset-build /var/www/html /var/www/html
|
|
|
|
# Replace the dev-equipped vendor/ with production-only deps. composer-deps-prod
|
|
# is built independently and is much smaller (no phpunit, no debugbar, no pail,
|
|
# no pint). Also wipe bootstrap/cache/*.php — package:discover ran with dev
|
|
# deps and recorded providers (Pail, Telescope etc) that no longer exist;
|
|
# Laravel rediscovers cleanly at first boot.
|
|
RUN rm -rf /var/www/html/vendor /var/www/html/bootstrap/cache/*.php
|
|
COPY --from=composer-deps-prod /var/www/html/vendor /var/www/html/vendor
|
|
|
|
RUN composer dump-autoload --optimize --classmap-authoritative --no-scripts \
|
|
&& chown -R www-data:www-data /var/www/html/storage /var/www/html/bootstrap/cache
|
|
|
|
ENV TRYPOST_TARGET=production
|
|
|
|
EXPOSE 80 8080
|
|
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
|
|
CMD curl -fsS http://127.0.0.1/up || exit 1
|
|
|
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|