Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminShoeibi committed Dec 17, 2021
1 parent d5b4a12 commit ab3c062
Show file tree
Hide file tree
Showing 14 changed files with 355 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions Alibaba.sln
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Fluentd/Fluentd.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions Fluentd/conf/fluent.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<source>
@type forward
port 24224
bind 0.0.0.0
</source>

<match *.**>
@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
</match>
68 changes: 68 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:
17 changes: 17 additions & 0 deletions src/Alibaba.DomesticFlight.API/Alibaba.DomesticFlight.API.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>84f151f4-5f5a-4daf-93e7-15b77d78455f</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions src/Alibaba.DomesticFlight.API/Controllers/LogsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Mvc;

namespace Alibaba.DomesticFlight.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class LogsController : ControllerBase
{
private readonly ILogger<LogsController> _logger;

public LogsController(ILogger<LogsController> logger)
{
_logger = logger;
}

[HttpGet("[action]")]
public async Task<IActionResult> 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();
}

}
Original file line number Diff line number Diff line change
@@ -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<WeatherForecastController> _logger;

public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}

[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> 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();
}
}
18 changes: 18 additions & 0 deletions src/Alibaba.DomesticFlight.API/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
33 changes: 33 additions & 0 deletions src/Alibaba.DomesticFlight.API/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
38 changes: 38 additions & 0 deletions src/Alibaba.DomesticFlight.API/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
12 changes: 12 additions & 0 deletions src/Alibaba.DomesticFlight.API/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
8 changes: 8 additions & 0 deletions src/Alibaba.DomesticFlight.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/Alibaba.DomesticFlight.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit ab3c062

Please sign in to comment.