Skip to content

Add Craft Cloud storage disks for Craft 6 - #212

Draft
timkelty wants to merge 9 commits into
5.xfrom
feature/craft-6-cloud-disks
Draft

timkelty wants to merge 9 commits into
5.xfrom
feature/craft-6-cloud-disks

Conversation

@timkelty

@timkelty timkelty commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a craft-cloud Laravel disk driver for the project's Craft Cloud bucket. On Craft Cloud (CRAFT_CLOUD set), it also puts upload sessions, temporary asset uploads and soft-deleted assets' files in the bucket.

CloudServiceProvider::register()
  Disks::extend()          # every environment: registers the craft-cloud driver
  if CRAFT_CLOUD
    Disks::configureCraftStorage()
      craft-cloud-tmp      # assets.uploadSessionDisk, assets.tempUploadDisk
      craft-cloud-trash    # assets.trashDisk
// config/filesystems.php
'images' => ['driver' => 'craft-cloud', 'prefix' => 'images'],
craft-cloud disk config            built s3 disk (AwsS3V3Adapter)
  prefix: images             ->      bucket: $CRAFT_CLOUD_PROJECT_ID
  root:   (default assets)           root:   {env}/assets, prefix images
  asset_transformer, throw...        url:    https://cdn.craft.cloud (+ root and prefix)
                                     other options kept as written

craft-cloud-tmp (Cloud only)       {env}/storage/tmp
  upload-sessions/{id}/file          same credentials and endpoint as asset disks,
  user_{id}/...                      so core copies finished uploads with CopyObject

craft-cloud-trash (Cloud only)     {env}/storage/trash
  {assetId}.{ext}                    soft-deleted files, restorable until garbage collection
  • No local fallback. Without the bucket variables, resolving the disk throws an error that names them1. Craft still boots.
  • No asset_transformer default. A disk that wants Cloud transforms sets 'asset_transformer' => 'craft-cloud' itself.
  • Upgrading from Craft 5: one disk per old filesystem handle, '{handle}' => ['driver' => 'craft-cloud', 'prefix' => '{old subpath}'].
  • Dependencies: adds league/flysystem-aws-s3-v3. Core comes from the baseline (Rebuild the 5.x baseline for Craft 6 beta #215), craftcms/cms 6.0.0-beta.3.
  • Defaults only. Each Craft storage setting and disk keeps the project's own value when it has one2.
  • Infra requirements:
    • bucket CORS: PUT from control panel origins, expose ETag
    • IAM for multipart uploads on {env}/assets and {env}/storage
    • a lifecycle rule on {env}/storage/tmp/ only, not {env}/storage/trash/, which garbage collection cleans
  • Proposed contract changes, not made here:
    • AWS_REGION instead of CRAFT_CLOUD_REGION
    • standard AWS_* credentials instead of CRAFT_CLOUD_ACCESS_*
    • a hardcoded CDN URL if nothing sets CRAFT_CLOUD_CDN_BASE_URL
  • Follow-ups: CDN purges on write, and the max-age/visibility object metadata.

Evidence

tests/Feature/DisksTest.php on Testbench, against the baseline's provider and then this branch:

  • Before: 5 failed, 2 passed. Storage::disk('images') throws Driver [craft-cloud] is not supported., uploads stay on core's local craft-tmp, and there's no trash disk.
    After: composer ci passes: Pint, PHPStan, and 13 passed (58 assertions).
✓ puts craft-cloud disks in the project bucket, under the environment, with CDN URLs
    path('photo.jpg')  = environment-id/assets/images/photo.jpg
    url('photo.jpg')   = https://cdn.craft.cloud/environment-id/assets/images/photo.jpg
    scoped volume url  = https://cdn.craft.cloud/environment-id/assets/images/volume/photo.jpg
✓ works off Craft Cloud with a bucket, storage endpoint and CDN base URL
✓ says which variables are missing when a disk is resolved without a bucket
✓ keeps the disk's other options, and its root within the environment
✓ puts upload sessions, temporary asset uploads and trashed files in the bucket on Craft Cloud
    trash path('42.jpg') = environment-id/storage/trash/42.jpg
✓ leaves Craft's storage disks alone off Craft Cloud
✓ leaves storage disks the project has chosen alone

Not run on Craft Cloud itself yet.

Related issues

Footnotes

  1. Required: CRAFT_CLOUD_PROJECT_ID, CRAFT_CLOUD_ENVIRONMENT_ID, and CRAFT_CLOUD_REGION or AWS_REGION. Optional: CRAFT_CLOUD_ACCESS_KEY/_SECRET/_TOKEN (otherwise the SDK finds credentials, such as the function's role), CRAFT_CLOUD_STORAGE_ENDPOINT (path-style, for MinIO), CRAFT_CLOUD_CDN_BASE_URL. Empty values count as unset. ↩

  2. Core redefines craft-tmp and craft-asset-temp on boot, which is why this PR changes the settings instead of those disks. Without a trash disk, soft-deleting an asset deletes its file. Project config YAML writes are turned off on Cloud by Run Craft Cloud's functions as Bref does #220, not here. ↩

@timkelty timkelty changed the title Register Craft Cloud storage as Laravel disks Add a craft-cloud disk driver for the project's Cloud bucket Nov 19, 2026
@timkelty timkelty changed the title Add a craft-cloud disk driver for the project's Cloud bucket Add Craft Cloud storage disks for Craft 6 Nov 19, 2026
@timkelty
timkelty force-pushed the feature/craft-6-cloud-disks branch 4 times, most recently from 3e8415e to c743473 Compare December 5, 2026 16:10
timkelty and others added 7 commits December 6, 2026 01:14
Adds a craft-cloud disk driver (S3 on the project bucket with CDN URLs on
Cloud, a local disk in public/uploads elsewhere), a default craft-cloud
assets disk, bucket disks for upload session staging and temporary asset
uploads on Cloud, and a cloud:disks command that prints disks for 3.x
AssetsFs filesystems before upgrading.

Amp-Thread-ID: https://ampcode.com/threads/T-79ed60c5-5654-4f30-8dbd-da4b0ecd4fb2
Co-authored-by: Amp <amp@ampcode.com>
Requires a core newer than 6.0.0-alpha.20, and locks 6.x at 8a13417, which
has disk-owned asset transformers (craftcms/cms#20542). Packagist hadn't
indexed that commit yet, so the lock was pointed at it by hand; core's
composer.json is the same as at the indexed commit (cc77dd6).

Also checks that Cloud disks share the credentials and endpoint Craft needs
to copy staged uploads within S3.

Amp-Thread-ID: https://ampcode.com/threads/T-79ed60c5-5654-4f30-8dbd-da4b0ecd4fb2
Co-authored-by: Amp <amp@ampcode.com>
Replaces the craft-cloud driver, its local fallback and subpath option, and
the cloud:disks command. On Craft Cloud, the provider sets the craft-cloud
disk's connection to the bucket's {env}/assets prefix and the CDN, keeping
the project's other options, and adds a craft-cloud-tmp disk in
{env}/storage/tmp for upload sessions and temporary asset uploads.
Elsewhere, the project defines craft-cloud itself, and upgraded filesystem
handles scope it.

Amp-Thread-ID: https://ampcode.com/threads/T-79ed60c5-5654-4f30-8dbd-da4b0ecd4fb2
Co-authored-by: Amp <amp@ampcode.com>
Brings back the craft-cloud driver, without its local fallback: it always
builds an S3 disk on the project's bucket, and throws when resolved without
the bucket variables, so it works off Cloud against a dev bucket or MinIO
but never quietly becomes another disk. Subfolders use Laravel's own
prefix option. Drops the default craft-cloud disk, and documents choosing
a local disk per environment instead.

Amp-Thread-ID: https://ampcode.com/threads/T-79ed60c5-5654-4f30-8dbd-da4b0ecd4fb2
Co-authored-by: Amp <amp@ampcode.com>
Moves Disks to CraftCms\Cloud and stages uploads behind the provider's
Lambda check. Uses AssetsConfig's upload disk settings from craftcms/cms
6.0.0-beta.3, ports the tests to Testbench, and restores the README's disk
docs. Adds league/flysystem-aws-s3-v3 to the baseline's dependencies.

Amp-Thread-ID: https://ampcode.com/threads/T-79ed60c5-5654-4f30-8dbd-da4b0ecd4fb2
Defaults assets.trashDisk to a craft-cloud-trash disk in {env}/storage/trash
when the project leaves it null, so soft-deleted assets can be restored.

Amp-Thread-ID: https://ampcode.com/threads/T-79ed60c5-5654-4f30-8dbd-da4b0ecd4fb2
Drops assertions on Laravel's scoped disks, the SDK's credentials and credential
filtering, and the trailing-slash trim Laravel already does on disk URLs.

Amp-Thread-ID: https://ampcode.com/threads/T-79ed60c5-5654-4f30-8dbd-da4b0ecd4fb2
@timkelty
timkelty force-pushed the feature/craft-6-cloud-disks branch from c743473 to a1f01cd Compare December 6, 2026 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant