From 14929e28b1ae1d39f597c4b634f5b4fc6d1dd61f Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 13 Jun 2022 13:50:28 +0000 Subject: [PATCH] ci: cache Arsenal Image Mounter files This commits add logic to cache files used to create a Windows RAM disk to avoid extra HTTP requests. --- .circleci/config.yml | 17 ++++++++++------- .circleci/win-ram-disk.ps1 | 38 +++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9271f8dde68b..aed85c99ab70 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ orbs: # Windows needs its own cache key because binaries in node_modules are different. # See https://circleci.com/docs/2.0/caching/#restoring-cache for how prefixes work in CircleCI. var_1: &cache_key v1-angular_devkit-14.19-{{ checksum "yarn.lock" }} -var_1_win: &cache_key_win v1-angular_devkit-win-14.19-{{ checksum "yarn.lock" }} +var_1_win: &cache_key_win v1-angular_devkit-win-16.10-{{ checksum "yarn.lock" }} var_3: &default_nodeversion '14.19' # Workspace initially persisted by the `setup` job, and then enhanced by `setup-and-build-win`. # https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs @@ -83,12 +83,6 @@ commands: at: *workspace_location setup_windows: steps: - - run: - # We use Arsenal Image Mounter (AIM) instead of ImDisk because of: https://github.com/nodejs/node/issues/6861 - # Useful resources for AIM: http://reboot.pro/index.php?showtopic=22068 - name: 'Arsenal Image Mounter (RAM Disk)' - command: | - pwsh ./.circleci/win-ram-disk.ps1 - run: nvm install 16.10 - run: nvm use 16.10 - run: npm install -g yarn@1.22.10 @@ -323,11 +317,20 @@ jobs: - restore_cache: keys: - *cache_key_win + - run: + # We use Arsenal Image Mounter (AIM) instead of ImDisk because of: https://github.com/nodejs/node/issues/6861 + # Useful resources for AIM: http://reboot.pro/index.php?showtopic=22068 + name: 'Arsenal Image Mounter (RAM Disk)' + command: | + pwsh ./.circleci/win-ram-disk.ps1 - run: yarn install --frozen-lockfile --cache-folder ../.cache/yarn - save_cache: key: *cache_key_win paths: - ~/.cache/yarn + # Path where Arsenal Image Mounter files are downloaded. + # Must match path in .circleci/win-ram-disk.ps1 + - ./aim # Run partial e2e suite on PRs only. Release branches will run the full e2e suite. - run: name: Execute E2E Tests diff --git a/.circleci/win-ram-disk.ps1 b/.circleci/win-ram-disk.ps1 index 40ce955067e2..5d16d8b8a11d 100644 --- a/.circleci/win-ram-disk.ps1 +++ b/.circleci/win-ram-disk.ps1 @@ -1,22 +1,30 @@ -# Download AIM Drivers and validate hash -Invoke-WebRequest "https://github.com/ArsenalRecon/Arsenal-Image-Mounter/raw/988930e4b3180ec34661504e6f9906f98943a022/DriverSetup/DriverFiles.zip" -OutFile "aim_drivers.zip" -UseBasicParsing -$aimDriversDownloadHash = (Get-FileHash aim_drivers.zip -a sha256).Hash -If ($aimDriversDownloadHash -ne "1F5AA5DD892C2D5E8A0083752B67C6E5A2163CD83B6436EA545508D84D616E02") { - throw "aim_drivers.zip hash is ${aimDriversDownloadHash} which didn't match the known version." -} -Expand-Archive -Path "aim_drivers.zip" +$aimContents = "./aim"; + +if (-not (Test-Path -Path $aimContents)) { + echo "Arsenal Image Mounter files not found in cache. Downloading..." + + # Download AIM Drivers and validate hash + Invoke-WebRequest "https://github.com/ArsenalRecon/Arsenal-Image-Mounter/raw/988930e4b3180ec34661504e6f9906f98943a022/DriverSetup/DriverFiles.zip" -OutFile "aim_drivers.zip" -UseBasicParsing + $aimDriversDownloadHash = (Get-FileHash aim_drivers.zip -a sha256).Hash + If ($aimDriversDownloadHash -ne "1F5AA5DD892C2D5E8A0083752B67C6E5A2163CD83B6436EA545508D84D616E02") { + throw "aim_drivers.zip hash is ${aimDriversDownloadHash} which didn't match the known version." + } + Expand-Archive -Path "aim_drivers.zip" -DestinationPath $aimContents/drivers -# Download AIM CLI and validate hash -Invoke-WebRequest "https://github.com/ArsenalRecon/Arsenal-Image-Mounter/raw/988930e4b3180ec34661504e6f9906f98943a022/Command%20line%20applications/aim_ll.zip" -OutFile "aim_ll.zip" -UseBasicParsing -$aimCliDownloadHash = (Get-FileHash aim_ll.zip -a sha256).Hash -If ($aimCliDownloadHash -ne "9AD3058F14595AC4A5E5765A9746737D31C219383766B624FCBA4C5ED96B20F3") { - throw "aim_ll.zip hash is ${aimCliDownloadHash} which didn't match the known version." + # Download AIM CLI and validate hash + Invoke-WebRequest "https://github.com/ArsenalRecon/Arsenal-Image-Mounter/raw/988930e4b3180ec34661504e6f9906f98943a022/Command%20line%20applications/aim_ll.zip" -OutFile "aim_ll.zip" -UseBasicParsing + $aimCliDownloadHash = (Get-FileHash aim_ll.zip -a sha256).Hash + If ($aimCliDownloadHash -ne "9AD3058F14595AC4A5E5765A9746737D31C219383766B624FCBA4C5ED96B20F3") { + throw "aim_ll.zip hash is ${aimCliDownloadHash} which didn't match the known version." + } + Expand-Archive -Path "aim_ll.zip" -DestinationPath $aimContents/cli +} else { + echo "Arsenal Image Mounter files found in cache. Skipping download." } -Expand-Archive -Path "aim_ll.zip" # Install AIM drivers -./aim_ll/x64/aim_ll.exe --install ./aim_drivers +./aim/cli/x64/aim_ll.exe --install ./aim/drivers # Setup RAM disk mount. Same parameters as ImDisk # See: https://support.circleci.com/hc/en-us/articles/4411520952091-Create-a-windows-RAM-disk -./aim_ll/x64/aim_ll.exe -a -s 5G -m X: -p "/fs:ntfs /q /y" +./aim/cli/x64/aim_ll.exe -a -s 5G -m X: -p "/fs:ntfs /q /y"