Merge pull request 'test' (#14) from test into main
Some checks failed
continuous-integration/drone Build encountered an error
Some checks failed
continuous-integration/drone Build encountered an error
Reviewed-on: $scheme://$host/MngomaLab/webapitest/pulls/14
This commit was merged in pull request #14.
This commit is contained in:
66
.drone.yml
66
.drone.yml
@@ -1,28 +1,3 @@
|
|||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: kubernetes
|
|
||||||
name: build
|
|
||||||
|
|
||||||
clone:
|
|
||||||
disable: false
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: dotnet restore
|
|
||||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
|
||||||
commands:
|
|
||||||
- dotnet restore
|
|
||||||
|
|
||||||
- name: dotnet build
|
|
||||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
|
||||||
commands:
|
|
||||||
- dotnet build --configuration Release
|
|
||||||
- ls ./SampleApi/bin/Release/net8.0/
|
|
||||||
|
|
||||||
- name: dotnet test
|
|
||||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
|
||||||
commands:
|
|
||||||
- dotnet test --configuration Release
|
|
||||||
|
|
||||||
---
|
---
|
||||||
kind: pipeline
|
kind: pipeline
|
||||||
type: kubernetes
|
type: kubernetes
|
||||||
@@ -44,43 +19,12 @@ steps:
|
|||||||
- name: docker build and push
|
- name: docker build and push
|
||||||
image: plugins/docker
|
image: plugins/docker
|
||||||
settings:
|
settings:
|
||||||
repo: registry-server.registry.svc.cluster.local:5000/sampleapi
|
repo: gitea.khongisa.co.za/khwezi/sampleapi
|
||||||
auto_tag: true
|
registry: gitea.khongisa.co.za
|
||||||
registry: registry-server.registry.svc.cluster.local:5000
|
insecure: false
|
||||||
insecure: true
|
|
||||||
username:
|
username:
|
||||||
from_secret: registry-username
|
from_secret: gitea-username
|
||||||
password:
|
password:
|
||||||
from_secret: registry-password
|
from_secret: gitea-password
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
context: ./SampleApi/bin/Release/net8.0/publish/
|
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
|
|
||||||
settings:
|
|
||||||
host: lead.mngoma.lab
|
|
||||||
username:
|
|
||||||
from_secret: host-username
|
|
||||||
password:
|
|
||||||
from_secret: host-password
|
|
||||||
port: 22
|
|
||||||
script:
|
|
||||||
- set -euo pipefail
|
|
||||||
- echo "Applying Kubernetes manifest via SSH..."
|
|
||||||
# Apply the manifest remotely via kubectl on the host
|
|
||||||
- ssh -o StrictHostKeyChecking=no $DRONE_REMOTE_USER@lead.mngoma.lab 'kubectl apply -f -' <<'EOF'
|
|
||||||
$(cat ./manifests/deploy.yml)
|
|
||||||
EOF
|
|
||||||
- echo "Manifest applied successfully."
|
|
||||||
|
|||||||
12
Dockerfile
12
Dockerfile
@@ -1,39 +1,27 @@
|
|||||||
# STAGE 1: Build
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
WORKDIR /src
|
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/"]
|
COPY ["SampleApi/SampleApi.csproj", "SampleApi/"]
|
||||||
RUN dotnet restore "SampleApi/SampleApi.csproj"
|
RUN dotnet restore "SampleApi/SampleApi.csproj"
|
||||||
|
|
||||||
# 2. Copy the rest of the code
|
|
||||||
COPY . .
|
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" \
|
RUN dotnet publish "SampleApi/SampleApi.csproj" \
|
||||||
-c Release \
|
-c Release \
|
||||||
-o /app/publish \
|
-o /app/publish \
|
||||||
--no-restore \
|
--no-restore \
|
||||||
/p:UseAppHost=false
|
/p:UseAppHost=false
|
||||||
|
|
||||||
# STAGE 2: Runtime
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# expose ports
|
|
||||||
ENV ASPNETCORE_HTTP_PORTS=8081
|
ENV ASPNETCORE_HTTP_PORTS=8081
|
||||||
EXPOSE 8081
|
EXPOSE 8081
|
||||||
|
|
||||||
# Copy the contents directly
|
|
||||||
COPY --from=build /app/publish .
|
COPY --from=build /app/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
|
RUN ls -la /app
|
||||||
|
|
||||||
# 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,99 +0,0 @@
|
|||||||
---
|
|
||||||
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: {}
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
# 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