diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3729ff0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.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 \ No newline at end of file diff --git a/Alibaba.sln b/Alibaba.sln new file mode 100644 index 0000000..d4eb5bd --- /dev/null +++ b/Alibaba.sln @@ -0,0 +1,48 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.31911.260 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8A254448-0777-4415-BC8D-3844CCEEE724}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Alibaba.DomesticFlight.API", "src\Alibaba.DomesticFlight.API\Alibaba.DomesticFlight.API.csproj", "{453C82BF-D43C-4CF1-8C08-BFA7E27A3DEA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4C1632CA-C244-4E86-8570-C64942D0B3D9}" + ProjectSection(SolutionItems) = preProject + .dockerignore = .dockerignore + docker-compose.yaml = docker-compose.yaml + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Fluentd", "Fluentd", "{88233EF9-8CC2-4FBA-B514-605A850263D0}" + ProjectSection(SolutionItems) = preProject + Fluentd\Fluentd.Dockerfile = Fluentd\Fluentd.Dockerfile + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "conf", "conf", "{FB283BED-9440-4CDF-B4DC-D53FACA042C0}" + ProjectSection(SolutionItems) = preProject + Fluentd\conf\fluent.conf = Fluentd\conf\fluent.conf + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {453C82BF-D43C-4CF1-8C08-BFA7E27A3DEA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {453C82BF-D43C-4CF1-8C08-BFA7E27A3DEA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {453C82BF-D43C-4CF1-8C08-BFA7E27A3DEA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {453C82BF-D43C-4CF1-8C08-BFA7E27A3DEA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {453C82BF-D43C-4CF1-8C08-BFA7E27A3DEA} = {8A254448-0777-4415-BC8D-3844CCEEE724} + {88233EF9-8CC2-4FBA-B514-605A850263D0} = {4C1632CA-C244-4E86-8570-C64942D0B3D9} + {FB283BED-9440-4CDF-B4DC-D53FACA042C0} = {88233EF9-8CC2-4FBA-B514-605A850263D0} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5D72BD92-F35F-4429-A60D-2F5CC3A73275} + EndGlobalSection +EndGlobal diff --git a/Fluentd/Fluentd.Dockerfile b/Fluentd/Fluentd.Dockerfile new file mode 100644 index 0000000..c9660aa --- /dev/null +++ b/Fluentd/Fluentd.Dockerfile @@ -0,0 +1,4 @@ +FROM fluent/fluentd:v1.14.3-debian-1.0 +USER root +RUN ["gem", "install","fluent-plugin-elasticsearch", "--version", "5.1.4"] +USER fluent \ No newline at end of file diff --git a/Fluentd/conf/fluent.conf b/Fluentd/conf/fluent.conf new file mode 100644 index 0000000..fde7410 --- /dev/null +++ b/Fluentd/conf/fluent.conf @@ -0,0 +1,18 @@ + + @type forward + port 24224 + bind 0.0.0.0 + + + + @type elasticsearch + host ElasticSearchContainer + port 9200 + logstash_format true + logstash_prefix fluentd + logstash_dateformat %Y%m%d + include_tag_key true + type_name access_log + tag_key @log_name + flush_interval 1s + \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..530c49a --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,68 @@ +services: + +############################# ASP.NET Core Web API ############################## + domestic-flight-api: + build: + context: . + dockerfile: src/Alibaba.DomesticFlight.API/Dockerfile + container_name: DomesticFlightApiContainer + environment: + - ASPNETCORE_ENVIRONMENT=Staging + ports: + - "5010:80" + restart: always + networks: + - Alibaba + #depends_on: + # - fluentd-service + logging: + driver: fluentd + options: + fluentd-address: localhost:24224 + fluentd-async: "true" + +############################# Fluentd ############################## + fluentd-service: + build: + context: . + dockerfile: Fluentd/Fluentd.Dockerfile + volumes: + - ./Fluentd/conf:/fluentd/etc + ports: + - "24224:24224" + - "24224:24224/udp" + networks: + - Alibaba + depends_on: + - ElasticSearchService + +############################# Elastic Search ############################## + ElasticSearchService: + image: docker.elastic.co/elasticsearch/elasticsearch:7.16.0 + container_name: ElasticSearchContainer + ports: + - "9200:9200" + - "9300:9300" + environment: + - xpack.security.enabled=false + - discovery.type=single-node + networks: + - Alibaba + restart: always + +############################# Kibana ############################## + KibanaService: + image: docker.elastic.co/kibana/kibana:7.16.0 + container_name: KibanaContainer + depends_on: + - ElasticSearchService + ports: + - "5601:5601" + environment: + - ELASTICSEARCH_HOSTS=http://ElasticSearchContainer:9200/ + networks: + - Alibaba + restart: always + +networks: + Alibaba: \ No newline at end of file diff --git a/src/Alibaba.DomesticFlight.API/Alibaba.DomesticFlight.API.csproj b/src/Alibaba.DomesticFlight.API/Alibaba.DomesticFlight.API.csproj new file mode 100644 index 0000000..eaef8ec --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/Alibaba.DomesticFlight.API.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + disable + enable + 84f151f4-5f5a-4daf-93e7-15b77d78455f + Linux + ..\.. + + + + + + + + diff --git a/src/Alibaba.DomesticFlight.API/Controllers/LogsController.cs b/src/Alibaba.DomesticFlight.API/Controllers/LogsController.cs new file mode 100644 index 0000000..2c58fe1 --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/Controllers/LogsController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Alibaba.DomesticFlight.API.Controllers; +[Route("api/[controller]")] +[ApiController] +public class LogsController : ControllerBase +{ + private readonly ILogger _logger; + + public LogsController(ILogger logger) + { + _logger = logger; + } + + [HttpGet("[action]")] + public async Task Iterate(ushort numberOfIteration) + { + for (int i = 0; i < numberOfIteration; i++) + { + _logger.LogInformation("{i} {Now} آرمین", i, DateTimeOffset.Now); + await Task.Delay(TimeSpan.FromSeconds(1)); + } + return Ok(); + } + +} diff --git a/src/Alibaba.DomesticFlight.API/Controllers/WeatherForecastController.cs b/src/Alibaba.DomesticFlight.API/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..dd8df46 --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/Controllers/WeatherForecastController.cs @@ -0,0 +1,31 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Alibaba.DomesticFlight.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 _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/src/Alibaba.DomesticFlight.API/Dockerfile b/src/Alibaba.DomesticFlight.API/Dockerfile new file mode 100644 index 0000000..c6edde7 --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/Dockerfile @@ -0,0 +1,18 @@ +FROM mcr.microsoft.com/dotnet/sdk:6.0.100-bullseye-slim-amd64 as build + +WORKDIR /repo +COPY ["src/Alibaba.DomesticFlight.API/Alibaba.DomesticFlight.API.csproj", "src/Alibaba.DomesticFlight.API/"] + +RUN dotnet restore "src/Alibaba.DomesticFlight.API/Alibaba.DomesticFlight.API.csproj" + +COPY . . + +RUN dotnet publish "src/Alibaba.DomesticFlight.API/Alibaba.DomesticFlight.API.csproj" -c Release -o /app/publish --no-restore + + +FROM mcr.microsoft.com/dotnet/aspnet:6.0.0-bullseye-slim-amd64 +ENV TZ=Asia/Tehran +WORKDIR /app +EXPOSE 80 +COPY --from=build /app/publish . +ENTRYPOINT ["dotnet", "Alibaba.DomesticFlight.API.dll"] \ No newline at end of file diff --git a/src/Alibaba.DomesticFlight.API/Program.cs b/src/Alibaba.DomesticFlight.API/Program.cs new file mode 100644 index 0000000..d67e5a6 --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/Program.cs @@ -0,0 +1,33 @@ +using System.Text.Encodings.Web; + +var builder = WebApplication.CreateBuilder(args); + +builder.Logging.ClearProviders(); +builder.Logging.AddJsonConsole(jsonConsoleFormatterOptions => +{ + jsonConsoleFormatterOptions.JsonWriterOptions = new() + { + Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping + }; +}); + + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +app.UseSwagger(); +app.UseSwaggerUI(); +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseHttpsRedirection(); +} + +app.MapControllers(); +app.Run(); diff --git a/src/Alibaba.DomesticFlight.API/Properties/launchSettings.json b/src/Alibaba.DomesticFlight.API/Properties/launchSettings.json new file mode 100644 index 0000000..e53fff7 --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/Properties/launchSettings.json @@ -0,0 +1,38 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:22903", + "sslPort": 44333 + } + }, + "profiles": { + "Alibaba.DomesticFlight.API": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:7101;http://localhost:5101", + "dotnetRunMessages": true + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "Docker": { + "commandName": "Docker", + "launchBrowser": true, + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", + "publishAllPorts": true, + "useSSL": true + } + } +} \ No newline at end of file diff --git a/src/Alibaba.DomesticFlight.API/WeatherForecast.cs b/src/Alibaba.DomesticFlight.API/WeatherForecast.cs new file mode 100644 index 0000000..314a63d --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace Alibaba.DomesticFlight.API; + +public class WeatherForecast +{ + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} diff --git a/src/Alibaba.DomesticFlight.API/appsettings.Development.json b/src/Alibaba.DomesticFlight.API/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/Alibaba.DomesticFlight.API/appsettings.json b/src/Alibaba.DomesticFlight.API/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/src/Alibaba.DomesticFlight.API/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}