Compare commits
52
Commits
21e4c3940a
..
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 |
+42
-56
@@ -1,82 +1,68 @@
|
|||||||
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: docker
|
||||||
name: cicd-pipeline
|
name: build-and-package
|
||||||
|
|
||||||
# Let Drone handle the clone automatically; it's faster and cleaner.
|
|
||||||
clone:
|
|
||||||
depth: 1
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# --- BUILD & TEST STAGE ---
|
- name: build-test-publish
|
||||||
- name: build-and-test
|
image: nexus.khongisa.co.za/sdk:10.0
|
||||||
image: mcr.microsoft.com/dotnet/sdk:10.0
|
|
||||||
commands:
|
commands:
|
||||||
- dotnet build --configuration Release
|
- dotnet restore --source https://nexus.khongisa.co.za/repository/nuget-group/index.json --no-cache
|
||||||
- dotnet test --configuration Release
|
- dotnet build --configuration Release --no-restore
|
||||||
|
- dotnet test --configuration Release --no-build
|
||||||
|
- dotnet publish --configuration Release --no-build
|
||||||
|
|
||||||
# --- PACKAGE STAGE ---
|
- name: docker-build-and-push
|
||||||
# We build the image locally first so we can scan it BEFORE pushing
|
|
||||||
- name: docker-build
|
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
registry: nexus.khongisa.co.za
|
registry: nexus.khongisa.co.za
|
||||||
repo: nexus.khongisa.co.za/mngomalab/webapitest
|
repo: nexus.khongisa.co.za/webapitest
|
||||||
tags: [ "${DRONE_BUILD_NUMBER}", "latest" ]
|
tags: [ "${DRONE_BUILD_NUMBER}", "latest" ]
|
||||||
username:
|
username: { from_secret: docker_username }
|
||||||
from_secret: docker_username
|
password: { from_secret: docker_password }
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
# This builds the image and loads it into the local cache for scanning
|
|
||||||
dry_run: true
|
|
||||||
# Set to false once you verify the scan passes, or see the step below
|
|
||||||
|
|
||||||
- name: vulnerability-scan
|
- name: vulnerability-scan
|
||||||
image: aquasec/trivy
|
image: aquasec/trivy:0.50.1
|
||||||
environment:
|
environment:
|
||||||
# Trivy needs these to pull the image from your Nexus to scan it
|
TRIVY_USERNAME: { from_secret: docker_username }
|
||||||
TRIVY_USERNAME:
|
TRIVY_PASSWORD: { from_secret: docker_password }
|
||||||
from_secret: docker_username
|
|
||||||
TRIVY_PASSWORD:
|
|
||||||
from_secret: docker_password
|
|
||||||
commands:
|
commands:
|
||||||
- trivy image --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/mngomalab/webapitest:${DRONE_BUILD_NUMBER}
|
- trivy image --image-src remote --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/webapitest:${DRONE_BUILD_NUMBER}
|
||||||
|
|
||||||
- name: docker-push
|
trigger:
|
||||||
image: plugins/docker
|
branch:
|
||||||
settings:
|
- main
|
||||||
registry: nexus.khongisa.co.za
|
event:
|
||||||
repo: nexus.khongisa.co.za/mngomalab/webapitest
|
exclude:
|
||||||
tags: [ "${DRONE_BUILD_NUMBER}", "latest" ]
|
- promote
|
||||||
username:
|
|
||||||
from_secret: docker_username
|
|
||||||
password:
|
|
||||||
from_secret: docker_password
|
|
||||||
|
|
||||||
# --- DEPLOY STAGE ---
|
---
|
||||||
- name: deploy-uat
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: deploy-to-uat
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- build-and-package
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- 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:
|
||||||
# Login to Nexus on the remote server
|
|
||||||
- echo $DOCKER_PASSWORD | docker login nexus.khongisa.co.za -u $DOCKER_USERNAME --password-stdin
|
- echo $DOCKER_PASSWORD | docker login nexus.khongisa.co.za -u $DOCKER_USERNAME --password-stdin
|
||||||
- docker pull nexus.khongisa.co.za/mngomalab/webapitest:latest
|
- docker pull nexus.khongisa.co.za/webapitest:latest
|
||||||
# Standard Linux cleanup
|
|
||||||
- docker stop webapi 2>/dev/null || true
|
- docker stop webapi 2>/dev/null || true
|
||||||
- docker rm 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/mngomalab/webapitest:latest
|
- docker run -d --name webapi --restart unless-stopped -e ASPNETCORE_ENVIRONMENT=Development -p 4000:8081 nexus.khongisa.co.za/webapitest:latest
|
||||||
environment:
|
environment:
|
||||||
DOCKER_USERNAME:
|
DOCKER_USERNAME: { from_secret: docker_username }
|
||||||
from_secret: docker_username
|
DOCKER_PASSWORD: { from_secret: docker_password }
|
||||||
DOCKER_PASSWORD:
|
|
||||||
from_secret: docker_password
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
event:
|
event:
|
||||||
exclude:
|
- promote
|
||||||
- promote
|
target:
|
||||||
|
- 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",
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.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="Polly" Version="8.6.6" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user