Skip to content

Commit

Permalink
feature #616 [CI] Optimise PR previews deployments by sharing resized…
Browse files Browse the repository at this point in the history
… images (ogizanagi)

This PR was squashed before being merged into the master branch.

Discussion
----------

[CI] Optimise PR previews deployments by sharing resized images

As an attempt to get faster PR preview deployments, by using a single folder of resized images (gh-pages resized/ root folder) ~and symlinks for each PR preview build.~

> [!Important]
> Actually, Github builds the archive during the ["pages build and deployment" by using `--dereference --hard-dereference`](https://github.com/Elao/elao_/actions/runs/9255598295/job/25459719762#step:3:10), so using symlinks does not save us anything regarding the deployment… 😢
>
> ![image](https://github.com/Elao/elao_/assets/2211145/d8f6c055-a0bc-441d-9bd5-354097a8e1c9)
>
> https://github.com/orgs/community/discussions/9104

So, instead, tweaks the app so we can configure the base URL to use for resized images. Hence, we can use relative `../../resized` base path to re-use the staging directory for PR previews (deployed to `/pr/{number}`). 🎉

| Before | After |
| - | - |
|![image](https://github.com/Elao/elao_/assets/2211145/09f5579f-9dfe-4e42-a35d-9810f8b7429f)|![image](https://github.com/Elao/elao_/assets/2211145/dcd01856-64b4-4fd6-9cad-f048d10ef1d7)|

Commits
-------

5da3cd0 Attempt to re-use same folder by changing resized img URL base path to reach parent staging deployment
d9ea5d1 [CI] Optimise PR previews deployments by sharing resized images
  • Loading branch information
ogizanagi committed May 27, 2024
2 parents f85afac + 5da3cd0 commit 7a188aa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/deploy_pr_preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ jobs:
env:
APP_ENV: prod
WEBPACK_PUBLIC_PATH: /elao_/pr/${{ github.event.number }}/build
# Will re-use the staging resized images folder in resized image URLs
GLIDE_RESIZED_URL_BASE_PATH: '../../resized'

- name: 'Build static site'
run: bin/console stenope:build --no-interaction -vv --ansi --ignore-content-not-found
Expand All @@ -85,6 +87,28 @@ jobs:
APP_FORCE_NO_INDEX: 1
APP_GITHUB_REF: ${{ github.head_ref }}
ROUTER_DEFAULT_URI: https://elao.github.io/elao_/pr/${{ github.event.number }}
# Will re-use the staging resized images folder in resized image URLs
GLIDE_RESIZED_URL_BASE_PATH: '../../resized'

- name: 'Deduplicate images'
run: |
# Merge the resized images from PR build folder to the cached folder (`public/resized`)
rsync -a build/resized/ public/resized/
# Remove the build resized images folder
rm -rf build/resized/
- name: '🖼️ Push resized images'
uses: JamesIves/github-pages-deploy-action@v4
with:
commit-message: |
[AUTO] Deploy PR #${{ github.event.number }} images
for commit ${{ github.sha }}
branch: gh-pages
folder: public/resized
target-folder: resized
clean: false # Sync we rsynced the images to merge from all source, we'll never delete anything from here.

# https://github.com/marketplace/actions/deploy-to-github-pages
- name: '🚀 Deploy'
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/deploy_staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,7 @@ jobs:
branch: gh-pages # The branch the action should deploy to.
folder: build # The folder the action should deploy.
clean: true # Automatically remove deleted files from the deploy branch
clean-exclude: 'pr/*' # Don't clean the PR deployments
# Don't clean the PR deployments nor their resized images
clean-exclude: |
pr/*
resized/*
3 changes: 3 additions & 0 deletions config/packages/glide.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
parameters:
glide_public_cache_path_resolved: '%env(string:default:glide_public_cache_path:GLIDE_RESIZED_URL_BASE_PATH)%'

glide:
base_url: /image/resize
source: '%kernel.project_dir%'
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Glide/Bundle/Resources/config/routing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ glide_image_resize:
path: ".+"

glide_image_resized_url:
path: '%glide_public_cache_path%/{path}'
path: '%glide_public_cache_path_resolved%/{path}'
requirements:
path: ".+"

0 comments on commit 7a188aa

Please sign in to comment.