Skip to content

Commit 71de691

Browse files
chore: gateway refactorings (#17816)
1 parent 134a58c commit 71de691

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+541
-430
lines changed

.github/workflows/deploy-runtime-gateway.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ jobs:
6161
uses: fluxcd/flux2/action@8454b02a32e48d775b9f563cb51fdcb1787b5b93 # v2.7.5
6262

6363
- name: docker build
64-
run: docker build -t ${{ env.IMAGE_REPO }} -f Dockerfile .
64+
working-directory: src
65+
run: docker build -t ${{ env.IMAGE_REPO }} -f Runtime/gateway/Dockerfile .
6566

6667
- name: scan image
6768
uses: aquasecurity/trivy-action@c1824fd6edce30d7ab345a9989de00bbd46ef284 # 0.34.0

src/.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Repository-wide defaults for image builds from src/ context.
2+
# Service-specific filtering should be handled in Dockerfile.dockerignore files.
3+
**/.DS_Store
4+
**/.cache
5+
**/.config
6+
**/.git
7+
**/.idea
8+
**/.vscode
9+
**/bin
10+
**/obj
11+
**/node_modules

src/Runtime/gateway/Dockerfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ RUN apt-get update && apt-get install -y clang zlib1g-dev && rm -rf /var/lib/apt
66
WORKDIR /build
77

88
# Copy project files and package management
9-
COPY Directory.Packages.props .
10-
COPY src/Altinn.Studio.Gateway.Api/Altinn.Studio.Gateway.Api.csproj Altinn.Studio.Gateway.Api/
11-
COPY src/Altinn.Studio.Gateway.Contracts/Altinn.Studio.Gateway.Contracts.csproj Altinn.Studio.Gateway.Contracts/
9+
COPY Runtime/gateway/Directory.Packages.props .
10+
COPY Runtime/gateway/src/Altinn.Studio.Gateway.Api/Altinn.Studio.Gateway.Api.csproj Altinn.Studio.Gateway.Api/
11+
COPY Runtime/gateway/src/Altinn.Studio.Gateway.Contracts/Altinn.Studio.Gateway.Contracts.csproj Altinn.Studio.Gateway.Contracts/
1212

1313
# Restore dependencies
1414
RUN dotnet restore Altinn.Studio.Gateway.Api/Altinn.Studio.Gateway.Api.csproj
1515

1616
# Copy source code
17-
COPY src/Altinn.Studio.Gateway.Api/ Altinn.Studio.Gateway.Api/
18-
COPY src/Altinn.Studio.Gateway.Contracts/ Altinn.Studio.Gateway.Contracts/
17+
COPY Runtime/gateway/src/Altinn.Studio.Gateway.Api/ Altinn.Studio.Gateway.Api/
18+
COPY Runtime/gateway/src/Altinn.Studio.Gateway.Contracts/ Altinn.Studio.Gateway.Contracts/
1919

2020
# Build and publish native AOT
2121
WORKDIR /build/Altinn.Studio.Gateway.Api
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Keep src/ build context minimal for gateway image.
2+
**
3+
!Runtime/gateway/Directory.Packages.props
4+
!Runtime/gateway/src/Altinn.Studio.Gateway.Api/**
5+
!Runtime/gateway/src/Altinn.Studio.Gateway.Contracts/**

src/Runtime/gateway/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ restore: ## Restore .NET packages and tools
4040

4141
build: ## Build Go and .NET projects
4242
@echo "Building Go packages..."
43-
@go build ./...
43+
@tmp_dir=$$(mktemp -d) && \
44+
go build -o "$$tmp_dir" ./... && \
45+
rm -rf "$$tmp_dir"
4446
@echo "Building .NET solution..."
4547
@dotnet build Altinn.Studio.Gateway.slnx
4648
@echo "✓ Build successful"

src/Runtime/gateway/cmd/tester/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ func setupRuntime(variant kind.KindContainerRuntimeVariant) (*harness.Result, er
193193
return nil, err
194194
}
195195

196+
srcRoot := filepath.Clean(filepath.Join(root, "../.."))
197+
dockerfile := filepath.Join(srcRoot, "Runtime", "gateway", "Dockerfile")
198+
196199
cfg := harness.Config{
197200
ProjectRoot: root,
198201
CachePath: cachePath,
@@ -206,8 +209,8 @@ func setupRuntime(variant kind.KindContainerRuntimeVariant) (*harness.Result, er
206209
Images: []harness.Image{
207210
{
208211
Name: "gateway",
209-
Context: ".",
210-
Dockerfile: "Dockerfile",
212+
Context: srcRoot,
213+
Dockerfile: dockerfile,
211214
Tag: "localhost:5001/gateway:latest",
212215
},
213216
},

src/Runtime/gateway/compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
services:
22
gateway:
33
build:
4-
context: .
5-
dockerfile: Dockerfile
4+
context: ../../
5+
dockerfile: Runtime/gateway/Dockerfile
66
ports:
77
- "8080:8080"
88
restart: unless-stopped

src/Runtime/gateway/src/Altinn.Studio.Gateway.Api/Application/HandleAlerts.cs renamed to src/Runtime/gateway/src/Altinn.Studio.Gateway.Api/Application/Alerts/HandleAlerts.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55
using Altinn.Studio.Gateway.Api.Clients.MetricsClient;
66
using Altinn.Studio.Gateway.Api.Settings;
77
using Altinn.Studio.Gateway.Contracts.Alerts;
8+
using Microsoft.Extensions.Options;
89

910
namespace Altinn.Studio.Gateway.Api.Application;
1011

1112
internal static class HandleAlerts
1213
{
13-
internal static async Task<IResult> GetAlertRulesAsync(
14+
internal static async Task<IResult> GetAlertRules(
1415
IServiceProvider serviceProvider,
15-
AlertsClientSettings alertsClientSettings,
16+
IOptionsMonitor<AlertsClientSettings> alertsClientSettings,
1617
CancellationToken cancellationToken
1718
)
1819
{
19-
IAlertsClient client = serviceProvider.GetRequiredKeyedService<IAlertsClient>(alertsClientSettings.Provider);
20+
IAlertsClient client = serviceProvider.GetRequiredKeyedService<IAlertsClient>(
21+
alertsClientSettings.CurrentValue.Provider
22+
);
2023

21-
IEnumerable<GrafanaAlertRule> alertRules = await client.GetAlertRulesAsync(cancellationToken);
24+
IEnumerable<GrafanaAlertRule> alertRules = await client.GetAlertRules(cancellationToken);
2225

2326
return Results.Ok(
2427
alertRules?.Select(alert =>
@@ -40,19 +43,20 @@ CancellationToken cancellationToken
4043
);
4144
}
4245

43-
internal static async Task<IResult> NotifyAlertsUpdatedAsync(
44-
GatewayContext gatewayContext,
46+
internal static async Task<IResult> NotifyAlertsUpdated(
47+
IOptionsMonitor<GatewayContext> gatewayContext,
4548
IServiceProvider serviceProvider,
46-
MetricsClientSettings metricsClientSettings,
49+
IOptionsMonitor<MetricsClientSettings> metricsClientSettings,
4750
DesignerClient designerClient,
4851
AlertPayload alertPayload,
4952
CancellationToken cancellationToken,
5053
string environment = "prod"
5154
)
5255
{
5356
IMetricsClient metricsClient = serviceProvider.GetRequiredKeyedService<IMetricsClient>(
54-
metricsClientSettings.Provider
57+
metricsClientSettings.CurrentValue.Provider
5558
);
59+
var currentGatewayContext = gatewayContext.CurrentValue;
5660

5761
var firstAlert = alertPayload.Alerts.FirstOrDefault();
5862
if (firstAlert is null)
@@ -91,9 +95,9 @@ out var interval
9195
var apps = alerts.Select(alertInstance => alertInstance.App).ToList();
9296

9397
var logsUrl = metricsClient.GetLogsUrl(
94-
gatewayContext.AzureSubscriptionId,
95-
gatewayContext.ServiceOwner,
96-
gatewayContext.Environment,
98+
currentGatewayContext.AzureSubscriptionId,
99+
currentGatewayContext.ServiceOwner,
100+
currentGatewayContext.Environment,
97101
apps,
98102
ruleId,
99103
from,
@@ -110,7 +114,7 @@ out var interval
110114
LogsUrl = logsUrl,
111115
};
112116

113-
await designerClient.NotifyAlertsUpdatedAsync(alert, environment, cancellationToken);
117+
await designerClient.NotifyAlertsUpdated(alert, environment, cancellationToken);
114118

115119
return Results.Ok();
116120
}

src/Runtime/gateway/src/Altinn.Studio.Gateway.Api/Application/HandleGetAppDeployment.cs renamed to src/Runtime/gateway/src/Altinn.Studio.Gateway.Api/Application/Deploy/HandleGetAppDeployment.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Altinn.Studio.Gateway.Api.Clients.K8s;
22
using Altinn.Studio.Gateway.Api.Settings;
3+
using Microsoft.Extensions.Options;
34

45
namespace Altinn.Studio.Gateway.Api.Application;
56

@@ -8,23 +9,28 @@ internal static class HandleGetAppDeployment
89
internal static async Task<IResult> GetAppDeploymentHandler(
910
string app,
1011
string originEnvironment,
11-
GatewayContext gatewayContext,
12+
IOptionsMonitor<GatewayContext> gatewayContext,
1213
HelmReleaseClient helmReleaseClient,
1314
ILogger<Program> logger,
1415
CancellationToken cancellationToken
1516
)
1617
{
17-
var helmReleaseName = HelmReleaseNameHelper.Generate(gatewayContext.ServiceOwner, app, originEnvironment);
18+
var currentGatewayContext = gatewayContext.CurrentValue;
19+
var helmReleaseName = HelmReleaseNameHelper.Generate(
20+
currentGatewayContext.ServiceOwner,
21+
app,
22+
originEnvironment
23+
);
1824

19-
var helmRelease = await helmReleaseClient.GetAsync(helmReleaseName, "default", cancellationToken);
25+
var helmRelease = await helmReleaseClient.Get(helmReleaseName, "default", cancellationToken);
2026

2127
if (helmRelease is null)
2228
return Results.NotFound();
2329

2430
if (
2531
!HelmReleaseMapping.TryCreateAppDeployment(
2632
helmRelease,
27-
gatewayContext.Environment,
33+
currentGatewayContext.Environment,
2834
out var deployment,
2935
out var error
3036
)

src/Runtime/gateway/src/Altinn.Studio.Gateway.Api/Application/HandleIsAppDeployed.cs renamed to src/Runtime/gateway/src/Altinn.Studio.Gateway.Api/Application/Deploy/HandleIsAppDeployed.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Altinn.Studio.Gateway.Api.Clients.K8s;
22
using Altinn.Studio.Gateway.Api.Settings;
33
using Altinn.Studio.Gateway.Contracts.Deploy;
4+
using Microsoft.Extensions.Options;
45

56
namespace Altinn.Studio.Gateway.Api.Application;
67

@@ -9,13 +10,18 @@ internal static class HandleIsAppDeployed
910
internal static async Task<IResult> IsAppDeployedHandler(
1011
string app,
1112
string originEnvironment,
12-
GatewayContext gatewayContext,
13+
IOptionsMonitor<GatewayContext> gatewayContext,
1314
HelmReleaseClient helmReleaseClient,
1415
CancellationToken cancellationToken
1516
)
1617
{
17-
var helmReleaseName = HelmReleaseNameHelper.Generate(gatewayContext.ServiceOwner, app, originEnvironment);
18-
var helmRelease = await helmReleaseClient.GetAsync(helmReleaseName, "default", cancellationToken);
18+
var currentGatewayContext = gatewayContext.CurrentValue;
19+
var helmReleaseName = HelmReleaseNameHelper.Generate(
20+
currentGatewayContext.ServiceOwner,
21+
app,
22+
originEnvironment
23+
);
24+
var helmRelease = await helmReleaseClient.Get(helmReleaseName, "default", cancellationToken);
1925
return Results.Ok(new IsAppDeployedResponse(helmRelease is not null));
2026
}
2127
}

0 commit comments

Comments
 (0)