ci(deploy): add production settings, Dockerfile, k8s manifests, and Forgejo deployment workflow
Some checks failed
Build, Test, and Deploy / build-and-deploy (push) Failing after 2m17s
Some checks failed
Build, Test, and Deploy / build-and-deploy (push) Failing after 2m17s
This commit is contained in:
parent
ef9424f6f4
commit
d15b3c51ac
8 changed files with 245 additions and 1 deletions
30
.forgejo/workflows/deploy.yaml
Normal file
30
.forgejo/workflows/deploy.yaml
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
name: Build, Test, and Deploy
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: self-hosted
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Build and Package Docker Image
|
||||||
|
run: |
|
||||||
|
docker build \
|
||||||
|
-t git.ch4t.buzz/buzzparty/openforce:${{ github.sha }} \
|
||||||
|
-t git.ch4t.buzz/buzzparty/openforce:latest \
|
||||||
|
.
|
||||||
|
|
||||||
|
- name: Push to Forgejo Registry
|
||||||
|
run: |
|
||||||
|
docker push git.ch4t.buzz/buzzparty/openforce:${{ github.sha }}
|
||||||
|
docker push git.ch4t.buzz/buzzparty/openforce:latest
|
||||||
|
|
||||||
|
- name: Roll out to Kubernetes
|
||||||
|
run: |
|
||||||
|
kubectl set image deployment/openforce \
|
||||||
|
openforce=git.ch4t.buzz/buzzparty/openforce:${{ github.sha }} \
|
||||||
|
-n default
|
||||||
|
kubectl rollout status deployment/openforce -n default --timeout=180s
|
||||||
47
Dockerfile
Normal file
47
Dockerfile
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
# Stage 1: Build Vue 3 Frontend
|
||||||
|
FROM node:20-alpine AS frontend-builder
|
||||||
|
WORKDIR /app/frontend
|
||||||
|
|
||||||
|
COPY frontend/package*.json ./
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
COPY frontend/ ./
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
|
# Stage 2: Python / Django Runtime
|
||||||
|
FROM python:3.11-slim
|
||||||
|
|
||||||
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||||
|
PYTHONUNBUFFERED=1 \
|
||||||
|
DJANGO_SETTINGS_MODULE=openforce.settings.prod \
|
||||||
|
PORT=8000
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install system dependencies
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
build-essential \
|
||||||
|
libpq-dev \
|
||||||
|
curl \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Install Python requirements
|
||||||
|
COPY requirements.txt .
|
||||||
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
|
# Copy application source
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Copy built frontend assets to frontend/dist
|
||||||
|
COPY --from=frontend-builder /app/frontend/dist /app/frontend/dist
|
||||||
|
|
||||||
|
# Collect static files into STATIC_ROOT
|
||||||
|
RUN mkdir -p /app/staticfiles /app/data && \
|
||||||
|
python manage.py collectstatic --noinput
|
||||||
|
|
||||||
|
RUN chmod +x /app/entrypoint.sh
|
||||||
|
|
||||||
|
EXPOSE 8000
|
||||||
|
|
||||||
|
# Start via entrypoint
|
||||||
|
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||||
10
entrypoint.sh
Executable file
10
entrypoint.sh
Executable file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Run database migrations
|
||||||
|
echo "Running database migrations..."
|
||||||
|
python manage.py migrate --noinput
|
||||||
|
|
||||||
|
# Start Gunicorn server
|
||||||
|
echo "Starting Gunicorn server..."
|
||||||
|
exec gunicorn --bind 0.0.0.0:8000 --workers 3 --timeout 120 openforce.wsgi:application
|
||||||
108
k8s.yaml
Normal file
108
k8s.yaml
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: openforce
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: openforce
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: openforce
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: openforce
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: openforce
|
||||||
|
image: git.ch4t.buzz/buzzparty/openforce:latest
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- containerPort: 8000
|
||||||
|
name: http
|
||||||
|
env:
|
||||||
|
- name: DJANGO_SETTINGS_MODULE
|
||||||
|
value: "openforce.settings.prod"
|
||||||
|
- name: DJANGO_SECRET_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: openforce-secret
|
||||||
|
key: DJANGO_SECRET_KEY
|
||||||
|
optional: true
|
||||||
|
- name: SQLITE_DB_PATH
|
||||||
|
value: "/app/data/db.sqlite3"
|
||||||
|
volumeMounts:
|
||||||
|
- name: openforce-data
|
||||||
|
mountPath: /app/data
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
memory: "256Mi"
|
||||||
|
cpu: "100m"
|
||||||
|
limits:
|
||||||
|
memory: "512Mi"
|
||||||
|
cpu: "500m"
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: 8000
|
||||||
|
httpHeaders:
|
||||||
|
- name: Host
|
||||||
|
value: crm.ch4t.buzz
|
||||||
|
initialDelaySeconds: 10
|
||||||
|
periodSeconds: 10
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /
|
||||||
|
port: 8000
|
||||||
|
httpHeaders:
|
||||||
|
- name: Host
|
||||||
|
value: crm.ch4t.buzz
|
||||||
|
initialDelaySeconds: 15
|
||||||
|
periodSeconds: 20
|
||||||
|
volumes:
|
||||||
|
- name: openforce-data
|
||||||
|
emptyDir: {}
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: openforce
|
||||||
|
namespace: default
|
||||||
|
labels:
|
||||||
|
app: openforce
|
||||||
|
spec:
|
||||||
|
type: ClusterIP
|
||||||
|
ports:
|
||||||
|
- port: 80
|
||||||
|
targetPort: 8000
|
||||||
|
protocol: TCP
|
||||||
|
name: http
|
||||||
|
selector:
|
||||||
|
app: openforce
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: openforce
|
||||||
|
namespace: default
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||||
|
spec:
|
||||||
|
ingressClassName: traefik
|
||||||
|
rules:
|
||||||
|
- host: crm.ch4t.buzz
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: openforce
|
||||||
|
port:
|
||||||
|
number: 80
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- crm.ch4t.buzz
|
||||||
|
secretName: openforce-tls
|
||||||
5
openforce/asgi.py
Normal file
5
openforce/asgi.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
from django.core.asgi import get_asgi_application
|
||||||
|
|
||||||
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', os.environ.get('DJANGO_SETTINGS_MODULE', 'openforce.settings.prod'))
|
||||||
|
application = get_asgi_application()
|
||||||
43
openforce/settings/prod.py
Normal file
43
openforce/settings/prod.py
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import os
|
||||||
|
from .base import *
|
||||||
|
|
||||||
|
DEBUG = False
|
||||||
|
|
||||||
|
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'insecure-prod-key-override-via-env')
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = [
|
||||||
|
'crm.ch4t.buzz',
|
||||||
|
'localhost',
|
||||||
|
'127.0.0.1',
|
||||||
|
]
|
||||||
|
|
||||||
|
# CSRF & Security Headers
|
||||||
|
CSRF_TRUSTED_ORIGINS = [
|
||||||
|
'https://crm.ch4t.buzz',
|
||||||
|
]
|
||||||
|
|
||||||
|
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
||||||
|
SECURE_SSL_REDIRECT = os.environ.get('SECURE_SSL_REDIRECT', 'false').lower() in ('true', '1')
|
||||||
|
SESSION_COOKIE_SECURE = True
|
||||||
|
CSRF_COOKIE_SECURE = True
|
||||||
|
SECURE_BROWSER_XSS_FILTER = True
|
||||||
|
SECURE_CONTENT_TYPE_NOSNIFF = True
|
||||||
|
X_FRAME_OPTIONS = 'DENY'
|
||||||
|
|
||||||
|
# Database configuration: support SQLite persistent volume or PostgreSQL via env
|
||||||
|
DATABASE_URL = os.environ.get('DATABASE_URL')
|
||||||
|
if DATABASE_URL:
|
||||||
|
import dj_database_url # optional if installed
|
||||||
|
DATABASES = {
|
||||||
|
'default': dj_database_url.config(default=DATABASE_URL, conn_max_age=600)
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
DB_PATH = os.environ.get('SQLITE_DB_PATH', str(BASE_DIR / 'data' / 'db.sqlite3'))
|
||||||
|
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
|
||||||
|
DATABASES = {
|
||||||
|
'default': {
|
||||||
|
'ENGINE': 'django.db.backends.sqlite3',
|
||||||
|
'NAME': DB_PATH,
|
||||||
|
'ATOMIC_REQUESTS': True,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import os
|
import os
|
||||||
from django.core.wsgi import get_wsgi_application
|
from django.core.wsgi import get_wsgi_application
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'openforce.settings.base')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', os.environ.get('DJANGO_SETTINGS_MODULE', 'openforce.settings.prod'))
|
||||||
application = get_wsgi_application()
|
application = get_wsgi_application()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ psycopg2-binary>=2.9
|
||||||
jsonschema>=4.0
|
jsonschema>=4.0
|
||||||
django-cors-headers>=4.0
|
django-cors-headers>=4.0
|
||||||
whitenoise>=6.5
|
whitenoise>=6.5
|
||||||
|
gunicorn>=21.2.0
|
||||||
pytest>=7.0
|
pytest>=7.0
|
||||||
pytest-django>=4.5
|
pytest-django>=4.5
|
||||||
pytest-cov>=4.0
|
pytest-cov>=4.0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue