Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/72 on prem installer #84

Merged
merged 3 commits into from
Oct 24, 2024
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: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
.ipynb_checkpoints
.DS_Store
.virtual_documents
.virtual_documents
app.env
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.12.3

WORKDIR /usr/src/app
WORKDIR /app

COPY . .

Expand Down
2 changes: 1 addition & 1 deletion backend/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.12.3

WORKDIR /usr/src/app
WORKDIR /app

COPY . .

Expand Down
20 changes: 20 additions & 0 deletions db/docker-entrypoint-initdb.d.prod/000-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -e


psql -v ON_ERROR_STOP=1 --username "postgres" <<-EOSQL

CREATE USER "${DB_USER}" WITH CREATEDB PASSWORD '${DB_PASSWORD}';

CREATE DATABASE "${DB_SCHEMA}"
WITH OWNER = "${DB_USER}"
TEMPLATE = template0
ENCODING = 'UTF8'
LC_COLLATE = 'en_US.UTF-8'
LC_CTYPE = 'en_US.UTF-8';

\c "${DB_SCHEMA}"

CREATE EXTENSION IF NOT EXISTS ltree WITH SCHEMA public;

EOSQL
12 changes: 12 additions & 0 deletions self-hosted/app.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DB_HOST=<<your postgresql ip>>
POSTGRES_PASSWORD=<<yout superadmin postgres user password>>
DB_PASSWORD=<<your standard postgresql user password>>
DB_SCHEMA=<<your postgresql schema name>>
DB_USER=<<your standart postgresql db user>>
DEBUG="False"
SECRET_KEY=<<your Django secret key>>
NEXT_AUTH_SECRET_KEY=<<your secret for Next auth>>
MAILJET_APIKEY=<<your mailjet api key from mailjet portal>>
MAILJET_SECRET=<<your mailjet api secret from mailjet portal>>
WEBDOMAIN=<<your exposed domain url, keep on https:// format>>
TRAEFIK_CERTIFICATESRESOLVERS_MYRESOLVER_ACME_EMAIL=<<administrator email for Letsencrypt registration>>
20 changes: 20 additions & 0 deletions self-hosted/docker-compose.frontend-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
services:
frontend_build:
image: akvo/akvo-node-18-alpine:20230831.105309.b9593b7
container_name: frontend_build
env_file: "./app.env"
working_dir: /app
environment:
- CI_COMMIT=${CI_COMMIT}
command:
- /bin/bash
- -c
- |
cp i18n frontend/ -R
mv frontend/next.config.prod.mjs frontend/next.config.mjs
echo 'WEBDOMAIN=${WEBDOMAIN}' >> frontend/.env
echo 'NEXT_AUTH_SECRET_KEY=${SECRET_KEY}' >> frontend/.env
cd frontend && yarn install --no-progress --frozen-lock && yarn build
volumes:
- ..:/app:delegated
79 changes: 79 additions & 0 deletions self-hosted/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
services:
mainnetwork:
image: alpine:3.14
command: ["tail", "-f", "/dev/null"]
ports:
- 8000:8000 # backend port
- 5050:5050 # pgAdmin port
- 80:80 # traefik port http
- 443:443 # traefik port https
- 81:81 # frontend port
traefik:
image: traefik:v3.0
container_name: traefik
env_file: "./app.env"
restart: unless-stopped
environment:
- TRAEFIK_PROVIDERS_FILE_FILENAME=/traefik-config/dynamic.yml
- TRAEFIK_PROVIDERS_FILE_WATCH=true
- TRAEFIK_ENTRYPOINTS_WEB_ADDRESS=:80
- TRAEFIK_ENTRYPOINTS_WEBSECURE_ADDRESS=:443
- TRAEFIK_CERTIFICATESRESOLVERS_MYRESOLVER_ACME_STORAGE=/letsencrypt/acme.json
- TRAEFIK_CERTIFICATESRESOLVERS_MYRESOLVER_ACME_TLSCHALLENGE=true
- TRAEFIK_LOG_LEVEL=DEBUG
- TRAEFIK_LOG=true
- TRAEFIK_LOG_FORMAT=common
- TRAEFIK_ACCESSLOG=false
- TRAEFIK_ACCESSLOG_FILEPATH=/var/log/traefik/access.log
- TRAEFIK_ACCESSLOG_FORMAT=common
entrypoint: ["sh", "-c", "/generate_dynamic_config.sh && traefik"]
volumes:
- "traefik-certificates:/letsencrypt"
- "./generate_dynamic_config.sh:/generate_dynamic_config.sh:ro"
- "/traefik-config"
network_mode: service:mainnetwork

db:
env_file: "./app.env"
image: postgres:12-alpine
container_name: db
restart: unless-stopped
volumes:
- ../db/docker-entrypoint-initdb.d.prod:/docker-entrypoint-initdb.d
- pg-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 2s
timeout: 5s
retries: 5
network_mode: service:mainnetwork

backend:
container_name: backend
build:
context: ../backend
dockerfile: Dockerfile.prod
env_file: "./app.env"
restart: unless-stopped
working_dir: /app
depends_on:
db:
condition: service_healthy
network_mode: service:mainnetwork

frontend:
container_name: frontend
build:
context: ../frontend
dockerfile: Dockerfile
env_file: "./app.env"
restart: unless-stopped
working_dir: /app
network_mode: service:mainnetwork
depends_on:
- backend

volumes:
traefik-certificates:
pg-data:
56 changes: 56 additions & 0 deletions self-hosted/generate_dynamic_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

# Remove 'https://' from WEBDOMAIN if present
WEBDOMAIN=${WEBDOMAIN#https://}

cat << EOF > /traefik-config/dynamic.yml
http:
routers:
frontend-service-router-80:
rule: "Host(\`${WEBDOMAIN}\`)"
service: frontend-service
entrypoints: web
middlewares:
- redirect-to-https

frontend-service-router-443:
entrypoints:
- websecure
rule: "Host(\`${WEBDOMAIN}\`)"
service: frontend-service
tls:
certResolver: myresolver

api-service-router-80:
rule: "Host(\`${WEBDOMAIN}\`) && PathPrefix(\`/api\`)"
service: api-service
entrypoints: web
middlewares:
- redirect-to-https

api-service-router-443:
entrypoints:
- websecure
rule: "Host(\`${WEBDOMAIN}\`) && PathPrefix(\`/api\`)"
service: api-service
tls:
certResolver: myresolver

middlewares:
redirect-to-https:
redirectScheme:
scheme: "https"
permanent: true

services:
frontend-service:
loadBalancer:
servers:
- url: "http://localhost:3000"

api-service:
loadBalancer:
servers:
- url: "http://localhost:8000"

EOF
14 changes: 14 additions & 0 deletions self-hosted/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -euv

#Git Pull
git pull

#Rebuild Frontend
CI_COMMIT=latest docker compose -f docker-compose.frontend-build.yml up --build

#Rebuild App
CI_COMMIT=latest docker compose -f docker-compose.yml build --no-cache

#Restart Service
docker compose -f docker-compose.yml stop && docker compose -f docker-compose.yml up -d
5 changes: 5 additions & 0 deletions self-hosted/restart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -euv

#Restart App
docker compose -f docker-compose.yml restart
14 changes: 14 additions & 0 deletions self-hosted/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -euv

#Git Pull
git pull

#Rebuild Frontend
CI_COMMIT=latest docker compose -f docker-compose.frontend-build.yml up --build

#Rebuild App
CI_COMMIT=latest docker compose -f docker-compose.yml build --no-cache

#Restart Service
docker compose -f docker-compose.yml stop && docker compose -f docker-compose.yml up -d