Compare commits
162
Commits
2b3bd2897c
...
otel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3572902300 | ||
|
|
085b69d388 | ||
|
|
dbb7dc168b | ||
|
|
31333ea168 | ||
|
|
e26c79a9d7 | ||
|
|
200789e832 | ||
|
|
ae1440fce3 | ||
|
|
b58b5777fd | ||
|
|
3e84af9bb5 | ||
|
|
83dfdc2cc3 | ||
|
|
bbdb27b116 | ||
|
|
31f2439033 | ||
|
|
1da1328870 | ||
|
|
15a2ad0b89 | ||
|
|
3b5ca4f5b0 | ||
|
|
d179d2d79d | ||
|
|
1526648d9a | ||
|
|
b6813057a4 | ||
|
|
d1f723c135 | ||
|
|
7882b380b5 | ||
|
|
423281d071 | ||
|
|
75ecf71370 | ||
|
|
44fbc613a3 | ||
|
|
5fa7d49bcd | ||
|
|
a922531f50 | ||
|
|
f356ecdcc0 | ||
|
|
9acebb67fe | ||
|
|
7d32a83af2 | ||
|
|
e140319a05 | ||
|
|
3752da6ebe | ||
|
|
a4766c3d48 | ||
|
|
1937d2eaa1 | ||
|
|
14c2205a8d | ||
|
|
c2a8b5c797 | ||
|
|
e5b37e9e60 | ||
|
|
c584d39270 | ||
|
|
bdf1c92ab5 | ||
|
|
81e93b0e4e | ||
|
|
89f619eefa | ||
|
|
2acbf51413 | ||
|
|
b46848dd56 | ||
|
|
30e0bc2b87 | ||
|
|
903c17e7f8 | ||
|
|
52f10f9181 | ||
|
|
bd3cba05cb | ||
|
|
521fa1dbc5 | ||
|
|
007f606bb6 | ||
|
|
21d2a7981e | ||
|
|
ef6262282d | ||
|
|
502182a370 | ||
|
|
1d4009cc68 | ||
|
|
c6799a146a | ||
|
|
21e4c3940a | ||
|
|
6bd60452f2 | ||
|
|
0c901d32d8 | ||
|
|
52e24bb8f2 | ||
|
|
38cbf5b656 | ||
|
|
a8ad599af2 | ||
|
|
1263ad8571 | ||
|
|
5dff86c4fa | ||
|
|
8d12af4e10 | ||
|
|
6a29032748 | ||
|
|
099bc0c515 | ||
|
|
634ad82d2c | ||
|
|
1cb1481ab8 | ||
|
|
59c08d2314 | ||
|
|
f6bcbb6674 | ||
|
|
496e6b653d | ||
|
|
6f395f9db7 | ||
|
|
4c86a810da | ||
|
|
080d09fca3 | ||
|
|
1ee31554ce | ||
|
|
18bc75b687 | ||
|
|
3d1e3f29df | ||
|
|
dd5ad891ab | ||
|
|
c03dc29446 | ||
|
|
247aa96d19 | ||
|
|
24e439558f | ||
|
|
de0820dcc2 | ||
|
|
1917a60867 | ||
|
|
7071441d12 | ||
|
|
c43ce20bbe | ||
|
|
48b884ae72 | ||
|
|
26c90e1697 | ||
|
|
1e66974684 | ||
|
|
a6a32817c5 | ||
|
|
03574c720f | ||
|
|
b3fa0e5138 | ||
|
|
201850a3d4 | ||
|
|
c8aef17e95 | ||
|
|
900e72779f | ||
|
|
8c6b400a2d | ||
|
|
28d02037f8 | ||
|
|
324e25c24b | ||
|
|
5e00dd6726 | ||
|
|
cdeae28f27 | ||
|
|
5ee124790f | ||
|
|
671e8b986f | ||
|
|
8b23dfa534 | ||
|
|
176fdb2930 | ||
|
|
42361d94a8 | ||
|
|
a4822ec103 | ||
|
|
5cc239854e | ||
|
|
dc79c658dd | ||
|
|
c3c52965ed | ||
|
|
3ce3d88fae | ||
|
|
0ded289b1f | ||
|
|
71dd02a122 | ||
|
|
83505ee117 | ||
|
|
45c3c77bb3 | ||
|
|
06ed9d2bad | ||
|
|
84d18a4745 | ||
|
|
0ea4a0829d | ||
|
|
1fa3f6bb4b | ||
|
|
467a385c2a | ||
|
|
eb681300c2 | ||
|
|
06a910e894 | ||
|
|
358d27464a | ||
|
|
2372a8a24a | ||
|
|
49639fc1e2 | ||
|
|
4b8bf81c05 | ||
|
|
4eb185aece | ||
|
|
d57b924425 | ||
|
|
6843b105b8 | ||
|
|
64ac839d3c | ||
|
|
e2d89c651a | ||
|
|
c81a4451d6 | ||
|
|
abe5f37dc0 | ||
|
|
9116076bac | ||
|
|
41d757a5e2 | ||
|
|
1a8e9abb3e | ||
|
|
46606e3350 | ||
|
|
09558ce984 | ||
|
|
3887cd4843 | ||
|
|
a20c90039b | ||
|
|
1babfacede | ||
|
|
da229bf4ec | ||
|
|
eeac0b1e83 | ||
|
|
6bc8e5e703 | ||
|
|
7fd69b8265 | ||
|
|
8fce29f5ab | ||
|
|
3f754b3614 | ||
|
|
79a3d87668 | ||
|
|
3e590eed2c | ||
|
|
833bfafa7f | ||
|
|
be8db08307 | ||
|
|
2477602874 | ||
|
|
2d4f851d23 | ||
|
|
8afd460a3c | ||
|
|
7ee42ef018 | ||
|
|
f5d3146bed | ||
|
|
10d9186f92 | ||
|
|
00f7fa2d99 | ||
|
|
41538c6376 | ||
|
|
1d3f833b92 | ||
|
|
94ad00974d | ||
|
|
f77157498a | ||
|
|
95faa86e6b | ||
|
|
45171382f0 | ||
|
|
1cb55e2eb9 | ||
|
|
eb4884eab5 | ||
|
|
077cdfd781 |
+3
-1
@@ -27,4 +27,6 @@ README.md
|
|||||||
!.git/config
|
!.git/config
|
||||||
!.git/packed-refs
|
!.git/packed-refs
|
||||||
!.git/refs/heads/**
|
!.git/refs/heads/**
|
||||||
|
# Ensure the build output is NOT ignored
|
||||||
|
!**/bin/Release/**/publish/
|
||||||
|
!**/publish/
|
||||||
|
|||||||
+59
-38
@@ -1,47 +1,68 @@
|
|||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: package
|
name: build-and-package
|
||||||
|
|
||||||
clone:
|
|
||||||
disable: true
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: clone
|
- name: build-test-publish
|
||||||
image: alpine/git
|
image: nexus.khongisa.co.za/sdk:10.0
|
||||||
commands:
|
commands:
|
||||||
- git clone https://gitea.khongisa.co.za/MngomaLab/webapitest.git .
|
- dotnet restore --source https://nexus.khongisa.co.za/repository/nuget-group/index.json --no-cache
|
||||||
- git checkout ${DRONE_COMMIT}
|
- dotnet build --configuration Release --no-restore
|
||||||
|
- dotnet test --configuration Release --no-build
|
||||||
|
- dotnet publish --configuration Release --no-build
|
||||||
|
|
||||||
- name: dotnet publish
|
- name: docker-build-and-push
|
||||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
|
||||||
commands:
|
|
||||||
- dotnet publish --configuration Release
|
|
||||||
- ls ./SampleApi/bin/Release/net8.0/publish/
|
|
||||||
|
|
||||||
- name: docker login
|
|
||||||
image: docker:20.10
|
|
||||||
environment:
|
|
||||||
DOCKER_USERNAME:
|
|
||||||
from_secret: docker_username
|
|
||||||
DOCKER_PASSWORD:
|
|
||||||
from_secret: docker_password
|
|
||||||
commands:
|
|
||||||
- echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin
|
|
||||||
- docker info | grep "Registry"
|
|
||||||
|
|
||||||
- name: docker build and push
|
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
repo: khwezi/webapitest
|
registry: nexus.khongisa.co.za
|
||||||
registry: index.docker.io
|
repo: nexus.khongisa.co.za/webapitest
|
||||||
username:
|
tags: [ "${DRONE_BUILD_NUMBER}", "latest" ]
|
||||||
from_secret: docker_username
|
username: { from_secret: docker_username }
|
||||||
password:
|
password: { from_secret: docker_password }
|
||||||
from_secret: docker_password
|
|
||||||
dockerfile: Dockerfile
|
- name: vulnerability-scan
|
||||||
context: .
|
image: aquasec/trivy:0.50.1
|
||||||
force_tag: true
|
environment:
|
||||||
tags:
|
TRIVY_USERNAME: { from_secret: docker_username }
|
||||||
- latest
|
TRIVY_PASSWORD: { from_secret: docker_password }
|
||||||
- ${DRONE_BUILD_NUMBER}
|
commands:
|
||||||
|
- trivy image --image-src remote --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/webapitest:${DRONE_BUILD_NUMBER}
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
branch:
|
||||||
|
- main
|
||||||
|
event:
|
||||||
|
exclude:
|
||||||
|
- promote
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: deploy-to-uat
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- build-and-package
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: uat-deployment
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: { from_secret: ssh_host }
|
||||||
|
username: { from_secret: ssh_user }
|
||||||
|
password: { from_secret: ssh_password }
|
||||||
|
script:
|
||||||
|
- echo $DOCKER_PASSWORD | docker login nexus.khongisa.co.za -u $DOCKER_USERNAME --password-stdin
|
||||||
|
- docker pull nexus.khongisa.co.za/webapitest:latest
|
||||||
|
- docker stop webapi 2>/dev/null || true
|
||||||
|
- docker rm webapi 2>/dev/null || true
|
||||||
|
- docker run -d --name webapi --restart unless-stopped -e ASPNETCORE_ENVIRONMENT=Development -p 4000:8081 nexus.khongisa.co.za/webapitest:latest
|
||||||
|
environment:
|
||||||
|
DOCKER_USERNAME: { from_secret: docker_username }
|
||||||
|
DOCKER_PASSWORD: { from_secret: docker_password }
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
event:
|
||||||
|
- promote
|
||||||
|
target:
|
||||||
|
- staging
|
||||||
+5
-3
@@ -1,9 +1,11 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
FROM nexus.khongisa.co.za/aspnet:10.0 AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY ./SampleApi/bin/Release/net8.0/publish/ .
|
USER app
|
||||||
|
|
||||||
|
COPY --chown=app:app ./SampleApi/bin/Release/net10.0/publish/ .
|
||||||
|
|
||||||
ENV ASPNETCORE_HTTP_PORTS=8081
|
|
||||||
EXPOSE 8081
|
EXPOSE 8081
|
||||||
|
ENV ASPNETCORE_HTTP_PORTS=8081
|
||||||
|
|
||||||
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||||
|
|
||||||
|
namespace SampleApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class DemoController : ControllerBase
|
||||||
|
{
|
||||||
|
private static readonly ActivitySource MyActivitySource = new("SampleApi");
|
||||||
|
|
||||||
|
// GET: api/<DemoController>
|
||||||
|
[HttpGet]
|
||||||
|
public IEnumerable<string> Get(ILogger<DemoController> logger)
|
||||||
|
{
|
||||||
|
using var activity = MyActivitySource.StartActivity("ManualTraceTest");
|
||||||
|
activity?.SetTag("test.status", "success");
|
||||||
|
|
||||||
|
logger.LogInformation("sample api log");
|
||||||
|
|
||||||
|
return new string[] { "value1", "value2" };
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET api/<DemoController>/5
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public string Get(int id)
|
||||||
|
{
|
||||||
|
return "value";
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST api/<DemoController>
|
||||||
|
[HttpPost]
|
||||||
|
public void Post([FromBody] string value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT api/<DemoController>/5
|
||||||
|
[HttpPut("{id}")]
|
||||||
|
public void Put(int id, [FromBody] string value)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE api/<DemoController>/5
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
public void Delete(int id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+62
-6
@@ -1,25 +1,81 @@
|
|||||||
|
using OpenTelemetry.Exporter;
|
||||||
|
using OpenTelemetry.Logs;
|
||||||
|
using OpenTelemetry.Metrics;
|
||||||
|
using OpenTelemetry.Resources;
|
||||||
|
using OpenTelemetry.Trace;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// ONLY FOR TESTING: Allow untrusted certificates
|
||||||
|
var handler = new HttpClientHandler
|
||||||
|
{
|
||||||
|
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true
|
||||||
|
};
|
||||||
|
builder.Services.AddHttpClient("OtlpClient").ConfigurePrimaryHttpMessageHandler(() => handler);
|
||||||
|
|
||||||
|
// 1. Define Resource Information
|
||||||
|
var resourceBuilder = ResourceBuilder.CreateDefault()
|
||||||
|
.AddService("SampleApi");
|
||||||
|
|
||||||
|
// 2. Configuration Variables
|
||||||
|
// Using the API Key from your aspire-dashboard-auth secret
|
||||||
|
var oltpApiKey = "mc3G63K2j5ZOEsi0AjMojLTXm1KEZFctzIIjSwDiTGut8qGSkPuWwxGP1RbscJUo";
|
||||||
|
|
||||||
|
// Pointing to your Traefik IngressRoute.
|
||||||
|
// The SDK will append /v1/traces, /v1/metrics, etc., to this base URL
|
||||||
|
var oltpAddress = "https://aspire.khongisa.co.za/otlp-grpc";
|
||||||
|
//var oltpAddress = "https://aspire.khongisa.co.za/otlp-http";
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
|
|
||||||
|
// 3. Configure OpenTelemetry Logging
|
||||||
|
builder.Logging.AddOpenTelemetry(logging =>
|
||||||
|
{
|
||||||
|
logging.SetResourceBuilder(resourceBuilder);
|
||||||
|
logging.AddOtlpExporter(opt =>
|
||||||
|
{
|
||||||
|
opt.Endpoint = new Uri(oltpAddress);
|
||||||
|
opt.Protocol = OtlpExportProtocol.Grpc; // Switched to gRPC
|
||||||
|
// Note: Headers are only needed if you re-enable ApiKey auth mode
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// 4. Configure Tracing and Metrics
|
||||||
|
builder.Services.AddOpenTelemetry()
|
||||||
|
.WithTracing(tracing => tracing
|
||||||
|
.SetResourceBuilder(resourceBuilder)
|
||||||
|
.AddAspNetCoreInstrumentation()
|
||||||
|
.AddHttpClientInstrumentation()
|
||||||
|
.AddOtlpExporter(opt =>
|
||||||
|
{
|
||||||
|
opt.Endpoint = new Uri(oltpAddress);
|
||||||
|
opt.Protocol = OtlpExportProtocol.Grpc;
|
||||||
|
}))
|
||||||
|
.WithMetrics(metrics => metrics
|
||||||
|
.SetResourceBuilder(resourceBuilder)
|
||||||
|
.AddMeter("SampleApi")
|
||||||
|
.AddAspNetCoreInstrumentation()
|
||||||
|
.AddRuntimeInstrumentation()
|
||||||
|
.AddOtlpExporter(opt =>
|
||||||
|
{
|
||||||
|
opt.Endpoint = new Uri(oltpAddress);
|
||||||
|
opt.Protocol = OtlpExportProtocol.Grpc;
|
||||||
|
}));
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseRouting();
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
app.Run();
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"applicationUrl": "http://localhost:5221"
|
"applicationUrl": "http://0.0.0.0:5000"
|
||||||
},
|
},
|
||||||
"https": {
|
"https": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<UserSecretsId>cfe6b4ce-2d40-4273-b3a3-e4df67304fc5</UserSecretsId>
|
<UserSecretsId>cfe6b4ce-2d40-4273-b3a3-e4df67304fc5</UserSecretsId>
|
||||||
@@ -9,8 +9,14 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.15.3" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.15.3" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.15.2" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.15.1" />
|
||||||
|
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.15.1" />
|
||||||
|
<PackageReference Include="Polly" Version="8.6.6" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user