From f81b93f87eeaf34507df33ba8243c2d072512aa1 Mon Sep 17 00:00:00 2001 From: Drew Garrett Date: Wed, 30 Aug 2023 07:31:48 -0500 Subject: [PATCH] Using azcopy --- .github/workflows/pr-preview.yml | 52 ++++++-------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/.github/workflows/pr-preview.yml b/.github/workflows/pr-preview.yml index a2db95d..30c56d7 100644 --- a/.github/workflows/pr-preview.yml +++ b/.github/workflows/pr-preview.yml @@ -133,52 +133,18 @@ jobs: exit 1 } + # Generate a proper SAS token + $container = Get-AzStorageContainer -Context $acct.Context -Name `$web + $token = New-AzStorageContainerSASToken -Context $acct.Context -Name `$web -Permission rwdl -ExpiryTime (Get-Date).AddMinutes(10) + $containerUri = [System.UriBuilder]::new($container.blobContainerClient.Uri) + $containerUri.Query = $token + $containerUriStr = $containerUri.Uri.ToString() + # Enforce a robots.txt which blocks all crawlers "User-agent: *`nDisallow: /" | Out-File -FilePath robots.txt -Force - - # We must upload the proper content types - # We have a known quantity of file types in use - # https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types - # Discovered: get-childitem -Recurse -File | Select-Object -Unique Extension - $exts = @{ - ".htm" = "text/html" - ".html" = "text/html" - ".png" = "image/png" - ".jpg" = "image/jpeg" - ".ico" = "image/vnd.microsoft.icon" - ".eot" = "application/vnd.ms-fontobject" - ".svg" = "image/svg+xml" - ".ttf" = "font/ttf" - ".woff" = "font/woff" - ".woff2" = "font/woff2" - ".json" = "application/json" - ".jpeg" = "image/jpeg" - ".gif" = "image/gif" - ".js" = "text/javascript" - ".css" = "text/css" - ".webm" = "video/webm" - ".webp" = "image/webp" - } - - $defaultType = "application/octet-stream" - - # Copy all files recursively from the current directory - # Escape with backtick the $web container name - Get-ChildItem -File -Recurse | ForEach-Object -Parallel { - $contentType = $defaultType - if ($exts.ContainsKey($_.Extension)) { - $contentType = $exts[$_.Extension] - } else { - Write-Warning "Missing contentType: $($_.Extension)" - } - - # Because we've modified the pipeline, Set-AzStorageBlobContent no longer respects the relative path - # We must set that ourselves - $relativePath = (Resolve-Path -LiteralPath $_.FullName -Relative) -replace '^\.\/','' - - Set-AzStorageBlobContent -File $_.FullName -Blob $relativePath -Container `$web -Context $acct.Context -Properties @{"ContentType" = $contentType } -Force - } + # Using AzCopy should make this easy with content type autodetection + azcopy sync . "$containerUriStr" --recursive --delete-destination true - name: logout run: |