Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server/.gitignore
server/Dockerfile
server/entrypoint.sh
40 changes: 12 additions & 28 deletions .github/workflows/containers-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,20 @@ jobs:
# - name: 'Pull previous Docker container image: :latest'
# run: docker pull "${DOCKER_REPOSITORY}:latest" || true

- name: "Pull previous Docker container image: frontend-static:latest"
run: docker pull "${DOCKER_REPOSITORY}/frontend-static:latest" || true
- name: "Pull previous Docker container image: app:latest"
run: docker pull "${DOCKER_REPOSITORY}/app:latest" || true

- name: "Build Docker container image: frontend-static:latest"
- name: "Build Docker container image: app:latest"
run: |
docker build \
--cache-from "${DOCKER_REPOSITORY}/frontend-static:latest" \
--file frontend/Dockerfile.demo \
--build-arg SERVER_NAME=localhost \
--tag "${DOCKER_REPOSITORY}/frontend-static:latest" \
--tag "${DOCKER_REPOSITORY}/frontend-static:${DOCKER_TAG}" \
frontend
- name: "Push Docker container image frontend-static:latest"
run: docker push "${DOCKER_REPOSITORY}/frontend-static:latest"
--cache-from "${DOCKER_REPOSITORY}/app:latest" \
--file Dockerfile.prod \
--tag "${DOCKER_REPOSITORY}/app:latest" \
--tag "${DOCKER_REPOSITORY}/app:${DOCKER_TAG}" \
.

- name: "Push Docker container image frontend-static:v*"
run: docker push "${DOCKER_REPOSITORY}/frontend-static:${DOCKER_TAG}"
#
#
# - name: 'Build Docker container image: backend:latest'
# run: |
# cd backend && \
# make && \
# docker image tag "${DOCKER_REPOSITORY}/backend/local:latest" "${DOCKER_REPOSITORY}/backend:latest"
#
# - name: Push Docker container image backend:latest
# run: docker push "${DOCKER_REPOSITORY}/backend:latest"
#
# - name: Push Docker container image backend:v*
# run: docker push "${DOCKER_REPOSITORY}/backend:${DOCKER_TAG}"
- name: "Push Docker container image app:latest"
run: docker push "${DOCKER_REPOSITORY}/app:latest"

# - name: Push Docker container image :v*"
# run: docker push "${DOCKER_REPOSITORY}:${DOCKER_TAG}"
- name: "Push Docker container image app:v*"
run: docker push "${DOCKER_REPOSITORY}/app:${DOCKER_TAG}"
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
config/*
.idea/
env*
config/env/*
!config/env/*.example
.idea/
52 changes: 52 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Multi-stage Dockerfile for Balancer Application
# Produces a single image with Django backend serving the React frontend

# Stage 1: Build Frontend
FROM node:18 AS frontend-builder

WORKDIR /frontend

# Copy frontend package files
COPY frontend/package*.json ./

# Install dependencies
RUN npm ci --legacy-peer-deps

# Copy frontend source
COPY frontend/ ./

# Build frontend - outputs to dist/ as configured in vite.config.ts
RUN npm run build

# Stage 2: Build Backend
FROM python:3.11.4-slim-bullseye

# Set work directory
WORKDIR /usr/src/app

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Install system dependencies
RUN apt-get update && apt-get install -y netcat && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
RUN pip install --upgrade pip
COPY server/requirements.txt .
RUN pip install -r requirements.txt

# Copy backend application code
COPY server/ .

# Copy frontend build from frontend-builder stage to where Django expects it
COPY --from=frontend-builder /frontend/dist ./build

# Expose port
EXPOSE 8000

# Run entrypoint
ENTRYPOINT ["./entrypoint.prod.sh"]

# Start gunicorn
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000", "--noreload"]
3 changes: 0 additions & 3 deletions config/env/.env.prod.db

This file was deleted.

2 changes: 1 addition & 1 deletion config/env/env.dev → config/env/dev.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ OPENAI_API_KEY=
ANTHROPIC_API_KEY=
PINECONE_API_KEY=
EMAIL_HOST_USER=
EMAIL_HOST_PASSWORD=
EMAIL_HOST_PASSWORD=
3 changes: 0 additions & 3 deletions config/env/env.prod.db

This file was deleted.

6 changes: 4 additions & 2 deletions config/env/env.prod → config/env/prod.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
DEBUG=0
SECRET_KEY=change_this
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=balancer_prod
SQL_USER=set_me
Expand All @@ -10,5 +9,8 @@ SQL_HOST=db
SQL_PORT=5432
DATABASE=postgres
LOGIN_REDIRECT_URL=
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
PINECONE_API_KEY=
EMAIL_HOST_USER=
EMAIL_HOST_PASSWORD=
EMAIL_HOST_PASSWORD=
File renamed without changes.
19 changes: 0 additions & 19 deletions deploy/manifests/balancer/base/configmap.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: Deployment
metadata:
labels:
app: balancer
service: backend
name: balancer
spec:
replicas: 1
Expand All @@ -17,16 +16,16 @@ spec:
app: balancer
spec:
containers:
- image: ghcr.io/codeforphilly/balancer-main/backend
name: balancer
- image: ghcr.io/codeforphilly/balancer-main/app
name: app
envFrom:
- configMapRef:
- secretRef:
name: balancer-config
ports:
- containerPort: 8000
readinessProbe:
httpGet:
path: /
path: /admin/
port: 8000
initialDelaySeconds: 30
periodSeconds: 10
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: balancer
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-staging"
annotations: {}
spec:
ingressClassName: nginx
tls:
- hosts:
- balancertestsite.com
- HOSTNAME_PLACEHOLDER
secretName: balancer-tls
rules:
- host: balancertestsite.com
- host: HOSTNAME_PLACEHOLDER
http:
paths:
# All traffic routes to balancer service (which serves both API and frontend)
- path: /
pathType: Prefix
backend:
service:
name: balancer
port:
number: 80
number: 8000
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- deployment.yml
- service.yml
- configmap.yml
- ingress.yml
- namespace.yaml
- deployment.yaml
- service.yaml
- ingress.yaml
4 changes: 4 additions & 0 deletions deploy/manifests/balancer/base/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: balancer
29 changes: 29 additions & 0 deletions deploy/manifests/balancer/base/secret.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Secret Template for Balancer Application
#
# This file documents the required secret keys for the balancer application.
#
# IMPORTANT: This file is a TEMPLATE only. Do NOT create a Secret manifest in this
# repository. Secrets should be created in each target cluster using cluster-specific
# tools (e.g., SealedSecrets in the cfp-sandbox-cluster).
#
apiVersion: v1
kind: Secret
metadata:
name: balancer-config
namespace: balancer
type: Opaque
stringData:
DATABASE: postgres
DEBUG: '1'
DJANGO_ALLOWED_HOSTS: localhost 127.0.0.1 [::1] balancer.sandbox.k8s.phl.io
LOGIN_REDIRECT_URL: ''
OPENAI_API_KEY: openapi_key_here
PINECONE_API_KEY: pinecone_key_here
REACT_APP_API_BASE_URL: https://balancer.sandbox.k8s.phl.io/
SECRET_KEY: randomly_generated_key_ere
SQL_ENGINE: django.db.backends.postgresql
SQL_HOST: sql_host_here
SQL_PORT: '5432'
SQL_DATABASE: balancer_dev
SQL_USER: balancer
SQL_PASSWORD: sql_password_here
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
spec:
ports:
- name: http
port: 80
port: 8000
targetPort: 8000
selector:
app: balancer
26 changes: 26 additions & 0 deletions deploy/manifests/balancer/overlays/dev/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: balancer

resources:
- ../../base

images:
- name: ghcr.io/codeforphilly/balancer-main/app
newTag: latest

patches:
- target:
kind: Ingress
name: balancer
patch: |-
- op: add
path: /metadata/annotations/cert-manager.io~1cluster-issuer
value: letsencrypt-staging
- op: replace
path: /spec/tls/0/hosts/0
value: localhost
- op: replace
path: /spec/rules/0/host
value: localhost
11 changes: 0 additions & 11 deletions deploy/manifests/balancer/overlays/dev/kustomization.yml

This file was deleted.

21 changes: 0 additions & 21 deletions deployment.sh

This file was deleted.

9 changes: 5 additions & 4 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: balancer-prod
version: "3.8"

services:
backend:
image: balancer-backend
app:
image: balancer-app
build:
context: server
context: .
dockerfile: Dockerfile.prod
ports:
- "8000:8000"
env_file:
- ./config/env/env.dev
- ./config/env/prod.env
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
ports:
- "8000:8000"
env_file:
- ./config/env/env.dev
- ./config/env/dev.env
depends_on:
- db
volumes:
Expand Down
2 changes: 0 additions & 2 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ dist
dist-ssr
*.local

config/env/env.dev

# Editor directories and files
.vscode/*
!.vscode/extensions.json
Expand Down
Loading