Commit API
parent
510fe2c2ba
commit
d4b01c3eb2
@ -0,0 +1,33 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Expedience.Api.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class WeatherForecastController : ControllerBase
|
||||||
|
{
|
||||||
|
private static readonly string[] Summaries = new[]
|
||||||
|
{
|
||||||
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||||
|
};
|
||||||
|
|
||||||
|
private readonly ILogger<WeatherForecastController> _logger;
|
||||||
|
|
||||||
|
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet(Name = "GetWeatherForecast")]
|
||||||
|
public IEnumerable<WeatherForecast> Get()
|
||||||
|
{
|
||||||
|
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||||
|
{
|
||||||
|
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||||
|
TemperatureC = Random.Shared.Next(-20, 55),
|
||||||
|
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||||
|
})
|
||||||
|
.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,39 @@
|
|||||||
|
# Set the base image
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:7.0.202-jammy-arm64v8 AS build
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
# Copy the project files
|
||||||
|
COPY Expedience.Models/Expedience.Models.csproj Expedience.Models/
|
||||||
|
COPY Expedience.Api/Expedience.Api.csproj Expedience.Api/
|
||||||
|
|
||||||
|
# Restore the packages
|
||||||
|
RUN dotnet restore Expedience.Api/Expedience.Api.csproj
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the project
|
||||||
|
RUN dotnet build "Expedience.Api/Expedience.Api.csproj" -c Release -o /app/build
|
||||||
|
|
||||||
|
# Publish the project
|
||||||
|
ARG TARGET_RUNTIME=linux-x64
|
||||||
|
RUN dotnet publish "Expedience.Api/Expedience.Api.csproj" -c Release -o /app/publish --self-contained --runtime $TARGET_RUNTIME
|
||||||
|
|
||||||
|
# Set the base image for the final runtime
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:7.0.4-jammy-arm64v8
|
||||||
|
|
||||||
|
# Set the working directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the published files
|
||||||
|
COPY --from=build /app/publish .
|
||||||
|
|
||||||
|
# Set the ASPNETCORE_ENVIRONMENT environment variable
|
||||||
|
ENV ASPNETCORE_ENVIRONMENT=Production
|
||||||
|
|
||||||
|
# Expose the port the application will run on
|
||||||
|
EXPOSE 7033
|
||||||
|
|
||||||
|
# Set the entry point for the container
|
||||||
|
ENTRYPOINT ["dotnet", "Expedience.Api.dll"]
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
using Expedience.Api.Consumers;
|
||||||
|
using Expedience.Api.Db;
|
||||||
|
using Expedience.Api.Encryption;
|
||||||
|
using MassTransit;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
var connectionString = builder.Configuration.GetConnectionString("Expedience");
|
||||||
|
builder.Services.AddDbContext<ExpedienceContext>(options =>
|
||||||
|
options.UseNpgsql(connectionString));
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
var rabbitMqHost = builder.Configuration.GetSection("RabbitMq")["Host"];
|
||||||
|
builder.Services.AddMassTransit(opt =>
|
||||||
|
{
|
||||||
|
opt.AddConsumersFromNamespaceContaining<DutyCompletionResultConsumer>();
|
||||||
|
|
||||||
|
opt.UsingRabbitMq((context, cfg) =>
|
||||||
|
{
|
||||||
|
cfg.Host(rabbitMqHost);
|
||||||
|
cfg.ConfigureEndpoints(context);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<IDecryptor, Decryptor>();
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
var scope = app.Services.CreateScope();
|
||||||
|
var dbContext = scope.ServiceProvider.GetRequiredService<ExpedienceContext>();
|
||||||
|
|
||||||
|
dbContext.Database.EnsureCreated();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
namespace Expedience.Api
|
||||||
|
{
|
||||||
|
public class WeatherForecast
|
||||||
|
{
|
||||||
|
public DateOnly Date { get; set; }
|
||||||
|
|
||||||
|
public int TemperatureC { get; set; }
|
||||||
|
|
||||||
|
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||||
|
|
||||||
|
public string? Summary { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: expedience-api-deployment
|
||||||
|
namespace: expedience
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: expedience-api
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: expedience-api
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: expedience-api
|
||||||
|
image: registry.ilitirit.net/expedience-api:latest
|
||||||
|
ports:
|
||||||
|
- containerPort: 7033
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: registry-credentials
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: expedience-api-ingress
|
||||||
|
namespace: expedience
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: "nginx"
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||||
|
spec:
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- expedience-api.ilitirit.net
|
||||||
|
secretName: expedience-api-certificate
|
||||||
|
rules:
|
||||||
|
- host: expedience-api.ilitirit.net
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- pathType: ImplementationSpecific
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: expedience-api-service
|
||||||
|
port:
|
||||||
|
number: 7033
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: expedience-api-service
|
||||||
|
namespace: expedience
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: expedience-api
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 7033
|
||||||
|
targetPort: 7033
|
||||||
|
type: ClusterIP
|
||||||
Loading…
Reference in New Issue