Refactored the pipeline to deploy using SSH

This commit is contained in:
Khwezi
2025-10-18 14:00:17 +02:00
parent fa7a755883
commit 31d4c4af55
2 changed files with 100 additions and 90 deletions

View File

@@ -99,6 +99,6 @@ steps:
namespace: sampleapi namespace: sampleapi
ca: ca:
from_secret: k8s-cert from_secret: k8s-cert
server: https://lead:6443 server: https://lead.mngoma.lab:6443
token: token:
from_secret: k8s-token from_secret: k8s-token

View File

@@ -1,92 +1,102 @@
--- ---
apiVersion: v1 kind: pipeline
kind: Namespace type: kubernetes
metadata: name: build
name: experiments
labels: clone:
name: experiments disable: true
steps:
- name: git clone
image: drone/git
environment:
REPO_URL: http://gitea-server.gitea.svc.cluster.local:3000/mngomalab/sampleapi.git
commands:
- git clone $REPO_URL .
- git checkout $DRONE_COMMIT
- 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
--- ---
apiVersion: v1 kind: pipeline
kind: ConfigMap type: kubernetes
metadata: name: package
name: sampleapi-config
namespace: experiments depends_on:
data: - build
appname: "SampleApi"
clone:
disable: true
steps:
- name: git clone
image: drone/git
environment:
REPO_URL: http://gitea-server.gitea.svc.cluster.local:3000/mngomalab/sampleapi.git
commands:
- git clone $REPO_URL .
- git checkout $DRONE_COMMIT
- 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/
--- ---
apiVersion: apps/v1 kind: pipeline
kind: Deployment type: kubernetes
metadata: name: deploy
name: sampleapi
namespace: experiments depends_on:
labels: - package
app: sampleapi
spec: clone:
replicas: 1 disable: true
selector:
matchLabels: steps:
app: sampleapi - name: deploy via SSH
template: image: appleboy/drone-ssh
metadata: settings:
labels: host: lead.mngoma.lab
app: sampleapi username:
spec: from_secret: host-username
containers: password:
- name: sampleapi from_secret: host-password
image: registry.registry.svc.cluster.local:5000/experiments/sampleapi:latest port: 22
imagePullPolicy: Always script:
ports: - |
- name: http set -euo pipefail
containerPort: 8080 echo "Applying Kubernetes manifest via SSH..."
- name: https ssh -o StrictHostKeyChecking=no $DRONE_REMOTE_USER@lead.mngoma.lab 'kubectl apply -f -' <<'EOF'
containerPort: 8081 $(cat ./manifests/deploy.yml)
--- EOF
apiVersion: v1 echo "Manifest applied successfully."
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: {}