feat: initial mdBook setup with CI/CD
- mdBook structure - Multi-image Docker build - Deploy to books.softwarehuset.com
This commit is contained in:
parent
98d32b5f16
commit
f8d7067ea0
11 changed files with 231 additions and 0 deletions
77
.forgejo/workflows/ci.yml
Normal file
77
.forgejo/workflows/ci.yml
Normal file
|
|
@ -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
|
||||
20
Dockerfile
Normal file
20
Dockerfile
Normal file
|
|
@ -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;"]
|
||||
13
book.toml
Normal file
13
book.toml
Normal file
|
|
@ -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"
|
||||
38
k8s/base/deployment.yaml
Normal file
38
k8s/base/deployment.yaml
Normal file
|
|
@ -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
|
||||
23
k8s/base/ingress.yaml
Normal file
23
k8s/base/ingress.yaml
Normal file
|
|
@ -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
|
||||
17
k8s/base/kustomization.yaml
Normal file
17
k8s/base/kustomization.yaml
Normal file
|
|
@ -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
|
||||
10
k8s/base/service.yaml
Normal file
10
k8s/base/service.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: books
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: books
|
||||
7
k8s/prod/kustomization.yaml
Normal file
7
k8s/prod/kustomization.yaml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
namespace: books
|
||||
|
||||
resources:
|
||||
- ../base
|
||||
7
src/README.md
Normal file
7
src/README.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Softwarehuset Books
|
||||
|
||||
Dokumentation og guides fra Softwarehuset.
|
||||
|
||||
## Indhold
|
||||
|
||||
- **Guides** - Kom i gang med vores projekter
|
||||
7
src/SUMMARY.md
Normal file
7
src/SUMMARY.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Summary
|
||||
|
||||
[Introduction](./README.md)
|
||||
|
||||
# Guides
|
||||
|
||||
- [Getting Started](./getting-started.md)
|
||||
12
src/getting-started.md
Normal file
12
src/getting-started.md
Normal file
|
|
@ -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).
|
||||
Loading…
Add table
Add a link
Reference in a new issue