diff --git a/.github/workflows/Assignment1.yml b/.github/workflows/Assignment1.yml new file mode 100644 index 0000000..b861b80 --- /dev/null +++ b/.github/workflows/Assignment1.yml @@ -0,0 +1,82 @@ +name: Assignment 1 + +on: + workflow_dispatch: + push: + branches: + - Assignment1 + paths: + - 'Assignment1/**' + - '.github/workflows/Assignment1.yml' + +# Required for OIDC authentication +permissions: + id-token: write + contents: read + +env: + DOTNET_VERSION: '8.0.x' + AZURE_WEBAPP_NAME: 'cscd396-jake-webapp' + WEBAPP_PACKAGE_PATH: 'Assignment1/WebApp' + +jobs: + list-azure-resources: + name: Login and List Azure Resources + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Azure Login with OIDC + uses: azure/login@v2 + with: + client-id: ${{ vars.CLIENT_ID }} + tenant-id: ${{ vars.TENANT_ID }} + subscription-id: ${{ vars.SUBSCRIPTION_ID }} + + - name: Run Assignment1.ps1 - List Resources + shell: pwsh + run: | + ./Assignment1/Assignment1.ps1 + + - name: Logout from Azure + if: always() + run: az logout + + build-and-deploy-webapp: + name: Build and Deploy .NET Web App + runs-on: ubuntu-latest + needs: list-azure-resources + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + + - name: Build and publish + run: | + dotnet publish ${{ env.WEBAPP_PACKAGE_PATH }}/WebApp.csproj \ + --configuration Release \ + --output ./publish + + - name: Azure Login with OIDC + uses: azure/login@v2 + with: + client-id: ${{ vars.CLIENT_ID }} + tenant-id: ${{ vars.TENANT_ID }} + subscription-id: ${{ vars.SUBSCRIPTION_ID }} + + - name: Deploy to Azure App Service + uses: azure/webapps-deploy@v3 + with: + app-name: ${{ env.AZURE_WEBAPP_NAME }} + package: ./publish + + - name: Logout from Azure + if: always() + run: az logout diff --git a/Assignment1/Assignment1.ps1 b/Assignment1/Assignment1.ps1 new file mode 100644 index 0000000..f6b773a --- /dev/null +++ b/Assignment1/Assignment1.ps1 @@ -0,0 +1,20 @@ +# Assignment 1 - Azure Resource Listing Script +# CSCD 396 - DevOps + +# Your Azure Subscription ID +$subscription_id = "d7dc33ae-d588-44a6-bda7-3e08dbd66d6f" + +# Set the active subscription +az account set --subscription $subscription_id + +# List all resources in the subscription +Write-Host "=== All Resources in Subscription ===" +az resource list --subscription $subscription_id --output table + +Write-Host "" +Write-Host "=== Resource Groups ===" +az group list --subscription $subscription_id --output table + +Write-Host "" +Write-Host "=== Storage Accounts ===" +az storage account list --subscription $subscription_id --output table diff --git a/Assignment1/WebApp/Pages/Index.cshtml b/Assignment1/WebApp/Pages/Index.cshtml new file mode 100644 index 0000000..a27eea2 --- /dev/null +++ b/Assignment1/WebApp/Pages/Index.cshtml @@ -0,0 +1,8 @@ +@page +@model IndexModel +@{ + ViewData["Title"] = "Home"; +} + +

CSCD 396 - Assignment 1

+

Deployed to Azure App Service via GitHub Actions.

diff --git a/Assignment1/WebApp/Pages/Index.cshtml.cs b/Assignment1/WebApp/Pages/Index.cshtml.cs new file mode 100644 index 0000000..d58644a --- /dev/null +++ b/Assignment1/WebApp/Pages/Index.cshtml.cs @@ -0,0 +1,8 @@ +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WebApp.Pages; + +public class IndexModel : PageModel +{ + public void OnGet() { } +} diff --git a/Assignment1/WebApp/Pages/Shared/_Layout.cshtml b/Assignment1/WebApp/Pages/Shared/_Layout.cshtml new file mode 100644 index 0000000..5da57f6 --- /dev/null +++ b/Assignment1/WebApp/Pages/Shared/_Layout.cshtml @@ -0,0 +1,11 @@ + + + + + + @ViewData["Title"] - CSCD 396 + + + @RenderBody() + + diff --git a/Assignment1/WebApp/Pages/_ViewImports.cshtml b/Assignment1/WebApp/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..8179c16 --- /dev/null +++ b/Assignment1/WebApp/Pages/_ViewImports.cshtml @@ -0,0 +1,3 @@ +@using WebApp +@namespace WebApp.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/Assignment1/WebApp/Pages/_ViewStart.cshtml b/Assignment1/WebApp/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..820a2f6 --- /dev/null +++ b/Assignment1/WebApp/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} diff --git a/Assignment1/WebApp/Program.cs b/Assignment1/WebApp/Program.cs new file mode 100644 index 0000000..1e57432 --- /dev/null +++ b/Assignment1/WebApp/Program.cs @@ -0,0 +1,12 @@ +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddRazorPages(); + +var app = builder.Build(); + +app.UseHttpsRedirection(); +app.UseStaticFiles(); +app.UseRouting(); +app.MapRazorPages(); + +app.Run(); diff --git a/Assignment1/WebApp/WebApp.csproj b/Assignment1/WebApp/WebApp.csproj new file mode 100644 index 0000000..1b28a01 --- /dev/null +++ b/Assignment1/WebApp/WebApp.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + enable + + +