Compare commits
10 Commits
91a4ba55a3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bcdebe2036 | |||
| 2e1bdb2cfd | |||
| e64e676b14 | |||
| bde48cbe60 | |||
| 96f43895fb | |||
| 630d5d9f40 | |||
| 24a9f9edae | |||
| a523a9930c | |||
| 0a24e72a19 | |||
| 5a4693b714 |
@@ -22,19 +22,17 @@ jobs:
|
||||
dotnet-version: '8.0.x'
|
||||
|
||||
- name: Restore dependencies
|
||||
run: dotnet restore ./Astrocore.sln
|
||||
run: dotnet restore ./Astrocore.Api/Astrocore.Api.csproj
|
||||
|
||||
- name: Build
|
||||
run: dotnet build ./Astrocore.sln -c Release --no-restore
|
||||
run: dotnet build ./Astrocore.Api/Astrocore.Api.csproj -c Release --no-restore
|
||||
|
||||
- name: Publish
|
||||
run: dotnet publish ./Astrocore/Astrocore.Api/Astrocore.Api.csproj -c Release -o ./Astrocore/Astrocore.Api/out
|
||||
|
||||
- name: Log in to Docker Registry
|
||||
run: echo "${{ secrets.DOCKER_REGISTRY_PASSWORD }}" | docker login ${{ env.REGISTRY }} -u ${{ secrets.DOCKER_REGISTRY_USERNAME }} --password-stdin
|
||||
run: dotnet publish ./Astrocore.Api/Astrocore.Api.csproj -c Release -o ./Astrocore.Api/out
|
||||
|
||||
- name: Build Docker image
|
||||
run: docker build -t $REGISTRY/$IMAGE_NAME:latest ./Astrocore/Astrocore.Api
|
||||
run: docker build -t $REGISTRY/$IMAGE_NAME:latest -f ./Astrocore.Api/Dockerfile .
|
||||
|
||||
|
||||
- name: Push Docker image
|
||||
run: docker push $REGISTRY/$IMAGE_NAME:latest
|
||||
|
||||
30
Astrocore.Api/.dockerignore
Normal file
30
Astrocore.Api/.dockerignore
Normal file
@@ -0,0 +1,30 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
@@ -5,10 +5,13 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>916bd77d-132b-42cb-93e0-55d05b0d4f4b</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<DockerfileContext>.</DockerfileContext>
|
||||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FFMpegCore" Version="5.2.0" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
68
Astrocore.Api/Controllers/TextToSpeechController.cs
Normal file
68
Astrocore.Api/Controllers/TextToSpeechController.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Astrocore.Api.Controllers
|
||||
{
|
||||
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class TextToSpeechController : ControllerBase
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
public TextToSpeechController(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Index(string message)
|
||||
{
|
||||
var client = _httpClientFactory.CreateClient();
|
||||
var body = $"msg={Uri.EscapeDataString(message)}&lang=Geraint&source=ttsmp3";
|
||||
var request = new HttpRequestMessage(HttpMethod.Post, "https://ttsmp3.com/makemp3_new.php")
|
||||
{
|
||||
Content = new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded")
|
||||
};
|
||||
|
||||
var response = await client.SendAsync(request);
|
||||
var json = await response.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(json);
|
||||
var mp3File = doc.RootElement.GetProperty("URL").GetString();
|
||||
var mp3Bytes = await client.GetByteArrayAsync(mp3File);
|
||||
var tempDir = Path.GetTempPath();
|
||||
var fileNameGuid = Guid.NewGuid().ToString();
|
||||
var mp3Path = Path.Combine(tempDir, $"{fileNameGuid}.mp3");
|
||||
var dfpwmPath = Path.Combine(tempDir, $"{fileNameGuid}.dfpwm");
|
||||
|
||||
await System.IO.File.WriteAllBytesAsync(mp3Path, mp3Bytes);
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "ffmpeg",
|
||||
Arguments = $"-i \"{mp3Path}\" -ac 1 -c:a dfpwm -ar 48k \"{dfpwmPath}\"",
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false
|
||||
}
|
||||
};
|
||||
|
||||
process.Start();
|
||||
string errorOutput = await process.StandardError.ReadToEndAsync();
|
||||
process.WaitForExit();
|
||||
|
||||
if (!System.IO.File.Exists(dfpwmPath))
|
||||
{
|
||||
return StatusCode(500, $"FFmpeg failed: {errorOutput}");
|
||||
|
||||
}
|
||||
|
||||
var dfpwmBytes = await System.IO.File.ReadAllBytesAsync(dfpwmPath);
|
||||
return File(dfpwmBytes, "application/octet-stream", $"{fileNameGuid}.dfpwm");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,45 @@
|
||||
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
# Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
|
||||
# For more information, please see https://aka.ms/containercompat
|
||||
|
||||
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0-nanoserver-1809 AS base
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||
WORKDIR /app
|
||||
|
||||
# Install ffmpeg before switching user
|
||||
RUN apt-get update && \
|
||||
apt-get install -y ffmpeg && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
USER $APP_UID
|
||||
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
|
||||
# This stage is used to build the service project
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["Astrocore.Api/Astrocore.Api.csproj", "Astrocore.Api/"]
|
||||
RUN dotnet restore "./Astrocore.Api/Astrocore.Api.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Astrocore.Api"
|
||||
RUN dotnet build "./Astrocore.Api.csproj" -c %BUILD_CONFIGURATION% -o /app/build
|
||||
RUN dotnet build "./Astrocore.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
# This stage is used to publish the service project to be copied to the final stage
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./Astrocore.Api.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
|
||||
RUN dotnet publish "./Astrocore.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
|
||||
# Install ffmpeg
|
||||
#RUN apt-get update && \
|
||||
#apt-get install -y ffmpeg && \
|
||||
#rm -rf /var/lib/apt/lists/*
|
||||
|
||||
USER $APP_UID
|
||||
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Astrocore.Api.dll"]
|
||||
ENTRYPOINT ["dotnet", "Astrocore.Api.dll"]
|
||||
|
||||
32
Astrocore.Api/Dockerfile.original
Normal file
32
Astrocore.Api/Dockerfile.original
Normal file
@@ -0,0 +1,32 @@
|
||||
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
# Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
|
||||
# For more information, please see https://aka.ms/containercompat
|
||||
|
||||
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0-nanoserver-1809 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 8080
|
||||
EXPOSE 8081
|
||||
|
||||
|
||||
# This stage is used to build the service project
|
||||
FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["Astrocore.Api/Astrocore.Api.csproj", "Astrocore.Api/"]
|
||||
RUN dotnet restore "./Astrocore.Api/Astrocore.Api.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/Astrocore.Api"
|
||||
RUN dotnet build "./Astrocore.Api.csproj" -c %BUILD_CONFIGURATION% -o /app/build
|
||||
|
||||
# This stage is used to publish the service project to be copied to the final stage
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./Astrocore.Api.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "Astrocore.Api.dll"]
|
||||
@@ -8,7 +8,7 @@ namespace Astrocore.Api
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddHttpClient();
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
@@ -16,20 +16,11 @@ namespace Astrocore.Api
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
|
||||
19
docker-compose.dcproj
Normal file
19
docker-compose.dcproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectVersion>2.1</ProjectVersion>
|
||||
<DockerTargetOS>Linux</DockerTargetOS>
|
||||
<DockerPublishLocally>False</DockerPublishLocally>
|
||||
<ProjectGuid>a88d4e72-07da-43d3-b2a5-a71f5278b0e1</ProjectGuid>
|
||||
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
|
||||
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/swagger</DockerServiceUrl>
|
||||
<DockerServiceName>astrocore.api</DockerServiceName>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Include="docker-compose.override.yml">
|
||||
<DependentUpon>docker-compose.yml</DependentUpon>
|
||||
</None>
|
||||
<None Include="docker-compose.yml" />
|
||||
<None Include=".dockerignore" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
12
docker-compose.override.yml
Normal file
12
docker-compose.override.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
services:
|
||||
astrocore.api:
|
||||
environment:
|
||||
- ASPNETCORE_ENVIRONMENT=Development
|
||||
- ASPNETCORE_HTTP_PORTS=8080
|
||||
- ASPNETCORE_HTTPS_PORTS=8081
|
||||
ports:
|
||||
- "8080"
|
||||
- "8081"
|
||||
volumes:
|
||||
- ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro
|
||||
- ${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro
|
||||
6
docker-compose.yml
Normal file
6
docker-compose.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
services:
|
||||
astrocore.api:
|
||||
image: ${DOCKER_REGISTRY-}astrocoreapi
|
||||
build:
|
||||
context: Astrocore.Api
|
||||
dockerfile: Dockerfile
|
||||
11
launchSettings.json
Normal file
11
launchSettings.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"profiles": {
|
||||
"Docker Compose": {
|
||||
"commandName": "DockerCompose",
|
||||
"commandVersion": "1.0",
|
||||
"serviceActions": {
|
||||
"astrocore.api": "StartDebugging"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user