Compare commits

...

10 Commits

Author SHA1 Message Date
bcdebe2036 updated
Some checks are pending
Build and Push Docker Image / build-and-push (push) Waiting to run
2025-06-16 19:44:44 -04:00
2e1bdb2cfd updated 2025-06-16 19:43:30 -04:00
e64e676b14 UPDATED 2025-06-16 19:25:43 -04:00
bde48cbe60 updated 2025-06-16 18:56:40 -04:00
96f43895fb Added TTS 2025-06-16 18:52:35 -04:00
630d5d9f40 removed https 2025-06-16 17:25:14 -04:00
24a9f9edae updated 2025-06-16 17:09:07 -04:00
a523a9930c updated 2025-06-16 17:06:20 -04:00
0a24e72a19 updated container file 2025-06-16 17:04:24 -04:00
5a4693b714 updated 2025-06-16 17:01:06 -04:00
11 changed files with 211 additions and 28 deletions

View File

@@ -22,19 +22,17 @@ jobs:
dotnet-version: '8.0.x' dotnet-version: '8.0.x'
- name: Restore dependencies - name: Restore dependencies
run: dotnet restore ./Astrocore.sln run: dotnet restore ./Astrocore.Api/Astrocore.Api.csproj
- name: Build - 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 - name: Publish
run: dotnet publish ./Astrocore/Astrocore.Api/Astrocore.Api.csproj -c Release -o ./Astrocore/Astrocore.Api/out run: dotnet publish ./Astrocore.Api/Astrocore.Api.csproj -c Release -o ./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
- name: Build Docker image - 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 - name: Push Docker image
run: docker push $REGISTRY/$IMAGE_NAME:latest run: docker push $REGISTRY/$IMAGE_NAME:latest

View 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/**

View File

@@ -5,10 +5,13 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>916bd77d-132b-42cb-93e0-55d05b0d4f4b</UserSecretsId> <UserSecretsId>916bd77d-132b-42cb-93e0-55d05b0d4f4b</UserSecretsId>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS> <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>.</DockerfileContext>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="FFMpegCore" Version="5.2.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup> </ItemGroup>

View 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");
}
}
}

View File

@@ -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. # 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) # 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 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 8080
EXPOSE 8081 EXPOSE 8081
# This stage is used to build the service project # 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 ARG BUILD_CONFIGURATION=Release
WORKDIR /src WORKDIR /src
COPY ["Astrocore.Api/Astrocore.Api.csproj", "Astrocore.Api/"] COPY ["Astrocore.Api/Astrocore.Api.csproj", "Astrocore.Api/"]
RUN dotnet restore "./Astrocore.Api/Astrocore.Api.csproj" RUN dotnet restore "./Astrocore.Api/Astrocore.Api.csproj"
COPY . . COPY . .
WORKDIR "/src/Astrocore.Api" 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 # This stage is used to publish the service project to be copied to the final stage
FROM build AS publish FROM build AS publish
ARG BUILD_CONFIGURATION=Release 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) # 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 FROM base AS final
WORKDIR /app 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 . COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Astrocore.Api.dll"] ENTRYPOINT ["dotnet", "Astrocore.Api.dll"]

View 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"]

View File

@@ -8,7 +8,7 @@ namespace Astrocore.Api
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddHttpClient();
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
@@ -16,20 +16,11 @@ namespace Astrocore.Api
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI();
}
app.UseHttpsRedirection(); app.UseHttpsRedirection();
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();
app.Run(); app.Run();
} }
} }

19
docker-compose.dcproj Normal file
View 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>

View 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
View File

@@ -0,0 +1,6 @@
services:
astrocore.api:
image: ${DOCKER_REGISTRY-}astrocoreapi
build:
context: Astrocore.Api
dockerfile: Dockerfile

11
launchSettings.json Normal file
View File

@@ -0,0 +1,11 @@
{
"profiles": {
"Docker Compose": {
"commandName": "DockerCompose",
"commandVersion": "1.0",
"serviceActions": {
"astrocore.api": "StartDebugging"
}
}
}
}