From 3a7dd7d458030ec69b97550d73845ebe5739d26f Mon Sep 17 00:00:00 2001 From: shakee93 Date: Tue, 17 Sep 2024 08:57:18 +0530 Subject: [PATCH 01/31] feat: add more visiblity when test mode is turned on --- .../app/page-optimizer/components/Header.tsx | 68 +++++++------- .../components/TestModeSwitcher.tsx | 57 ++++++------ .../src/app/page-optimizer/index.tsx | 88 ++++++++++++++----- .../components/ui/test-mode-notification.tsx | 6 +- 4 files changed, 131 insertions(+), 88 deletions(-) diff --git a/includes/admin/page-optimizer/src/app/page-optimizer/components/Header.tsx b/includes/admin/page-optimizer/src/app/page-optimizer/components/Header.tsx index caf97797b..6a86103d1 100644 --- a/includes/admin/page-optimizer/src/app/page-optimizer/components/Header.tsx +++ b/includes/admin/page-optimizer/src/app/page-optimizer/components/Header.tsx @@ -1,41 +1,43 @@ import { - DevicePhoneMobileIcon} from "@heroicons/react/24/outline"; + DevicePhoneMobileIcon +} from "@heroicons/react/24/outline"; import React from "react"; -import {useAppContext} from "../../../context/app"; +import { useAppContext } from "../../../context/app"; import TooltipText from "components/ui/tooltip-text"; -import {ThunkDispatch} from "redux-thunk"; -import {AppAction, RootState} from "../../../store/app/appTypes"; -import {useDispatch, useSelector} from "react-redux"; -import {changeReport, fetchReport} from "../../../store/app/appActions"; -import {optimizerData} from "../../../store/app/appSelector"; +import { ThunkDispatch } from "redux-thunk"; +import { AppAction, RootState } from "../../../store/app/appTypes"; +import { useDispatch, useSelector } from "react-redux"; +import { changeReport, fetchReport } from "../../../store/app/appActions"; +import { optimizerData } from "../../../store/app/appSelector"; import AppButton from "components/ui/app-button"; -import {cn} from "lib/utils"; +import { cn } from "lib/utils"; import { LogOut, Monitor, - RefreshCw} from "lucide-react"; + RefreshCw +} from "lucide-react"; import useCommonDispatch from "hooks/useCommonDispatch"; -import {AnimatePresence, motion} from "framer-motion"; -import {setCommonState} from "../../../store/common/commonActions"; +import { AnimatePresence, motion } from "framer-motion"; +import { setCommonState } from "../../../store/common/commonActions"; import UnsavedChanges from "app/page-optimizer/components/footer/unsaved-changes"; import UrlPreview from "app/page-optimizer/components/footer/url-preview"; import SaveChanges from "app/page-optimizer/components/footer/save-changes"; -import {useRootContext} from "../../../context/root"; +import { useRootContext } from "../../../context/root"; -const Header = ({ url }: { url: string}) => { +const Header = ({ url }: { url: string }) => { const { - setShowOptimizer , + setShowOptimizer, options, version, } = useAppContext() const { activeReport, - loading, + loading, testMode, reanalyze } = useSelector(optimizerData); - const {inProgress } = useCommonDispatch() + const { inProgress } = useCommonDispatch() const { dispatch: commonDispatch } = useCommonDispatch() @@ -43,7 +45,7 @@ const Header = ({ url }: { url: string}) => { const dispatch: ThunkDispatch = useDispatch(); const { isDark } = useRootContext(); - + return ( @@ -72,7 +74,7 @@ const Header = ({ url }: { url: string}) => {
+ className='select-none relative flex dark:bg-brand-800 py-0.5 bg-brand-200/80 rounded-2xl cursor-pointer'>
{
dispatch(changeReport('mobile'))} - className={`relative z-1 text-sm flex flex-column gap-2 px-5 py-3 font-medium rounded-2xl`}> - + className={`relative z-1 text-sm flex flex-column gap-2 px-5 py-3 font-medium rounded-2xl`}> +
dispatch(changeReport('desktop'))} - className={`relative z-1 text-sm flex flex-column gap-2 pl-2 px-5 py-3 font-medium rounded-2xl`}> - + className={`relative z-1 text-sm flex flex-column gap-2 pl-2 px-5 py-3 font-medium rounded-2xl`}> +
- + { text='Analyze the page'> + className={cn( + 'transition-none rounded-none h-12 px-3 pr-3.5 ' + + 'border-r-0 border-l border-t-0 border-b-0 bg-transparent ', + )} + variant='outline'>
+ )} /> Analyze
@@ -139,7 +141,7 @@ const Header = ({ url }: { url: string}) => {
<> - + { setShowOptimizer(false) @@ -151,7 +153,7 @@ const Header = ({ url }: { url: string}) => { + )} /> @@ -168,9 +170,9 @@ const Header = ({ url }: { url: string}) => { ease: 'easeInOut', duration: 0.5, }} - className="z-[100000] w-full text-[13px] bg-[#D9CAEB] items-center text-center py-0.5 top-[74px] absolute dark:bg-brand-950" + className="z-[100000] w-full text-[13px] bg-[#f7b250] items-center text-center py-0.5 top-[74px] absolute dark:bg-brand-950" > - Test Mode turned on, + Test Mode turned on, optimizations are safely previewed without affecting your live website. Perfect for experimentation and fine-tuning. )} diff --git a/includes/admin/page-optimizer/src/app/page-optimizer/components/TestModeSwitcher.tsx b/includes/admin/page-optimizer/src/app/page-optimizer/components/TestModeSwitcher.tsx index a03a898ca..17637f2ac 100644 --- a/includes/admin/page-optimizer/src/app/page-optimizer/components/TestModeSwitcher.tsx +++ b/includes/admin/page-optimizer/src/app/page-optimizer/components/TestModeSwitcher.tsx @@ -1,25 +1,25 @@ import { m } from "framer-motion"; -import React, {useEffect, useState} from "react"; -import {useSelector} from "react-redux"; -import {setCommonState} from "../../../store/common/commonActions"; +import React, { useEffect, useState } from "react"; +import { useSelector } from "react-redux"; +import { setCommonState } from "../../../store/common/commonActions"; import TooltipText from "components/ui/tooltip-text"; -import {Circle, Loader} from "lucide-react"; -import {ArrowTopRightOnSquareIcon} from "@heroicons/react/24/outline"; -import {TestModeLine} from "app/page-optimizer/components/icons/line-icons"; +import { Circle, Loader } from "lucide-react"; +import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline"; +import { TestModeLine } from "app/page-optimizer/components/icons/line-icons"; import useCommonDispatch from "hooks/useCommonDispatch"; -import {useTestModeUtils} from "hooks/testModeUtils"; -import {useAppContext} from "../../../context/app"; -import {optimizerData} from "../../../store/app/appSelector"; -import {cn} from "lib/utils"; +import { useTestModeUtils } from "hooks/testModeUtils"; +import { useAppContext } from "../../../context/app"; +import { optimizerData } from "../../../store/app/appSelector"; +import { cn } from "lib/utils"; const TestModeSwitcher = () => { - const {testMode} = useSelector(optimizerData); + const { testMode } = useSelector(optimizerData); const [loadingStatus, setLoadingStatus] = useState(false); - const {testModeStatus, testModeLoading, dispatch} = useCommonDispatch(); - const {handleTestModeSwitchChange} = useTestModeUtils(); - const {options} = useAppContext(); - const { revisions} = useSelector(optimizerData); + const { testModeStatus, testModeLoading, dispatch } = useCommonDispatch(); + const { handleTestModeSwitchChange } = useTestModeUtils(); + const { options } = useAppContext(); + const { revisions } = useSelector(optimizerData); useEffect(() => { if (testMode) { @@ -41,7 +41,7 @@ const TestModeSwitcher = () => {
+ className='select-none relative flex dark:bg-brand-800 py-0.5 pl-[2px] pr-[4px] rounded-2xl cursor-pointer bg-brand-0'> {/*
{
{ className={`relative z-1 items-center text-sm flex gap-2 px-3 py-2.5 font-medium rounded-2xl ${testMode ? 'text-brand-500' : ''}`} > + className={cn(`w-1.5 stroke-0 ${testMode ? 'fill-brand-300' : 'fill-green-600'} animate-ping absolute inline-flex opacity-75`)} /> + className={cn(`w-1.5 stroke-0 ${testMode ? 'fill-brand-300' : 'fill-green-600'} relative inline-flex`)} /> Live
@@ -79,7 +79,7 @@ const TestModeSwitcher = () => { await handleSwitchChange(true); } }} - className={`relative justify-center items-center z-1 text-sm flex pl-6 pr-5 py-2.5 whitespace-nowrap font-medium rounded-2xl ${testMode ? 'text-brand-0' : 'text-brand-500'}`} + className={`relative justify-center items-center z-1 text-sm flex pl-6 pr-5 py-2.5 whitespace-nowrap font-medium rounded-2xl ${testMode ? 'text-brand-500' : 'text-brand-500'}`} > Test Mode
@@ -94,17 +94,16 @@ const TestModeSwitcher = () => { } }} - className={`flex gap-2 items-center text-sm h-12 rounded-[14px] bg-brand-0 dark:bg-brand-930/90 px-4 py-2 ${ - revisions?.length > 0 - ? '' : ''}`} data-tour="preview-button"> + className={`flex gap-2 items-center text-sm h-12 rounded-[14px] bg-brand-0 dark:bg-brand-930/90 px-4 py-2 ${revisions?.length > 0 + ? '' : ''}`} data-tour="preview-button"> - {loadingStatus ? : - } + {loadingStatus ? : + }
- +
} diff --git a/includes/admin/page-optimizer/src/app/page-optimizer/index.tsx b/includes/admin/page-optimizer/src/app/page-optimizer/index.tsx index 67ea90797..213c6ba79 100644 --- a/includes/admin/page-optimizer/src/app/page-optimizer/index.tsx +++ b/includes/admin/page-optimizer/src/app/page-optimizer/index.tsx @@ -1,16 +1,16 @@ -import React, {Dispatch, SetStateAction, useEffect, useRef, useState, lazy} from "react"; +import React, { Dispatch, SetStateAction, useEffect, useRef, useState, lazy } from "react"; import Header from "app/page-optimizer/components/Header"; import PageSpeedScore from "app/page-optimizer/components/performance-widgets/PageSpeedScore"; -import {useSelector} from "react-redux"; -import {useAppContext} from "../../context/app"; -import {cn} from "lib/utils"; +import { useSelector } from "react-redux"; +import { useAppContext } from "../../context/app"; +import { cn } from "lib/utils"; import Loading from "components/loading"; import OptimizerInProgress from "components/optimizer-in-progress"; -import {optimizerData} from "../../store/app/appSelector"; +import { optimizerData } from "../../store/app/appSelector"; import { Loader } from "lucide-react"; -import {m, AnimatePresence} from "framer-motion"; -import {Toaster} from "components/ui/toaster"; +import { m, AnimatePresence } from "framer-motion"; +import { Toaster } from "components/ui/toaster"; import usePerformanceColors from "hooks/usePerformanceColors"; import Performance from "app/page-optimizer/spaces/Performance"; import SpeedIndex from "app/page-optimizer/spaces/Metrics"; @@ -24,7 +24,7 @@ export interface AuditComponentRef { } export default function PageOptimizer() { - const {data, loading, error} = useSelector(optimizerData); + const { data, loading, error, testMode } = useSelector(optimizerData); const [performanceIcon, progressbarColor, progressbarBg] = usePerformanceColors(data?.performance); const { dispatch, activeMetric } = useCommonDispatch() @@ -42,7 +42,7 @@ export default function PageOptimizer() { useEffect(() => { if (savingData) { - const content = document.getElementById('rapidload-page-optimizer-content'); + const content = document.getElementById('rapidload-page-optimizer-content'); content?.scrollTo(0, 0) } @@ -57,7 +57,7 @@ export default function PageOptimizer() { transition={{ ease: 'linear', duration: 0.04, - }} + }} id='rapidload-page-optimizer-wrapper' translate="no" className={cn( @@ -66,42 +66,84 @@ export default function PageOptimizer() { "notranslate" )}> -
+ + {testMode && + +
+ } + + + +
+ 'overflow-y-auto scrollbar-stable w-full h-fit pb-20 -mt-[70px] ', + 'dark:bg-brand-900 bg-brand-200/60 min-h-screen', + savingData && 'relative overflow-hidden', + + )}>
{(savingData || invalidatingCache) && (
- + {savingData && 'Saving Changes...'} {invalidatingCache && 'Flushing Cache...'}
)} +
+ {/* + {testMode && ( + + Test Mode Activated + + optimizations are safely previewed without affecting your live website. Perfect for experimentation and fine-tuning. + + + )} + */} +
<> + {togglePerformance && ( )} @@ -111,10 +153,10 @@ export default function PageOptimizer() { {activeMetric ? ( - + ) : ( - + )} @@ -123,7 +165,7 @@ export default function PageOptimizer() {
- + ); } diff --git a/includes/admin/page-optimizer/src/components/ui/test-mode-notification.tsx b/includes/admin/page-optimizer/src/components/ui/test-mode-notification.tsx index fdd958a97..972ef0ea5 100644 --- a/includes/admin/page-optimizer/src/components/ui/test-mode-notification.tsx +++ b/includes/admin/page-optimizer/src/components/ui/test-mode-notification.tsx @@ -27,9 +27,9 @@ function TestModeNotification() { transition={{ ease: "linear", duration: 0.5 }} className="z-[110000] w-full text-sm bg-purple-700/30 items-center text-center py-2" > - - Test Mode turned on, - {" "} + + Test Mode turned on, + {" "} optimizations are safely previewed without affecting your live website. Perfect for experimentation and fine-tuning. From b8487ac209aed185ec74556690567b3349cecf5d Mon Sep 17 00:00:00 2001 From: shakeeb Date: Tue, 17 Sep 2024 14:00:00 +0530 Subject: [PATCH 02/31] update readme text --- readme.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.txt b/readme.txt index 2d494d7dd..f1ad466f7 100644 --- a/readme.txt +++ b/readme.txt @@ -155,6 +155,8 @@ RapidLoad accepts both broad and star(*) expressions and regular expression excl == Changelog == += 2.3.4 - 17/09/2024 = + = 2.3.3 - 12/09/2024 = * fix: Missing `@media` styles in chunked critical CSS files. From abed5feec7c0fc0265d1bd084dd6bb003661d17c Mon Sep 17 00:00:00 2001 From: shakee93 Date: Tue, 17 Sep 2024 14:20:44 +0530 Subject: [PATCH 03/31] feat: minor refinement in the UI --- .../app/page-optimizer/components/Header.tsx | 32 +++++++++---------- .../src/app/page-optimizer/index.tsx | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/includes/admin/page-optimizer/src/app/page-optimizer/components/Header.tsx b/includes/admin/page-optimizer/src/app/page-optimizer/components/Header.tsx index 6a86103d1..9c5848a6e 100644 --- a/includes/admin/page-optimizer/src/app/page-optimizer/components/Header.tsx +++ b/includes/admin/page-optimizer/src/app/page-optimizer/components/Header.tsx @@ -161,22 +161,22 @@ const Header = ({ url }: { url: string }) => {
- {testMode && ( - - Test Mode turned on, - optimizations are safely previewed without affecting your live website. Perfect for experimentation and fine-tuning. - - )} - + {testMode && ( + + Test Mode turned on, + optimizations are safely previewed without affecting your live website. Perfect for experimentation and fine-tuning. + + )} + ) } diff --git a/includes/admin/page-optimizer/src/app/page-optimizer/index.tsx b/includes/admin/page-optimizer/src/app/page-optimizer/index.tsx index 213c6ba79..088d995df 100644 --- a/includes/admin/page-optimizer/src/app/page-optimizer/index.tsx +++ b/includes/admin/page-optimizer/src/app/page-optimizer/index.tsx @@ -70,7 +70,7 @@ export default function PageOptimizer() { {testMode &&
} From d98d234dae9d8f7585b85cd978e7f7c3e8147202 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Tue, 17 Sep 2024 17:03:42 +0530 Subject: [PATCH 04/31] feat: minify google fonts inline style --- includes/modules/font/RapidLoad_Font_Enqueue.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/modules/font/RapidLoad_Font_Enqueue.php b/includes/modules/font/RapidLoad_Font_Enqueue.php index 7a6d59efd..8727c6d19 100644 --- a/includes/modules/font/RapidLoad_Font_Enqueue.php +++ b/includes/modules/font/RapidLoad_Font_Enqueue.php @@ -174,7 +174,9 @@ public function self_host_google_fonts(){ if($this->font_handler){ $content = $this->font_handler->add_display_swap_to_inline_styles($content); } - $inline_style_content = sprintf('', $version, $content); + $minifier = new \MatthiasMullie\Minify\CSS(); + $minifier->add($content); + $inline_style_content = sprintf('', $version, $minifier->minify()); $title_content = $this->dom->find( 'title' )[0]->outertext; $this->dom->find( 'title' )[0]->outertext = $title_content . $inline_style_content; }else{ From 5818d1903e240e5fa486a7e713c4d10ab3228456 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Wed, 18 Sep 2024 12:37:17 +0530 Subject: [PATCH 05/31] test permissions --- unusedcss.php | 1 - 1 file changed, 1 deletion(-) diff --git a/unusedcss.php b/unusedcss.php index dedeeef57..3dfee913e 100644 --- a/unusedcss.php +++ b/unusedcss.php @@ -8,7 +8,6 @@ Author URI: https://rapidload.io/ */ - if ( ! defined( 'ABSPATH' ) ) { exit; } From 0e22dedd7a6e73889e28b4ddf183e5ffa6a3b58b Mon Sep 17 00:00:00 2001 From: shakeeb Date: Wed, 18 Sep 2024 12:49:51 +0530 Subject: [PATCH 06/31] update permission for cache folder too --- .../workflows/deploy-wordpress-plugin-preview-lightsail.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 54e0b954a..3543c2332 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -204,7 +204,7 @@ jobs: EOF - name: Set up environment and grant permissions - if: ${{ github.event.action == 'opened' }} + #if: ${{ github.event.action == 'opened' }} run: | ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF set -x @@ -214,6 +214,9 @@ jobs: # Grant 666 permissions to wp-config.php sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" + + # Grant 777 permissions to cache folder (or specify desired permission level) + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod -R 777 /bitnami/wordpress/wp-content/cache" EOF - name: Update domain in wp-config.php From fbb30bc10d723eaddd321e0807b9915aaa3c87b7 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Wed, 18 Sep 2024 13:11:18 +0530 Subject: [PATCH 07/31] update permission for cache folder too --- .github/workflows/deploy-wordpress-plugin-preview-lightsail.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 3543c2332..0143e0393 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -204,7 +204,7 @@ jobs: EOF - name: Set up environment and grant permissions - #if: ${{ github.event.action == 'opened' }} + if: ${{ github.event.action == 'opened' }} run: | ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF set -x From 51f50f5a9343c54e96d80043e77a05ff32106a49 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Wed, 18 Sep 2024 13:15:40 +0530 Subject: [PATCH 08/31] update permission for cache folder too --- .../deploy-wordpress-plugin-preview-lightsail.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 0143e0393..417e5a4f6 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -204,7 +204,7 @@ jobs: EOF - name: Set up environment and grant permissions - if: ${{ github.event.action == 'opened' }} + #if: ${{ github.event.action == 'opened' }} run: | ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF set -x @@ -212,11 +212,8 @@ jobs: DOMAIN="pr-${INSTANCE_ID}.rapidload.live" WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") - # Grant 666 permissions to wp-config.php - sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" - - # Grant 777 permissions to cache folder (or specify desired permission level) - sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod -R 777 /bitnami/wordpress/wp-content/cache" + # Grant 666 permissions to wp-config.php to cache folder + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php && chmod -R 777 /bitnami/wordpress/wp-content/cache" EOF - name: Update domain in wp-config.php From f09fe710d59f17c1c8fe4ce98d22c36529758c59 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Wed, 18 Sep 2024 13:47:26 +0530 Subject: [PATCH 09/31] rollback update permission for cache folder --- .../workflows/deploy-wordpress-plugin-preview-lightsail.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 417e5a4f6..77d9f6f9b 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -204,7 +204,7 @@ jobs: EOF - name: Set up environment and grant permissions - #if: ${{ github.event.action == 'opened' }} + if: ${{ github.event.action == 'opened' }} run: | ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF set -x @@ -213,7 +213,7 @@ jobs: WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") # Grant 666 permissions to wp-config.php to cache folder - sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php && chmod -R 777 /bitnami/wordpress/wp-content/cache" + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" EOF - name: Update domain in wp-config.php From 2b9c86e56bd8232a889d277e28002145c155cb55 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Wed, 18 Sep 2024 13:53:33 +0530 Subject: [PATCH 10/31] update permission --- .github/workflows/deploy-wordpress-plugin-preview-lightsail.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 77d9f6f9b..2a304aeba 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -213,7 +213,7 @@ jobs: WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") # Grant 666 permissions to wp-config.php to cache folder - sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php && chmod 666 /bitnami/wordpress/wp-content" EOF - name: Update domain in wp-config.php From 38435bb8d16ce53abad375930bc4a3fd37bbd10b Mon Sep 17 00:00:00 2001 From: shakeeb Date: Wed, 18 Sep 2024 16:58:33 +0530 Subject: [PATCH 11/31] update permission --- unusedcss.php | 1 + 1 file changed, 1 insertion(+) diff --git a/unusedcss.php b/unusedcss.php index 3dfee913e..dedeeef57 100644 --- a/unusedcss.php +++ b/unusedcss.php @@ -8,6 +8,7 @@ Author URI: https://rapidload.io/ */ + if ( ! defined( 'ABSPATH' ) ) { exit; } From 4c97332bcb95f099e464d87fac1cd0abfc174b98 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Wed, 18 Sep 2024 17:33:38 +0530 Subject: [PATCH 12/31] remove permission update clause --- .github/workflows/deploy-wordpress-plugin-preview-lightsail.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 2a304aeba..77d9f6f9b 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -213,7 +213,7 @@ jobs: WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") # Grant 666 permissions to wp-config.php to cache folder - sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php && chmod 666 /bitnami/wordpress/wp-content" + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" EOF - name: Update domain in wp-config.php From 2b9cfec643bbcdde8900a926b7912420ac6281e6 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 09:39:12 +0530 Subject: [PATCH 13/31] update file permission --- includes/RapidLoad_FileSystem.php | 2 +- includes/modules/cache/RapidLoad_Cache_Store.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/RapidLoad_FileSystem.php b/includes/RapidLoad_FileSystem.php index 0498b1919..910da26a1 100644 --- a/includes/RapidLoad_FileSystem.php +++ b/includes/RapidLoad_FileSystem.php @@ -7,7 +7,7 @@ class RapidLoad_FileSystem { - public function put_contents( $file_location, $css , $mode = null){ + public function put_contents( $file_location, $css , $mode = 0755){ return @file_put_contents($file_location, $css, $mode); } diff --git a/includes/modules/cache/RapidLoad_Cache_Store.php b/includes/modules/cache/RapidLoad_Cache_Store.php index 31b34811a..0a1357dab 100644 --- a/includes/modules/cache/RapidLoad_Cache_Store.php +++ b/includes/modules/cache/RapidLoad_Cache_Store.php @@ -991,7 +991,7 @@ private static function create_cache_file( $page_contents ) { return; } - $new_cache_file_created = file_put_contents( $new_cache_file, $page_contents, LOCK_EX ); + $new_cache_file_created = file_put_contents( $new_cache_file, $page_contents, 0755 ); if ( $new_cache_file_created !== false ) { clearstatcache(); From 06fd7c8d43621091582b4030acd8f60a97c51203 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 09:41:14 +0530 Subject: [PATCH 14/31] update file permission --- includes/RapidLoad_FileSystem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/RapidLoad_FileSystem.php b/includes/RapidLoad_FileSystem.php index 910da26a1..264606244 100644 --- a/includes/RapidLoad_FileSystem.php +++ b/includes/RapidLoad_FileSystem.php @@ -8,7 +8,7 @@ class RapidLoad_FileSystem { public function put_contents( $file_location, $css , $mode = 0755){ - return @file_put_contents($file_location, $css, $mode); + return @file_put_contents($file_location, $css, 0755); } public function exists( $dir ){ From d579de3648cc8685224e8035079c1c9f38c0775b Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 10:36:50 +0530 Subject: [PATCH 15/31] remove set wp-config.php permission step --- ...loy-wordpress-plugin-preview-lightsail.yml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 77d9f6f9b..cc0729238 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -203,18 +203,18 @@ jobs: sudo docker-compose -f /home/bitnami/wp-\${INSTANCE_ID}/docker-compose.yml logs wordpress EOF - - name: Set up environment and grant permissions - if: ${{ github.event.action == 'opened' }} - run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF - set -x - INSTANCE_ID=${{ github.event.number }} - DOMAIN="pr-${INSTANCE_ID}.rapidload.live" - WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + #- name: Set up environment and grant permissions + #if: ${{ github.event.action == 'opened' }} + #run: | + #ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF + #set -x + #INSTANCE_ID=${{ github.event.number }} + #DOMAIN="pr-${INSTANCE_ID}.rapidload.live" + #WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") # Grant 666 permissions to wp-config.php to cache folder - sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" - EOF + #sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" + #EOF - name: Update domain in wp-config.php if: ${{ github.event.action == 'opened' }} From be29de25742aa6ec4d75af77347524a7ef8987cb Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 10:55:05 +0530 Subject: [PATCH 16/31] rollback remove set wp-config.php permission step --- ...loy-wordpress-plugin-preview-lightsail.yml | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index cc0729238..77d9f6f9b 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -203,18 +203,18 @@ jobs: sudo docker-compose -f /home/bitnami/wp-\${INSTANCE_ID}/docker-compose.yml logs wordpress EOF - #- name: Set up environment and grant permissions - #if: ${{ github.event.action == 'opened' }} - #run: | - #ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF - #set -x - #INSTANCE_ID=${{ github.event.number }} - #DOMAIN="pr-${INSTANCE_ID}.rapidload.live" - #WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + - name: Set up environment and grant permissions + if: ${{ github.event.action == 'opened' }} + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF + set -x + INSTANCE_ID=${{ github.event.number }} + DOMAIN="pr-${INSTANCE_ID}.rapidload.live" + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") # Grant 666 permissions to wp-config.php to cache folder - #sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" - #EOF + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" + EOF - name: Update domain in wp-config.php if: ${{ github.event.action == 'opened' }} From 2897de5550e9c30e76f78d4bac6edff95c6eed0c Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 10:57:36 +0530 Subject: [PATCH 17/31] update cache folder permission --- .../deploy-wordpress-plugin-preview-lightsail.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 77d9f6f9b..5c9a2692d 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -216,6 +216,19 @@ jobs: sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" EOF + - name: Create cache folder and grant 777 permissions + if: ${{ github.event.action == 'opened' }} + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa bitnami@${{ secrets.SSH_HOST }} << EOF + set -x + INSTANCE_ID=${{ github.event.number }} + DOMAIN="pr-${INSTANCE_ID}.rapidload.live" + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + + # Create cache folder if it doesn't exist and grant 777 permissions + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "if [ ! -d /bitnami/wordpress/wp-content/cache ]; then mkdir -p /bitnami/wordpress/wp-content/cache; fi && chmod -R 777 /bitnami/wordpress/wp-content/cache" + EOF + - name: Update domain in wp-config.php if: ${{ github.event.action == 'opened' }} run: | From 9056ebe8a29e76db5d8026ae67ecda193dc74fbd Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 11:31:44 +0530 Subject: [PATCH 18/31] test rapidload cache store on directory creation --- includes/modules/cache/RapidLoad_Cache_Store.php | 6 +++--- includes/modules/css/critical-css/CriticalCSS.php | 3 ++- includes/modules/css/minify-css/MinifyCSS.php | 2 +- includes/modules/css/unused-css/UnusedCSS.php | 2 +- includes/modules/font/RapidLoad_Font.php | 2 +- includes/modules/javascript/JavaScript.php | 2 +- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/includes/modules/cache/RapidLoad_Cache_Store.php b/includes/modules/cache/RapidLoad_Cache_Store.php index 0a1357dab..0ab9c2a4d 100644 --- a/includes/modules/cache/RapidLoad_Cache_Store.php +++ b/includes/modules/cache/RapidLoad_Cache_Store.php @@ -730,7 +730,7 @@ public static function create_settings_file( $settings ) { return ( $new_settings_file_created === false ) ? false : $new_settings_file; } - private static function mkdir_p( $dir ) { + public static function mkdir_p( $dir ) { $mode_octal = (int) apply_filters( 'rapidload_mkdir_mode', 0755 ); $mode_string = decoct( $mode_octal ); // Get the last three digits (e.g. '755'). @@ -742,7 +742,7 @@ private static function mkdir_p( $dir ) { } // Directory validation - $valid = false; + /*$valid = false; if ( ! empty( RAPIDLOAD_CACHE_DIR ) && strpos( $dir, RAPIDLOAD_CACHE_DIR ) === 0 ) { $valid = true; } @@ -751,7 +751,7 @@ private static function mkdir_p( $dir ) { } if ( ! $valid || strpos( $dir, '../' ) !== false ) { return false; - } + }*/ if ( ! wp_mkdir_p( $dir ) ) { return false; diff --git a/includes/modules/css/critical-css/CriticalCSS.php b/includes/modules/css/critical-css/CriticalCSS.php index 414bd64bd..0eb2f61d1 100644 --- a/includes/modules/css/critical-css/CriticalCSS.php +++ b/includes/modules/css/critical-css/CriticalCSS.php @@ -419,7 +419,8 @@ public function init_base_dir() { } // make dir if not exists - $created = $this->file_system->mkdir( self::$base_dir ); + //$created = $this->file_system->mkdir( self::$base_dir ); + $created = RapidLoad_Cache_Store::mkdir_p( self::$base_dir ); if (!$created || ! $this->file_system->is_writable( self::$base_dir ) || ! $this->file_system->is_readable( self::$base_dir ) ) { return false; diff --git a/includes/modules/css/minify-css/MinifyCSS.php b/includes/modules/css/minify-css/MinifyCSS.php index e190798d8..0b434a69d 100644 --- a/includes/modules/css/minify-css/MinifyCSS.php +++ b/includes/modules/css/minify-css/MinifyCSS.php @@ -110,7 +110,7 @@ public function init_base_dir() { } // make dir if not exists - $created = $this->file_system->mkdir( self::$base_dir ); + $created = RapidLoad_Cache_Store::mkdir_p( self::$base_dir ); if (!$created || ! $this->file_system->is_writable( self::$base_dir ) || ! $this->file_system->is_readable( self::$base_dir ) ) { return false; diff --git a/includes/modules/css/unused-css/UnusedCSS.php b/includes/modules/css/unused-css/UnusedCSS.php index b2f4f0ca5..cd4064b09 100644 --- a/includes/modules/css/unused-css/UnusedCSS.php +++ b/includes/modules/css/unused-css/UnusedCSS.php @@ -596,7 +596,7 @@ public function init_base_dir() { } // make dir if not exists - $created = $this->file_system->mkdir( self::$base_dir ); + $created = RapidLoad_Cache_Store::mkdir_p( self::$base_dir ); if (!$created || ! $this->file_system->is_writable( self::$base_dir ) || ! $this->file_system->is_readable( self::$base_dir ) ) { return false; diff --git a/includes/modules/font/RapidLoad_Font.php b/includes/modules/font/RapidLoad_Font.php index ff174ca81..2eec00459 100644 --- a/includes/modules/font/RapidLoad_Font.php +++ b/includes/modules/font/RapidLoad_Font.php @@ -144,7 +144,7 @@ public function init_base_dir() { } // make dir if not exists - $created = $this->file_system->mkdir( self::$base_dir ); + $created = RapidLoad_Cache_Store::mkdir_p( self::$base_dir ); if (!$created || ! $this->file_system->is_writable( self::$base_dir ) || ! $this->file_system->is_readable( self::$base_dir ) ) { return false; diff --git a/includes/modules/javascript/JavaScript.php b/includes/modules/javascript/JavaScript.php index dd22e9767..197c6c00c 100644 --- a/includes/modules/javascript/JavaScript.php +++ b/includes/modules/javascript/JavaScript.php @@ -113,7 +113,7 @@ public function init_base_dir() { } // make dir if not exists - $created = $this->file_system->mkdir( self::$base_dir ); + $created = RapidLoad_Cache_Store::mkdir_p( self::$base_dir ); if (!$created || ! $this->file_system->is_writable( self::$base_dir ) || ! $this->file_system->is_readable( self::$base_dir ) ) { return false; From b84aa4f924639d82f60a7238755c290e302b3858 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 11:44:17 +0530 Subject: [PATCH 19/31] fix directory validation --- includes/modules/cache/RapidLoad_Cache_Store.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/modules/cache/RapidLoad_Cache_Store.php b/includes/modules/cache/RapidLoad_Cache_Store.php index 0ab9c2a4d..4368c5ad0 100644 --- a/includes/modules/cache/RapidLoad_Cache_Store.php +++ b/includes/modules/cache/RapidLoad_Cache_Store.php @@ -748,10 +748,10 @@ public static function mkdir_p( $dir ) { } if ( ! empty( RAPIDLOAD_SETTINGS_DIR ) && strpos( $dir, RAPIDLOAD_SETTINGS_DIR ) === 0 ) { $valid = true; - } - if ( ! $valid || strpos( $dir, '../' ) !== false ) { - return false; }*/ + if ( strpos( $dir, '../' ) !== false ) { + return false; + } if ( ! wp_mkdir_p( $dir ) ) { return false; From f4f7d44243e9b65b88a1b8d045a0473371171f13 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 12:17:32 +0530 Subject: [PATCH 20/31] update preload images when fetching page speed --- .../modules/optimizer/RapidLoad_Optimizer.php | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/includes/modules/optimizer/RapidLoad_Optimizer.php b/includes/modules/optimizer/RapidLoad_Optimizer.php index 115f8d0e4..e3dbb8e75 100644 --- a/includes/modules/optimizer/RapidLoad_Optimizer.php +++ b/includes/modules/optimizer/RapidLoad_Optimizer.php @@ -399,31 +399,6 @@ public static function post_optimizer_function($data){ } - $preload_images = []; - - if (isset($data->audits) && is_array($data->audits)) { - - $lcp_audit = array_filter($data->audits, function($audit) { - return $audit->id === 'prioritize-lcp-image'; - }); - - if (!empty($lcp_audit)) { - $lcp_audit = reset($lcp_audit); - - if (isset($lcp_audit->files) && isset($lcp_audit->files->debugData) && !empty($lcp_audit->files->debugData->initiatorPath)) { - foreach ($lcp_audit->files->debugData->initiatorPath as $path) { - if (isset($path->url) && preg_match('/\.(jpg|jpeg|jpg|png|gif)$/i', $path->url)) { - $preload_images[] = $path->url; - } - } - } - } - } - - if(!empty($preload_images)){ - self::$options['uucss_preload_lcp_image'] = implode("\n",$preload_images); - } - if(self::$strategy == "desktop"){ self::$job->set_desktop_options(self::$options); }else{ @@ -566,6 +541,38 @@ public function fetch_page_speed($url, $result){ $optimization->save(); } + $preload_images = []; + + if (isset($result->audits) && is_array($result->audits)) { + + $lcp_audit = array_filter($result->audits, function($audit) { + return $audit->id === 'prioritize-lcp-image'; + }); + + if (!empty($lcp_audit)) { + $lcp_audit = reset($lcp_audit); + + if (isset($lcp_audit->files) && isset($lcp_audit->files->debugData) && !empty($lcp_audit->files->debugData->initiatorPath)) { + foreach ($lcp_audit->files->debugData->initiatorPath as $path) { + if (isset($path->url) && preg_match('/\.(jpg|jpeg|jpg|png|gif)$/i', $path->url)) { + $preload_images[] = $path->url; + } + } + } + } + } + + if(!empty($preload_images)){ + self::$options['uucss_preload_lcp_image'] = implode("\n",$preload_images); + if(self::$strategy == "desktop"){ + self::$job->set_desktop_options(self::$options); + self::$job->save(); + }else{ + self::$job->set_mobile_options(self::$options); + self::$job->save(); + } + } + return[ 'url' => $url, 'success' => true, @@ -1285,10 +1292,6 @@ public function optimizer_update_settings($result, $general_settings = null){ unset(self::$options['uucss_enable_image_delivery']); } - if(!empty($preload_images)){ - self::$options['uucss_preload_lcp_image'] = implode("\n",$preload_images); - } - if(isset(self::$options['uucss_self_host_google_fonts']) && self::$options['uucss_self_host_google_fonts'] == "1"){ self::$options['uucss_enable_font_optimization'] = "1"; }else{ From 1a539b83f5eea3fdd9236d8f9be60dbfb767bd5b Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 16:32:49 +0530 Subject: [PATCH 21/31] clear comments --- includes/modules/cache/RapidLoad_Cache_Store.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/includes/modules/cache/RapidLoad_Cache_Store.php b/includes/modules/cache/RapidLoad_Cache_Store.php index 4368c5ad0..bdc586352 100644 --- a/includes/modules/cache/RapidLoad_Cache_Store.php +++ b/includes/modules/cache/RapidLoad_Cache_Store.php @@ -741,14 +741,6 @@ public static function mkdir_p( $dir ) { return true; } - // Directory validation - /*$valid = false; - if ( ! empty( RAPIDLOAD_CACHE_DIR ) && strpos( $dir, RAPIDLOAD_CACHE_DIR ) === 0 ) { - $valid = true; - } - if ( ! empty( RAPIDLOAD_SETTINGS_DIR ) && strpos( $dir, RAPIDLOAD_SETTINGS_DIR ) === 0 ) { - $valid = true; - }*/ if ( strpos( $dir, '../' ) !== false ) { return false; } From a8a9deb193477cf8aa2ef9a9775a1d30f8288528 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 16:34:02 +0530 Subject: [PATCH 22/31] update permission level --- .../workflows/deploy-wordpress-plugin-preview-lightsail.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 5c9a2692d..9284a7ff6 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -225,8 +225,8 @@ jobs: DOMAIN="pr-${INSTANCE_ID}.rapidload.live" WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") - # Create cache folder if it doesn't exist and grant 777 permissions - sudo docker exec -u root -i \${WP_CONTAINER} sh -c "if [ ! -d /bitnami/wordpress/wp-content/cache ]; then mkdir -p /bitnami/wordpress/wp-content/cache; fi && chmod -R 777 /bitnami/wordpress/wp-content/cache" + # Create cache folder if it doesn't exist and grant 755 permissions + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "if [ ! -d /bitnami/wordpress/wp-content/cache ]; then mkdir -p /bitnami/wordpress/wp-content/cache; fi && chmod -R 755 /bitnami/wordpress/wp-content/cache" EOF - name: Update domain in wp-config.php From 8cf704e634cd28ed883cb499c817716cdbeebf15 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Thu, 19 Sep 2024 16:35:50 +0530 Subject: [PATCH 23/31] update WordPress support version --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index f1ad466f7..ee2bccc60 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: shakee93, futtta Donate link: Tags: unusedcss, criticalcss, rapidload, image optimization, minify js Requires at least: 5.0 -Tested up to: 6.4 +Tested up to: 6.6 Stable tag: 2.3.3 Requires PHP: 5.4 License: GPLv3 From b5f07db8e3b2fb49fa1be2e2d47c7dfd03cf1296 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Fri, 20 Sep 2024 17:30:47 +0530 Subject: [PATCH 24/31] add pr env for linode server --- ...deploy-wordpress-plugin-preview-linode.yml | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 .github/workflows/deploy-wordpress-plugin-preview-linode.yml diff --git a/.github/workflows/deploy-wordpress-plugin-preview-linode.yml b/.github/workflows/deploy-wordpress-plugin-preview-linode.yml new file mode 100644 index 000000000..3f4fd5359 --- /dev/null +++ b/.github/workflows/deploy-wordpress-plugin-preview-linode.yml @@ -0,0 +1,160 @@ +name: Deploy WordPress Test Environment on Pull Request + +on: + pull_request: + types: [opened, synchronize] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Get the branch name + run: | + echo "Branch name: ${{ github.head_ref }}" + + - name: Check for merge conflicts + run: | + git fetch origin + git checkout ${{ github.head_ref }} + git merge origin/${{ github.base_ref }} --no-commit --no-ff || echo "::set-output name=conflict::true" + id: merge_check + + - name: Comment on PR if there are merge conflicts + if: steps.merge_check.outputs.conflict == 'true' + run: | + curl -X POST -H "Authorization: token ${{ secrets.SSH_GITHUB_TOKEN }}" \ + -d "{\"body\": \"There are merge conflicts in this pull request. Please resolve the conflicts before merging.\"}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments" + continue-on-error: true + + - name: Configure SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} 'echo SSH successfully configured' + + - name: Set environment variables + run: | + echo "INSTANCE_ID=${{ github.event.number }}" >> $GITHUB_ENV + echo "WORDPRESS_PORT=$((3000 + ${{ github.event.number }}))" >> $GITHUB_ENV + + - name: Comment on PR + if: ${{ github.event.action == 'opened' }} + run: | + curl -X POST -H "Authorization: token ${{ secrets.SSH_GITHUB_TOKEN }}" \ + -d "{\"body\": \"WordPress instance for this PR is available at https://pr-${{ github.event.number }}.rapidload.live\"}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments" + + - name: Create dynamic Nginx config + if: ${{ github.event.action == 'opened' }} + run: | + INSTANCE_ID=${{ github.event.number }} + WORDPRESS_PORT=$((3000 + INSTANCE_ID)) + CONFIG_FILE_NAME="pr-${INSTANCE_ID}.rapidload.live.conf" + LOCAL_CONFIG_FILE_PATH="./${CONFIG_FILE_NAME}" + REMOTE_CONFIG_FILE_PATH="/root/${CONFIG_FILE_NAME}" # Updated to root directory + TARGET_CONFIG_FILE_PATH="/etc/nginx/conf/vhosts/${CONFIG_FILE_NAME}" # Update Nginx path if required + + # Create the Nginx config file locally + cat < ${LOCAL_CONFIG_FILE_PATH} + + server { + listen 443; + server_name pr-${INSTANCE_ID}.rapidload.live; + + location / { + proxy_pass http://localhost:${WORDPRESS_PORT}; + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto \$scheme; + } + } + + server { + listen 80; + server_name pr-${INSTANCE_ID}.rapidload.live; + + location / { + proxy_pass http://localhost:${WORDPRESS_PORT}; + proxy_set_header Host \$host; + proxy_set_header X-Real-IP \$remote_addr; + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto \$scheme; + } + } + EOF + + # Copy the config file to the remote server's /root directory + scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${LOCAL_CONFIG_FILE_PATH} root@${{ secrets.SSH_HOST }}:${REMOTE_CONFIG_FILE_PATH} + + # Move the config file to the target directory using sudo + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} "sudo mv ${REMOTE_CONFIG_FILE_PATH} ${TARGET_CONFIG_FILE_PATH}" + + - name: Restart Nginx + if: ${{ github.event.action == 'opened' }} + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} 'sudo systemctl restart nginx' # Updated restart command + + - name: Add DNS A Record to Cloudflare + if: ${{ github.event.action == 'opened' }} + run: | + CF_API_TOKEN=${{ secrets.CF_API_TOKEN }} + ZONE_ID=${{ secrets.CF_ZONE_ID }} + RECORD_NAME=pr-${{ github.event.number }} + RECORD_CONTENT=${{ secrets.SSH_HOST }} + curl -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records" \ + -H "Authorization: Bearer ${CF_API_TOKEN}" \ + -H "Content-Type: application/json" \ + --data '{ + "type": "A", + "name": "'"${RECORD_NAME}"'", + "content": "'"${RECORD_CONTENT}"'", + "ttl": 1, + "proxied": true + }' + + - name: Create dynamic docker-compose file + if: ${{ github.event.action == 'opened' }} + run: | + INSTANCE_ID=${{ github.event.number }} + WORDPRESS_PORT=$((3000 + INSTANCE_ID)) + WP_USERNAME=${{ secrets.WP_USERNAME }} + WP_PASSWORD=${{ secrets.WP_PASSWORD }} + SSH_HOST=${{ secrets.SSH_HOST }} + + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${SSH_HOST} < Date: Fri, 20 Sep 2024 17:32:58 +0530 Subject: [PATCH 25/31] prevent lightsail pr from running --- .github/workflows/deploy-wordpress-plugin-preview-lightsail.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml index 9284a7ff6..6d5fe63fe 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-lightsail.yml @@ -6,6 +6,7 @@ on: jobs: deploy: + if: false # This will prevent the job from running runs-on: ubuntu-latest steps: From aadea8b01139c811e8cf30fca25acb425cf779d4 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Fri, 20 Sep 2024 17:34:21 +0530 Subject: [PATCH 26/31] update secret keys --- .../deploy-wordpress-plugin-preview-linode.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-linode.yml b/.github/workflows/deploy-wordpress-plugin-preview-linode.yml index 3f4fd5359..fcd03b7a5 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-linode.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-linode.yml @@ -34,10 +34,10 @@ jobs: - name: Configure SSH run: | mkdir -p ~/.ssh - echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa + echo "${{ secrets.SSH_PRIVATE_KEY_LINODE }}" > ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa - ssh-keyscan ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts - ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} 'echo SSH successfully configured' + ssh-keyscan ${{ secrets.SSH_HOST_LINODE }} >> ~/.ssh/known_hosts + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} 'echo SSH successfully configured' - name: Set environment variables run: | @@ -92,15 +92,15 @@ jobs: EOF # Copy the config file to the remote server's /root directory - scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${LOCAL_CONFIG_FILE_PATH} root@${{ secrets.SSH_HOST }}:${REMOTE_CONFIG_FILE_PATH} + scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${LOCAL_CONFIG_FILE_PATH} root@${{ secrets.SSH_HOST_LINODE }}:${REMOTE_CONFIG_FILE_PATH} # Move the config file to the target directory using sudo - ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} "sudo mv ${REMOTE_CONFIG_FILE_PATH} ${TARGET_CONFIG_FILE_PATH}" + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} "sudo mv ${REMOTE_CONFIG_FILE_PATH} ${TARGET_CONFIG_FILE_PATH}" - name: Restart Nginx if: ${{ github.event.action == 'opened' }} run: | - ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} 'sudo systemctl restart nginx' # Updated restart command + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} 'sudo systemctl restart nginx' # Updated restart command - name: Add DNS A Record to Cloudflare if: ${{ github.event.action == 'opened' }} @@ -108,7 +108,7 @@ jobs: CF_API_TOKEN=${{ secrets.CF_API_TOKEN }} ZONE_ID=${{ secrets.CF_ZONE_ID }} RECORD_NAME=pr-${{ github.event.number }} - RECORD_CONTENT=${{ secrets.SSH_HOST }} + RECORD_CONTENT=${{ secrets.SSH_HOST_LINODE }} curl -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records" \ -H "Authorization: Bearer ${CF_API_TOKEN}" \ -H "Content-Type: application/json" \ @@ -127,7 +127,7 @@ jobs: WORDPRESS_PORT=$((3000 + INSTANCE_ID)) WP_USERNAME=${{ secrets.WP_USERNAME }} WP_PASSWORD=${{ secrets.WP_PASSWORD }} - SSH_HOST=${{ secrets.SSH_HOST }} + SSH_HOST=${{ secrets.SSH_HOST_LINODE }} ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${SSH_HOST} < Date: Fri, 20 Sep 2024 17:45:46 +0530 Subject: [PATCH 27/31] add remaining steps --- ...deploy-wordpress-plugin-preview-linode.yml | 230 ++++++++++++++++++ 1 file changed, 230 insertions(+) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-linode.yml b/.github/workflows/deploy-wordpress-plugin-preview-linode.yml index fcd03b7a5..25cf5d2f0 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-linode.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-linode.yml @@ -68,6 +68,9 @@ jobs: listen 443; server_name pr-${INSTANCE_ID}.rapidload.live; + ssl_certificate /etc/nginx/ssl/selfsigned.crt; + ssl_certificate_key /etc/nginx/ssl/selfsigned.key; + location / { proxy_pass http://localhost:${WORDPRESS_PORT}; proxy_set_header Host \$host; @@ -158,3 +161,230 @@ jobs: ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << EOF sudo docker network prune -f EOF + + - name: Deploy WordPress + if: ${{ github.event.action == 'opened' }} + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + INSTANCE_ID=${{ github.event.number }} + WORDPRESS_PORT=$((3000 + INSTANCE_ID)) + export INSTANCE_ID WORDPRESS_PORT + + # Get the container IDs + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + DB_CONTAINER=\$(sudo docker ps -q --filter "name=mariadb_\${INSTANCE_ID}") + + echo "WP_CONTAINER ID: \${WP_CONTAINER}" + echo "DB_CONTAINER ID: \${DB_CONTAINER}" + + # Stop and remove any existing Docker services using the same ports + # if [ ! -z "\$WP_CONTAINER" ]; then + # sudo docker stop \${WP_CONTAINER} + # sudo docker rm \${WP_CONTAINER} + # fi + + # if [ ! -z "\$DB_CONTAINER" ]; then + # sudo docker stop \${DB_CONTAINER} + # sudo docker rm \${DB_CONTAINER} + # fi + + # Start the new services + sudo docker-compose -f /root/wp-\${INSTANCE_ID}/docker-compose.yml up -d + sleep 30 # wait for the services to start + sudo docker-compose -f /root/wp-\${INSTANCE_ID}/docker-compose.yml logs wordpress + EOF + + - name: Set up environment and grant permissions + if: ${{ github.event.action == 'opened' }} + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + set -x + INSTANCE_ID=${{ github.event.number }} + DOMAIN="pr-${INSTANCE_ID}.rapidload.live" + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + + # Grant 666 permissions to wp-config.php to cache folder + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "chmod 666 /bitnami/wordpress/wp-config.php" + EOF + + - name: Create cache folder and grant 755 permissions + if: ${{ github.event.action == 'opened' }} + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + set -x + INSTANCE_ID=${{ github.event.number }} + DOMAIN="pr-${INSTANCE_ID}.rapidload.live" + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + + # Create cache folder if it doesn't exist and grant 755 permissions + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "if [ ! -d /bitnami/wordpress/wp-content/cache ]; then mkdir -p /bitnami/wordpress/wp-content/cache; fi && chmod -R 755 /bitnami/wordpress/wp-content/cache" + EOF + + - name: Update domain in wp-config.php + if: ${{ github.event.action == 'opened' }} + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + set -x + INSTANCE_ID=${{ github.event.number }} + DOMAIN="pr-${INSTANCE_ID}.rapidload.live" + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + + echo "update domain for : \${WP_CONTAINER}" + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "sed -i 's/127.0.0.1/\${DOMAIN}/g; s|http://|https://|g' /bitnami/wordpress/wp-config.php" + EOF + + - name: Update RAPIDLOAD_DEV_MODE in wp-config.php + if: ${{ github.event.action == 'opened' }} + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + set -x + INSTANCE_ID=${{ github.event.number }} + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + + echo "update RAPIDLOAD_DEV_MODE for : \${WP_CONTAINER}" + sudo docker exec -u root -i \${WP_CONTAINER} sh -c 'sed -i "/^\/\*\* Sets up WordPress vars and included files. \*\//i if ( ! defined( \x27RAPIDLOAD_DEV_MODE\x27 ) ) { define( \x27RAPIDLOAD_DEV_MODE\x27, true ); }" /bitnami/wordpress/wp-config.php' + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "grep -A 2 'RAPIDLOAD_DEV_MODE' /bitnami/wordpress/wp-config.php" + EOF + + - name: Update WP_CACHE in wp-config.php + if: ${{ github.event.action == 'opened' }} + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + set -x + INSTANCE_ID=${{ github.event.number }} + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + + echo "update WP_CACHE for : \${WP_CONTAINER}" + sudo docker exec -u root -i \${WP_CONTAINER} sh -c 'sed -i "/^\/\*\* Sets up WordPress vars and included files. \*\//i if ( ! defined( \x27WP_CACHE\x27 ) ) { define( \x27WP_CACHE\x27, true ); }" /bitnami/wordpress/wp-config.php' + sudo docker exec -u root -i \${WP_CONTAINER} sh -c "grep -A 2 'WP_CACHE' /bitnami/wordpress/wp-config.php" + EOF + + - name: Update robots.txt in Docker container + if: ${{ github.event.action == 'opened' }} + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + INSTANCE_ID=${{ github.event.number }} + WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") + + # Create or update robots.txt to prevent Google indexing + sudo docker exec -u root -i ${WP_CONTAINER} sh -c "echo -e 'User-agent: *\nDisallow: /' > /bitnami/wordpress/robots.txt" + EOF + + - name: Clone or Update WordPress Plugin Repository in Docker Container + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + INSTANCE_ID=${{ github.event.number }} + WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") + PLUGIN_PATH=/bitnami/wordpress/wp-content/plugins/autoptimize-unusedcss + PLUGIN_DIR=/bitnami/wordpress/wp-content/plugins + + sudo docker exec -u root -i ${WP_CONTAINER} sh -c " + if [ -d ${PLUGIN_PATH} ]; then + echo 'Plugin directory exists. Running git pull...' + cd ${PLUGIN_PATH} + git pull origin ${{ github.head_ref }} + else + cd ${PLUGIN_DIR} + echo 'Cloning plugin repository...' + git config --global http.postBuffer 524288000 + git clone --depth 1 -b ${{ github.head_ref }} --single-branch https://github.com/shakee93/autoptimize-unusedcss.git ${PLUGIN_PATH} + fi + " + if [ $? -eq 0 ]; then + echo "Plugin repository updated successfully in ${WP_CONTAINER}" + else + echo "Failed to update plugin repository in ${WP_CONTAINER}" + fi + EOF + + - name: Run npm build in Docker Container + run: | + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + INSTANCE_ID=${{ github.event.number }} + WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") + PLUGIN_PATH=/bitnami/wordpress/wp-content/plugins/autoptimize-unusedcss/includes/admin/page-optimizer + sudo docker exec -u root -i ${WP_CONTAINER} sh -c " + cd ${PLUGIN_PATH} + if [ -f package.json ]; then + echo 'Running npm install...' + npm install + echo 'Running npm run build...' + npm run build + else + echo 'package.json not found in ${PLUGIN_PATH}' + fi + " + if [ $? -eq 0 ]; then + echo "npm run build executed successfully in ${WP_CONTAINER}" + else + echo "Failed to run npm build in ${WP_CONTAINER}" + fi + EOF + + - name: Activate Plugin in Docker Container + if: ${{ github.event.action == 'opened' }} + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + INSTANCE_ID=${{ github.event.number }} + WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") + if [ -n "${WP_CONTAINER}" ]; then + sudo docker exec -i ${WP_CONTAINER} sh -c "wp plugin activate autoptimize-unusedcss --allow-root" + if [ $? -eq 0 ]; then + echo "Plugin unusedcss activated successfully in ${WP_CONTAINER}" + else + echo "Failed to activate plugin unusedcss in ${WP_CONTAINER}" + fi + + sudo docker exec -i ${WP_CONTAINER} sh -c "wp rapidload update_db --allow-root" + sudo docker exec -i ${WP_CONTAINER} sh -c "wp option update siteurl 'https://pr-${{ github.event.number }}.rapidload.live' --allow-root" + sudo docker exec -i ${WP_CONTAINER} sh -c "wp option update home 'https://pr-${{ github.event.number }}.rapidload.live' --allow-root" + sudo docker exec -i ${WP_CONTAINER} sh -c "wp search-replace 'http://127.0.0.1' 'https://pr-${{ github.event.number }}.rapidload.live' --all-tables --allow-root" + sudo docker exec -i ${WP_CONTAINER} sh -c "wp rapidload connect '${{ secrets.RAPIDLOAD_LICENSE_KEY }}' --uucss=1 --cpcss=1 --url='https://pr-${{ github.event.number }}.rapidload.live' --allow-root" + + else + echo "No container found with name wordpress_${INSTANCE_ID}" + fi + EOF + + - name: Disable plugin upload capability + if: ${{ github.event.action == 'opened' }} + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + INSTANCE_ID=${{ github.event.number }} + WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") + + # Remove the 'upload_plugins' capability from the 'administrator' role + sudo docker exec -u root -i ${WP_CONTAINER} sh -c "echo \"define('DISALLOW_FILE_MODS', true);\" >> /bitnami/wordpress/wp-config.php" + EOF + + - name: Clean up old Docker containers and volumes + #if: ${{ github.event.action == 'opened' }} + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + # Remove Docker containers older than 30 days + old_containers=$(sudo docker ps -a --filter "status=exited" --format "{{.ID}} {{.CreatedAt}}" | while read id created; do + if [ $(date -d "$created" +%s) -lt $(date -d '30 days ago' +%s) ]; then + echo $id + fi + done) + if [ ! -z "$old_containers" ]; then + echo "Removing old containers: $old_containers" + sudo docker rm $old_containers + else + echo "No old containers found." + fi + + # Remove dangling Docker volumes older than 30 days + old_volumes=$(sudo docker volume ls -q --filter "dangling=true" | while read volume; do + created=$(sudo docker volume inspect -f '{{.CreatedAt}}' $volume | head -n 1 | sed 's/\(.*\)+0000 UTC/\1/') + if [ $(date -d "$created" +%s) -lt $(date -d '30 days ago' +%s) ]; then + echo $volume + fi + done) + if [ ! -z "$old_volumes" ]; then + echo "Removing old volumes: $old_volumes" + sudo docker volume rm $old_volumes + else + echo "No old volumes found." + fi + EOF From 9639ca17ad817e43b589c8aa585baa671b8e0021 Mon Sep 17 00:00:00 2001 From: shakeeb Date: Fri, 20 Sep 2024 17:52:18 +0530 Subject: [PATCH 28/31] update secret key --- ...deploy-wordpress-plugin-preview-linode.yml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy-wordpress-plugin-preview-linode.yml b/.github/workflows/deploy-wordpress-plugin-preview-linode.yml index 25cf5d2f0..97e0998b8 100644 --- a/.github/workflows/deploy-wordpress-plugin-preview-linode.yml +++ b/.github/workflows/deploy-wordpress-plugin-preview-linode.yml @@ -165,7 +165,7 @@ jobs: - name: Deploy WordPress if: ${{ github.event.action == 'opened' }} run: | - ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << EOF INSTANCE_ID=${{ github.event.number }} WORDPRESS_PORT=$((3000 + INSTANCE_ID)) export INSTANCE_ID WORDPRESS_PORT @@ -197,7 +197,7 @@ jobs: - name: Set up environment and grant permissions if: ${{ github.event.action == 'opened' }} run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << EOF set -x INSTANCE_ID=${{ github.event.number }} DOMAIN="pr-${INSTANCE_ID}.rapidload.live" @@ -210,7 +210,7 @@ jobs: - name: Create cache folder and grant 755 permissions if: ${{ github.event.action == 'opened' }} run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << EOF set -x INSTANCE_ID=${{ github.event.number }} DOMAIN="pr-${INSTANCE_ID}.rapidload.live" @@ -223,7 +223,7 @@ jobs: - name: Update domain in wp-config.php if: ${{ github.event.action == 'opened' }} run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << EOF set -x INSTANCE_ID=${{ github.event.number }} DOMAIN="pr-${INSTANCE_ID}.rapidload.live" @@ -236,7 +236,7 @@ jobs: - name: Update RAPIDLOAD_DEV_MODE in wp-config.php if: ${{ github.event.action == 'opened' }} run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << EOF set -x INSTANCE_ID=${{ github.event.number }} WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") @@ -249,7 +249,7 @@ jobs: - name: Update WP_CACHE in wp-config.php if: ${{ github.event.action == 'opened' }} run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << EOF + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << EOF set -x INSTANCE_ID=${{ github.event.number }} WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") @@ -262,7 +262,7 @@ jobs: - name: Update robots.txt in Docker container if: ${{ github.event.action == 'opened' }} run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << 'EOF' INSTANCE_ID=${{ github.event.number }} WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") @@ -272,7 +272,7 @@ jobs: - name: Clone or Update WordPress Plugin Repository in Docker Container run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << 'EOF' INSTANCE_ID=${{ github.event.number }} WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") PLUGIN_PATH=/bitnami/wordpress/wp-content/plugins/autoptimize-unusedcss @@ -299,7 +299,7 @@ jobs: - name: Run npm build in Docker Container run: | - ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + ssh -v -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << 'EOF' INSTANCE_ID=${{ github.event.number }} WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") PLUGIN_PATH=/bitnami/wordpress/wp-content/plugins/autoptimize-unusedcss/includes/admin/page-optimizer @@ -324,7 +324,7 @@ jobs: - name: Activate Plugin in Docker Container if: ${{ github.event.action == 'opened' }} run: | - ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << 'EOF' INSTANCE_ID=${{ github.event.number }} WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") if [ -n "${WP_CONTAINER}" ]; then @@ -349,7 +349,7 @@ jobs: - name: Disable plugin upload capability if: ${{ github.event.action == 'opened' }} run: | - ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << 'EOF' INSTANCE_ID=${{ github.event.number }} WP_CONTAINER=$(sudo docker ps -q --filter "name=wordpress_${INSTANCE_ID}") @@ -360,7 +360,7 @@ jobs: - name: Clean up old Docker containers and volumes #if: ${{ github.event.action == 'opened' }} run: | - ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST }} << 'EOF' + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << 'EOF' # Remove Docker containers older than 30 days old_containers=$(sudo docker ps -a --filter "status=exited" --format "{{.ID}} {{.CreatedAt}}" | while read id created; do if [ $(date -d "$created" +%s) -lt $(date -d '30 days ago' +%s) ]; then From ae2c027340fa198f2a1e03b83c9cd4f1c30f687d Mon Sep 17 00:00:00 2001 From: shakeeb Date: Fri, 20 Sep 2024 18:19:14 +0530 Subject: [PATCH 29/31] update delete test env from linode action file --- .../clean-wordpress-plugin-preview-linode.yml | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 .github/workflows/clean-wordpress-plugin-preview-linode.yml diff --git a/.github/workflows/clean-wordpress-plugin-preview-linode.yml b/.github/workflows/clean-wordpress-plugin-preview-linode.yml new file mode 100644 index 000000000..44b48bceb --- /dev/null +++ b/.github/workflows/clean-wordpress-plugin-preview-linode.yml @@ -0,0 +1,122 @@ +name: Clean Linode on Pull Request close + +on: + pull_request: + types: [closed] + +jobs: + pr-closed: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Get the branch name + run: | + echo "Branch name: ${{ github.head_ref }}" + + - name: Configure SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.SSH_PRIVATE_KEY_LINODE }}" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} 'echo SSH successfully configured' + + - name: Set environment variables + run: | + echo "INSTANCE_ID=${{ github.event.number }}" >> $GITHUB_ENV + + - name: Delete Nginx config + run: | + INSTANCE_ID=${{ github.event.number }} + CONFIG_FILE_NAME="pr-${INSTANCE_ID}.rapidload.live.conf" + TARGET_CONFIG_FILE_PATH="/etc/nginx/conf/vhosts/${CONFIG_FILE_NAME}" # Updated to correct Nginx path + + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} \ + "if [ -f '$TARGET_CONFIG_FILE_PATH' ]; then \ + echo 'Deleting $TARGET_CONFIG_FILE_PATH'; \ + sudo rm '$TARGET_CONFIG_FILE_PATH'; \ + else \ + echo 'File $TARGET_CONFIG_FILE_PATH does not exist'; \ + fi" + + - name: Restart Nginx + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} 'sudo systemctl restart nginx' # Correct Nginx restart command + + #- name: Delete DNS A Record from Cloudflare + #run: | + #CF_API_TOKEN=${{ secrets.CF_API_TOKEN }} + #ZONE_ID=${{ secrets.CF_ZONE_ID }} + #RECORD_NAME=pr-${{ github.event.number }} + + # Fetch the DNS record ID + #RECORD_ID=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records?type=A&name=${RECORD_NAME}" \ + #-H "Authorization: Bearer ${CF_API_TOKEN}" \ + #-H "Content-Type: application/json" | jq -r '.result[0].id') + + # Check if the RECORD_ID is not null + #if [ -n "$RECORD_ID" ]; then + #echo "Deleting DNS record with ID $RECORD_ID" + #curl -X DELETE "https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/dns_records/${RECORD_ID}" \ + #-H "Authorization: Bearer ${CF_API_TOKEN}" \ + #-H "Content-Type: application/json" + #else + #echo "DNS record not found" + #fi + + - name: Clean Docker WordPress + run: | + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${{ secrets.SSH_HOST_LINODE }} << EOF + INSTANCE_ID=${{ github.event.number }} + WORDPRESS_PORT=$((3000 + INSTANCE_ID)) + export INSTANCE_ID WORDPRESS_PORT + + # Get the container IDs + WP_CONTAINER=\$(sudo docker ps -q --filter "name=wordpress_\${INSTANCE_ID}") + DB_CONTAINER=\$(sudo docker ps -q --filter "name=mariadb_\${INSTANCE_ID}") + + echo "WP_CONTAINER ID: \${WP_CONTAINER}" + echo "DB_CONTAINER ID: \${DB_CONTAINER}" + + # Stop and remove any existing Docker services using the same ports + if [ ! -z "\$WP_CONTAINER" ]; then + sudo docker stop \${WP_CONTAINER} + sudo docker rm \${WP_CONTAINER} + fi + + if [ ! -z "\$DB_CONTAINER" ]; then + sudo docker stop \${DB_CONTAINER} + sudo docker rm \${DB_CONTAINER} + fi + + # Remove existing volumes + WP_VOLUME=\$(sudo docker volume ls -q --filter name=wordpress_data_\${INSTANCE_ID}) + if [ ! -z "\$WP_VOLUME" ]; then + sudo docker volume rm -f \${WP_VOLUME} + fi + + DB_VOLUME=\$(sudo docker volume ls -q --filter name=mariadb_data_\${INSTANCE_ID}) + if [ ! -z "\$DB_VOLUME" ]; then + sudo docker volume rm -f \${DB_VOLUME} + fi + + EOF + + - name: Delete docker-compose file + run: | + INSTANCE_ID=${{ github.event.number }} + SSH_HOST=${{ secrets.SSH_HOST }} + + ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa root@${SSH_HOST_LINODE} < Date: Fri, 20 Sep 2024 18:20:17 +0530 Subject: [PATCH 30/31] prevent lightsail clean action file from running --- .github/workflows/clean-wordpress-plugin-preview-lightsail.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/clean-wordpress-plugin-preview-lightsail.yml b/.github/workflows/clean-wordpress-plugin-preview-lightsail.yml index ecb2c9226..cc2f4d053 100644 --- a/.github/workflows/clean-wordpress-plugin-preview-lightsail.yml +++ b/.github/workflows/clean-wordpress-plugin-preview-lightsail.yml @@ -6,6 +6,7 @@ on: jobs: pr-closed: + if: false # This will prevent the job from running runs-on: ubuntu-latest steps: From 852d1a7bc133545bbdc649f33b0bca2645a7e08f Mon Sep 17 00:00:00 2001 From: shakee93 Date: Mon, 23 Sep 2024 17:39:39 +0530 Subject: [PATCH 31/31] fix: flush cache not working fix: value not working --- .../admin/page-optimizer/src/components/RapidLoadActions.tsx | 2 +- includes/admin/page-optimizer/src/store/app/appActions.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/page-optimizer/src/components/RapidLoadActions.tsx b/includes/admin/page-optimizer/src/components/RapidLoadActions.tsx index e19534a8a..cd12ebb9f 100644 --- a/includes/admin/page-optimizer/src/components/RapidLoadActions.tsx +++ b/includes/admin/page-optimizer/src/components/RapidLoadActions.tsx @@ -56,7 +56,7 @@ const RapidLoadActions: React.FC = () => { } : a )) - let result = await fetch(options?.ajax_url + action.action.replace(/&/g, '&')); + let result = await fetch(action.action.replace(/&/g, '&')); toast({ duration: 10, diff --git a/includes/admin/page-optimizer/src/store/app/appActions.ts b/includes/admin/page-optimizer/src/store/app/appActions.ts index d182f9380..18b48f10c 100644 --- a/includes/admin/page-optimizer/src/store/app/appActions.ts +++ b/includes/admin/page-optimizer/src/store/app/appActions.ts @@ -158,7 +158,7 @@ const transformSettings = (data: any) => { inputs: input.inputs.map(i => { return { ...i, - value: i.control_type === 'checkbox' ? input.value === '1' || input.value === true : i.value + value: i.control_type === 'checkbox' ? i.value === '1' || i.value === true : i.value } }) }),