Skip to content

codez-one/CZ.Azure.FileExchange

Repository files navigation

CZ.Azure.FileExchange

This project provides a website to share fast files with the help of azure. You get an upload website that looks like this:

Upload

The important thing there is the guid that is displayed after uploading a file. This can be used on the download page:

Download

A demo can be used here: https://kind-dune-004c2c103.azurestaticapps.net

Status

Azure DevOps GitHub Action
Build Status Azure Static Web Apps CI/CD

Deployment

In every release of this repository you will find a azuredeploy.json. Just take this json and deploy it here. After this you have in your resource group an storage account and a static web app.

After this download the two ZIPs of the release (API.zip & Frontend.zip) and extract them.

After this you can run the script deploy.ps1 with the following parameters from any powershell:

$token = Read-Host -MaskInput;
./deploy.ps1 -Token $token -appBuildOutput path-to-the-extrated-frontend-zip -apiBuildOutput path-to-the-extracted-api-zip

Information: The token you get in the azure portal from the overview page of the static webapp. It's called deployment token.

Build App

Important: If you want deploy this, build it on linux!

dotnet build
dotnet publish .\src\CZ.Azure.FileExchange\ -o temp/fe
dotnet publish .\src\CZ.Azure.FileExchange.Api\ -o temp/api

Run the App local

Pull and run azurite on your local machine. (it will simulate azure blob storage on your machine)

docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 mcr.microsoft.com/azure-storage/azurite

after that you need to configure cors rules on the storage emulator. You can do this with the following powershell script:

$accountKey = (Read-Host -MaskInput -Prompt "Storage Account Key");
$body = "<?xml version=`"1.0`" encoding=`"utf-8`"?>
<StorageServiceProperties>
    <Cors>
        <CorsRule>
            <AllowedOrigins>*</AllowedOrigins>
            <AllowedMethods>GET,PUT,OPTIONS,HEAD</AllowedMethods>
            <AllowedHeaders>*</AllowedHeaders>
            <ExposedHeaders>*</ExposedHeaders>
            <MaxAgeInSeconds>200</MaxAgeInSeconds>
        </CorsRule>
    </Cors>
</StorageServiceProperties>"
$lenght = $body.Length;
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256;
$hmacsha.key = [Convert]::FromBase64String($accountKey);
$date = (Get-Date).ToUniversalTime().ToString("R");
$test = "PUT`n`n`n$lenght`n`n`n`n`n`n`n`n`nx-ms-date:$($date)`nx-ms-version:2018-03-28`n/devstoreaccount1/devstoreaccount1`ncomp:properties`nrestype:service";
$signature1 = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($test));
$auth = [System.Convert]::ToBase64String($signature1);
Invoke-WebRequest -Method Put "http://127.0.0.1:10000/devstoreaccount1?restype=service&comp=properties" -Headers @{"Authorization" = "SharedKey devstoreaccount1:$($auth)"; "x-ms-version"= "2018-03-28"; "x-ms-date" = $date } -Body $body

Publish the App

$token = Read-Host -MaskInput;
./build/deploy.ps1 -Token $token -appBuildOutput ./temp/fe/wwwroot/ -apiBuildOutput ./temp/api/

Important: You must configure your storage account with the cors ruls, so it accepts request from your static websites hostname....

  • enjoy

Publish a stage

To publish a stage the deploy script needs some more parameters:

$token = Read-Host -MaskInput;
$branchName = git branch --show-current;
$PrId = "Replace this string with the Id of your PR here";
$PrTitle = "Replace this string with the title of your PR";
./build/deploy.ps1 -Token $token -appBuildOutput ./temp/fe/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName $PrId -pullrequestTitle $PrTitle -branchName $branchName

Delete a stage

To delete a stage just add the delete parameter:

$token = Read-Host -MaskInput;
$branchName = git branch --show-current;
$PrId = "Replace this string with the Id of your PR here";
$PrTitle = "Replace this string with the title of your PR";
./build/deploy.ps1 -Token $token -appBuildOutput ./temp/fe/wwwroot/ -apiBuildOutput ./temp/api/ -envrionmentName $PrId -pullrequestTitle $PrTitle -branchName $branchName -Delete