From f8d7067ea0284a984502a290d691ea1af09af307 Mon Sep 17 00:00:00 2001 From: Djohn Date: Sat, 7 Feb 2026 11:03:35 +0100 Subject: [PATCH] feat: initial mdBook setup with CI/CD - mdBook structure - Multi-image Docker build - Deploy to books.softwarehuset.com --- .forgejo/workflows/ci.yml | 77 +++++++++++++++++++++++++++++++++++++ Dockerfile | 20 ++++++++++ book.toml | 13 +++++++ k8s/base/deployment.yaml | 38 ++++++++++++++++++ k8s/base/ingress.yaml | 23 +++++++++++ k8s/base/kustomization.yaml | 17 ++++++++ k8s/base/service.yaml | 10 +++++ k8s/prod/kustomization.yaml | 7 ++++ src/README.md | 7 ++++ src/SUMMARY.md | 7 ++++ src/getting-started.md | 12 ++++++ 11 files changed, 231 insertions(+) create mode 100644 .forgejo/workflows/ci.yml create mode 100644 Dockerfile create mode 100644 book.toml create mode 100644 k8s/base/deployment.yaml create mode 100644 k8s/base/ingress.yaml create mode 100644 k8s/base/kustomization.yaml create mode 100644 k8s/base/service.yaml create mode 100644 k8s/prod/kustomization.yaml create mode 100644 src/README.md create mode 100644 src/SUMMARY.md create mode 100644 src/getting-started.md diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..123092a --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,77 @@ +# books +name: books + +on: + push: + branches: [main] + pull_request: + +env: + REGISTRY: code.core.ci/softwarehuset + IMAGES: | + ./Dockerfile|books|. + +jobs: + docker: + name: docker + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Login to registry + run: echo "${{ secrets.FORGEJO_TOKEN }}" | docker login code.core.ci -u djohn --password-stdin + + - name: Build & Push images + run: | + set -e + + if [ "${{ github.event_name }}" = "pull_request" ]; then + TAG="pr-${{ github.event.number }}" + else + TAG="${{ github.sha }}" + fi + + IS_MAIN="${{ github.ref == 'refs/heads/main' }}" + + echo "${{ env.IMAGES }}" | grep -v '^[[:space:]]*$' | while IFS='|' read -r dockerfile image context; do + dockerfile=$(echo "$dockerfile" | xargs) + image=$(echo "$image" | xargs) + context=$(echo "$context" | xargs) + + [ -z "$dockerfile" ] && continue + + FULL_IMAGE="${{ env.REGISTRY }}/${image}" + + echo "🐳 Building: ${FULL_IMAGE}:${TAG}" + docker build -f "${dockerfile}" -t "${FULL_IMAGE}:${TAG}" "${context}" + docker push "${FULL_IMAGE}:${TAG}" + + if [ "$IS_MAIN" = "true" ]; then + docker tag "${FULL_IMAGE}:${TAG}" "${FULL_IMAGE}:latest" + docker push "${FULL_IMAGE}:latest" + fi + done + + deploy: + name: deploy + needs: [docker] + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + container: + image: bitnami/kubectl:1.31 + steps: + - name: Checkout + env: + TOKEN: ${{ secrets.FORGEJO_TOKEN }} + run: | + cd /tmp && git clone --depth=1 "https://djohn:${TOKEN}@code.core.ci/${{ github.repository }}.git" repo + - name: Deploy + env: + KUBECONFIG_DATA: ${{ secrets.KUBE_CONFIG }} + run: | + echo "$KUBECONFIG_DATA" | base64 -d > /tmp/kubeconfig + export KUBECONFIG=/tmp/kubeconfig + cd /tmp/repo/k8s/prod + kubectl kustomize . | kubectl apply -f - + kubectl -n books set image deployment/books web=${{ env.REGISTRY }}/books:${{ github.sha }} + kubectl -n books rollout status deployment/books --timeout=120s diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0c41470 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Build stage +FROM rust:1.75-alpine AS builder + +RUN apk add --no-cache musl-dev +RUN cargo install mdbook --version 0.4.40 + +WORKDIR /book +COPY book.toml . +COPY src/ src/ + +RUN mdbook build + +# Runtime stage +FROM nginx:alpine + +COPY --from=builder /book/book /usr/share/nginx/html + +EXPOSE 80 + +CMD ["nginx", "-g", "daemon off;"] diff --git a/book.toml b/book.toml new file mode 100644 index 0000000..600afa4 --- /dev/null +++ b/book.toml @@ -0,0 +1,13 @@ +[book] +title = "Softwarehuset Books" +authors = ["Softwarehuset"] +language = "da" +src = "src" + +[build] +build-dir = "book" + +[output.html] +default-theme = "light" +preferred-dark-theme = "navy" +git-repository-url = "https://code.core.ci/softwarehuset/books" diff --git a/k8s/base/deployment.yaml b/k8s/base/deployment.yaml new file mode 100644 index 0000000..9dc4d7c --- /dev/null +++ b/k8s/base/deployment.yaml @@ -0,0 +1,38 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: books +spec: + replicas: 1 + selector: + matchLabels: + app: books + template: + metadata: + labels: + app: books + spec: + containers: + - name: web + image: books + ports: + - containerPort: 80 + resources: + requests: + memory: "32Mi" + cpu: "10m" + limits: + memory: "64Mi" + cpu: "100m" + livenessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 5 + periodSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 3 + periodSeconds: 5 diff --git a/k8s/base/ingress.yaml b/k8s/base/ingress.yaml new file mode 100644 index 0000000..2ad0301 --- /dev/null +++ b/k8s/base/ingress.yaml @@ -0,0 +1,23 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: books + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod +spec: + ingressClassName: traefik + tls: + - hosts: + - books.softwarehuset.com + secretName: books-tls + rules: + - host: books.softwarehuset.com + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: books + port: + number: 80 diff --git a/k8s/base/kustomization.yaml b/k8s/base/kustomization.yaml new file mode 100644 index 0000000..7c99920 --- /dev/null +++ b/k8s/base/kustomization.yaml @@ -0,0 +1,17 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - deployment.yaml + - service.yaml + - ingress.yaml + +labels: + - pairs: + app: books + includeSelectors: true + +images: + - name: books + newName: code.core.ci/softwarehuset/books + newTag: latest diff --git a/k8s/base/service.yaml b/k8s/base/service.yaml new file mode 100644 index 0000000..d401080 --- /dev/null +++ b/k8s/base/service.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Service +metadata: + name: books +spec: + ports: + - port: 80 + targetPort: 80 + selector: + app: books diff --git a/k8s/prod/kustomization.yaml b/k8s/prod/kustomization.yaml new file mode 100644 index 0000000..59099d7 --- /dev/null +++ b/k8s/prod/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: books + +resources: + - ../base diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..8d15546 --- /dev/null +++ b/src/README.md @@ -0,0 +1,7 @@ +# Softwarehuset Books + +Dokumentation og guides fra Softwarehuset. + +## Indhold + +- **Guides** - Kom i gang med vores projekter diff --git a/src/SUMMARY.md b/src/SUMMARY.md new file mode 100644 index 0000000..21f9782 --- /dev/null +++ b/src/SUMMARY.md @@ -0,0 +1,7 @@ +# Summary + +[Introduction](./README.md) + +# Guides + +- [Getting Started](./getting-started.md) diff --git a/src/getting-started.md b/src/getting-started.md new file mode 100644 index 0000000..65949e4 --- /dev/null +++ b/src/getting-started.md @@ -0,0 +1,12 @@ +# Getting Started + +Velkommen til Softwarehuset. + +## Forudsætninger + +- Git +- Docker + +## Næste skridt + +Udforsk vores repos på [code.core.ci/softwarehuset](https://code.core.ci/softwarehuset).