Initial: C# .NET 8 API + Dockerfile + Pipeline + K8s manifests
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
*.user
|
||||||
|
*.suo
|
||||||
|
.vs/
|
||||||
27
.woodpecker.yml
Normal file
27
.woodpecker.yml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
when:
|
||||||
|
- event: push
|
||||||
|
branch: main
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
|
commands:
|
||||||
|
- dotnet restore
|
||||||
|
- dotnet build --no-restore
|
||||||
|
- dotnet publish -c Release -o /tmp/publish --no-restore
|
||||||
|
|
||||||
|
- name: docker
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
registry: registry.ci-cd.svc.cluster.local:5000
|
||||||
|
repo: registry.ci-cd.svc.cluster.local:5000/demo/demo-api
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- ${CI_COMMIT_SHA:0:8}
|
||||||
|
insecure: true
|
||||||
|
|
||||||
|
- name: deploy
|
||||||
|
image: bitnami/kubectl:latest
|
||||||
|
commands:
|
||||||
|
- kubectl set image deployment/demo-api api=registry.ci-cd.svc.cluster.local:5000/demo/demo-api:${CI_COMMIT_SHA:0:8} -n apps || echo "First deploy - will create"
|
||||||
|
- kubectl rollout status deployment/demo-api -n apps --timeout=60s || true
|
||||||
5
DemoApi.csproj
Normal file
5
DemoApi.csproj
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
13
Dockerfile
Normal file
13
Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
WORKDIR /src
|
||||||
|
COPY *.csproj .
|
||||||
|
RUN dotnet restore
|
||||||
|
COPY . .
|
||||||
|
RUN dotnet publish -c Release -o /app
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /app .
|
||||||
|
EXPOSE 5000
|
||||||
|
ENV ASPNETCORE_URLS=http://+:5000
|
||||||
|
ENTRYPOINT ["dotnet", "DemoApi.dll"]
|
||||||
13
Program.cs
Normal file
13
Program.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
app.MapGet("/", () => new {
|
||||||
|
service = "demo-api",
|
||||||
|
version = "1.0.0",
|
||||||
|
hostname = Environment.MachineName,
|
||||||
|
timestamp = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
|
||||||
|
app.MapGet("/health", () => Results.Ok(new { status = "healthy" }));
|
||||||
|
|
||||||
|
app.Run("http://0.0.0.0:5000");
|
||||||
73
k8s/deployment.yaml
Normal file
73
k8s/deployment.yaml
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: demo-api
|
||||||
|
namespace: apps
|
||||||
|
spec:
|
||||||
|
replicas: 2
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: demo-api
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: demo-api
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: api
|
||||||
|
image: registry.ci-cd.svc.cluster.local:5000/demo/demo-api:latest
|
||||||
|
ports:
|
||||||
|
- containerPort: 5000
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 10m
|
||||||
|
memory: 64Mi
|
||||||
|
limits:
|
||||||
|
memory: 256Mi
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 5000
|
||||||
|
initialDelaySeconds: 10
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /health
|
||||||
|
port: 5000
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: demo-api
|
||||||
|
namespace: apps
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: demo-api
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 5000
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: demo-api
|
||||||
|
namespace: apps
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||||
|
spec:
|
||||||
|
ingressClassName: traefik
|
||||||
|
rules:
|
||||||
|
- host: api.136.248.82.18.nip.io
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: demo-api
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- api.136.248.82.18.nip.io
|
||||||
|
secretName: demo-api-tls
|
||||||
Reference in New Issue
Block a user