- Shell 60.6%
- Dockerfile 39.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| .forgejo/workflows | ||
| .gitattributes | ||
| ci.Dockerfile | ||
| README.md | ||
| update-ci-image.sh | ||
Shared CI workflows
Reusable workflows and a shared Docker image for testing and deploying Laravel applications over FTPS.
Use the deployment workflow
Create .forgejo/workflows/deploy.yml in the application repository:
name: Test and deploy
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: my-project-production
cancel-in-progress: false
jobs:
deploy:
uses: janbrodda/ci-workflows/.forgejo/workflows/laravel-ftps.yml@main
secrets: inherit
Use a project-specific concurrency group. The @main reference picks up the current shared workflow on each new deployment run. Changes in this repository do not trigger deployments in application repositories by themselves.
The application repository must have access to a runner with the laravel-php85 label. This repository must remain publicly accessible for cross-repository workflow calls.
Application requirements
| Area | Requirement |
|---|---|
| Runtime | The application and its dependencies support PHP 8.5 and Node.js 24. |
| Composer | Commit composer.json and an up-to-date composer.lock. Both development and production dependency installations must succeed. |
| Frontend | Provide a build script in package.json and exactly one committed lockfile: package-lock.json or pnpm-lock.yaml. |
| Package manager | The workflow selects npm or pnpm 12 from the lockfile and installs without changing it. Both lockfiles together, or neither lockfile, cause a failure. |
| Installation hooks | Frontend dependencies must work with --ignore-scripts. Dependency installation hooks are not executed. The explicit build and asset-test scripts are executed. |
| Application tests | php artisan test --compact --display-warnings must succeed with SQLite and MariaDB 11.4. The PostgreSQL test pass and service are currently disabled in CI. |
| Test configuration | Allow the workflow's DB_CONNECTION, DB_DATABASE, DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD and DB_URL values to take effect. Do not force a different connection in PHPUnit configuration or test setup for the main test suite. Tests must not require production credentials or access production services. |
| Asset tests | A non-empty test:assets script in package.json enables the asset-test step. Without it, the step is shown as skipped; failing scripts block deployment. |
| Browser tests | Playwright/Chromium tests are currently disabled in CI, including browser preparation and caching. Project scripts and local/agent test execution are unaffected. |
| Project structure | Provide app, bootstrap, config, lang, routes, public, resources and database/migrations. Currently, lang is required even if empty locally; Git must retain the directory, for example with a .gitkeep file. |
| Production files | Required application files must be in the directories above or in vendor. Only artisan and composer.json are copied from the repository root. Additional root files and custom directories require a workflow change. |
The Prepare test environment step copies .env.example to .env only when .env is absent. Using Node's built-in modules before dependency installation, it also detects non-empty test:assets and test:browser scripts in package.json and exposes the assets and browser step outputs. Asset tests use this detection; browser steps remain skipped while RUN_BROWSER_TESTS is 'false'.
The workflow installs dependencies, builds assets and runs the SQLite and MariaDB test passes. PostgreSQL and browser tests are retained but disabled in the shared workflow only. Once the frontend build succeeds, enabled database tests continue even if an asset test or another database test fails. Any failed step prevents deployment.
Composer and frontend download caches are saved immediately after their respective dependency installations succeed, before the frontend build and tests. Later failures do not discard these caches. An exact cache hit skips the save step; a fallback hit is saved under the current lockfile's cache key.
Optional browser tests
Currently disabled in CI: RUN_BROWSER_TESTS is set to 'false' in the shared workflow. The following describes the retained functionality when re-enabled. Tests can still be run independently in each project, including by an agent.
A project opts in with a non-empty test:browser script, normally playwright test, and an installed @playwright/test dependency. The workflow resolves the actual installed Playwright CLI (including pnpm dependency layouts); it does not install an unpinned CLI with npx. Chromium binaries are restored into /tmp/playwright-browsers under a cache key containing the Playwright version, OS, architecture and Bookworm/Chromium cache format. An exact cache hit skips the browser installation step; browser tests run with either a restored cache or a successful browser installation. A new cache is saved immediately after successful browser installation; test failures do not discard the download. Linux system packages come from the Docker image and are not part of this cache.
Browser tests run before production dependencies are prepared or files are uploaded. The step provides CI=true, APP_ENV=testing, a test-only APP_KEY and APP_AUTO_MIGRATE=false. Each project must configure its own disposable database, test service credentials, application startup and any OAuth test keys. Production credentials, data and services must not be used. Only Chromium is installed; the script/configuration must select Chromium or its emulated viewports. Firefox and WebKit are not enabled by this workflow.
Browser test output is available in the workflow log. The shared workflow does not upload test reports or other browser test artifacts.
Rollout: Rebuild laravel-ci:php85 with the updated Dockerfile before starting a new application deployment with browser tests. Updating this shared repository does not rebuild the runner image or trigger application deployments.
Required repository secrets
Set these secrets in each application repository:
| Secret | Value |
|---|---|
DEPLOY_URL |
Public HTTPS application base URL, such as https://example.com. |
FTPS_SERVER |
FTPS server hostname. |
FTPS_USERNAME |
FTPS username. |
FTPS_PASSWORD |
FTPS password. |
FTPS_PATH |
Application root directory on the FTPS server, ending in /. Use ./ for the account root. |
The workflow uses explicit FTPS on port 21. FTPS_PATH points to the application root, not its public subdirectory.
Production server requirements
- Install PHP compatible with the application and its required extensions. CI uses PHP 8.5.
- Point the web server's document root to
public. - Configure the production
.env, includingAPP_KEY, database and service credentials, on the server. The workflow does not upload an.envfile. - Provide the production database and writable
storageandbootstrap/cachedirectories. - Provide a publicly reachable
/upendpoint that runs pending application migrations and returns an HTTP error status if they fail. Laravel's default health endpoint alone does not run migrations. Projects using the existing automatic-migration middleware must keepAPP_AUTO_MIGRATEenabled in production. - Provide a publicly reachable homepage at
/. Both/upand/are checked after the upload; HTTP errors fail the workflow. These checks do not validate page content or browser behavior. - Configure queue workers, scheduled tasks and storage links separately when the application needs them.
After tests pass, the workflow removes development Composer dependencies and assembles a production package. It uploads application files, production dependencies, resources, migrations and built assets. The production .env, SQLite database files and existing storage contents are not part of the package. Migrations run on the server through /up after the upload.
Shared Docker image
ci.Dockerfile provides PHP 8.5, Node.js 24, Composer 2, pnpm 12 and the tools required by the workflow. It includes database drivers for SQLite, MySQL/MariaDB and PostgreSQL, plus GD with JPEG, PNG and WebP support. Chromium system libraries and fonts are installed via playwright install-deps chromium, using playwright@latest by default. The PLAYWRIGHT_VERSION build argument and PLAYWRIGHT_DEPENDENCIES_VERSION environment variable retain the symbolic value latest; the resolved concrete version is not stored. The image update script installs playwright@latest in a disposable container to verify an actual Chromium launch. Browser binaries are downloaded per project rather than baked into the image.
On the Docker host used by the runner, keep ci.Dockerfile and update-ci-image.sh together and run:
sudo ./update-ci-image.sh
The script pulls current base images, rebuilds without the layer cache and checks the candidate image before tagging it as laravel-ci:php85. It validates PHP extensions, then installs a temporary matching Playwright/Chromium headless shell in a disposable container and actually launches it to render a test page. Browser files from this smoke test are not retained in the image. The smoke-test container uses an init process and 1 GiB shared memory. Consider an increased shared-memory allocation for runner job containers as well. A failed build or check leaves the previous shared image in place. It requires Docker and flock on the host.
Configure the runner to use the local image, retaining its other settings and labels:
runner:
labels:
- "laravel-php85:docker://laravel-ci:php85"
container:
force_pull: false
The build and the runner must use the same Docker daemon. Restart the runner after changing its configuration.
For weekly rebuilds, assuming this repository is checked out at /opt/laravel-ci, add the following to /etc/cron.d/laravel-ci:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
15 4 * * 1 root /bin/sh /opt/laravel-ci/update-ci-image.sh >> /var/log/laravel-ci-build.log 2>&1
This runs on Mondays at 04:15 in the host's timezone. It updates the base images and installed tools, but does not pull changes to this Git repository. Run git pull in the host checkout when the Dockerfile or update script changes.