craftcms/cloud

There is no license information available for the latest version (2.0.1) of this package.

Installs: 2 665

Dependents: 4

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 1

Type:yii2-extension

2.0.1 2024-04-24 20:31 UTC

This package is auto-updated.

Last update: 2024-04-24 20:33:05 UTC


README

Craft Cloud icon

Craft Cloud Extension

Welcome to Craft Cloud!

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.

When installed, the extension automatically bootstraps itself and makes necessary application configuration changes for the detected environment:

  • 🌩️ Cloud: There’s no infrastructure settings to worry about—database, queue, cache, and session configuration is handled for you.
  • 💻 Local development: Craft runs normally, in your favorite development environment.

✨ To learn more about Cloud, check out our website—or dive right in with Craft Console. Interested in everything the extension does to get your app ready for Cloud? Read our Cloud extension deep-dive, in the knowledge base.

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 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 a project to Cloud, the cloud/up command will run, wrapping Craft’s built-in up command 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.

Developer Features

Template Helpers

artifactUrl()

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

{# Output a script tag with a build-specific URL: #}
<script src="{{ 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.

isCraftCloud

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

{% if isCraftCloud %}
  Welcome to Cloud!
{% endif %}

Aliases

The following aliases are available, in addition to those provided by Craft.

@web

On Cloud, the @web alias is guaranteed to be the correct environment URL for each HTTP context, whether that be a preview domain or custom domain.

@artifactBaseUrl

Equivalent to artifactUrl(), this allows Project Config 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. These options are provided strictly for reference, and have limited utility outside the platform.

Option Type Description
artifactBaseUrl `string null`
s3ClientOptions array Additional settings to pass to the Aws\S3\S3Client instance when accessing storage APIs.
cdnBaseUrl string Used when building URLs to assets and other build artifacts.
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.
buildId string UUID of the current build.
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`
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.

These options can also be set via environment overrides beginning with CRAFT_CLOUD_.