Skip to content

Commit eea403e

Browse files
authored
Add badges and improve deployment (#22)
* add badges * improve deployment story * make the deploy ps1 more linux frindly * fix the defaul cors rules * fix azure pipeline yaml * fix name of deployments * change deployment in azure devops * try to fix azure part in the yaml * remove stupid code. * fix pathes in the azure deployment * finally fix the azure pipeline * add link to demo * fix azure pipelines yml * fix .net build * fix archive * fix caseing in archive task * fix azure pipeline again
1 parent a73abe5 commit eea403e

File tree

5 files changed

+100
-32
lines changed

5 files changed

+100
-32
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111

1212
jobs:
1313
build_and_deploy_job:
14-
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
14+
if: (github.event_name == 'pull_request' && github.event.action != 'closed')
1515
runs-on: ubuntu-latest
1616
name: Build and Deploy Job
1717
steps:
@@ -80,4 +80,4 @@ jobs:
8080
- name: compile bicep
8181
uses: Azure/bicep-build-action@v1.0.0
8282
with:
83-
bicepFilePath: main.bicep
83+
bicepFilePath: main.bicep

Readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ This can be used on the download page:
1010

1111
![Download](docs/.assets/ce9c3c1a-eb2d-4222-befb-fc57b8823404.png)
1212

13+
A demo can be used here:
14+
[https://kind-dune-004c2c103.azurestaticapps.net](https://kind-dune-004c2c103.azurestaticapps.net)
15+
16+
## Status
17+
18+
| Azure DevOps | GitHub Action |
19+
| ------------ | ------------- |
20+
| [![Build Status](https://dev.azure.com/czon/CZ.Azure.FileExchange/_apis/build/status/codez-one.CZ.Azure.FileExchange?branchName=main)](https://dev.azure.com/czon/CZ.Azure.FileExchange/_build/latest?definitionId=9&branchName=main) | [![Azure Static Web Apps CI/CD](https://github.com/codez-one/CZ.Azure.FileExchange/actions/workflows/main.yml/badge.svg)](https://github.com/codez-one/CZ.Azure.FileExchange/actions/workflows/main.yml) |
21+
1322
## Deployment
1423

1524
In every [release](https://github.com/codez-one/CZ.Azure.FileExchange/releases/latest) of this repository you will find a `azuredeploy.json`.
@@ -29,6 +38,8 @@ $token = Read-Host -MaskInput;
2938
3039
### Build App
3140

41+
> Important: If you want deploy this, build it on linux!
42+
3243
```powershell
3344
dotnet build
3445
dotnet publish .\src\CZ.Azure.FileExchange\ -o temp/fe

azure-pipelines.yml

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ stages:
4040
displayName: Publish frontend
4141
inputs:
4242
command: 'publish'
43-
projects: CZ.Azure.FileExchange.csproj
43+
projects: $(workingDirectory)/src/CZ.Azure.FileExchange/CZ.Azure.FileExchange.csproj
4444
arguments: --output $(workingDirectory)/fe/ --configuration Release
4545
zipAfterPublish: false
4646
workingDirectory: $(workingDirectory)/src/CZ.Azure.FileExchange/
47+
publishWebProjects: false
4748
- task: DotNetCoreCLI@2
4849
displayName: Publish api
4950
inputs:
5051
command: 'publish'
51-
projects: CZ.Azure.FileExchange.Api.csproj
52+
projects: $(workingDirectory)/src/CZ.Azure.FileExchange.Api/CZ.Azure.FileExchange.Api.csproj
5253
arguments: --output $(workingDirectory)/api --configuration Release
5354
zipAfterPublish: false
5455
workingDirectory: $(workingDirectory)/src/CZ.Azure.FileExchange.Api/
56+
publishWebProjects: false
5557
- script: 'az bicep build --file $(workingDirectory)/main.bicep --outfile $(Build.ArtifactStagingDirectory)/azuredeploy.json'
5658
displayName: build bicep file
5759
- task: ArchiveFiles@2
@@ -68,26 +70,31 @@ stages:
6870
archiveFile: $(Build.ArtifactStagingDirectory)/API.zip
6971
archiveType: zip
7072
includeRootFolder: false
71-
rootFolderOrFile: $(workingDirectory)/api/CZ.Azure.FileExchange/
73+
rootFolderOrFile: $(workingDirectory)/api/CZ.Azure.FileExchange.Api/
7274
replaceExistingArchive: true
75+
- task: CopyFiles@2
76+
displayName: "copy deploy script to the artifact bundle"
77+
inputs:
78+
SourceFolder: $(workingDirectory)/build/
79+
Contents: '**.ps1'
80+
TargetFolder: $(Build.ArtifactStagingDirectory)/
7381
- task: PublishBuildArtifacts@1
7482
inputs:
7583
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
7684
ArtifactName: 'drop'
7785
publishLocation: Container
7886

79-
- stage: Release
80-
displayName: Release to github
87+
- stage: ReleaseToGithub
88+
displayName: Release to Github
8189
dependsOn: Build
8290
condition: succeeded()
8391

8492
jobs:
85-
- deployment: Deploy
86-
displayName: Deploy
93+
- deployment: DeployGithub
94+
displayName: "Deploy - Github Release"
8795
environment: 'development'
8896
pool:
8997
vmImage: $(vmImageName)
90-
9198
strategy:
9299
runOnce:
93100
deploy:
@@ -107,4 +114,36 @@ stages:
107114
tagSource: userSpecifiedTag
108115
tag: $(Build.BuildNumber)
109116
changeLogCompareToRelease: 'lastFullRelease'
110-
changeLogType: 'commitBased'
117+
changeLogType: 'commitBased'
118+
- stage: ReleaseToAzure
119+
displayName: Release to Azure
120+
dependsOn: Build
121+
condition: succeeded()
122+
jobs:
123+
- deployment: DeployAzure
124+
displayName: "Deploy - Azure Environment"
125+
environment: 'development'
126+
pool:
127+
vmImage: $(vmImageName)
128+
strategy:
129+
runOnce:
130+
deploy:
131+
steps:
132+
- task: AzureResourceManagerTemplateDeployment@3
133+
displayName: "Deploy ARM template to Azure"
134+
inputs:
135+
deploymentScope: 'Resource Group'
136+
azureResourceManagerConnection: 'Nutzungsbasierte Bezahlung (current) (be99037d-eba5-4420-a2d3-0812c5dd9c51)'
137+
subscriptionId: 'be99037d-eba5-4420-a2d3-0812c5dd9c51'
138+
action: 'Create Or Update Resource Group'
139+
resourceGroupName: 'pajetestfileshare'
140+
location: 'West Europe'
141+
templateLocation: 'Linked artifact'
142+
csmFile: '$(Pipeline.Workspace)/drop/azuredeploy.json'
143+
overrideParameters: '-name pajetestfileshare'
144+
deploymentMode: 'Incremental'
145+
- task: PowerShell@2
146+
displayName: "Deploy static webapp"
147+
inputs:
148+
filePath: '$(Pipeline.Workspace)/drop/deploy.ps1'
149+
arguments: '-Token $(staticWebSiteSecret) -appBuildOutput $(Pipeline.Workspace)/drop/Frontend.zip -apiBuildOutput $(Pipeline.Workspace)/drop/API.zip -branchName main -Verbose'

build/deploy.ps1

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ param (
1515
# Set a custom working directory.
1616
[Parameter(Mandatory = $false)]
1717
[string]
18-
$workingDir = "$pwd\temp\temp\",
18+
$workingDir = "$pwd/temp/temp/",
1919
# Set a branch name that is used in the deciption of the envrionment
2020
[Parameter(Mandatory = $false)]
2121
[string]
@@ -34,8 +34,8 @@ param (
3434
$Delete
3535
)
3636
$EventInfo = $null;
37-
if ($false -eq [string]::IsNullOrWhiteSpace($pullrequestTitle) -or
38-
$false -eq [string]::IsNullOrWhiteSpace($envrionmentName) -or
37+
if ($false -eq [string]::IsNullOrWhiteSpace($pullrequestTitle) -or
38+
$false -eq [string]::IsNullOrWhiteSpace($envrionmentName) -or
3939
$false -eq [string]::IsNullOrWhiteSpace($branchName)
4040
) {
4141
$EventInfo = @{
@@ -90,29 +90,46 @@ if($Delete){
9090
break;
9191
}
9292

93-
New-Item -ItemType Directory -Force $workingDir;
94-
Compress-Archive "$apiBuildOutput\*" -DestinationPath $workingDir/api.zip;
95-
Compress-Archive "$appBuildOutput\*" -DestinationPath $workingDir/app.zip;
96-
$apiHash = (Get-FileHash $workingDir/api.zip -Algorithm MD5).Hash;
97-
98-
99-
100-
93+
$apiZipToUpload = ([string]::Empty);
94+
if((Get-Item $apiBuildOutput).PSIsContainer){
95+
New-Item -ItemType Directory -Force $workingDir;
96+
$apiZipToUpload = "$workingDir/api.zip";
97+
Compress-Archive "$apiBuildOutput\*" -DestinationPath $apiZipToUpload -Force;
98+
}else{
99+
$apiZipToUpload = $apiBuildOutput;
100+
}
101+
$appZipToUpload = ([string]::Empty);
102+
if((Get-Item $appBuildOutput).PSIsContainer){
103+
New-Item -ItemType Directory -Force $workingDir;
104+
$appZipToUpload = "$workingDir/app.zip";
105+
Compress-Archive "$appBuildOutput\*" -DestinationPath $appZipToUpload -Force;
106+
}else{
107+
$appZipToUpload = $appBuildOutput;
108+
}
109+
$apiHash = (Get-FileHash $apiZipToUpload -Algorithm MD5).Hash;
110+
111+
function Get-ArchiveEntriesCount {
112+
param (
113+
[string]$pathToZip
114+
)
115+
$fileHandle = [System.IO.Compression.ZipFile]::OpenRead("$pathToZip");
116+
$count = $fileHandle.Entries.Count;
117+
$fileHandle.Dispose();
118+
return $count;
119+
}
101120

102121
$siteUrl = $response.response.siteUrl;
103122
Write-Verbose "The site to be update is: $siteUrl";
104123

105-
106-
107124
$metaDeployInforamtion = @{
108125
EventInfo = $EventInfo;
109126
PollingInfo = $null;
110127
UploadInfo = @{
111128
# this must be always different. Else it wouldn't upload the api
112129
ApiContentHash = "$apiHash";
113-
ApiSizeInBytes = (Get-Item $workingDir/api.zip).Length;
114-
AppFileCount = (Get-ChildItem $appPath -Recurse -File | Measure-Object).Count;
115-
AppSizeInBytes = (Get-Item $workingDir/app.zip).Length;
130+
ApiSizeInBytes = (Get-Item $apiZipToUpload).Length;
131+
AppFileCount = (Get-ArchiveEntriesCount -pathToZip $appZipToUpload);
132+
AppSizeInBytes = (Get-Item $appZipToUpload).Length;
116133
ConfiguredRoles = @();
117134
DefaultFileType = "index.html";
118135
# this can be anything
@@ -142,7 +159,7 @@ $metaDeployInforamtionBody;
142159
if ($null -ne $response.response.packageUris.api -and
143160
[string]::IsNullOrWhiteSpace($response.response.packageUris.api) -eq $false) {
144161
$blobGuid = (New-Guid).Guid.ToString();
145-
Invoke-WebRequest -Method Put -Uri $response.response.packageUris.api -InFile $workingDir/api.zip -Headers @{
162+
Invoke-WebRequest -Method Put -Uri $response.response.packageUris.api -InFile $apiZipToUpload -Headers @{
146163
"x-ms-blob-type" = "BlockBlob";
147164
"x-ms-client-request-id" = "$blobGuid";
148165
"x-ms-return-client-request-id" = "true";
@@ -156,7 +173,7 @@ else {
156173
if ($null -ne $response.response.packageUris.app -and
157174
[string]::IsNullOrWhiteSpace($response.response.packageUris.app) -eq $false) {
158175
$blobGuid = (New-Guid).Guid.ToString();
159-
Invoke-WebRequest -Method Put -Uri $response.response.packageUris.app -InFile $workingDir/app.zip -Headers @{
176+
Invoke-WebRequest -Method Put -Uri $response.response.packageUris.app -InFile $appZipToUpload -Headers @{
160177
"x-ms-blob-type" = "BlockBlob";
161178
"x-ms-client-request-id" = "$blobGuid";
162179
"x-ms-return-client-request-id" = "true";
@@ -189,7 +206,8 @@ while (
189206
$response;
190207
Start-Sleep 2;
191208
}
192-
193-
Remove-Item -Recurse -Force $workingDir;
209+
if((Test-Path $workingDir)){
210+
Remove-Item -Recurse -Force $workingDir;
211+
}
194212
$response.response.siteUrl;
195213
Write-Output "::set-output name=SiteUrl::$($response.response.siteUrl)";

main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource storageBlobServiceConfig 'Microsoft.Storage/storageAccounts/blobService
4343
corsRules: [
4444
{
4545
allowedOrigins: [
46-
website.properties.defaultHostname
46+
'https://${website.properties.defaultHostname}'
4747
'https://*.${location}.azurestaticapps.net'
4848
]
4949
exposedHeaders: [

0 commit comments

Comments
 (0)