Set up docker image and k8s deployment

This commit is contained in:
2025-02-28 12:51:11 -06:00
parent b7230950b2
commit f3e047eccc
8 changed files with 100 additions and 3 deletions

10
.dockerignore Normal file
View File

@@ -0,0 +1,10 @@
ALttPRandomizer/appsettings.json
ALttPRandomizer/appsettings.Development.json
ALttPRandomizer/[Oo]bj
ALttPRandomizer/[Bb]in
*/__pycache__
*/.github
*/_vendor
ALttPDoorRandomizer/DR_*
ALttPDoorRandomizer/data/base2current.json

View File

@@ -17,6 +17,9 @@
</ItemGroup>
<ItemGroup>
<None Update="appsettings.Docker.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.Development.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>

View File

@@ -2,12 +2,14 @@
using System;
public class ServiceOptions {
public string Baserom { get; set; } = null!;
public string PythonPath { get; set; } = null!;
public string RandomizerPath { get; set; } = null!;
public AzureSettings AzureSettings { get; set; } = new AzureSettings();
}
public class AzureSettings {
public string? ClientId { get; set; }
public Uri BlobstoreEndpoint { get; set; } = null!;
}
}

View File

@@ -4,6 +4,7 @@
using ALttPRandomizer.Azure;
using ALttPRandomizer.Options;
using ALttPRandomizer.Service;
using global::Azure.Core;
using global::Azure.Identity;
using global::Azure.Storage.Blobs;
using Microsoft.AspNetCore.Builder;
@@ -20,7 +21,7 @@
builder.Configuration
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.Development.json")
.AddJsonFile("appsettings.Development.json", true)
.AddEnvironmentVariables();
builder.Services.Configure<ServiceOptions>(builder.Configuration.GetSection("ALttPRandomizer"));
@@ -34,7 +35,13 @@
var provider = builder.Services.BuildServiceProvider();
var settings = provider.GetRequiredService<IOptionsMonitor<ServiceOptions>>().CurrentValue!;
var token = new DefaultAzureCredential();
var options = new DefaultAzureCredentialOptions();
if (settings.AzureSettings.ClientId != null) {
options.ManagedIdentityClientId = new(settings.AzureSettings.ClientId);
}
var token = new DefaultAzureCredential(options);
var seedClient = new BlobContainerClient(settings.AzureSettings.BlobstoreEndpoint, token);
builder.Services.AddSingleton(seedClient);

View File

@@ -37,7 +37,8 @@
var args = start.ArgumentList;
args.Add("DungeonRandomizer.py");
args.Add("--rom=../alttp.sfc");
args.Add("--rom");
args.Add(this.Configuration.Baserom);
args.Add("--bps");
args.Add("--outputpath");

View File

@@ -0,0 +1,16 @@
{
"ALttPRandomizer": {
"baserom": "/randomizer/alttp.sfc",
"pythonPath": "/usr/bin/python3",
"randomizerPath": "/randomizer",
"azureSettings": {
"clientId": "2f242de5-7595-432c-b41d-30d21b2064f2",
"blobstoreEndpoint": "https://alttprstorage.blob.core.windows.net/seeds"
}
},
"Logging": {
"LogLevel": {
"Default": "Information"
}
}
}

37
Dockerfile Normal file
View File

@@ -0,0 +1,37 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0-azurelinux3.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ALttPRandomizer/ ALttPRandomizer/
WORKDIR "/src/ALttPRandomizer"
RUN dotnet build "./ALttPRandomizer.csproj" -c $BUILD_CONFIGURATION -o /app/build
RUN dotnet publish "./ALttPRandomizer.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM mcr.microsoft.com/dotnet/aspnet:8.0-azurelinux3.0 AS final
EXPOSE 8080
EXPOSE 8081
RUN tdnf install -y python3
RUN mkdir -p /randomizer/data
RUN touch /randomizer/data/base2current.json
RUN chown $APP_UID:$APP_UID /randomizer/data/base2current.json
USER $APP_UID
RUN python3 -m ensurepip --upgrade
WORKDIR /randomizer
COPY alttp.sfc .
COPY ALttPDoorRandomizer/resources/app/meta/manifests/pip_requirements.txt requirements.txt
RUN python3 -m pip install -r requirements.txt
COPY ALttPDoorRandomizer/ .
WORKDIR /app
COPY --from=build /app/publish .
COPY ALttPRandomizer/appsettings.Docker.json appsettings.json
ENTRYPOINT ["dotnet", "ALttPRandomizer.dll"]

21
deployment.yaml Normal file
View File

@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: alttpr-backend
spec:
selector:
matchLabels:
app: alttpr-backend
template:
metadata:
labels:
app: alttpr-backend
spec:
nodeSelector:
kubernetes.io/os: linux
containers:
- name: alttpr-backend
image: alttpracr.azurecr.io/alttpr-backend
ports:
- containerPort: 8080
name: http