mirror of
https://github.com/techgarage-ir/MTWireGuard.git
synced 2025-08-16 07:37:50 +02:00
Multiarch new method
This commit is contained in:
parent
768d5084f2
commit
0c015d6024
5 changed files with 68 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -370,3 +370,5 @@ FodyWeavers.xsd
|
||||||
/build.bat
|
/build.bat
|
||||||
/publish.bat
|
/publish.bat
|
||||||
/run.bat
|
/run.bat
|
||||||
|
/api doc
|
||||||
|
/UI/Properties/launchSettings.json
|
||||||
|
|
40
Application/ApplicationLifetimeService.cs
Normal file
40
Application/ApplicationLifetimeService.cs
Normal 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()
|
||||||
|
{
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
Dockerfile
12
Dockerfile
|
@ -1,6 +1,14 @@
|
||||||
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS publish
|
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS publish
|
||||||
WORKDIR /src
|
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 project files
|
||||||
COPY *.sln .
|
COPY *.sln .
|
||||||
COPY UI/*.csproj ./UI/
|
COPY UI/*.csproj ./UI/
|
||||||
|
@ -9,7 +17,7 @@ COPY MikrotikAPI/*.csproj ./MikrotikAPI/
|
||||||
COPY Serilog.Ui.SqliteProvider/*.csproj ./Serilog.Ui.SqliteProvider/
|
COPY Serilog.Ui.SqliteProvider/*.csproj ./Serilog.Ui.SqliteProvider/
|
||||||
|
|
||||||
# Restore packages
|
# Restore packages
|
||||||
RUN dotnet restore --runtime linux-$BUILDARCH
|
RUN dotnet restore --runtime $RID
|
||||||
|
|
||||||
# Copy other files
|
# Copy other files
|
||||||
COPY UI/. ./UI/
|
COPY UI/. ./UI/
|
||||||
|
@ -21,7 +29,7 @@ COPY Serilog.Ui.SqliteProvider/. ./Serilog.Ui.SqliteProvider/
|
||||||
RUN dotnet publish "./UI/MTWireGuard.csproj" -c Release \
|
RUN dotnet publish "./UI/MTWireGuard.csproj" -c Release \
|
||||||
-o /app/publish \
|
-o /app/publish \
|
||||||
--no-restore \
|
--no-restore \
|
||||||
--runtime linux-$BUILDARCH \
|
--runtime $RID \
|
||||||
--self-contained true \
|
--self-contained true \
|
||||||
/p:WarningLevel=0 \
|
/p:WarningLevel=0 \
|
||||||
/p:PublishTrimmed=true
|
/p:PublishTrimmed=true
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
@{
|
@{
|
||||||
string username = Environment.GetEnvironmentVariable("MT_USER");
|
string username = Environment.GetEnvironmentVariable("MT_USER") ?? "";
|
||||||
}
|
}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
"MT_IP": "192.168.0.96",
|
"MT_IP": "192.168.0.96",
|
||||||
"MT_USER": "admin",
|
"MT_USER": "admin",
|
||||||
"MT_PASS": "",
|
"MT_PASS": "admin",
|
||||||
"MT_PUBLIC_IP": "192.168.0.96"
|
"MT_PUBLIC_IP": "192.168.0.96"
|
||||||
},
|
},
|
||||||
"hotReloadEnabled": true,
|
"hotReloadEnabled": true,
|
||||||
|
@ -34,6 +34,20 @@
|
||||||
},
|
},
|
||||||
"publishAllPorts": true,
|
"publishAllPorts": true,
|
||||||
"useSSL": 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": {
|
"iisSettings": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue