Compare commits
5 Commits
ddfb70adc2
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| cba49b734c | |||
| 98a77049cd | |||
| d7ae020130 | |||
| a281d9cce9 | |||
| 434c5b2792 |
115
.gitea/workflows/build-push.yaml
Normal file
115
.gitea/workflows/build-push.yaml
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
name: Build and Push Container Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths-ignore:
|
||||||
|
- "deploy/**"
|
||||||
|
env:
|
||||||
|
REGISTRY: reg.milasholsting.dk
|
||||||
|
IMAGE_NAME: taskarr/taskarr
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
with:
|
||||||
|
config-inline: |
|
||||||
|
[registry."reg.milasholsting.dk"]
|
||||||
|
http = false
|
||||||
|
insecure = true
|
||||||
|
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
flavor:
|
||||||
|
latest=false
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
tags: |
|
||||||
|
type=sha,prefix=sha-,format=short
|
||||||
|
type=raw,value=latest
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Containerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
build-args: |
|
||||||
|
DATABASE_URL=${{ secrets.DATABASE_URL }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Extract metadata for Migrator
|
||||||
|
id: meta-migrator
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-migrator
|
||||||
|
tags: |
|
||||||
|
type=sha,prefix=sha-,format=short
|
||||||
|
type=raw,value=latest
|
||||||
|
|
||||||
|
- name: Build and push Migrator image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Containerfile.migrator
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta-migrator.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta-migrator.outputs.labels }}
|
||||||
|
build-args: |
|
||||||
|
DATABASE_URL=${{ secrets.DATABASE_URL }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
|
||||||
|
- name: Install Kustomize
|
||||||
|
run: |
|
||||||
|
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
|
||||||
|
sudo mv kustomize /usr/local/bin/
|
||||||
|
|
||||||
|
- name: Update Kustomize
|
||||||
|
run: |
|
||||||
|
# 1. Extract specifically the SHA tag from the metadata outputs
|
||||||
|
# This looks at the JSON output and finds the tag matching our 'sha-' prefix
|
||||||
|
IMAGE_TAG=$(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[] | select(contains("sha-"))' | cut -d: -f2)
|
||||||
|
|
||||||
|
echo "Targeting Tag: $IMAGE_TAG"
|
||||||
|
|
||||||
|
# 2. Update the manifest
|
||||||
|
cd deploy/overlays/production
|
||||||
|
kustomize edit set image election=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG
|
||||||
|
|
||||||
|
kustomize edit set image election-migration=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-migrator:$IMAGE_TAG
|
||||||
|
- name: Commit and Push Change
|
||||||
|
run: |
|
||||||
|
# 1. Set identity to fix the "Author identity unknown" error
|
||||||
|
git config user.name "Gitea Action"
|
||||||
|
git config user.email "actions@gitea.io"
|
||||||
|
|
||||||
|
# 2. Stage the change
|
||||||
|
git add deploy/overlays/production/kustomization.yaml
|
||||||
|
|
||||||
|
# 3. Only commit if the file actually changed (prevents empty commit errors)
|
||||||
|
if git diff --staged --quiet; then
|
||||||
|
echo "No changes to commit"
|
||||||
|
else
|
||||||
|
git commit -m "chore(deploy): update image to ${{ steps.meta.outputs.version }}"
|
||||||
|
git push origin master
|
||||||
|
fi
|
||||||
53
Containerfile
Normal file
53
Containerfile
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Stage 1: Install dependencies
|
||||||
|
FROM docker.io/oven/bun:1.3.3-alpine AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json bun.lock ./
|
||||||
|
|
||||||
|
RUN apk add --no-cache python3 make g++
|
||||||
|
|
||||||
|
RUN bun i --frozen-lockfile
|
||||||
|
|
||||||
|
# Stage 2: Build the SvelteKit application
|
||||||
|
FROM docker.io/oven/bun:1.3.3-alpine AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ARG DATABASE_URL
|
||||||
|
ENV DATABASE_URL=$DATABASE_URL
|
||||||
|
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application with the Node.js adapter
|
||||||
|
RUN bun run build
|
||||||
|
|
||||||
|
# Prune dev dependencies after build
|
||||||
|
# We will have to wait for bun support big sad
|
||||||
|
# RUN bun prune --omit=dev
|
||||||
|
|
||||||
|
# Stage 3: Production runtime
|
||||||
|
FROM docker.io/oven/bun:1.3.3-alpine AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
# Create non-root user
|
||||||
|
RUN addgroup --system --gid 1001 sveltekit
|
||||||
|
RUN adduser --system --uid 1001 sveltekit
|
||||||
|
|
||||||
|
# Copy the built application
|
||||||
|
COPY --from=builder --chown=sveltekit:sveltekit /app/build ./build
|
||||||
|
|
||||||
|
# Copy production dependencies
|
||||||
|
COPY --from=builder --chown=sveltekit:sveltekit /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Copy package.json for module resolution
|
||||||
|
COPY --chown=sveltekit:sveltekit package.json .
|
||||||
|
|
||||||
|
USER sveltekit
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
ENV PORT=3000
|
||||||
|
ENV HOST=0.0.0.0
|
||||||
|
|
||||||
|
# Start the SvelteKit server
|
||||||
|
CMD ["bun", "--bun", "build/index.js"]
|
||||||
21
Containerfile.migrator
Normal file
21
Containerfile.migrator
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Stage 1: Install dependencies
|
||||||
|
FROM docker.io/oven/bun:1.3.3-alpine AS deps
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json bun.lock ./
|
||||||
|
|
||||||
|
RUN apk add --no-cache python3 make g++
|
||||||
|
|
||||||
|
RUN bun i --frozen-lockfile
|
||||||
|
|
||||||
|
# Stage 2: Build the SvelteKit application
|
||||||
|
FROM docker.io/oven/bun:1.3.3-alpine AS builder
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
ARG DATABASE_URL
|
||||||
|
ENV DATABASE_URL=$DATABASE_URL
|
||||||
|
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
CMD ["bun", "--bun", "run", "db:migrate"]
|
||||||
|
|
||||||
0
deploy/.gitkeep
Normal file
0
deploy/.gitkeep
Normal file
12
deploy/base/app-secret.yaml
Normal file
12
deploy/base/app-secret.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: secrets.hashicorp.com/v1beta1
|
||||||
|
kind: HCPStaticSecret
|
||||||
|
metadata:
|
||||||
|
name: taskarr-ap
|
||||||
|
spec:
|
||||||
|
method: GET
|
||||||
|
mount: secret
|
||||||
|
path: taskarr/app
|
||||||
|
destination:
|
||||||
|
name: taskarr-app
|
||||||
|
create: true
|
||||||
|
refreshAfter: 1h
|
||||||
12
deploy/base/cert.yaml
Normal file
12
deploy/base/cert.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: cert-manager.io/v1
|
||||||
|
kind: Certificate
|
||||||
|
metadata:
|
||||||
|
name: taskarr-tls
|
||||||
|
spec:
|
||||||
|
secretName: taskarr-tls
|
||||||
|
issuerRef:
|
||||||
|
name: letsencrypt-prod
|
||||||
|
kind: ClusterIssuer
|
||||||
|
dnsNames:
|
||||||
|
- taskarr.milasholsting.dk
|
||||||
|
|
||||||
13
deploy/base/database-secret.yaml
Normal file
13
deploy/base/database-secret.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
apiVersion: secrets.hashicorp.com/v1beta1
|
||||||
|
kind: HCPStaticSecret
|
||||||
|
metadata:
|
||||||
|
name: taskarr-db
|
||||||
|
spec:
|
||||||
|
method: GET
|
||||||
|
mount: secret
|
||||||
|
path: taskarr/db
|
||||||
|
destination:
|
||||||
|
name: taskarr-db
|
||||||
|
create: true
|
||||||
|
refreshAfter: 1h
|
||||||
|
|
||||||
76
deploy/base/deployment.yaml
Normal file
76
deploy/base/deployment.yaml
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: taskarr
|
||||||
|
labels:
|
||||||
|
app: taskarr
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: taskarr
|
||||||
|
replicas: 1
|
||||||
|
strategy:
|
||||||
|
rollingUpdate:
|
||||||
|
maxSurge: 25%
|
||||||
|
maxUnavailable: 25%
|
||||||
|
type: RollingUpdate
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
annotations:
|
||||||
|
kubectl.kubernetes.io/default-container: taskarr
|
||||||
|
labels:
|
||||||
|
app: taskarr
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: taskarr
|
||||||
|
image: main
|
||||||
|
imagePullPolicy: IfNotPresent
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 100Mi
|
||||||
|
limits:
|
||||||
|
cpu: 100m
|
||||||
|
memory: 100Mi
|
||||||
|
livenessProbe:
|
||||||
|
tcpSocket:
|
||||||
|
port: 3000
|
||||||
|
initialDelaySeconds: 5
|
||||||
|
timeoutSeconds: 5
|
||||||
|
successThreshold: 1
|
||||||
|
failureThreshold: 3
|
||||||
|
periodSeconds: 10
|
||||||
|
ports:
|
||||||
|
- containerPort: 3000
|
||||||
|
name: http
|
||||||
|
env:
|
||||||
|
- name: DATABASE_URL
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: taskarr-app
|
||||||
|
key: DATABASE_URL
|
||||||
|
- name: ORIGIN
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: taskarr-app
|
||||||
|
key: ORIGIN
|
||||||
|
- name: BETTER_AUTH_SECRET
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: taskarr-app
|
||||||
|
key: BETTER_AUTH_SECRET
|
||||||
|
- name: GITEA_CLIENT_SECRET
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: taskarr-app
|
||||||
|
key: GITEA_CLIENT_SECRET
|
||||||
|
- name: GITEA_CLIENT_ID
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: taskarr-app
|
||||||
|
key: GITEA_CLIENT_ID
|
||||||
|
|
||||||
|
restartPolicy: Always
|
||||||
|
---
|
||||||
|
|
||||||
19
deploy/base/ingress.yaml
Normal file
19
deploy/base/ingress.yaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
apiVersion: traefik.io/v1alpha1
|
||||||
|
kind: IngressRoute
|
||||||
|
metadata:
|
||||||
|
name: taskarr-ingress
|
||||||
|
namespace: vhsmp
|
||||||
|
spec:
|
||||||
|
entryPoints:
|
||||||
|
- websecure
|
||||||
|
- web
|
||||||
|
routes:
|
||||||
|
- match: Host(`taskarr.milasholsting.dk`)
|
||||||
|
kind: Rule
|
||||||
|
services:
|
||||||
|
- name: taskarr
|
||||||
|
port: 3000
|
||||||
|
tls:
|
||||||
|
secretName: taskarr-tls
|
||||||
|
|
||||||
|
|
||||||
15
deploy/base/kustomization.yaml
Normal file
15
deploy/base/kustomization.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
namespace: taskarr
|
||||||
|
|
||||||
|
resources:
|
||||||
|
- ./deployment.yaml
|
||||||
|
- ./ingress.yaml
|
||||||
|
- ./cert.yaml
|
||||||
|
- ./service.yaml
|
||||||
|
- ./migration-job.yaml
|
||||||
|
- ./postgres-service.yaml
|
||||||
|
- ./postgres-storage.yaml
|
||||||
|
- ./postgres.yaml
|
||||||
|
- ./database-secret.yaml
|
||||||
|
- ./app-secret.yaml
|
||||||
35
deploy/base/migration-job.yaml
Normal file
35
deploy/base/migration-job.yaml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# https://kubernetes.io/docs/concepts/workloads/controllers/job/
|
||||||
|
apiVersion: batch/v1
|
||||||
|
kind: Job
|
||||||
|
metadata:
|
||||||
|
name: taskarr-migration
|
||||||
|
annotations:
|
||||||
|
# 1. Tells Argo this is a hook to run during sync
|
||||||
|
argocd.argoproj.io/hook: Sync
|
||||||
|
|
||||||
|
# 2. Ensures the migration runs BEFORE the deployment
|
||||||
|
argocd.argoproj.io/sync-wave: "1"
|
||||||
|
|
||||||
|
# 3. Deletes the job after it succeeds so it can run again next time
|
||||||
|
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
|
||||||
|
labels:
|
||||||
|
app: taskarr-migration
|
||||||
|
spec:
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
name: taskarr-migration
|
||||||
|
labels:
|
||||||
|
app: taskarr-migration
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: taskarr-migrator
|
||||||
|
image: migrator
|
||||||
|
env:
|
||||||
|
- name: DATABASE_URL
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: election
|
||||||
|
key: DATABASE_URL
|
||||||
|
|
||||||
|
restartPolicy: OnFailure
|
||||||
|
dnsPolicy: ClusterFirst
|
||||||
12
deploy/base/postgres-service.yaml
Normal file
12
deploy/base/postgres-service.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: postgres-service
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: postgres
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 5432
|
||||||
|
targetPort: 5432
|
||||||
|
type: ClusterIP
|
||||||
11
deploy/base/postgres-storage.yaml
Normal file
11
deploy/base/postgres-storage.yaml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: postgres-pvc
|
||||||
|
spec:
|
||||||
|
storageClassName: local-path
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 5Gi
|
||||||
42
deploy/base/postgres.yaml
Normal file
42
deploy/base/postgres.yaml
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: postgres
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: postgres
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: postgres
|
||||||
|
image: postgres:18
|
||||||
|
ports:
|
||||||
|
- containerPort: 5432
|
||||||
|
env:
|
||||||
|
- name: POSTGRES_DB
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: taskarr-db
|
||||||
|
key: DATABASE
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: taskarr-db
|
||||||
|
key: USER
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: taskarr-db
|
||||||
|
key: PASSWORD
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: /var/lib/postgresql
|
||||||
|
name: postgredb
|
||||||
|
volumes:
|
||||||
|
- name: postgredb
|
||||||
|
persistentVolumeClaim:
|
||||||
|
claimName: postgres-pvc
|
||||||
15
deploy/base/service.yaml
Normal file
15
deploy/base/service.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# https://kubernetes.io/docs/concepts/services-networking/service/
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: taskarr
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: taskarr
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- name: taskarr
|
||||||
|
protocol: TCP
|
||||||
|
port: 3000
|
||||||
|
targetPort: 3000
|
||||||
|
|
||||||
26
deploy/overlays/production/deployment.yaml
Normal file
26
deploy/overlays/production/deployment.yaml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: taskarr # Must match the name in base/
|
||||||
|
spec:
|
||||||
|
replicas: 2 # Scale up for production
|
||||||
|
template:
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: main # This name must match base EXACTLY
|
||||||
|
ports: # Adding this back into the patch solves the diff
|
||||||
|
- containerPort: 3000
|
||||||
|
name: taskarr
|
||||||
|
# Production-specific resource limits
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
cpu: "1"
|
||||||
|
memory: "1Gi"
|
||||||
|
requests:
|
||||||
|
cpu: "500m"
|
||||||
|
memory: "512Mi"
|
||||||
|
# Adding a production-only environment variable
|
||||||
|
env:
|
||||||
|
- name: NODE_ENV
|
||||||
|
value: "production"
|
||||||
|
|
||||||
24
deploy/overlays/production/kustomization.yaml
Normal file
24
deploy/overlays/production/kustomization.yaml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
|
||||||
|
# 1. Point to the base manifests
|
||||||
|
resources:
|
||||||
|
- ../../base
|
||||||
|
|
||||||
|
# 2. Apply the production-specific changes
|
||||||
|
patches:
|
||||||
|
- path: deployment.yaml
|
||||||
|
target:
|
||||||
|
kind: Deployment
|
||||||
|
name: taskarr
|
||||||
|
|
||||||
|
# 4. Change the namespace for this overlay
|
||||||
|
namespace: taskarr
|
||||||
|
|
||||||
|
images:
|
||||||
|
- name: main
|
||||||
|
newName: reg.milasholsting.dk/taskarr/taskarr
|
||||||
|
newTag: latest
|
||||||
|
- name: migrator
|
||||||
|
newName: reg.milasholsting.dk/taskarr/migrator
|
||||||
|
newTag: latest
|
||||||
Reference in New Issue
Block a user