|
| 1 | +name: Deploy Everything |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + env: |
| 6 | + required: true |
| 7 | + default: "Test" |
| 8 | + type: string |
| 9 | + secrets: |
| 10 | + AZURE_CREDENTIALS: |
| 11 | + required: true |
| 12 | + AZURE_STATIC_WEB_APPS_API_TOKEN: |
| 13 | + required: true |
| 14 | + TERRAFORM_STATE_ACCESS_KEY: |
| 15 | + required: true |
| 16 | + |
| 17 | +env: |
| 18 | + AZURE_WEBAPP_PACKAGE_PATH: PocketDDD.Server.WebAPI/publish |
| 19 | + CONFIGURATION: Release |
| 20 | + DOTNET_CORE_VERSION: 8.0.x |
| 21 | + WORKING_DIRECTORY: PocketDDD.Server/PocketDDD.Server.WebAPI |
| 22 | + |
| 23 | +jobs: |
| 24 | + deploy_terraform: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + name: Deploy terraform |
| 27 | + environment: ${{ inputs.env }} |
| 28 | + defaults: |
| 29 | + run: |
| 30 | + working-directory: ./terraform |
| 31 | + |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + - name: Log in with Azure |
| 35 | + uses: azure/login@v1 |
| 36 | + with: |
| 37 | + creds: '${{ secrets.AZURE_CREDENTIALS }}' |
| 38 | + - name: Setup terraform |
| 39 | + uses: hashicorp/setup-terraform@v3 |
| 40 | + - run: | |
| 41 | + terraform init -backend-config="key=${{ inputs.env }}.terraform.tfstate" |
| 42 | +
|
| 43 | + terraform apply -auto-approve --var-file ../tfvars/${{ inputs.env }}.tfvars |
| 44 | + env: |
| 45 | + ARM_ACCESS_KEY: ${{ secrets.TERRAFORM_STATE_ACCESS_KEY }} |
| 46 | +
|
| 47 | + build_api_server: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + name: Build API Server |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + - name: Setup .NET SDK |
| 53 | + uses: actions/setup-dotnet@v4 |
| 54 | + with: |
| 55 | + dotnet-version: ${{ env.DOTNET_CORE_VERSION }} |
| 56 | + - name: Restore |
| 57 | + run: dotnet restore "${{ env.WORKING_DIRECTORY }}" |
| 58 | + - name: Build |
| 59 | + run: dotnet build "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-restore |
| 60 | + - name: Test |
| 61 | + run: dotnet test "${{ env.WORKING_DIRECTORY }}" --no-build |
| 62 | + - name: Publish |
| 63 | + run: dotnet publish "${{ env.WORKING_DIRECTORY }}" --configuration ${{ env.CONFIGURATION }} --no-build --output "${{ env.AZURE_WEBAPP_PACKAGE_PATH }}" |
| 64 | + - name: Publish Artifacts |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: webapp |
| 68 | + path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |
| 69 | + |
| 70 | + deploy_api_server: |
| 71 | + name: Deploy API Server |
| 72 | + runs-on: ubuntu-latest |
| 73 | + environment: ${{ inputs.env }} |
| 74 | + needs: [deploy_terraform, build_api_server] |
| 75 | + steps: |
| 76 | + - name: Log in with Azure |
| 77 | + uses: azure/login@v1 |
| 78 | + with: |
| 79 | + creds: '${{ secrets.AZURE_CREDENTIALS }}' |
| 80 | + - name: Download artifact from build job |
| 81 | + uses: actions/download-artifact@v4 |
| 82 | + with: |
| 83 | + name: webapp |
| 84 | + path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |
| 85 | + - name: Deploy to Azure WebApp |
| 86 | + uses: azure/webapps-deploy@v2 |
| 87 | + with: |
| 88 | + app-name: pocketddd-${{ inputs.env }}-api-server-web-app |
| 89 | + package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }} |
| 90 | + |
| 91 | + build_and_deploy_blazor_client: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + environment: ${{ inputs.env }} |
| 94 | + name: Build and Deploy Blazor Client |
| 95 | + needs: deploy_terraform |
| 96 | + steps: |
| 97 | + - uses: actions/checkout@v2 |
| 98 | + with: |
| 99 | + submodules: true |
| 100 | + - name: Log in with Azure |
| 101 | + uses: azure/login@v1 |
| 102 | + with: |
| 103 | + creds: '${{ secrets.AZURE_CREDENTIALS }}' |
| 104 | + |
| 105 | + - run: | |
| 106 | + cp PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/appsettings.${{ inputs.env }}.json PocketDDD.BlazorClient/PocketDDD.BlazorClient/wwwroot/appsettings.Production.json |
| 107 | +
|
| 108 | + - run: | |
| 109 | + apiToken=$(az staticwebapp secrets list --name pocketddd-${{ inputs.env }}-blazorclient --query "properties.apiKey" -o tsv) |
| 110 | + echo "WEB_APP_API_TOKEN=$apiToken" >> "$GITHUB_ENV" |
| 111 | +
|
| 112 | + - name: Build And Deploy |
| 113 | + id: builddeploy |
| 114 | + uses: Azure/static-web-apps-deploy@v1 |
| 115 | + with: |
| 116 | + azure_static_web_apps_api_token: ${{ env.WEB_APP_API_TOKEN }} |
| 117 | + repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments) |
| 118 | + action: "upload" |
| 119 | + ###### Repository/Build Configurations - These values can be configured to match your app requirements. ###### |
| 120 | + # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig |
| 121 | + app_location: "/PocketDDD.BlazorClient/PocketDDD.BlazorClient" # App source code path |
| 122 | + api_location: "" # Api source code path - optional |
| 123 | + output_location: "wwwroot" # Built app content directory - optional |
| 124 | + ###### End of Repository/Build Configurations ###### |
0 commit comments