Skip to content

Commit 12a20cd

Browse files
committed
Task-985370-WolfiLinux Sample Committed
1 parent 4131206 commit 12a20cd

15 files changed

+317
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md
26+
!**/.gitignore
27+
!.git/HEAD
28+
!.git/config
29+
!.git/packed-refs
30+
!.git/refs/heads/**
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Syncfusion.HtmlConverter;
4+
using Syncfusion.Drawing;
5+
using Syncfusion.Pdf;
6+
7+
namespace HTMLtoPDF_Wolfi_Docker.Controllers
8+
{
9+
[Route("[controller]")]
10+
[ApiController]
11+
public class PdfController : ControllerBase
12+
{
13+
14+
public IActionResult ConvertPDF()
15+
{
16+
try
17+
{
18+
//Initialize the HTML to PDF converter.
19+
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
20+
21+
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings();
22+
blinkConverterSettings.CommandLineArguments.Add("--disable-gpu");
23+
blinkConverterSettings.BlinkPath = "/usr/lib/chromium";
24+
//Assign Blink converter settings to HTML converter
25+
htmlConverter.ConverterSettings = blinkConverterSettings;
26+
27+
//Convert URL to PDF
28+
PdfDocument document = htmlConverter.Convert("https://www.google.com");
29+
MemoryStream fileStream = new MemoryStream();
30+
//Save and close the PDF document.
31+
document.Save(fileStream);
32+
document.Close(true);
33+
fileStream.Position = 0;
34+
return new FileStreamResult(fileStream, "application/pdf") {FileDownloadName="HtmlToPdf_Output.pdf" };
35+
}
36+
catch (Exception ex)
37+
{
38+
return Content(ex.Message.ToString());
39+
}
40+
}
41+
}
42+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace HTMLtoPDF_Wolfi_Docker.Controllers
4+
{
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
}
33+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# 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.
2+
3+
# This stage is used when running from VS in fast mode (Default for Debug configuration)
4+
FROM cgr.dev/chainguard/aspnet-runtime:latest-dev AS base
5+
USER root
6+
7+
RUN apk update && \
8+
apk upgrade && \
9+
apk add --update ca-certificates && \
10+
apk add chromium --update-cache --repository http://nl.alpinelinux.org/alpine/edge/community \
11+
rm -rf /var/cache/apk/*
12+
WORKDIR /app
13+
EXPOSE 8080
14+
EXPOSE 8081
15+
16+
17+
# This stage is used to build the service project
18+
FROM cgr.dev/chainguard/dotnet-sdk:latest-dev AS build
19+
USER root
20+
ARG BUILD_CONFIGURATION=Release
21+
WORKDIR /src
22+
COPY ["HTMLtoPDF_Wolfi_Docker.csproj", "."]
23+
RUN dotnet restore "./HTMLtoPDF_Wolfi_Docker.csproj"
24+
COPY . .
25+
WORKDIR "/src/."
26+
RUN dotnet build "./HTMLtoPDF_Wolfi_Docker.csproj" -c $BUILD_CONFIGURATION -o /app/build
27+
28+
# This stage is used to publish the service project to be copied to the final stage
29+
FROM build AS publish
30+
ARG BUILD_CONFIGURATION=Release
31+
RUN dotnet publish "./HTMLtoPDF_Wolfi_Docker.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
32+
33+
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
34+
FROM base AS final
35+
WORKDIR /app
36+
COPY --from=publish /app/publish .
37+
ENTRYPOINT ["dotnet", "HTMLtoPDF_Wolfi_Docker.dll"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<UserSecretsId>1f4eb02c-222e-412a-8b02-7b438a5b3550</UserSecretsId>
8+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
9+
<DockerfileContext>.</DockerfileContext>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
14+
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Linux" Version="*" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>Container (Dockerfile)</ActiveDebugProfile>
5+
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
6+
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
7+
</PropertyGroup>
8+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@HTMLtoPDF_Wolfi_Docker_HostAddress = http://localhost:5235
2+
3+
GET {{HTMLtoPDF_Wolfi_Docker_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36429.23 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTMLtoPDF_Wolfi_Docker", "HTMLtoPDF_Wolfi_Docker.csproj", "{F9F4204B-A007-4790-BA53-4E96F3B241C3}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F9F4204B-A007-4790-BA53-4E96F3B241C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F9F4204B-A007-4790-BA53-4E96F3B241C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F9F4204B-A007-4790-BA53-4E96F3B241C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F9F4204B-A007-4790-BA53-4E96F3B241C3}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {46981BBE-DD89-4B09-BC15-F2D0F6065DFA}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace HTMLtoPDF_Wolfi_Docker
2+
{
3+
public class Program
4+
{
5+
public static void Main(string[] args)
6+
{
7+
var builder = WebApplication.CreateBuilder(args);
8+
9+
// Add services to the container.
10+
11+
builder.Services.AddControllers();
12+
13+
var app = builder.Build();
14+
15+
// Configure the HTTP request pipeline.
16+
17+
app.UseHttpsRedirection();
18+
19+
app.UseAuthorization();
20+
21+
22+
app.MapControllers();
23+
24+
app.Run();
25+
}
26+
}
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"profiles": {
3+
"http": {
4+
"commandName": "Project",
5+
"environmentVariables": {
6+
"ASPNETCORE_ENVIRONMENT": "Development"
7+
},
8+
"dotnetRunMessages": true,
9+
"applicationUrl": "http://localhost:5235"
10+
},
11+
"https": {
12+
"commandName": "Project",
13+
"environmentVariables": {
14+
"ASPNETCORE_ENVIRONMENT": "Development"
15+
},
16+
"dotnetRunMessages": true,
17+
"applicationUrl": "https://localhost:7267;http://localhost:5235"
18+
},
19+
"Container (Dockerfile)": {
20+
"commandName": "Docker",
21+
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
22+
"environmentVariables": {
23+
"ASPNETCORE_HTTPS_PORTS": "8081",
24+
"ASPNETCORE_HTTP_PORTS": "8080"
25+
},
26+
"publishAllPorts": true,
27+
"useSSL": true
28+
}
29+
},
30+
"$schema": "https://json.schemastore.org/launchsettings.json"
31+
}

0 commit comments

Comments
 (0)