Skip to content
Draft
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
10 changes: 0 additions & 10 deletions .env.example

This file was deleted.

6 changes: 0 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@

/.gitattributes export-ignore
/.gitignore export-ignore
/.lintstagedrc.json export-ignore
/.prettierignore export-ignore
/.prettierrc.json export-ignore
/.releaserc.yaml export-ignore
/composer.lock export-ignore
/ecs.php export-ignore
/package.json export-ignore
/package-lock.json export-ignore
/phpstan.neon export-ignore
/webpack.config.js export-ignore
39 changes: 5 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
push:
branches:
- 3.x
- 5.x
pull_request:
permissions:
contents: read
Expand All @@ -17,34 +17,11 @@ jobs:
with:
node_version: '18'
php_version: '8.3'
jobs: '["ecs", "prettier"]'
jobs: '["ecs"]'

compatibility:
name: Compatibility (Craft ${{ matrix.craft }})
static-analysis:
name: Static Analysis
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- craft: '^4.6'
flysystem: '^1.0'
- craft: '^5'
flysystem: '^2.0'
services:
mysql:
image: mysql:8.0
ports:
- 33066:3306
env:
MYSQL_DATABASE: db
MYSQL_USER: db
MYSQL_PASSWORD: db
MYSQL_ROOT_PASSWORD: root
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -udb -pdb"
--health-interval=10s
--health-timeout=5s
--health-retries=10
steps:
- uses: actions/checkout@v4

Expand All @@ -54,13 +31,7 @@ jobs:
coverage: none

- name: Resolve dependencies
run: composer update "craftcms/cms:${{ matrix.craft }}" "craftcms/flysystem:${{ matrix.flysystem }}" --with-all-dependencies --no-interaction --no-progress --prefer-dist --no-audit

- name: Prepare test environment
run: composer test:init
run: composer update --with-all-dependencies --no-interaction --no-progress --prefer-dist --no-audit

- name: Run PHPStan
run: composer phpstan

- name: Run unit tests
run: composer test
2 changes: 0 additions & 2 deletions .husky/pre-commit

This file was deleted.

4 changes: 0 additions & 4 deletions .lintstagedrc.json

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierignore

This file was deleted.

5 changes: 0 additions & 5 deletions .prettierrc.json

This file was deleted.

4 changes: 1 addition & 3 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
branches:
- main
- '1.x'
- '2.x'
- '5.x'
tagFormat: '${version}'
plugins:
- '@semantic-release/commit-analyzer'
Expand Down
123 changes: 10 additions & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,120 +1,17 @@
<a href="https://craftcms.com/cloud" rel="noopener" target="_blank" title="Craft Cloud"><img src="https://raw.githubusercontent.com/craftcms/.github/v3/profile/product-icons/craft-cloud.svg" alt="Craft Cloud icon" width="65"></a>
# Craft Cloud

# Craft Cloud Extension
Craft Cloud runtime integration for Craft CMS 6.

Welcome to [**Craft Cloud**](https://craftcms.com/cloud)!
This package is intentionally small while the Craft 6 integration is rebuilt. It currently provides:

This repository contains source code for the `craftcms/cloud` Composer package, which is required to run a Craft project on our first-party hosting platform, Craft Cloud.
- Bref Lambda handlers under the `craft\cloud\bref` namespace.
- A Laravel service provider that configures Craft Cloud queue and cache defaults when running in Cloud/Lambda.

When installed, the extension automatically [bootstraps](https://www.yiiframework.com/doc/guide/2.0/en/runtime-bootstrapping) itself and makes necessary [application configuration](https://craftcms.com/docs/5.x/reference/config/app.html) changes for the detected environment:
## Runtime Configuration

- :cloud_with_lightning: **Cloud:** There’s no infrastructure settings to worry about—database, queue, cache, and session configuration is handled for you.
- :computer: **Local development:** Craft runs normally, in your favorite [development environment](https://craftcms.com/docs/5.x/install.html).
When `CRAFT_CLOUD` or `AWS_LAMBDA_RUNTIME_API` is present, `craft\cloud\CloudServiceProvider` configures:

:sparkles: To learn more about Cloud, check out [our website](https://craftcms.com/cloud)—or dive right in with [Craft Console](https://console.craftcms.com/cloud). Interested in everything the extension does to get your app ready for Cloud? Read our [Cloud extension deep-dive](https://craftcms.com/knowledge-base/cloud-extension), in the knowledge base.
- `queue.default` as an SQS connection using `CRAFT_CLOUD_SQS_URL`.
- `cache.default` as a Laravel `failover` store.

## Installation

The Cloud extension can be installed in any existing Craft 4.6+ project by running `php craft setup/cloud`. Craft will add the `craftcms/cloud` package and run the extension’s own setup wizard.

> [!TIP]
> This process includes the creation of a [`craft-cloud.yaml` configuration file](https://craftcms.com/knowledge-base/cloud-config) which helps Cloud understand your project’s structure and determines which versions of PHP and Node your project will use during builds and at runtime.

When you [deploy](https://craftcms.com/knowledge-base/cloud-deployment) a project to Cloud, the `cloud/up` command will run, wrapping Craft’s built-in [`up` command](https://craftcms.com/docs/5.x/reference/cli.html#up) and adding the cache and session tables (if they’re not already present).

## Filesystem

When setting up your project’s assets, use the provided **Craft Cloud** filesystem type. Read more about [managing assets in Cloud projects](https://craftcms.com/knowledge-base/cloud-assets).

## Testing

The Codeception `unit` suite on `3.x` boots Craft and expects a local test database.

```bash
composer test:init
composer test:up
composer test
composer test:down
```

`composer test:init` will create `tests/.env` from `tests/.env.example` if it does not already exist. `composer test:up` uses that file when starting the MySQL service defined in `tests/docker-compose.yaml`.

For local compatibility work on `3.x`, it can be helpful to keep your main checkout on the default/latest Craft 5 dependency set and use a separate Git worktree for Craft 4 so each checkout can keep its own `vendor/`, `composer.lock`, and `tests/.env` state.

```bash
git worktree add ../cloud-3x-craft4 3.x

# In the Craft 4 worktree:
composer update "craftcms/cms:^4.6" "craftcms/flysystem:^1.0" --with-all-dependencies --no-audit

# In your main checkout:
composer update "craftcms/cms:^5" "craftcms/flysystem:^2.0" --with-all-dependencies
```

## Developer Features

### Template Helpers

#### `cloud.artifactUrl()`

Generates a URL to a resource that was uploaded to the CDN during the build and deployment process.

```twig
{# Output a script tag with a build-specific URL: #}
<script src="{{ cloud.artifactUrl('dist/js/app.js') }}"></script>

{# You can also use the extension-provided alias: #}
{% js '@artifactBaseUrl/dist/js/app.js' %}
```

Read more about [how to use artifact URLs](https://craftcms.com/knowledge-base/cloud-builds#artifact-uRLs).

#### `cloud.isCraftCloud`

`true` when the app detects it is running on Cloud infrastructure, `false` otherwise.

```twig
{% if cloud.isCraftCloud %}
Welcome to Cloud!
{% endif %}
```

### Aliases

The following aliases are available, in addition to [those provided by Craft](https://craftcms.com/docs/5.x/configure.html#aliases).

#### `@web`

On Cloud, the `@web` alias is guaranteed to be the correct environment URL for each HTTP context, whether that be a [preview domain](https://craftcms.com/knowledge-base/cloud-domains#preview-domains) or [custom domain](https://craftcms.com/knowledge-base/cloud-domains#adding-a-domain).

#### `@artifactBaseUrl`

Equivalent to [`cloud.artifactUrl()`](#artifactUrl), this allows [Project Config](https://craftcms.com/docs/5.x/system/project-config.html) settings to take advantage of dynamic, build-specific CDN URLs.

## Configuration

Most configuration (to Craft and the extension itself) is handled directly by Cloud infrastructure, through [environment overrides](https://craftcms.com/docs/5.x/configure.html#environment-overrides). These options are provided strictly for reference, and have limited utility outside the platform.

| Option | Type | Description |
|-----------------------|----------------|---------------------------------------------------------------------------------------------------------------------------------|
| `artifactBaseUrl` | `string\|null` | Directly set a fully-qualified URL to build artifacts. |
| `s3ClientOptions` | `array` | Additional settings to pass to the `Aws\S3\S3Client` instance when accessing storage APIs. |
| `cdnBaseUrl` | `string` | Used when building URLs to [assets](#filesystem) and other build [artifacts](#artifacturl). |
| `sqsUrl` | `string` | Determines how Craft communicates with the underlying queue provider. |
| `projectId` | `string` | UUID of the current project. |
| `environmentId` | `string` | UUID of the current [environment](https://craftcms.com/knowledge-base/cloud-environments). |
| `buildId` | `string` | UUID of the current [build](https://craftcms.com/knowledge-base/cloud-builds). |
| `accessKey` | `string` | AWS access key, used for communicating with storage APIs. |
| `accessSecret` | `string` | AWS access secret, used in conjunction with the `accessKey`. |
| `accessToken` | `string` | AWS access token. |
| `redisUrl` | `string` | Connection string for the environment’s Redis instance. |
| `signingKey` | `string` | A secret value used to protect transform URLs against abuse. |
| `useAssetBundleCdn` | `boolean` | Whether or not to enable the CDN for asset bundles. |
| `previewDomain` | `string\|null` | Set when accessing an environment from its [preview domain](https://craftcms.com/knowledge-base/cloud-domains#preview-domains). |
| `useQueue` | `boolean` | Whether or not to use Cloud’s SQS-backed queue driver. |
| `region` | `string` | The app region, chosen when creating the project. |
| `useAssetCdn` | `boolean` | Whether or not to enable the CDN for uploaded assets. |
| `useArtifactCdn` | `boolean` | Whether or not to enable the CDN for build artifacts and asset bundles. |
| `staticCacheDuration` | `int` | The default duration, in seconds, to statically cache requests. |
> [!TIP]
> These options can also be set via environment overrides beginning with `CRAFT_CLOUD_`.
The cache store uses the Cloud Redis/Valkey endpoint when `CRAFT_CLOUD_CACHE_SRV` or `CRAFT_CLOUD_REDIS_URL` is available, then falls back to Laravel’s database and array stores.
8 changes: 0 additions & 8 deletions autoload.php

This file was deleted.

21 changes: 0 additions & 21 deletions codeception.yml

This file was deleted.

46 changes: 14 additions & 32 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,61 +1,43 @@
{
"minimum-stability": "dev",
"name": "craftcms/cloud",
"type": "yii2-extension",
"description": "Craft Cloud runtime integration for Craft CMS.",
"license": "proprietary",
"type": "library",
"require": {
"ext-curl": "*",
"bref/bref": "^3",
"bref/extra-php-extensions": "^3",
"craftcms/cms": "^4.6 || ^5",
"craftcms/flysystem": "^1.0.0 || ^2.0.0",
"league/flysystem-aws-s3-v3": "^3.15",
"league/uri": "^7.6",
"league/uri-components": "^7.6",
"yiisoft/yii2-redis": "^2.0",
"yiisoft/yii2-queue": "^2.3.7",
"phlak/semver": "^4.1",
"99designs/http-signatures": "^4.0",
"symfony/process": "^6",
"bref/laravel-bridge": "^3.0",
"craftcms/cms": "^6",
"aws/aws-sdk-php": "^3.342.6",
"craftcms/yii2-cache-cascade": "^1.2.1"
"symfony/process": "^7.4.5 || ^8.0.5"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main",
"codeception/codeception": "^5.0",
"vlucas/phpdotenv": "^5.0",
"codeception/module-asserts": "~3.1.0",
"codeception/module-yii2": "^1.0"
"craftcms/phpstan": "dev-main"
},
"scripts": {
"cs:check": "ecs check --ansi",
"cs:fix": "ecs check --ansi --fix",
"phpstan": "phpstan --memory-limit=1G",
"test:init": "@php -r \"file_exists('tests/.env') || copy('tests/.env.example', 'tests/.env');\"",
"test:up": [
"@test:init",
"docker compose --env-file tests/.env -f tests/docker-compose.yaml up -d --wait"
],
"test:down": "docker compose --env-file tests/.env -f tests/docker-compose.yaml down",
"test": "codecept run unit",
"test:coverage": "codecept run unit --coverage"
"phpstan": "phpstan --memory-limit=1G --debug"
},
"autoload": {
"psr-4": {
"craft\\cloud\\": "src/"
},
"files": [
"autoload.php"
]
}
},
"prefer-stable": true,
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
},
"extra": {
"bootstrap": "craft\\cloud\\Module"
"laravel": {
"providers": [
"craft\\cloud\\CloudServiceProvider"
]
}
}
}
Loading
Loading