Skip to content
Open
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
47 changes: 47 additions & 0 deletions .agents/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
# Prepares an Amp orb: PHP 8.5, Composer, and PHP dependencies. The workbench
# (Craft on SQLite) builds itself when its service starts; see .amp/services.yaml.
set -euo pipefail

cd "$(dirname "${BASH_SOURCE[0]}")/.."
export COMPOSER_NO_INTERACTION=1 COMPOSER_ALLOW_SUPERUSER=1

scratch=$(mktemp -d)
trap 'rm -rf -- "$scratch"' EXIT

# Debian's PHP is too old for Craft 6, so use the Sury packages.
if [[ ! -f /usr/share/keyrings/debsuryorg-archive-keyring.gpg ]]; then
curl -fsSL https://packages.sury.org/debsuryorg-archive-keyring.deb -o "$scratch/sury.deb"
sudo dpkg -i "$scratch/sury.deb"
fi
if [[ ! -f /etc/apt/sources.list.d/php.list ]]; then
. /etc/os-release
echo "deb [signed-by=/usr/share/keyrings/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $VERSION_CODENAME main" |
sudo tee /etc/apt/sources.list.d/php.list >/dev/null
fi

# The extensions CI installs, plus what Craft needs to serve the workbench.
packages=(php8.5-cli php8.5-bcmath php8.5-curl php8.5-gd php8.5-intl php8.5-mbstring
php8.5-sqlite3 php8.5-xml php8.5-zip unzip)
missing=()
for package in "${packages[@]}"; do
if [[ $(dpkg-query -W -f='${Status}' "$package" 2>/dev/null || true) != 'install ok installed' ]]; then
missing+=("$package")
fi
done
if ((${#missing[@]})); then
sudo apt-get update -qq
sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends "${missing[@]}"
fi
sudo update-alternatives --set php /usr/bin/php8.5

if ! command -v composer >/dev/null; then
curl -fsSL https://getcomposer.org/installer -o "$scratch/composer-setup.php"
expected=$(curl -fsSL https://composer.github.io/installer.sig)
actual=$(php -r 'echo hash_file("sha384", $argv[1]);' "$scratch/composer-setup.php")
[[ $actual == "$expected" ]] || { echo 'Composer installer checksum mismatch' >&2; exit 1; }
php "$scratch/composer-setup.php" --2 --install-dir="$scratch" --filename=composer
sudo install -m 755 "$scratch/composer" /usr/local/bin/composer
fi

composer install --prefer-dist --no-progress
8 changes: 8 additions & 0 deletions .amp/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
workbench:
command: >-
composer build --no-interaction &&
APP_URL="$PUBLIC_URL" exec php vendor/bin/testbench serve --host=127.0.0.1 --port="$PORT" --no-reload --no-interaction
portal:
title: Craft Cloud workbench
description: Craft 6 with craftcms/cloud. Sign in as admin / password.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@

/.gitattributes export-ignore
/.gitignore export-ignore
/.release-it.json export-ignore
/composer.lock export-ignore
/mago.toml export-ignore
/package-lock.json export-ignore
/package.json export-ignore
/phpunit.xml.dist export-ignore
/tests/ export-ignore
/.agents/ export-ignore
/.amp/ export-ignore
/AGENTS.md export-ignore
/testbench.yaml export-ignore
/workbench/ export-ignore
14 changes: 14 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"npm": false,
"git": {
"commit": false,
"tag": false,
"push": false,
"requireBranch": ["5.x"]
},
"github": {
"release": true,
"autoGenerate": true,
"draft": true
}
}
8 changes: 0 additions & 8 deletions .releaserc.yaml

This file was deleted.

22 changes: 22 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# craftcms/cloud

Laravel package that runs Craft CMS 6 on Craft Cloud. Namespace `CraftCms\Cloud`, PHP 8.5.

## Commands

- `composer test`: Pest, with Orchestra Testbench booting Craft's and Cloud's providers (`tests/TestCase.php`).
- `composer lint` / `composer fix`: Mago. CI runs `composer validate --strict`, lint, and tests.
- `composer serve`: builds and serves the workbench on `127.0.0.1:8000`.

## Workbench

`testbench.yaml` plus `workbench/` make a Craft 6 site with this package installed, on SQLite, in Testbench's skeleton under `vendor/orchestra/testbench-core/laravel`. `composer build` creates the database and runs `craft:install` (admin / password); it's a no-op once Craft is installed.

In an orb, run `amp orb services ensure` to start it behind a portal. `composer install` and `composer dump-autoload` purge the skeleton, including the database, so run `amp orb service restart workbench` afterwards.

Craft Cloud is detected from `CRAFT_CLOUD` or `AWS_LAMBDA_RUNTIME_API`, so the workbench runs the off-Cloud code paths.

## Constraints

- `src/bref/handlers/*.php` are Lambda handler paths referenced by Cloud's infrastructure. Don't move or rename them.
- Read `CRAFT_CLOUD_*` variables through `CraftCms\Cloud\Cloud::env()`.
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,40 @@
# Craft Cloud Package
# Craft Cloud

Run Craft CMS on Craft Cloud.
Runs Craft CMS 6 on [Craft Cloud](https://craftcms.com/cloud).

```bash
composer require craftcms/cloud
```

Laravel discovers `CraftCms\Cloud\CloudServiceProvider` automatically. Outside Craft Cloud it changes nothing, so the same project runs locally as usual.

## What it configures on Craft Cloud

Craft Cloud is detected from `CRAFT_CLOUD` or `AWS_LAMBDA_RUNTIME_API`. When either is set, the provider:

- **Queue:** uses the environment's SQS queue (`CRAFT_CLOUD_SQS_URL`) as the default connection, dispatching after commit.
- **Cache:** uses Laravel's `failover` store: Valkey (`CRAFT_CLOUD_REDIS_URL`, with 1-second timeouts), then the database, then memory. Valkey needs the `redis` PHP extension, which Craft Cloud's PHP configuration enables.
- **Logging:** sends the default channel to stderr, which is all Lambda collects.
- **Sessions:** replaces `file` or `cookie` sessions with `database` sessions. Other drivers are left alone.

## Lambda handlers

The Cloud platform runs these files as Lambda handlers, so their paths must not change:

- `src/bref/handlers/job-sqs-cmd.php` runs queued jobs in-process with bref/laravel-bridge.
- `src/bref/handlers/command-sqs-cmd.php` runs Craft console commands sent by the platform and posts their output back.

## Development

```bash
composer install
composer test # Pest, with Orchestra Testbench booting Craft
composer lint # Mago
composer fix
```

Releases are tagged by hand with [release-it](https://github.com/release-it/release-it), which drafts a GitHub release:

```bash
npx release-it 5.0.0-beta.1
```
38 changes: 25 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,49 @@
"license": "proprietary",
"type": "library",
"require": {
"ext-curl": "*",
"bref/bref": "^3",
"bref/extra-php-extensions": "^3",
"bref/laravel-bridge": "^3.0",
"craftcms/cms": "^6",
"symfony/process": "^7.4.5 || ^8.0.5"
"bref/laravel-bridge": "^3.1.7",
"craftcms/cms": "^6.0.0-beta.1",
"symfony/process": "^7.4.5 || ^8.0.5",
"guzzlehttp/guzzle": "^7.8"
},
"require-dev": {
"carthage-software/mago": "^1.1.0",
"pestphp/pest": "^4.0"
"pestphp/pest": "^4.0",
"orchestra/testbench": "^11.0"
},
"scripts": {
"lint": "mago lint --minimum-fail-level=warning && mago format --check",
"fix": "mago lint --fix --format-after-fix && mago format",
"test": [
"Composer\\Config::disableProcessTimeout",
"./vendor/bin/pest --compact"
],
"post-autoload-dump": [
"@clear",
"@prepare"
],
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": [
"@php vendor/bin/testbench package:create-sqlite-db --ansi",
"@php vendor/bin/testbench workbench:build --ansi"
],
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve --ansi"
]
},
"autoload": {
"psr-4": {
"craft\\cloud\\": "src/"
"CraftCms\\Cloud\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"craft\\cloud\\tests\\": "tests/"
},
"files": [
"tests/Support/functions.php"
]
"CraftCms\\Cloud\\Tests\\": "tests/"
}
},
"prefer-stable": true,
"config": {
Expand All @@ -48,7 +60,7 @@
"extra": {
"laravel": {
"providers": [
"craft\\cloud\\CloudServiceProvider"
"CraftCms\\Cloud\\CloudServiceProvider"
]
}
}
Expand Down
Loading
Loading