-
Notifications
You must be signed in to change notification settings - Fork 82
IBX-3766 [CLOUD] Fastly Image Optimizer Integration #1864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ae95fb8
IBX-3766 [CLOUD] Fastly Image Optimizer Integration
MagdalenaZuba 99d76af
Apply suggestions from code review
MagdalenaZuba 7d76e1a
corrections after review
MagdalenaZuba 71fa98b
corrections after review
MagdalenaZuba 0864101
corrections after review
MagdalenaZuba 3d45151
corrections after review
MagdalenaZuba b5df95a
corrections after review
MagdalenaZuba f269dcd
Corrections after review
MagdalenaZuba e0af9e7
Corrections after review
MagdalenaZuba 87b1004
corrections
MagdalenaZuba f764a0b
Apply suggestions from code review
MagdalenaZuba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| --- | ||
| description: Configure Fastly Image Optimiser. | ||
| --- | ||
|
|
||
| # Fastly Image Optimiser (Fastly IO) | ||
|
|
||
| The Fastly Image Optimizer (Fastly IO) is an external service that provides real-time image optimisation for multiple input and output formats. | ||
| It serves and caches image requests from your origin server, making your website faster and more efficient. | ||
|
|
||
| To be able to configure this feature you need: | ||
|
|
||
| - [Platform.sh project](https://docs.platform.sh/guides/ibexa/deploy.html) | ||
| - [Fastly IO subscription](https://docs.fastly.com/en/guides/about-fastly-image-optimizer) | ||
|
|
||
| ## Enable shielding | ||
|
|
||
| To use Fastly Image Optimizer, you need shielding, for more details | ||
| see [Enabling and disabling shielding](https://developer.fastly.com/learning/concepts/shielding/). | ||
|
|
||
| To enable shielding, add [`snippet_re_enable_shielding.vcl`](https://github.com/ibexa/fastly/blob/main/fastly/snippet_re_enable_shielding.vcl) snippet to your config. | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Next, use command below in Fastly CLI: | ||
|
|
||
| ```bash | ||
| - fastly vcl snippet create --name="Re-Enable shielding on restart" --version=active --autoclone --priority 100 --type recv --content=vendor/ibexa/fastly/fastly/snippet_re_enable_shielding.vcl | ||
| - fastly service-version activate --version=latest | ||
| ``` | ||
|
|
||
| ## VCL configuration | ||
|
|
||
| To manipulate your Fastly VCL configuration directly from the command line, | ||
MagdalenaZuba marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| you need to [install Fastly CLI](https://developer.fastly.com/learning/tools/cli#installing) | ||
| and define `FASTLY_SERVICE_ID` and `FASTLY_KEY` environmental variables. | ||
|
|
||
| This is an example VCL snippet uploaded by using `vcl_recv` hook: | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| fastly vcl custom create --name="Ibexa VCL" --main --version=latest --autoclone --content=vendor/ibexa/fastly/fastly/ez_main.vcl | ||
| fastly vcl snippet create --name="Shielding" --version=active --autoclone --type recv --content=vendor/ibexa/fastly/fastly/snippet_re_enable_shielding.vcl | ||
| ``` | ||
|
|
||
| Fastly passes requests through the image optimizer by adding the `x-fastly-imageopto-api` header in `vcl_recv`. | ||
| You need to restrict optimizer by file path and extension to only apply to image requests: | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```vcl | ||
| if (req.url.ext ~ "(?i)^(gif|png|jpe?g|webp)$") { | ||
| if (req.url.path ~ "^/var/([a-zA-Z0-9_-]+)/storage/images") { | ||
| set req.http.x-fastly-imageopto-api = "fastly"; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| You can define what image formats will be included, for example: `gif|png|jpe?g|webp` | ||
| and which paths should be used as a source of images, for example: `^/var/([a-zA-Z0-9_-]+)/storage/images`. For more configuration options, see [Enabling image optimization](https://developer.fastly.com/reference/io/#enabling-image-optimization). | ||
|
|
||
| After you save this snippet or create your own, you can upload it from the command line using: | ||
|
|
||
| ```bash | ||
| fastly vcl snippet create --name="Shielding" --version=active --autoclone --type recv --content=vendor/ibexa/fastly/fastly/snippet_re_enable_shielding.vcl | ||
| ``` | ||
|
|
||
| ## Define SiteAccess for Fastly IO | ||
|
|
||
| Fastly IO configuration is SiteAccess aware. | ||
| You can define what handler should be used for a specific SiteAccess under `variation_handler_identifier`. | ||
| You need to set it up as `fastly`, so Fastly IO can generate all image links. | ||
| By default, it is set as `alias`, and it points to a build in image optimiser. | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```yaml | ||
| ibexa: | ||
| fastly: | ||
| variation_handler_identifier: 'fastly' | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Image configuration | ||
|
|
||
| When you define image variation keys for Fastly IO keep in mind | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| that they should reflect variations in your original setup. | ||
| The built-in image optimiser serves as backup to Fastly IO, | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| and in case of system failure it needs to be able to serve the same image variations. | ||
|
|
||
| Fastly IO image filters are not compatible with our built-in filters, | ||
| because of that you will not be able to reflect your original filters accurately with Fastly. | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The script below will help you find replacement filters within Fastly configuration for the basic filters. | ||
| For more optimization options on Fastly side, see [Fastly IO reference](https://developer.fastly.com/reference/io/). | ||
|
|
||
| To generate your original image configuration run: | ||
|
|
||
| ```bash | ||
| php bin/console ibexa:fastly:migrate-configuration | ||
| ``` | ||
|
|
||
| Paste the configuration to `config/packages/ibexa.yaml` to define the same variations for Fastly IO: | ||
|
|
||
| ```yaml | ||
| system: | ||
MagdalenaZuba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| default: | ||
| fastly_variations: | ||
| reference: | ||
| reference: original | ||
| configuration: | ||
| width: 600 | ||
| height: 600 | ||
| fit: bounds | ||
| small: | ||
| reference: reference | ||
| configuration: | ||
| width: 100 | ||
| height: 100 | ||
| fit: bounds | ||
| tiny: | ||
| reference: reference | ||
| configuration: | ||
| width: 30 | ||
| height: 30 | ||
| fit: bounds | ||
| medium: | ||
| reference: reference | ||
| configuration: | ||
| width: 200 | ||
| height: 200 | ||
| fit: bounds | ||
| large: | ||
| reference: reference | ||
| configuration: | ||
| width: 300 | ||
| height: 300 | ||
| fit: bounds | ||
| gallery: | ||
| reference: original | ||
| configuration: { } | ||
| ezplatform_admin_ui_profile_picture_user_menu: | ||
| reference: reference | ||
| configuration: | ||
| width: 30 | ||
| height: 30 | ||
| fit: bounds | ||
| crop: '30,30,x0,y0' | ||
| ``` | ||
|
|
||
| You can select defined image variations during Content item creation in the image options. | ||
| Variations can include different sizing options and other filters that are applied to the image. | ||
|
|
||
|  | ||
|
|
||
|
|
||
|
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK Fastly IO (and Fastly integration) does not need a Platform.sh project, the site can be hosted somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took these requirements from Platform.sh doc as it was specified as a baseline in the Ibexa feature requirements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add other options if we have any alternatives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be any hosting, even an old computer in the basement - right now it sounds to me as if it's a Platform.sh-only feature