Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for appsettings #18

Merged
merged 6 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ on:
description: "Publish workflow artifacts"
type: boolean
default: false
settings_file:
description: "The filename of the appsettings file"
type: string

jobs:
shifty-build:
name: Build webapp
uses: ./.github/workflows/shifty-build.yml
with:
publish_artifacts: ${{ inputs.publish_artifacts }}
settings_file: ${{ inputs.settings_file }}
secrets: inherit

infra-build:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ jobs:
secrets: inherit
with:
environment: dev
settings_file: "dev.appsettings.json"
1 change: 1 addition & 0 deletions .github/workflows/deploy-prd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ jobs:
secrets: inherit
with:
environment: prd
settings_file: "prd.appsettings.json"
5 changes: 5 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ on:
type: string
required: true
description: "Target Environment. Can either be 'dev' or 'prd'"
settings_file:
type: string
required: true
description: "The filename of the appsettings file to use"

jobs:
build-all:
name: Build codebase
uses: ./.github/workflows/build.yml
with:
publish_artifacts: true
settings_file: ${{ inputs.settings_file }}
secrets: inherit

deploy:
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Pull Request

on:
pull_request:
branches: [ main ]

jobs:
build:
uses: ./.github/workflows/build.yml
secrets: inherit
with:
settings_file: "appsettings.json"
5 changes: 5 additions & 0 deletions .github/workflows/shifty-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:
description: "Publish workflow artifacts"
type: boolean
default: false
settings_file:
description: "The filename of the appsettings file"
type: string

jobs:
build-test:
Expand All @@ -24,6 +27,8 @@ jobs:
dotnet-version: 6.x
- name: Restore dependencies
run: dotnet restore .
- name: Settings override
run: mv -f "infrastructure/${{ inputs.settings_file }}" Shifty.App/wwwroot/appsettings.json
- name: Build Shifty App
run: dotnet build . --no-restore /p:ContinuousIntegrationBuild=true --configuration Release
- name: Run tests
Expand Down
8 changes: 4 additions & 4 deletions Shifty.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Blazored.LocalStorage;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using MudBlazor.Services;
using Shifty.Api.Generated.AnalogCoreV1;
Expand All @@ -19,13 +20,12 @@ public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");

ConfigureServices(builder.Services);
ConfigureServices(builder.Services, builder.Configuration);

await builder.Build().RunAsync();
}

public static void ConfigureServices(IServiceCollection services)
public static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddMudServices(config =>
{
Expand All @@ -38,7 +38,7 @@ public static void ConfigureServices(IServiceCollection services)
services.AddScoped(sp => sp.GetRequiredService<IHttpClientFactory>()
.CreateClient("AnalogCoreV1"));
services.AddHttpClient("AnalogCoreV1",
client => client.BaseAddress = new Uri("https://core.dev.analogio.dk/"))
client => client.BaseAddress = new Uri(configuration["ApiHost"]))
.AddHttpMessageHandler<RequestAuthenticationHandler>();
services.AddScoped(provider =>
new AnalogCoreV1(provider.GetRequiredService<IHttpClientFactory>().CreateClient("AnalogCoreV1")));
Expand Down
3 changes: 3 additions & 0 deletions Shifty.App/wwwroot/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ApiHost": "http://localhost:8080"
}
3 changes: 3 additions & 0 deletions infrastructure/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ApiHost": "http://localhost:8080"
}
3 changes: 3 additions & 0 deletions infrastructure/dev.appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ApiHost": "https://core.dev.analogio.dk"
}
3 changes: 3 additions & 0 deletions infrastructure/prd.appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ApiHost": "https://core.prd.analogio.dk"
}
2 changes: 1 addition & 1 deletion infrastructure/shifty.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource staticwebapp 'Microsoft.Web/staticSites@2022-03-01' = {
properties: {
allowConfigFileUpdates: false
repositoryUrl: 'https://github.com/AnalogIO/shifty-webapp'
branch: 'develop'
branch: 'main'
provider: 'GitHub'
stagingEnvironmentPolicy: 'Disabled'
enterpriseGradeCdnStatus: 'Disabled'
Expand Down