Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Craft 6 removed Craft filesystems. Volumes now name a Laravel disk, and core's
remove_craft_filesystemsmigration won't run until there's a disk for each oldfshandle. This makes Craft Cloud storage available as Laravel disks, so new projects can use it and 3.x projects can upgrade.craft-clouddriver. Projects define disks inconfig/filesystems.php:CRAFT_CLOUDorAWS_LAMBDA_RUNTIME_APIis set), this becomes ans3disk:CRAFT_CLOUD_PROJECT_ID, root{env}/assets/{subpath}CRAFT_CLOUD_REGIONorAWS_REGIONCRAFT_CLOUD_ACCESS_KEY/_SECRET/_TOKEN; without them, the SDK uses the function's own credentialsCRAFT_CLOUD_STORAGE_ENDPOINThttps://cdn.craft.cloud/{env}/assets/{subpath}/…. The base URL can be changed per disk withurl, or globally withCRAFT_CLOUD_CDN_BASE_URL.public/uploads/{subpath}with/uploads/{subpath}URLs, like 3.x's local fallback, so the same config works in local development.prefixthat core'sscopeddisks pass in carry through, so volume subpaths end up inside the disk's own subpath.Default disks. Each one is only added when the project hasn't defined a disk with that name:
craft-cloud{env}/assets(localpublic/uploadsoff Cloud)craft-cloud-uploads{env}/storage/tmp/uploadscraft-cloud-temp{env}/storage/tmp, the same place as 3.x'sTmpFsOn Cloud,
uploadSessionDiskandtempAssetUploadDiskdefault to the last two, so upload sessions and temporary uploads outlive a single invocation. Projects that set either one, in config or withCRAFT_*env vars, keep their own value.php craft cloud:disksreads thefsproject config before the upgrade. It prints acraft-clouddisk entry for each 3.xcraft\cloud\fs\AssetsFs, using the same handle and carrying oversubpathandexpires, ready to paste intoconfig/filesystems.php. It warns aboutbaseUrl/localFsPath/localFsUrlsettings, which don't carry over. It only prints; it doesn't editconfig/filesystems.php.How this differs from #210
…/{env}/assets/{env}/assets/…), because Laravel's S3url()already appends the disk'sroot. Hereurlis just the CDN base URL, and a test covers it.GeneralConfig::$uploadSessionDisk, not with anUploadSessionStartinglistener. The same mechanism coverstempAssetUploadDisk, which has no event.What core lets us redefine
craft-tmp/craft-asset-temp: no. Core'sFilesystemServiceProvidersets both every time it boots. Instead, this points Craft's settings at Cloud disks.rebrand: left alone. Core doesn't define it. It reserves the name, and its only reader is the deprecatedcp/rebrand/{type}/{filename}route, which calls->path()andfile_exists(). That only works on a local disk, and Craft 6 has no rebrand upload left to write to S3. Projects should usecpLogoUrl/cpIconUrl, for example pointing at an asset on the CDN.Notes for review
league/flysystem-aws-s3-v3and bumps the lockedcraftcms/cmsfrom6.0.0-alpha.1to6.0.0-alpha.20, which hasuploadSessionDiskand the disk-based volumes. The lock file diff is mostly that bump.craft-clouddisks always usepublic/uploads, whatever theirroot. Only asset disks are registered off Cloud, so this only matters if a project defines its own non-assetcraft-clouddisk locally.CRAFT_CLOUD_PROJECT_IDorCRAFT_CLOUD_ENVIRONMENT_IDon Cloud, resolving acraft-clouddisk throws, instead of writing outside the environment's prefix.CloudServiceProvider. This PR's change there is two lines at the top ofregister().Follow-ups (not in this PR)
invalidateCdnPath()maps to decorating the driver's adapter, but it depends on the purge API.max-ageandvisibilityobject metadata the CDN relies on.expiresis accepted, andcloud:diskswrites it out, but it isn't applied yet.baseUrl, which replaced the whole URL,{env}/assetsincluded. The disk'surlonly replaces the CDN host.Related issues