Multiarch new method

This commit is contained in:
Tech Garage 2024-09-10 00:58:14 +03:30
parent 768d5084f2
commit 0c015d6024
5 changed files with 68 additions and 4 deletions

2
.gitignore vendored
View file

@ -370,3 +370,5 @@ FodyWeavers.xsd
/build.bat
/publish.bat
/run.bat
/api doc
/UI/Properties/launchSettings.json

View file

@ -0,0 +1,40 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MTWireGuard.Application
{
public class ApplicationLifetimeService(IHostApplicationLifetime hostApplicationLifetime, ILogger logger) : IHostedService
{
public Task StartAsync(CancellationToken cancellationToken)
{
hostApplicationLifetime.ApplicationStarted.Register(OnStarted);
hostApplicationLifetime.ApplicationStopping.Register(OnStopping);
hostApplicationLifetime.ApplicationStopped.Register(OnStopped);
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
=> Task.CompletedTask;
private void OnStarted()
{
logger.LogInformation("Registered: {Name}!", Environment.UserName);
}
private void OnStopping()
{
logger.LogWarning("Exiting: {MachineName}!", Environment.MachineName);
}
private void OnStopped()
{
// ...
}
}
}

View file

@ -1,6 +1,14 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS publish
WORKDIR /src
# Define platform
ARG TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
RID=linux-x64 ; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
RID=linux-arm64 ; \
fi
# Copy project files
COPY *.sln .
COPY UI/*.csproj ./UI/
@ -9,7 +17,7 @@ COPY MikrotikAPI/*.csproj ./MikrotikAPI/
COPY Serilog.Ui.SqliteProvider/*.csproj ./Serilog.Ui.SqliteProvider/
# Restore packages
RUN dotnet restore --runtime linux-$BUILDARCH
RUN dotnet restore --runtime $RID
# Copy other files
COPY UI/. ./UI/
@ -21,7 +29,7 @@ COPY Serilog.Ui.SqliteProvider/. ./Serilog.Ui.SqliteProvider/
RUN dotnet publish "./UI/MTWireGuard.csproj" -c Release \
-o /app/publish \
--no-restore \
--runtime linux-$BUILDARCH \
--runtime $RID \
--self-contained true \
/p:WarningLevel=0 \
/p:PublishTrimmed=true

View file

@ -1,5 +1,5 @@
@{
string username = Environment.GetEnvironmentVariable("MT_USER");
string username = Environment.GetEnvironmentVariable("MT_USER") ?? "";
}
<!DOCTYPE html>
<html lang="en">

View file

@ -7,7 +7,7 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"MT_IP": "192.168.0.96",
"MT_USER": "admin",
"MT_PASS": "",
"MT_PASS": "admin",
"MT_PUBLIC_IP": "192.168.0.96"
},
"hotReloadEnabled": true,
@ -34,6 +34,20 @@
},
"publishAllPorts": true,
"useSSL": true
},
"WSL": {
"commandName": "WSL2",
"launchBrowser": true,
"launchUrl": "https://192.168.0.5:7220",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "https://192.168.0.5:7220;http://192.168.0.5:5220",
"MT_IP": "192.168.0.96",
"MT_PASS": "admin",
"MT_PUBLIC_IP": "192.168.0.96",
"MT_USER": "admin"
},
"distributionName": ""
}
},
"iisSettings": {