This commit is contained in:
commit
e4f9773a58
5 files changed
+76
No files matched your search
@@ -0,0 +1,35 @@
|
||||
name: build-scan-deploy
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths-ignore: ["k8s/**"]
|
||||
workflow_dispatch:
|
||||
env:
|
||||
REGISTRY: 192.168.0.43:3000
|
||||
IMAGE: 192.168.0.43:3000/joseph/hello-devops
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with: {token: "${{ secrets.REGISTRY_TOKEN }}"}
|
||||
- name: Install docker CLI
|
||||
run: curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-27.5.1.tgz | tar xz --strip-components=1 -C /usr/local/bin docker/docker
|
||||
- name: Lint Dockerfile
|
||||
run: docker run --rm -i hadolint/hadolint < Dockerfile || true
|
||||
- name: Build image
|
||||
run: |
|
||||
TAG=${GITHUB_SHA::7}
|
||||
echo "TAG=$TAG" >> $GITHUB_ENV
|
||||
docker build --build-arg VERSION=$TAG -t $IMAGE:$TAG -t $IMAGE:latest .
|
||||
- name: Scan with Trivy (fail on CRITICAL)
|
||||
run: docker run --rm -v /var/run/docker.sock:/var/run/docker.sock aquasec/trivy:latest image --severity CRITICAL --exit-code 1 --ignore-unfixed $IMAGE:$TAG
|
||||
- name: Push to Gitea registry
|
||||
run: |
|
||||
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login $REGISTRY -u joseph --password-stdin
|
||||
docker push $IMAGE:$TAG && docker push $IMAGE:latest
|
||||
- name: GitOps - bump image tag
|
||||
run: |
|
||||
sed -i "s#image: .*hello-devops:.*#image: $IMAGE:$TAG#" k8s/app.yaml
|
||||
git config user.name "gitea-actions"; git config user.email "[email protected]"
|
||||
git commit -am "deploy: hello-devops $TAG [skip ci]" && git push
|
||||
@@ -0,0 +1,5 @@
|
||||
FROM nginx:1.29-alpine
|
||||
ARG VERSION=dev
|
||||
COPY index.html /usr/share/nginx/html/index.html
|
||||
RUN sed -i "s/__VERSION__/${VERSION}/" /usr/share/nginx/html/index.html
|
||||
EXPOSE 80
|
||||
@@ -0,0 +1,4 @@
|
||||
# hello-devops
|
||||
Demo GitOps pipeline for the DevOps lab.
|
||||
Push to `main` → Gitea Actions builds + Trivy-scans the image → pushes to the Gitea registry → bumps the tag in `k8s/app.yaml` → Argo CD syncs it to k3s.
|
||||
Open: http://192.168.0.41/ (Traefik ingress)
|
||||
@@ -0,0 +1,3 @@
|
||||
<!doctype html><html><head><meta charset="utf-8"><title>Hello DevOps</title>
|
||||
<style>body{font-family:system-ui;background:#0f172a;color:#e2e8f0;display:grid;place-items:center;height:100vh;margin:0}div{text-align:center}code{color:#38bdf8}</style></head>
|
||||
<body><div><h1>Hello from the DevOps lab 🚀</h1><p>Built by Gitea Actions · scanned by Trivy · deployed by Argo CD on k3s</p><p>Version: <code>__VERSION__</code></p></div></body></html>
|
||||
@@ -0,0 +1,29 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata: {name: hello-devops, labels: {app: hello-devops}}
|
||||
spec:
|
||||
replicas: 2
|
||||
selector: {matchLabels: {app: hello-devops}}
|
||||
template:
|
||||
metadata: {labels: {app: hello-devops}}
|
||||
spec:
|
||||
containers:
|
||||
- name: web
|
||||
image: 192.168.0.43:3000/joseph/hello-devops:initial
|
||||
ports: [{containerPort: 80}]
|
||||
resources: {requests: {cpu: 10m, memory: 16Mi}, limits: {memory: 64Mi}}
|
||||
readinessProbe: {httpGet: {path: /, port: 80}}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata: {name: hello-devops}
|
||||
spec: {selector: {app: hello-devops}, ports: [{port: 80, targetPort: 80}]}
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata: {name: hello-devops}
|
||||
spec:
|
||||
ingressClassName: traefik
|
||||
rules:
|
||||
- http:
|
||||
paths: [{path: /, pathType: Prefix, backend: {service: {name: hello-devops, port: {number: 80}}}}]
|
||||
Reference in new issue
Block a user