Skip to content

Commit

Permalink
Using azcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
nerddtvg committed Aug 30, 2023
1 parent 0a8a9a8 commit f81b93f
Showing 1 changed file with 9 additions and 43 deletions.
52 changes: 9 additions & 43 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down

0 comments on commit f81b93f

Please sign in to comment.