Reduce runtime of optimize-image script #456
Closed
snedadah
wants to merge 18 commits from
shahanneda/optimze-image-script
into main
pull from: shahanneda/optimze-image-script
merge into: www:main
www:main
www:internship-guide-2
www:nextcloud-widget
www:exec-blurb
www:renovate/typescript-5.x
www:renovate/next-14.x
www:renovate/ical-generator-7.x
www:renovate/date-fns-3.x
www:renovate/typescript-eslint-parser-7.x
www:renovate/typescript-eslint-eslint-plugin-7.x
www:renovate/next-mdx-14.x
www:renovate/mdx-js-react-3.x
www:renovate/mdx-js-loader-3.x
www:renovate/node-18.x
www:Ev-New-Event-Csc-Circles-Easter-Egg-Hunt-March-27-2024-1711581834781
www:Ev-New-Event-Taxes-101-March-27-2024-1711581616630
www:Ev-New-Event-Csc-Circles-Movie-Night-March-27-2024-1711581333300
www:Ev-New-Event-Csc-Codeylympics-Ii-March-27-2024-1711581176020
www:Ev-New-Event-Csc-Trivia-Night-March-27-2024-1711580949130
www:Ev-New-Event-Info-Session-For-Ura-Grad-Opportunities-March-27-2024-1711580809155
www:Ev-New-Event-Internship-Insights-March-27-2024-1711580694779
www:Ev-New-Event-Jason-Goodison-Talk-March-27-2024-1711580404155
www:Ev-New-Event-Test-Event-March-27-2024-1711580239047
www:exec-blurbs
www:internship-guide
www:Ev-New-Event-Valentines-Code-Party-February-11-2024-1707695692668
www:Ev-New-Event-Csc-Codeylympics-February-11-2024-1707695587472
www:Ev-New-Event-Fall-2023-Elections-February-11-2024-1707695274434
www:Ev-New-Event-Csc-End-Of-Term-February-11-2024-1707694525395
www:Ev-New-Event-Csc-Dodgeball-Tournament-February-11-2024-1707694725304
www:Ev-New-Event-November-Code-Party-February-11-2024-1707681589953
www:Ev-New-Event-Trivia-Night-February-08-2024-1707443541421
www:Ev-New-Event-Escape-Mc-Manor-February-08-2024-1707443356540
www:Ev-New-Event-Recruiters-Panel-February-11-2024-1707682002638
www:Ev-New-Event-W24-Bootcamp-February-04-2024-1707084574336
www:Ev-New-Event-David-Wolever-Postgresql-Talk-February-04-2024-1707084327590
www:Ev-New-Event-Csc-Beginning-Of-Term-February-04-2024-1707083704858
www:Ev-New-Event-Csc-Beginning-Of-Term-February-04-2024-1707076757770
www:Ev-New-Event-Escape-Mc-Manor-February-01-2024-1706839752816
www:Ev-New-Event-Csc-Beginning-Of-Term-February-01-2024-1706830083872
www:update-team-page
www:Ev-New-Event-Csc-Beginning-Of-Term-January-22-2024-1705976938370
www:n4chung/update-online-membership-note
www:richard/update-exec-640
www:Ev-New-Event-Build-Networks-In-Tech-November-15-2023-1700094289813
www:Ev-New-Event-Build-Networks-In-Tech-November-15-2023-1700093575650
www:Ev-New-Event-Acing-The-Technical-Interview-W-Icpc-Coach-Christian-Lim-November-15-2023-1700090655704
www:fix-adding-class-profile-to-team-page
www:Ev-New-Event-A-November-06-2023-1699317492840
www:Ev-New-Event-A-November-06-2023-1699317323665
www:Ev-New-Event-A-November-06-2023-1699317144162
www:Ev-New-Event-A-November-06-2023-1699298328549
www:daniel-su/add-myself-to-website
www:renovate/node-21.x
www:Ev-New-Event-A-November-06-2023-1699296715918
www:Ev-New-Event-A-November-06-2023-1699296856594
www:Ev-New-Event-A-November-06-2023-1699297090365
www:Ev-New-Event-Test-November-06-2023-1699295917474
www:Ev-New-Event-Test-November-06-2023-1699296519244
www:renovate/remark-html-16.x
www:renovate/ldapts-7.x
www:renovate/npm-10.x
www:renovate/remark-15.x
www:add-s23-events
www:renovate/eslint-config-prettier-9.x
www:amy-remove-caffeine
www:anniesun/add-office-status
www:renovate/eslint-plugin-prettier-5.x
www:renovate/typescript-eslint-parser-5.x
www:renovate/prettier-3.x
www:renovate/postcss-preset-env-9.x
www:Ev-New-Event-Test-Event-June-17-2023-1687022992622
www:Ev-New-Event-Test-June-10-2023-1686447073380
www:Ev-New-Event-123-June-10-2023-1686446983999
www:Ev-New-Event-123-June-10-2023-1686446849710
www:Ev-New-Event-123-June-10-2023-1686446643513
www:Ev-New-Event-Test-June-10-2023-1686446470699
www:Ev-New-Event-Test-June-10-2023-1686437048471
www:Ev-New-Event-Test-Event-June-10-2023-1686436739371
www:Ev-New-Event-Test-Event-From-Eventr-June-10-2023-1686435846281
www:Ev-New-Event-Test-June-10-2023-1686435577325
www:shahanneda/add-tropical-code-party
www:add-imane-photo
www:Ev-New-Event-123-June-07-2023-1686113292428
www:Ev-New-Event-123-June-07-2023-1686113019308
www:meet-the-team
www:meet-team
www:meet_the_team
www:raymo-s23-updates
www:change_AVP_treasurer
www:jan-2023-constitution-changes
www:renovate/node-20.x
www:renovate/postcss-calc-9.x
www:renovate/react-dom-18.x
www:renovate/react-18.x
www:renovate/fs-extra-11.x
www:renovate/date-fns-tz-2.x
www:renovate/typescript-4.x
www:renovate/next-11.x
www:renovate/squoosh-lib-0.x
www:renovate/next-mdx-remote-3.x
www:renovate/next-mdx-11.x
www:April-Code-Party
www:add-name-to-web-committe
www:shahanneda/alt-tab-and-cp
www:darren/fix-dead-link
www:darren/add-class-profile-news
www:richardshuai/karaoke
www:shahanneda/update-team
www:w23-update-team
www:anniesun/update-blurbs
www:shahanneda/add-code-party-23
www:annies/add-circles-event
www:darren/add-news
www:anniesun/add-myself-to-webstite
www:darren/add-myself-to-website
www:shahanneda/add-myself
www:shahanneda/fix-name-parts
www:shahanneda/add-bot
www:update-events
www:shahanneda/add-events
www:shahanneda/fix-build-image-script
www:amy-add-alt-tab-f22
www:shahanneda/add-alt-tab-news
www:amy-events-karaoke
www:amy-update-annie-headshot-f22
www:amy-update-internship-repo-f22
www:amy-fix-vp-f22
www:amy-add-librarian-f22
www:shahanneda/update-exec-blurbs
www:shahanneda/add-code-party-1
www:shahanneda/update-project-program
www:a258wang-events-2022-09-28
www:amy-news-2022-09-14
www:news-2022-09-10
www:j285he-add-news-09-07
www:news-2022-09-08
www:amy-events-august-2022
www:amy-update-community-reps
www:shahanneda/add-event
www:2022-07-08-MUA-Update
www:amy-image-optimization-quick-fix-experiment
www:b72zhou-past-exec
www:neil-members
www:unix101-1
www:warning-header
www:ldap-exec-test
www:support-multiple-news-homepage
www:j285he-ldap-test-example
www:renovate/typescript-eslint-eslint-plugin-5.x
www:renovate/eslint-plugin-react-7.x
www:renovate/eslint-plugin-prettier-4.x
www:renovate/eslint-8.x
www:shahanneda-news-11jan2022
www:bonnie-team-member-card
www:fix-oc-burger
www:amy-random-shapes
Labels
No Label
a11y
Backlog
Blocked
Bug
Content
Dependencies
Design
Feature Request
Good First Issue
In Progress
Performance
Priority - High
Priority - Low
Priority - Medium
Untriaged
Milestone
Clear milestone
No items
No Milestone
Projects
Clear projects
No project
Assignees
Clear assignees
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.
No due date set.
Dependencies
No dependencies set.
Reference: www/www-new#456
Reference in New Issue
No description provided.
Delete Branch "shahanneda/optimze-image-script"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #441.
Changed optimize-images script to keep track of all the images it has already optimized (through a hash) in a
already-optimized-images.json
file.Removed the public/images folder from gitignore so that optimized images will be tracked.
Added better logging for the script
Fixed issue with script ignoring images that end with ".JPG" (uppercase)
If reviewers want, I can try to revert the images commit so the number of files changed is reduced, however, I don't think its that bad, if you scroll down all the way once and click the "show more" button one time its pretty easy to get to the changed code files.
Usage:
Now, the ideal case is everytime someone adds a new image, they should run
npm run build:images
locally, and commit that.However, if they forgot, that is fine, however, after a while if many images build up and we notice the build time going up again, someone should run
npm run build:images
and commit that to cache the optimized images.staging: https://csclub.uwaterloo.ca/~a3thakra/csc/shahanneda/optimze-image-script/about/team/
in the future, we should consider properly storing images in a cdn
WIP: Reduce runtime of optimize-image scriptto Reduce runtime of optimize-image script@ -0,0 +13,4 @@
import { ImagePool } from "@squoosh/lib";
import fse from "fs-extra";
import { default as getImageDimensions } from "image-size";
import SparkMD5 from "spark-md5";
Probably not very dangerous in this scenario, but we should just avoid md5 altogether since it's a broken hashing algorithm. Use a safer algorithm like sha256. You can use the nodejs builtin crypto library to do so. :)
Oh true, however my reasoning behind using MD5 is that it is one of the fastest hashing algorithms, and I doubt the unsafeness really effects our usecase.
The problem with checking in the public/images folder is that nothing is stopping anyone to add on to that folder.
It would be much better if we could:
public/images
artifact from a previous CI run before optimizing imagespublic/images
artifact and to overwrite the previous oneThis was we are never storing 2x the images in our repo and it avoids all manual work while decreasing build times.
cc @r389li can we setup artifactory or something and add it to drone? https://plugins.drone.io/plugins/artifactory
@a3thakra we definitely don't need Artifactory. What we can do is put the images in
/srv
on Caffeine, and then just link to them using Apache URL rewrites. Let me know if you have other ideas.Pull request closed