CI/CD (dev on branch, prod on tag) / build-and-deploy (push) Successful in 4m7s
94 lines
3.7 KiB
Markdown
94 lines
3.7 KiB
Markdown
# Portal
|
|
|
|
Interview portal for my Kubernetes home lab. A single-page Next.js site with two sections:
|
|
|
|
1. **The Lab** - diagrams of the request path and the CI/CD pipeline, plus a link list for `it-cost-prod`, `harbor` and `gitea`.
|
|
- Request path: GoDaddy DNS -> host Nginx :80 -> ingress-nginx :8081 -> Service -> Pod for the applications. `harbor` (`:8080`) and `gitea` (`:3001`) are pods in the same cluster, but each is exposed by its own LoadBalancer Service on a host port, so they are not behind ingress-nginx.
|
|
- CI/CD: git push -> Gitea Actions -> docker build -> Harbor -> Helm -> Kubernetes.
|
|
2. **Travel** - link to the travel map.
|
|
|
|
Everything is rendered by server components (no client JS), styled with Tailwind CSS 4, and shipped as a Next.js `standalone` build.
|
|
|
|
## Editing the content
|
|
|
|
All copy lives in one file: [`content/site.ts`](content/site.ts).
|
|
|
|
| What | Where |
|
|
| --- | --- |
|
|
| Name shown in the header | `profile.name` |
|
|
| Lab links, user and password | `labServices` |
|
|
| Travel map link, user and password | `travel` |
|
|
|
|
Replace every `TBD` with the real value. The diagrams themselves are in `components/lab/`.
|
|
|
|
> **Do not put real credentials here.** This repo and the rendered page are public to anyone who can reach them. Use a read-only demo account created just for interviewers.
|
|
|
|
## Local development
|
|
|
|
```bash
|
|
npm install
|
|
npm run dev # http://localhost:3000
|
|
npm run lint
|
|
npx tsc --noEmit
|
|
```
|
|
|
|
Production-like run:
|
|
|
|
```bash
|
|
npm run build
|
|
cp -r .next/static .next/standalone/.next/static
|
|
node .next/standalone/server.js
|
|
```
|
|
|
|
(`output: "standalone"` means `next start` is not the right entrypoint; the Dockerfile does the same copy.)
|
|
|
|
## Deployment
|
|
|
|
```
|
|
Dockerfile multi-stage image (node:24-alpine, non-root uid 1001, port 3000)
|
|
helm/ chart: Deployment + Service + Ingress
|
|
helm/values.yaml defaults
|
|
helm/values-dev.yaml dev overrides -> portal-dev.tomchien.com
|
|
helm/values-prod.yaml prod overrides -> tomchien.com
|
|
.gitea/workflows/cicd.yaml Gitea Actions pipeline
|
|
```
|
|
|
|
### Pipeline behaviour
|
|
|
|
| Trigger | Environment | Namespace / release | Image tag deployed |
|
|
| --- | --- | --- | --- |
|
|
| push to branch `dev` | dev | `portal-dev` | commit SHA |
|
|
| push of any tag | prod | `portal-prod` | the git tag |
|
|
|
|
- A tag is only deployed if its commit is an ancestor of `origin/main`; otherwise the job fails.
|
|
- Each run: lint the chart -> build the image -> push to Harbor (`host.docker.internal:8080/library/portal-<env>`) -> ensure namespace and `harbor-pull-secret` -> `helm upgrade --install --wait --atomic`.
|
|
- A failed Helm release is rolled back automatically (`--atomic`) and the job prints pod/event/log diagnostics.
|
|
- Concurrency is grouped per environment, so a `dev` push never cancels a running prod deploy.
|
|
|
|
### Required Gitea secrets
|
|
|
|
Repository -> Settings -> Actions -> Secrets:
|
|
|
|
| Secret | Value |
|
|
| --- | --- |
|
|
| `KUBE_CONFIG_DATA` | base64 of the kubeconfig the runner uses (`base64 -w0 ~/.kube/config`) |
|
|
| `HARBOR_USERNAME` | Harbor user with push rights on the `library` project |
|
|
| `HARBOR_PASSWORD` | that user's password / robot token |
|
|
|
|
### One-time prerequisites
|
|
|
|
- GoDaddy DNS: add an `A` record for `portal-dev` (and for `@` / `tomchien.com` if it is not already pointing at the Mac mini).
|
|
- Docker Desktop daemon must list `host.docker.internal:8080` under `insecure-registries` (Harbor is plain HTTP).
|
|
- If `tomchien.com/travelmap` is served by a different Service on the same host, give it its own Ingress with path `/travelmap`; ingress-nginx picks the longest matching path over this chart's `/`.
|
|
|
|
### Release flow
|
|
|
|
```bash
|
|
# dev
|
|
git push origin dev
|
|
|
|
# prod
|
|
git checkout main && git merge dev
|
|
git tag v1.0.0 && git push origin main v1.0.0
|
|
```
|