Compare commits
39
Commits
2acbf51413
...
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 |
+34
-49
@@ -1,83 +1,68 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: cicd-pipeline
|
||||
|
||||
# Let Drone handle the clone automatically; it's faster and cleaner.
|
||||
clone:
|
||||
depth: 1
|
||||
name: build-and-package
|
||||
|
||||
steps:
|
||||
- name: build-test-publish
|
||||
image: nexus.khongisa.co.za/mcr.microsoft.com/dotnet/sdk:10.0
|
||||
image: nexus.khongisa.co.za/sdk:10.0
|
||||
commands:
|
||||
- dotnet restore --source https://nexus.khongisa.co.za/repository/nuget-group/index.json --no-cache
|
||||
- dotnet build --configuration Release --no-restore
|
||||
- dotnet test --configuration Release --no-build
|
||||
- dotnet publish --configuration Release --no-build
|
||||
|
||||
# --- PACKAGE STAGE ---
|
||||
# We build the image locally first so we can scan it BEFORE pushing
|
||||
- name: docker-build
|
||||
- name: docker-build-and-push
|
||||
image: plugins/docker
|
||||
settings:
|
||||
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
|
||||
# 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: docker-push
|
||||
image: plugins/docker
|
||||
settings:
|
||||
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
|
||||
username: { from_secret: docker_username }
|
||||
password: { from_secret: docker_password }
|
||||
|
||||
- name: vulnerability-scan
|
||||
image: nexus.khongisa.co.za/aquasec/trivy:0.50.1
|
||||
image: aquasec/trivy:0.50.1
|
||||
environment:
|
||||
# Trivy needs these to pull the image from your Nexus to scan it
|
||||
TRIVY_USERNAME:
|
||||
from_secret: docker_username
|
||||
TRIVY_PASSWORD:
|
||||
from_secret: docker_password
|
||||
TRIVY_USERNAME: { from_secret: docker_username }
|
||||
TRIVY_PASSWORD: { from_secret: docker_password }
|
||||
commands:
|
||||
- trivy image --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/webapitest:${DRONE_BUILD_NUMBER}
|
||||
- trivy image --image-src remote --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/webapitest:${DRONE_BUILD_NUMBER}
|
||||
|
||||
# --- DEPLOY STAGE ---
|
||||
- name: deploy-uat
|
||||
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
|
||||
host: { from_secret: ssh_host }
|
||||
username: { from_secret: ssh_user }
|
||||
password: { from_secret: ssh_password }
|
||||
script:
|
||||
# Login to Nexus on the remote server
|
||||
- echo $DOCKER_PASSWORD | docker login nexus.khongisa.co.za -u $DOCKER_USERNAME --password-stdin
|
||||
- docker pull nexus.khongisa.co.za/webapitest:latest
|
||||
# Standard Linux cleanup
|
||||
- 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
|
||||
DOCKER_USERNAME: { from_secret: docker_username }
|
||||
DOCKER_PASSWORD: { from_secret: docker_password }
|
||||
|
||||
trigger:
|
||||
event:
|
||||
exclude:
|
||||
- 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
|
||||
|
||||
USER app
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
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
|
||||
|
||||
@@ -8,10 +9,17 @@ namespace SampleApi.Controllers
|
||||
[ApiController]
|
||||
public class DemoController : ControllerBase
|
||||
{
|
||||
private static readonly ActivitySource MyActivitySource = new("SampleApi");
|
||||
|
||||
// GET: api/<DemoController>
|
||||
[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" };
|
||||
}
|
||||
|
||||
|
||||
+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);
|
||||
|
||||
// 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.AddEndpointsApiExplorer();
|
||||
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();
|
||||
|
||||
@@ -13,10 +73,9 @@ if (app.Environment.IsDevelopment())
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.MapHealthChecks("/health");
|
||||
app.UseRouting();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
||||
@@ -8,7 +8,7 @@
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5221"
|
||||
"applicationUrl": "http://0.0.0.0:5000"
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
|
||||
<ItemGroup>
|
||||
<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="Swashbuckle.AspNetCore" Version="10.1.7" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user