Skip to content

Commit

Permalink
Merge pull request #16 from mule/development
Browse files Browse the repository at this point in the history
CI/CD pipelines now fully working and azure environment is setup
  • Loading branch information
mule authored Jul 21, 2023
2 parents 6fbfd79 + bd33fc2 commit 86adb4f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 36 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build on PR Branches

on:
push:
branches:
- 'pr-*'
- 'main'
pull_request:
branches:
- 'main'
env:
AZURE_WEBAPP_NAME: 'Abotti'
AZURE_WEBAPP_PACKAGE_PATH: '.'

jobs:
build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x' # Replace with your desired .NET version

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore --configuration Debug

# Set up Azurite using Docker
- name: Set up Azurite
run: docker run -d -p 10000:10000 -p 10001:10001 mcr.microsoft.com/azure-storage/azurite

# Run tests
- name: Run Tests
run: dotnet test --configuration Debug --filter Category!~PlaywrightTest

# Tear down Azurite container after tests are done (to free up resources)
- name: Tear down Azurite
run: docker stop $(docker ps -aqf "ancestor=mcr.microsoft.com/azure-storage/azurite") && docker rm $(docker ps -aqf "ancestor=mcr.microsoft.com/azure-storage/azurite")

# Publish to a temporary folder
- name: Publish
if: github.ref == 'refs/heads/main'
run: dotnet publish ./ChatGptBlazorApp --configuration Release --output ${{env.AZURE_WEBAPP_PACKAGE_PATH}}/dist


# Deploy to Azure Web App
- name: Deploy to azure
if: github.ref == 'refs/heads/main'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AzureAppService_PublishProfile_107CDD4B25B14E458AD5DF3CB34494EA}}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/dist
28 changes: 0 additions & 28 deletions .github/workflows/dotnet.yml

This file was deleted.

22 changes: 16 additions & 6 deletions ChatGptBlazorApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using OpenAI.ObjectModels;
using Serilog;
using ServiceAccessLayer.AiServices;
using Spectre.Console;

// Configure Serilog logger
Log.Logger = new LoggerConfiguration()
Expand All @@ -26,29 +25,40 @@
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddUserSecrets<Program>();


builder.Configuration.AddEnvironmentVariables();

Log.Information("Environment is {Environment}", builder.Environment.EnvironmentName);

builder.Configuration.AddUserSecrets<Program>();


var azureKeyVaultUriStr = builder.Configuration.GetValue<string>("AzureKeyVaultUri");
if (!string.IsNullOrEmpty(azureKeyVaultUriStr))
{
Log.Information("Adding Azure Key Vault to configuration");
var azureKeyVaultUri = new Uri(azureKeyVaultUriStr);


// var cred = new ManagedIdentityCredential("05e4ad6d-45ef-49a8-b9fc-053a1edf691a");
// Log.Debug("Azure Key Vault credential: {AzureKeyVaultCredential}", cred.ToJson());
builder.Configuration.AddAzureKeyVault(azureKeyVaultUri, new DefaultAzureCredential());
}

AnsiConsole.WriteLine(builder.Configuration.GetDebugView());
//AnsiConsole.WriteLine(builder.Configuration.GetDebugView());

var openAiKey = builder.Configuration["OpenAIServiceOptions:ApiKey"];
var blobStorageConnectionString = builder.Configuration.GetConnectionString("BlobStorage");

var openAiKey = builder.Configuration["openai-api-key"] ?? builder.Configuration["OpenAIServiceOptions:ApiKey"];
var blobStorageConnectionString = builder.Configuration["BlobStorage:ConnectionString"];
var blobStorageContainerName = builder.Configuration["BlobStorage:ContainerName"];

var connectionString = builder.Configuration.GetConnectionString("ChatGptBlazorAppContextConnection") ??
throw new InvalidOperationException(
"Connection string 'ChatGptBlazorAppContextConnection' not found.");
var config = builder.Configuration;


var adminUserIdStr = builder.Configuration.GetValue<string>("AdminUser:Id");
var adminUserId = Guid.Parse(adminUserIdStr);
var adminUserName = builder.Configuration.GetValue<string>("AdminUser:UserName");
Expand Down Expand Up @@ -142,7 +152,7 @@ await userRepo.InitializeAsync(new Dictionary<Guid, User>
}
catch (Exception e)
{
Log.Fatal("Application start-up failed", e);
Log.Fatal(e, "Application start-up failed {EMessage} ", e.Message);
}
finally
{
Expand Down
4 changes: 3 additions & 1 deletion ChatGptBlazorApp/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"BlobStorage": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;"
},
"BlobStorage": {
"ConnectionString": "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;",
"ContainerName": "abotti-db-dev"
}
}
2 changes: 2 additions & 0 deletions ChatGptBlazorAppTests/ChatPageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public ChatPageTests(PlaywrightFixture playwrightFixture)
this.playwrightFixture = playwrightFixture;
}


[Fact]
[Trait("Category", "PlaywrightTest")]
public async Task ShouldRenderPageCorrectly()
{
var url = "http://127.0.0.1:5000";
Expand Down
2 changes: 1 addition & 1 deletion openaiSDK/OpenAI.SDK/OpenAI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;netstandard2.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>Latest</LangVersion>
Expand All @@ -27,6 +26,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 86adb4f

Please sign in to comment.