From c056e1c9c69731386be4f0277292d33d09acf831 Mon Sep 17 00:00:00 2001 From: Fabian Date: Fri, 26 Oct 2018 00:01:19 +0200 Subject: [PATCH] Inital Project + DockerFile --- PdfService/.dockerignore | 2 + PdfService/.gitignore | 34 +++++++++++++++ PdfService/Controllers/ValuesController.cs | 45 ++++++++++++++++++++ PdfService/DOCKERFILE | 16 ++++++++ PdfService/PdfService.csproj | 13 ++++++ PdfService/Program.cs | 24 +++++++++++ PdfService/Properties/launchSettings.json | 30 ++++++++++++++ PdfService/Startup.cs | 48 ++++++++++++++++++++++ PdfService/appsettings.Development.json | 9 ++++ PdfService/appsettings.json | 8 ++++ PdfService/readme.me | 16 ++++++++ 11 files changed, 245 insertions(+) create mode 100644 PdfService/.dockerignore create mode 100644 PdfService/.gitignore create mode 100644 PdfService/Controllers/ValuesController.cs create mode 100644 PdfService/DOCKERFILE create mode 100644 PdfService/PdfService.csproj create mode 100644 PdfService/Program.cs create mode 100644 PdfService/Properties/launchSettings.json create mode 100644 PdfService/Startup.cs create mode 100644 PdfService/appsettings.Development.json create mode 100644 PdfService/appsettings.json create mode 100644 PdfService/readme.me diff --git a/PdfService/.dockerignore b/PdfService/.dockerignore new file mode 100644 index 0000000..a02c9ed --- /dev/null +++ b/PdfService/.dockerignore @@ -0,0 +1,2 @@ +bin\ +obj\ \ No newline at end of file diff --git a/PdfService/.gitignore b/PdfService/.gitignore new file mode 100644 index 0000000..a5ac8a2 --- /dev/null +++ b/PdfService/.gitignore @@ -0,0 +1,34 @@ +*.swp +*.*~ +project.lock.json +.DS_Store +*.pyc +nupkg/ + +# Visual Studio Code +.vscode + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +msbuild.log +msbuild.err +msbuild.wrn + +# Visual Studio 2015 +.vs/ \ No newline at end of file diff --git a/PdfService/Controllers/ValuesController.cs b/PdfService/Controllers/ValuesController.cs new file mode 100644 index 0000000..22dad6b --- /dev/null +++ b/PdfService/Controllers/ValuesController.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace PdfService.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ValuesController : ControllerBase + { + // GET api/values + [HttpGet] + public ActionResult> Get() + { + return new string[] { "value1", "value2" }; + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + return "value"; + } + + // POST api/values + [HttpPost] + public void Post([FromBody] string value) + { + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/PdfService/DOCKERFILE b/PdfService/DOCKERFILE new file mode 100644 index 0000000..827e85b --- /dev/null +++ b/PdfService/DOCKERFILE @@ -0,0 +1,16 @@ +FROM microsoft/dotnet:2.2.100-preview3-sdk AS build-env +WORKDIR /app + +# Copy csproj and restore as distinct layers +COPY *.csproj ./ +RUN dotnet restore + +# Copy everything else and build +COPY . ./ +RUN dotnet publish -c Release -o out + +# Build runtime image +FROM microsoft/dotnet:2.2.0-preview3-aspnetcore-runtime-alpine +WORKDIR /app +COPY --from=build-env /app/out . +ENTRYPOINT ["dotnet", "PdfService.dll"] \ No newline at end of file diff --git a/PdfService/PdfService.csproj b/PdfService/PdfService.csproj new file mode 100644 index 0000000..265f5a5 --- /dev/null +++ b/PdfService/PdfService.csproj @@ -0,0 +1,13 @@ + + + + netcoreapp2.2 + inprocess + + + + + + + + diff --git a/PdfService/Program.cs b/PdfService/Program.cs new file mode 100644 index 0000000..7199cb0 --- /dev/null +++ b/PdfService/Program.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace PdfService +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/PdfService/Properties/launchSettings.json b/PdfService/Properties/launchSettings.json new file mode 100644 index 0000000..36a41ad --- /dev/null +++ b/PdfService/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:27212", + "sslPort": 44350 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "api/values", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "PdfService": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "api/values", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file diff --git a/PdfService/Startup.cs b/PdfService/Startup.cs new file mode 100644 index 0000000..883e4ba --- /dev/null +++ b/PdfService/Startup.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; + +namespace PdfService +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); + } + + app.UseHttpsRedirection(); + app.UseMvc(); + } + } +} diff --git a/PdfService/appsettings.Development.json b/PdfService/appsettings.Development.json new file mode 100644 index 0000000..e203e94 --- /dev/null +++ b/PdfService/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/PdfService/appsettings.json b/PdfService/appsettings.json new file mode 100644 index 0000000..def9159 --- /dev/null +++ b/PdfService/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/PdfService/readme.me b/PdfService/readme.me new file mode 100644 index 0000000..d9724c6 --- /dev/null +++ b/PdfService/readme.me @@ -0,0 +1,16 @@ +# PDF Service + +Provides an API interface to generate PDF reports for given inputs +`POST`: `/generatePdf/` (TODO) + +# run with docker + +`docker build -t pdfservice .` if no local image is available +`docker run -p YOUR_PORT:80 pdfservice:latest` + +# run local +## requirements +- .net core 2.2 + +## commands +- `dotnet run` \ No newline at end of file -- 2.43.0