Skip to content

Commit

Permalink
feat: containerize the project
Browse files Browse the repository at this point in the history
  • Loading branch information
Justintime50 committed Sep 16, 2024
1 parent f31e729 commit 8fbc080
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Next Major Release

Containerizes the project

## v1.1.0 (2024-07-18)

- Adds support for Python 3.12
Expand Down
27 changes: 24 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
FROM nginx:1.25-alpine
FROM python:3.12

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
# Helps with Docker logging
ENV PYTHONUNBUFFERED=1

WORKDIR /app

RUN apt-get update && \
apt-get install -y \
ca-certificates \
curl \
gnupg \
lsb-release && \
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
echo "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" > /etc/apt/sources.list.d/docker.list && \
apt-get update && \
apt-get install -y docker-ce-cli

COPY . .

RUN pip install -e .

EXPOSE 5000

ENTRYPOINT [ "uwsgi", "--ini", "uwsgi.ini" ]
8 changes: 2 additions & 6 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
services:
harvey-nginx:
harvey:
deploy:
replicas: 2
mem_limit: '512m'
mem_limit: '1024m'
healthcheck:
test: ['CMD-SHELL', 'if [ ! -e /var/run/nginx.pid ]; then exit 1; else exit 0; fi']
start_period: 10s
start_interval: 1s
interval: 30s
timeout: 10s
retries: 3
labels:
- 'traefik.http.routers.harveyapi.rule=Host(`harveyapi.justinpaulhammond.com`) || Host(`www.harveyapi.justinpaulhammond.com`)'
- 'traefik.http.routers.harveyapi.tls=true'
- 'traefik.http.routers.harveyapi.tls.certresolver=letsencrypt'
8 changes: 6 additions & 2 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
services:
harvey-nginx:
harvey:
labels:
- "traefik.http.routers.harveyapi.rule=Host(`harveyapi.localhost`)"
- 'traefik.enable=true'
- 'traefik.http.routers.harveyapi.rule=Host(`harveyapi.localhost`)'
- 'traefik.http.services.harveyapi.loadbalancer.server.port=5000'
volumes:
- /Users/jhammond/harvey:/lala
11 changes: 5 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
services:
harvey-nginx:
harvey:
build: .
restart: always
networks:
- traefik
labels:
- traefik.enable=true
- 'traefik.docker.network=traefik'
extra_hosts:
- 'host.docker.internal:host-gateway'
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /Users/jhammond/harvey:/lala
- ./:/app

networks:
traefik:
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ install:

# Test the project end-to-end
integration:
venv/bin/python {{TEST_DIR}}/integration/test_deployment.py
python {{TEST_DIR}}/integration/test_deployment.py

# Sorts imports throughout the project
isort:
Expand Down
13 changes: 0 additions & 13 deletions nginx.conf

This file was deleted.

2 changes: 1 addition & 1 deletion test/integration/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
data = json.load(file)

request = requests.post(
'http://127.0.0.1:5000/deploy',
'http://harvey.localhost/deploy',
json=data,
headers={
'Content-Type': 'application/json',
Expand Down
14 changes: 7 additions & 7 deletions uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ stats = /tmp/harvey.stats
memory-report = true

; app setup
uwsgi-socket = 127.0.0.1:5000
http = 0.0.0.0:5000
module = wsgi:APP

; tuning
workers = 2
max-worker-lifetime = 300
socket-timeout = 30
# workers = 2
# max-worker-lifetime = 300
harakiri = 30
buffer-size = 24576

# crons
cron = 0 0 -1 -1 -1 venv/bin/python scripts/remove_old_logs.py
# cron = 0 0 -1 -1 -1 venv/bin/python scripts/remove_old_logs.py

; logging
daemonize = $(HOME)/harvey/logs/harvey.log
# daemonize = $(HOME)/harvey/logs/harvey.log
; TODO: unify timestamps since internal Python is logging with `asctime`
log-format = %(ltime) [pid: %(pid)|app: -|req: -/-] %(addr) (%(user)) {%(vars) vars in %(pktsize) bytes} %(method) %(uri) => generated %(rsize) bytes in %(msecs) msecs (%(proto) %(status)) %(headers) headers in %(hsize) bytes (%(switches) switches on core %(core))
log-maxsize = 2000000 ; 2mb
; log-maxsize = 2000000 ; 2mb

0 comments on commit 8fbc080

Please sign in to comment.