Compare commits
9 Commits
test
...
57ba629d2d
| Author | SHA1 | Date | |
|---|---|---|---|
| 57ba629d2d | |||
| d30ee959ee | |||
| 4e653fd91d | |||
| b4ee875ac8 | |||
| 7d395e2295 | |||
| ddc66efc16 | |||
| 82348a0112 | |||
| e495be1c0b | |||
| 5a530210c0 |
@@ -12,6 +12,7 @@
|
|||||||
**/*.dbmdl
|
**/*.dbmdl
|
||||||
**/*.jfm
|
**/*.jfm
|
||||||
**/azds.yaml
|
**/azds.yaml
|
||||||
|
**/bin
|
||||||
**/charts
|
**/charts
|
||||||
**/docker-compose*
|
**/docker-compose*
|
||||||
**/Dockerfile*
|
**/Dockerfile*
|
||||||
@@ -26,7 +27,4 @@ README.md
|
|||||||
!.git/HEAD
|
!.git/HEAD
|
||||||
!.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/
|
|
||||||
118
.drone.yml
118
.drone.yml
@@ -1,68 +1,86 @@
|
|||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: kubernetes
|
||||||
name: build-and-package
|
name: build
|
||||||
|
|
||||||
|
clone:
|
||||||
|
disable: false
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: build-test-publish
|
- name: dotnet restore
|
||||||
image: nexus.khongisa.co.za/sdk:10.0
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
commands:
|
commands:
|
||||||
- dotnet restore --source https://nexus.khongisa.co.za/repository/nuget-group/index.json --no-cache
|
- dotnet restore
|
||||||
- dotnet build --configuration Release --no-restore
|
|
||||||
- dotnet test --configuration Release --no-build
|
|
||||||
- dotnet publish --configuration Release --no-build
|
|
||||||
|
|
||||||
- name: docker-build-and-push
|
- name: dotnet build
|
||||||
image: plugins/docker
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
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 }
|
|
||||||
|
|
||||||
- name: vulnerability-scan
|
|
||||||
image: aquasec/trivy:0.50.1
|
|
||||||
environment:
|
|
||||||
TRIVY_USERNAME: { from_secret: docker_username }
|
|
||||||
TRIVY_PASSWORD: { from_secret: docker_password }
|
|
||||||
commands:
|
commands:
|
||||||
- trivy image --image-src remote --exit-code 1 --severity CRITICAL nexus.khongisa.co.za/webapitest:${DRONE_BUILD_NUMBER}
|
- dotnet build --configuration Release
|
||||||
|
- ls ./SampleApi/bin/Release/net8.0/
|
||||||
|
|
||||||
trigger:
|
- name: dotnet test
|
||||||
branch:
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
- main
|
commands:
|
||||||
event:
|
- dotnet test --configuration Release
|
||||||
exclude:
|
|
||||||
- promote
|
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: docker
|
type: kubernetes
|
||||||
name: deploy-to-uat
|
name: package
|
||||||
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- build-and-package
|
- build
|
||||||
|
|
||||||
|
clone:
|
||||||
|
disable: true
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: uat-deployment
|
- name: dotnet publish
|
||||||
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
|
commands:
|
||||||
|
- dotnet publish --configuration Release
|
||||||
|
- ls ./SampleApi/bin/Release/net8.0/publish/
|
||||||
|
|
||||||
|
- name: docker build and push
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: registry-server.registry.svc.cluster.local:5000/sampleapi
|
||||||
|
auto_tag: true
|
||||||
|
registry: registry-server.registry.svc.cluster.local:5000
|
||||||
|
insecure: true
|
||||||
|
username:
|
||||||
|
from_secret: registry-username
|
||||||
|
password:
|
||||||
|
from_secret: registry-password
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
context: ./SampleApi/bin/Release/net8.0/publish/
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
type: kubernetes
|
||||||
|
name: deploy
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- package
|
||||||
|
|
||||||
|
clone:
|
||||||
|
disable: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: deploy via SSH
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
settings:
|
settings:
|
||||||
host: { from_secret: ssh_host }
|
host: lead.mngoma.lab
|
||||||
username: { from_secret: ssh_user }
|
username:
|
||||||
password: { from_secret: ssh_password }
|
from_secret: host-username
|
||||||
|
password:
|
||||||
|
from_secret: host-password
|
||||||
|
port: 22
|
||||||
script:
|
script:
|
||||||
- echo $DOCKER_PASSWORD | docker login nexus.khongisa.co.za -u $DOCKER_USERNAME --password-stdin
|
- set -euo pipefail
|
||||||
- docker pull nexus.khongisa.co.za/webapitest:latest
|
- echo "Applying Kubernetes manifest via SSH..."
|
||||||
- docker stop webapi 2>/dev/null || true
|
# Apply the manifest remotely via kubectl on the host
|
||||||
- docker rm webapi 2>/dev/null || true
|
- ssh -o StrictHostKeyChecking=no $DRONE_REMOTE_USER@lead.mngoma.lab 'kubectl apply -f -' <<'EOF'
|
||||||
- docker run -d --name webapi --restart unless-stopped -e ASPNETCORE_ENVIRONMENT=Development -p 4000:8081 nexus.khongisa.co.za/webapitest:latest
|
$(cat ./manifests/deploy.yml)
|
||||||
environment:
|
EOF
|
||||||
DOCKER_USERNAME: { from_secret: docker_username }
|
- echo "Manifest applied successfully."
|
||||||
DOCKER_PASSWORD: { from_secret: docker_password }
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
event:
|
|
||||||
- promote
|
|
||||||
target:
|
|
||||||
- staging
|
|
||||||
|
|||||||
32
Dockerfile
32
Dockerfile
@@ -1,11 +1,35 @@
|
|||||||
FROM nexus.khongisa.co.za/aspnet:10.0 AS final
|
# STAGE 1: Build
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
# 1. Copy the .sln and .csproj files first to restore dependencies
|
||||||
|
# This makes builds faster by caching the 'restore' layer
|
||||||
|
COPY ["SampleApi/SampleApi.csproj", "SampleApi/"]
|
||||||
|
RUN dotnet restore "SampleApi/SampleApi.csproj"
|
||||||
|
|
||||||
|
# 2. Copy the rest of the code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# 3. Publish to a FLAT directory
|
||||||
|
# We use -o /app/publish and ensure no extra subfolders are created
|
||||||
|
RUN dotnet publish "SampleApi/SampleApi.csproj" \
|
||||||
|
-c Release \
|
||||||
|
-o /app/publish \
|
||||||
|
--no-restore \
|
||||||
|
/p:UseAppHost=false
|
||||||
|
|
||||||
|
# STAGE 2: Runtime
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
USER app
|
# Copy the contents directly
|
||||||
|
COPY --from=build /app/publish .
|
||||||
|
|
||||||
COPY --chown=app:app ./SampleApi/bin/Release/net10.0/publish/ .
|
# DEBUG: This will print the contents of /app during the build.
|
||||||
|
# If SampleApi.dll isn't in this list, the build will stop here.
|
||||||
|
RUN ls -la /app
|
||||||
|
|
||||||
EXPOSE 8081
|
# Set the environment to listen on the port you mapped in Compose
|
||||||
ENV ASPNETCORE_HTTP_PORTS=8081
|
ENV ASPNETCORE_HTTP_PORTS=8081
|
||||||
|
|
||||||
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
ENTRYPOINT ["dotnet", "SampleApi.dll"]
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
// 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
|
|
||||||
{
|
|
||||||
// GET: api/<DemoController>
|
|
||||||
[HttpGet]
|
|
||||||
public IEnumerable<string> Get()
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +1,25 @@
|
|||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
// Add services to the container.
|
||||||
|
|
||||||
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();
|
||||||
builder.Services.AddHealthChecks();
|
|
||||||
|
|
||||||
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.MapHealthChecks("/health");
|
|
||||||
app.UseRouting();
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net8.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,9 +9,8 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
|
||||||
<PackageReference Include="Polly" Version="8.6.6" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -5,6 +5,4 @@ services:
|
|||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
ports:
|
ports:
|
||||||
- "8081:8081"
|
- "8080:8081"
|
||||||
environment:
|
|
||||||
- ASPNETCORE_ENVIRONMENT=Development
|
|
||||||
|
|||||||
99
manifests/deploy.yml
Normal file
99
manifests/deploy.yml
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: experiments
|
||||||
|
labels:
|
||||||
|
name: experiments
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: sampleapi-config
|
||||||
|
namespace: experiments
|
||||||
|
data:
|
||||||
|
appname: "SampleApi"
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: sampleapi
|
||||||
|
namespace: experiments
|
||||||
|
labels:
|
||||||
|
app: sampleapi
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: sampleapi
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: sampleapi
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: sampleapi
|
||||||
|
image: registry.registry.svc.cluster.local:5000/experiments/sampleapi:latest
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: 8080
|
||||||
|
- name: https
|
||||||
|
containerPort: 8081
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "128Mi"
|
||||||
|
cpu: "250m"
|
||||||
|
limits:
|
||||||
|
memory: "256Mi"
|
||||||
|
cpu: "500m"
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: sampleapi
|
||||||
|
namespace: experiments
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
selector:
|
||||||
|
app: sampleapi
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
port: 80
|
||||||
|
targetPort: 8080
|
||||||
|
- name: https
|
||||||
|
port: 443
|
||||||
|
targetPort: 8081
|
||||||
|
---
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: IngressRoute
|
||||||
|
metadata:
|
||||||
|
name: sampleapi-http
|
||||||
|
namespace: experiments
|
||||||
|
spec:
|
||||||
|
entryPoints:
|
||||||
|
- web
|
||||||
|
routes:
|
||||||
|
- match: Host(`sampleapi.apps.mngoma.lab`)
|
||||||
|
kind: Rule
|
||||||
|
services:
|
||||||
|
- name: sampleapi
|
||||||
|
port: 80
|
||||||
|
scheme: http
|
||||||
|
---
|
||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: IngressRoute
|
||||||
|
metadata:
|
||||||
|
name: sampleapi-https
|
||||||
|
namespace: experiments
|
||||||
|
spec:
|
||||||
|
entryPoints:
|
||||||
|
- websecure
|
||||||
|
routes:
|
||||||
|
- match: Host(`sampleapi.apps.mngoma.lab`)
|
||||||
|
kind: Rule
|
||||||
|
services:
|
||||||
|
- name: sampleapi
|
||||||
|
port: 443
|
||||||
|
scheme: http
|
||||||
|
tls: {}
|
||||||
93
manifests/deployment.yaml.bak
Normal file
93
manifests/deployment.yaml.bak
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
# namespace
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: experiments
|
||||||
|
labels:
|
||||||
|
name: experiments
|
||||||
|
---
|
||||||
|
# config map
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ConfigMap
|
||||||
|
metadata:
|
||||||
|
name: sampleapi-configmap
|
||||||
|
namespace: experiments
|
||||||
|
data:
|
||||||
|
appname: "SampleApi"
|
||||||
|
---
|
||||||
|
# deployment
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: sampleapi-deployment
|
||||||
|
namespace: experiments
|
||||||
|
labels:
|
||||||
|
app: sampleapi
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: sampleapi
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: sampleapi
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: sampleapi
|
||||||
|
image: khwezi/mngomalab:latest
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
ports:
|
||||||
|
- name: http
|
||||||
|
containerPort: 8080
|
||||||
|
protocol: TCP
|
||||||
|
- name: https
|
||||||
|
containerPort: 8081
|
||||||
|
protocol: TCP
|
||||||
|
---
|
||||||
|
# service
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: sampleapi-service
|
||||||
|
namespace: experiments
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
selector:
|
||||||
|
app: sampleapi
|
||||||
|
app.kubernetes.io/instance: sampleapi
|
||||||
|
ports:
|
||||||
|
- port: 8080
|
||||||
|
targetPort: 80
|
||||||
|
- port: 8081
|
||||||
|
targetPort: 443
|
||||||
|
---
|
||||||
|
# ingress
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: sampleapi-ingress
|
||||||
|
namespace: experiments
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: sampleapi-secret
|
||||||
|
nginx.ingress.kubernetes.io/rewrite-target: /$1
|
||||||
|
nginx.ingress.kubernetes.io/ssl-redirect: "false"
|
||||||
|
cert-manager.io/private-key-size: "4096"
|
||||||
|
spec:
|
||||||
|
ingressClassName: nginx
|
||||||
|
rules:
|
||||||
|
- host: sampleapi.main.k3s.lab.mngoma.africa
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- pathType: Prefix
|
||||||
|
path: /
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: sampleapi-service
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- sampleapi.main.k3s.lab.mngoma.africa
|
||||||
|
secretName: sampleapi-secret
|
||||||
|
|
||||||
Reference in New Issue
Block a user