Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickZhao1989 committed Oct 19, 2024
0 parents commit b5aa675
Show file tree
Hide file tree
Showing 49 changed files with 4,616 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy .NET 8 Web API to Azure Web App

on:
push:
branches:
- main # Deploy only when code is pushed to the main branch

jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
AppServiceName: stgss6vrhey

steps:
- uses: actions/checkout@v4

- name: Set up .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.x' # Use .NET 8

- name: Set up dependency caching for faster builds
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Build the .NET app
run: dotnet build --configuration Release
working-directory: backend

- name: Publish the app
run: dotnet publish -c Release -o publish_output
working-directory: backend

- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: $AppServiceName # Replace with your Azure Web App name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: backend/publish_output

58 changes: 58 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Deploy Vite App to Azure Blob Storage

on:
push:
branches:
- main

jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
BlobStorageAccountName: stgss6vrhey

steps:
# Step 1: Checkout the repository
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20' # Use the appropriate Node.js version

# Step 3: Install dependencies
- name: Install dependencies
run: npm ci
working-directory: frontend

# Step 4: Build the Vite app
- name: Build Vite app
run: npm run build
working-directory: frontend

# Step 5: Upload build output as an artifact (optional)
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: build
path: frontend/dist

# Step 6: Install Azure CLI
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Azure CLI script
uses: azure/cli@v2
with:
azcliversion: latest
inlineScript: |
az storage blob upload-batch \
--account-name $BlobStorageAccountName \
--account-key ${{ secrets.AZURE_STORAGE_ACCOUNT_KEY }} \
--destination '$web' \
--source frontend/dist \
--overwrite
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/.DS_Store
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Patrick Zhao

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions OnedayHackDay-Azure-App.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BackendApi", "backend\BackendApi.csproj", "{DF92D804-C593-4D52-8B3E-44649B1D9931}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DF92D804-C593-4D52-8B3E-44649B1D9931}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF92D804-C593-4D52-8B3E-44649B1D9931}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF92D804-C593-4D52-8B3E-44649B1D9931}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF92D804-C593-4D52-8B3E-44649B1D9931}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46D6D1D9-D0D5-473D-A3DB-E0B7E7607876}
EndGlobalSection
EndGlobal
11 changes: 11 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Overview
Check subsequent Readme files for further information
- [Infra](./infrastructure/Readme.md)
- [Backend](./backend/README.md)
- [Frontend](./frontend/README.md)

# Useful command
## Create Service principal on Azure Entra Id
```shell
az ad sp create-for-rbac --name "<your-service-principal-name>" --sdk-auth --role contributor --scopes /subscriptions/<your-subscription-id>/resourceGroups/<resource-group-name>
```
96 changes: 96 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Ignore build outputs
bin/
obj/

# User-specific files
*.user
*.rsuser
*.suo
*.userosscache
*.sln.docstates

# ASP.NET Scaffolding
.scaffolding

# Environment variables
.env

# Rider/JetBrains IDE
.idea/
*.sln.iml

# VS Code files
.vscode/
.vscode/settings.json

# Visual Studio specific
.vscode/*
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.vs/
*.vcxproj.user
*.vcxproj.filters
*.dbmdl
*.opendb
*.opensdf
*.sdf
*.sqlite
*.sqlproj.user
*.cache
*.pdb
**/*.pdb
*.vspxproj
.vscode/*
launchSettings.json

# DotNet Core specifics
project.lock.json
project.fragment.lock.json
artifacts/
*.log
*.vspscc
*.vssscc
*.ide

# NuGet package directories
**/packages/
# except build/, which is used as an MSBuild target.
!packages/build/

# Including NuGet package sources
# Exclude directories with NuGet.exe as they contain only NuGet cache data
*.nupkg

# Ignore .NET SDK autogenerated files
*.pdb
*.dll
*.exe
*.app

# Ignore coverage tool output
coverage/
coverage.info
.coverage
*.coverage

# Ignore publish directories
publish/
publish-output/

# Ignore yarn & npm files
node_modules/
yarn-error.log
.yarn-integrity
.yarn-cache/

# Ignore IDE auto-generated files
.idea/
*.sln.iml

# Others
DumpStack.log*
logs/

TestDB.db
publish_output
20 changes: 20 additions & 0 deletions backend/BackendApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions backend/BackendApi.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@BackendApi_HostAddress = http://localhost:5075

GET {{BackendApi_HostAddress}}/HelloWorld/
Accept: application/json

###
20 changes: 20 additions & 0 deletions backend/Controllers/HelloWorldController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using MyWebApi.Entities;

[Route("api/[controller]")]
[ApiController]
public class HelloWorldController : ControllerBase
{
private readonly TestDbContext _context;

public HelloWorldController(TestDbContext context)
{
_context = context;
}

[HttpGet]
public ActionResult<string> HelloWorld()
{
return "Hello world";
}
}
72 changes: 72 additions & 0 deletions backend/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using MyWebApi.Entities;

[Route("api/[controller]")]
[ApiController]
public class ProductsController : ControllerBase
{
private readonly TestDbContext _context;

public ProductsController(TestDbContext context)
{
_context = context;
}

[HttpGet]
public async Task<ActionResult<IEnumerable<Product>>> GetProducts()
{
return await _context.Products.ToListAsync();
}

[HttpGet("{id}")]
public async Task<ActionResult<Product>> GetProduct(int id)
{
var product = await _context.Products.FindAsync(id);

if (product == null)
{
return NotFound();
}

return product;
}

[HttpPost]
public async Task<ActionResult<Product>> PostProduct(Product product)
{
_context.Products.Add(product);
await _context.SaveChangesAsync();

return CreatedAtAction(nameof(GetProduct), new { id = product.Id }, product);
}

[HttpPut("{id}")]
public async Task<IActionResult> PutProduct(int id, Product product)
{
if (id != product.Id)
{
return BadRequest();
}

_context.Entry(product).State = EntityState.Modified;
await _context.SaveChangesAsync();

return NoContent();
}

[HttpDelete("{id}")]
public async Task<IActionResult> DeleteProduct(int id)
{
var product = await _context.Products.FindAsync(id);
if (product == null)
{
return NotFound();
}

_context.Products.Remove(product);
await _context.SaveChangesAsync();

return NoContent();
}
}
Loading

0 comments on commit b5aa675

Please sign in to comment.