Compare commits
70
Commits
080d09fca3
...
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 |
+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/
|
||||||
|
|||||||
+43
-129
@@ -1,154 +1,68 @@
|
|||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: build
|
name: build-and-package
|
||||||
trigger:
|
|
||||||
event:
|
|
||||||
exclude:
|
|
||||||
- promote
|
|
||||||
|
|
||||||
clone:
|
|
||||||
disable: true
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: checkout
|
- 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 build
|
- name: docker-build-and-push
|
||||||
image: mcr.microsoft.com/dotnet/sdk:10.0
|
image: plugins/docker
|
||||||
commands:
|
settings:
|
||||||
- dotnet build --configuration Release
|
registry: nexus.khongisa.co.za
|
||||||
|
repo: nexus.khongisa.co.za/webapitest
|
||||||
|
tags: [ "${DRONE_BUILD_NUMBER}", "latest" ]
|
||||||
|
username: { from_secret: docker_username }
|
||||||
|
password: { from_secret: docker_password }
|
||||||
|
|
||||||
- name: dotnet test
|
- name: vulnerability-scan
|
||||||
image: mcr.microsoft.com/dotnet/sdk:10.0
|
image: aquasec/trivy:0.50.1
|
||||||
commands:
|
|
||||||
- dotnet test --configuration Release
|
|
||||||
---
|
|
||||||
x-docker-auth: &docker-auth
|
|
||||||
DOCKER_AUTH_CONFIG: |
|
|
||||||
{
|
|
||||||
"auths": {
|
|
||||||
"https://index.docker.io/v1/": {
|
|
||||||
"auth": "a2h3ZXppOlBHM0FRM0VPMFg="
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: package
|
|
||||||
depends_on:
|
|
||||||
- build
|
|
||||||
trigger:
|
|
||||||
event:
|
|
||||||
exclude:
|
|
||||||
- promote
|
|
||||||
|
|
||||||
clone:
|
|
||||||
disable: true
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: checkout
|
|
||||||
image: alpine/git
|
|
||||||
commands:
|
|
||||||
- git clone https://gitea.khongisa.co.za/MngomaLab/webapitest.git .
|
|
||||||
- git checkout ${DRONE_COMMIT}
|
|
||||||
|
|
||||||
- name: dotnet publish
|
|
||||||
image: mcr.microsoft.com/dotnet/sdk:10.0
|
|
||||||
commands:
|
|
||||||
- dotnet publish --configuration Release
|
|
||||||
|
|
||||||
|
|
||||||
- name: build and push
|
|
||||||
image: gcr.io/kaniko-project/executor:debug
|
|
||||||
environment:
|
environment:
|
||||||
<<: *docker-auth
|
TRIVY_USERNAME: { from_secret: docker_username }
|
||||||
|
TRIVY_PASSWORD: { from_secret: docker_password }
|
||||||
commands:
|
commands:
|
||||||
- mkdir -p /kaniko/.docker
|
- trivy image --image-src remote --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/webapitest:${DRONE_BUILD_NUMBER}
|
||||||
- echo "$DOCKER_AUTH_CONFIG" > /kaniko/.docker/config.json
|
|
||||||
- /kaniko/executor
|
|
||||||
--verbosity=debug
|
|
||||||
--context=.
|
|
||||||
--dockerfile=Dockerfile
|
|
||||||
--destination=index.docker.io/khwezi/webapitest:latest
|
|
||||||
--destination=index.docker.io/khwezi/webapitest:${DRONE_BUILD_NUMBER}
|
|
||||||
|
|
||||||
- name: volnerability scan
|
|
||||||
image: aquasec/trivy
|
|
||||||
commands:
|
|
||||||
- trivy image --exit-code 1 --timeout 15m --severity CRITICAL khwezi/webapitest:${DRONE_BUILD_NUMBER}
|
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: deploy
|
|
||||||
depends_on:
|
|
||||||
- package
|
|
||||||
trigger:
|
trigger:
|
||||||
|
branch:
|
||||||
|
- main
|
||||||
event:
|
event:
|
||||||
exclude:
|
exclude:
|
||||||
- promote
|
- promote
|
||||||
|
|
||||||
clone:
|
---
|
||||||
disable: true
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: deploy-to-uat
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- build-and-package
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: uat
|
- name: uat-deployment
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host:
|
host: { from_secret: ssh_host }
|
||||||
from_secret: ssh_host
|
username: { from_secret: ssh_user }
|
||||||
username:
|
password: { from_secret: ssh_password }
|
||||||
from_secret: ssh_user
|
|
||||||
password:
|
|
||||||
from_secret: ssh_password
|
|
||||||
script:
|
script:
|
||||||
- docker pull khwezi/webapitest:latest
|
- echo $DOCKER_PASSWORD | docker login nexus.khongisa.co.za -u $DOCKER_USERNAME --password-stdin
|
||||||
- docker stop webapi 2>NUL || echo "Container not running"
|
- docker pull nexus.khongisa.co.za/webapitest:latest
|
||||||
- docker rm webapi 2>NUL || echo "Container not found"
|
- docker stop webapi 2>/dev/null || true
|
||||||
- docker run -d --name webapi --restart unless-stopped -e ASPNETCORE_ENVIRONMENT=Development -p 4000:8081 khwezi/webapitest:latest
|
- 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
|
||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: golive
|
|
||||||
depends_on:
|
|
||||||
- deploy
|
|
||||||
|
|
||||||
clone:
|
|
||||||
disable: true
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: prod
|
|
||||||
image: appleboy/drone-ssh
|
|
||||||
environment:
|
environment:
|
||||||
PLUGIN_USER:
|
DOCKER_USERNAME: { from_secret: docker_username }
|
||||||
from_secret: ssh_prod_user
|
DOCKER_PASSWORD: { from_secret: docker_password }
|
||||||
PLUGIN_PASSWORD:
|
|
||||||
from_secret: ssh_prod_password
|
trigger:
|
||||||
PLUGIN_HOST:
|
|
||||||
from_secret: ssh_prod_host
|
|
||||||
settings:
|
|
||||||
settings:
|
|
||||||
script:
|
|
||||||
# - mkdir -p C:\Temp\docker-config
|
|
||||||
# - |
|
|
||||||
# echo "{\"credsStore\": \"\"}" > C:\Temp\docker-config\config.json
|
|
||||||
# - docker --config C:\Temp\docker-config pull khwezi/webapitest:latest
|
|
||||||
# - docker --config C:\Temp\docker-config stop webapi 2>NUL || echo "Container not running"
|
|
||||||
# - docker --config C:\Temp\docker-config rm webapi 2>NUL || echo "Container not found"
|
|
||||||
# - docker --config C:\Temp\docker-config run -d --name webapi --restart unless-stopped -e ASPNETCORE_ENVIRONMENT=Production -p 4001:8081 khwezi/webapitest:latest
|
|
||||||
- powershell -Command "if (!(Test-Path 'C:\Temp\docker-config')) { New-Item -Path 'C:\Temp\docker-config' -ItemType Directory }"
|
|
||||||
- powershell -Command "Set-Content -Path 'C:\Temp\docker-config\config.json' -Value '{\"credsStore\": \"\"}'"
|
|
||||||
- powershell -Command "docker --config C:\Temp\docker-config pull khwezi/webapitest:latest"
|
|
||||||
- powershell -Command "docker --config C:\Temp\docker-config stop webapi; exit 0"
|
|
||||||
- powershell -Command "docker --config C:\Temp\docker-config rm webapi; exit 0"
|
|
||||||
- powershell -Command "docker --config C:\Temp\docker-config run -d --name webapi --restart unless-stopped -e ASPNETCORE_ENVIRONMENT=Production -p 4001:8081 khwezi/webapitest:latest"
|
|
||||||
when:
|
|
||||||
event:
|
event:
|
||||||
- promote
|
- promote
|
||||||
target:
|
target:
|
||||||
- prod
|
- staging
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
|
FROM nexus.khongisa.co.za/aspnet:10.0 AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
USER app
|
USER app
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
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
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||||
|
|
||||||
@@ -8,10 +9,17 @@ namespace SampleApi.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class DemoController : ControllerBase
|
public class DemoController : ControllerBase
|
||||||
{
|
{
|
||||||
|
private static readonly ActivitySource MyActivitySource = new("SampleApi");
|
||||||
|
|
||||||
// GET: api/<DemoController>
|
// GET: api/<DemoController>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IEnumerable<string> Get()
|
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" };
|
return new string[] { "value1", "value2" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+62
-3
@@ -1,9 +1,69 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
// 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();
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
builder.Services.AddSwaggerGen();
|
builder.Services.AddSwaggerGen();
|
||||||
builder.Services.AddHealthChecks();
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
@@ -13,10 +73,9 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.MapHealthChecks("/health");
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseHttpsRedirection();
|
|
||||||
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",
|
||||||
|
|||||||
@@ -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