Set up docker image and k8s deployment
This commit is contained in:
10
.dockerignore
Normal file
10
.dockerignore
Normal 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
|
||||||
@@ -17,6 +17,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Update="appsettings.Docker.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="appsettings.Development.json">
|
<None Update="appsettings.Development.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
|||||||
@@ -2,12 +2,14 @@
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
public class ServiceOptions {
|
public class ServiceOptions {
|
||||||
|
public string Baserom { get; set; } = null!;
|
||||||
public string PythonPath { get; set; } = null!;
|
public string PythonPath { get; set; } = null!;
|
||||||
public string RandomizerPath { get; set; } = null!;
|
public string RandomizerPath { get; set; } = null!;
|
||||||
public AzureSettings AzureSettings { get; set; } = new AzureSettings();
|
public AzureSettings AzureSettings { get; set; } = new AzureSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AzureSettings {
|
public class AzureSettings {
|
||||||
|
public string? ClientId { get; set; }
|
||||||
public Uri BlobstoreEndpoint { get; set; } = null!;
|
public Uri BlobstoreEndpoint { get; set; } = null!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
using ALttPRandomizer.Azure;
|
using ALttPRandomizer.Azure;
|
||||||
using ALttPRandomizer.Options;
|
using ALttPRandomizer.Options;
|
||||||
using ALttPRandomizer.Service;
|
using ALttPRandomizer.Service;
|
||||||
|
using global::Azure.Core;
|
||||||
using global::Azure.Identity;
|
using global::Azure.Identity;
|
||||||
using global::Azure.Storage.Blobs;
|
using global::Azure.Storage.Blobs;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
@@ -20,7 +21,7 @@
|
|||||||
|
|
||||||
builder.Configuration
|
builder.Configuration
|
||||||
.AddJsonFile("appsettings.json")
|
.AddJsonFile("appsettings.json")
|
||||||
.AddJsonFile("appsettings.Development.json")
|
.AddJsonFile("appsettings.Development.json", true)
|
||||||
.AddEnvironmentVariables();
|
.AddEnvironmentVariables();
|
||||||
|
|
||||||
builder.Services.Configure<ServiceOptions>(builder.Configuration.GetSection("ALttPRandomizer"));
|
builder.Services.Configure<ServiceOptions>(builder.Configuration.GetSection("ALttPRandomizer"));
|
||||||
@@ -34,7 +35,13 @@
|
|||||||
var provider = builder.Services.BuildServiceProvider();
|
var provider = builder.Services.BuildServiceProvider();
|
||||||
var settings = provider.GetRequiredService<IOptionsMonitor<ServiceOptions>>().CurrentValue!;
|
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);
|
var seedClient = new BlobContainerClient(settings.AzureSettings.BlobstoreEndpoint, token);
|
||||||
|
|
||||||
builder.Services.AddSingleton(seedClient);
|
builder.Services.AddSingleton(seedClient);
|
||||||
|
|||||||
@@ -37,7 +37,8 @@
|
|||||||
|
|
||||||
var args = start.ArgumentList;
|
var args = start.ArgumentList;
|
||||||
args.Add("DungeonRandomizer.py");
|
args.Add("DungeonRandomizer.py");
|
||||||
args.Add("--rom=../alttp.sfc");
|
args.Add("--rom");
|
||||||
|
args.Add(this.Configuration.Baserom);
|
||||||
args.Add("--bps");
|
args.Add("--bps");
|
||||||
|
|
||||||
args.Add("--outputpath");
|
args.Add("--outputpath");
|
||||||
|
|||||||
16
ALttPRandomizer/appsettings.Docker.json
Normal file
16
ALttPRandomizer/appsettings.Docker.json
Normal 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
37
Dockerfile
Normal 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
21
deployment.yaml
Normal 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
|
||||||
Reference in New Issue
Block a user