Skip to content

Commit

Permalink
Merge pull request #5 from orertrr/docker-dev
Browse files Browse the repository at this point in the history
[Feature] Add `docker compose-dev.yml` for development
  • Loading branch information
toomore authored Oct 14, 2023
2 parents d3c77d6 + 4d77f5c commit 8962a7d
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PYTHONPATH=./
VERSION=23.09.01
2 changes: 1 addition & 1 deletion Dockerfile-base
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.18.3
FROM python:3.11.4-alpine3.18

WORKDIR /app
ADD pyproject.toml poetry.lock ./
Expand Down
16 changes: 16 additions & 0 deletions Dockerfile-base-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.11.4-alpine3.18

WORKDIR /app
ADD pyproject.toml poetry.lock ./
ENV PATH="/root/.local/bin:${PATH}"
RUN \
apk update && apk upgrade && \
apk add --no-cache python3 ca-certificates libmemcached-dev && \
apk add --no-cache --virtual .build-deps curl cmake zlib-dev \
g++ make gcc musl-dev python3-dev libffi-dev openssl-dev && \
curl -sSL https://install.python-poetry.org | python3 - && \
poetry install --with dev && \
apk del .build-deps && \
cd ~/.cache/ && \
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete && \
rm -rf /var/cache/apk/* /var/lib/apk/* /etc/apk/cache/*
142 changes: 142 additions & 0 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
services:
nginx:
build:
context: ./nginx
ports:
- 80:80
- 443:443
volumes:
- $PWD/nginx/sites:/etc/nginx/sites-available
# Uncomment the next line to add your ssl certificate and key to Nginx
# - /path/to/your/certificate_and_key:/etc/nginx/ssl
depends_on:
- web
networks:
- backend

web:
image: "secretaryweb-base:${VERSION}"
links:
- secretary_mongo:mongo
- queue_sender:rabbitmq
volumes:
- $PWD/celery_task:/app/celery_task:delegated
- $PWD/models:/app/models:delegated
- $PWD/module:/app/module:delegated
- $PWD/templates:/app/templates:delegated
- $PWD/view:/app/view:delegated
- $PWD/log:/app/log:cached
- $PWD/client_secret.json:/app/client_secret.json:delegated
- $PWD/setting.py:/app/setting.py:delegated
- $PWD/main.py:/app/main.py:delegated
depends_on:
- queue_sender
- secretary_mongo
ports:
- 5000:5000
- 5678:5678
networks:
- backend
entrypoint: [
"poetry",
"run",
"flask",
"--app",
"main:app",
"run",
"--host",
"0.0.0.0",
"--debug"
]

celery_worker:
image: "secretaryweb-base:${VERSION}"
links:
- secretary_mongo:mongo
- queue_sender:rabbitmq
volumes:
- $PWD/celery_task:/app/celery_task:delegated
- $PWD/models:/app/models:delegated
- $PWD/module:/app/module:delegated
- $PWD/log_docker_celery:/app/log_docker_celery:cached
- $PWD/templates:/app/templates:delegated
- $PWD/setting.py:/app/setting.py:delegated
- $PWD/main.py:/app/main.py:delegated
depends_on:
- queue_sender
- secretary_mongo
environment:
- C_FORCE_ROOT=true
networks:
- backend
entrypoint: [
"poetry",
"run",
"celery",
"-A",
"celery_task",
"worker",
"-B",
"-l",
"info",
"-O",
"fair",
"-c",
"4",
"--logfile",
"./log_docker_celery/log.log"
]

worker:
image: "secretaryweb-base:${VERSION}"
links:
- secretary_mongo:mongo
- queue_sender:rabbitmq
volumes:
- $PWD/celery_task:/app/celery_task:delegated
- $PWD/models:/app/models:delegated
- $PWD/module:/app/module:delegated
- $PWD/templates:/app/templates:delegated
- $PWD/view:/app/view:delegated
- $PWD/log:/app/log:cached
- $PWD/log_docker_celery:/app/log_docker_celery:cached
- $PWD/setting.py:/app/setting.py:delegated
- $PWD/main.py:/app/main.py:delegated
depends_on:
- queue_sender
- secretary_mongo
networks:
- backend
environment:
- PYTHONPATH=/app
command: sh

secretary_mongo:
image: "mongo:6.0.6-jammy"
ports:
- 27017:27017
volumes:
- mongodata:/data
- mongodb:/data/db
- mongoconfig:/data/configdb
networks:
- backend

queue_sender:
image: "rabbitmq:3.11.18-management-alpine"
depends_on:
- secretary_mongo
networks:
- backend
volumes:
- rabbitdata:/var/lib/rabbitmq

networks:
backend:
driver: bridge

volumes:
mongodata: {}
mongodb: {}
mongoconfig: {}
rabbitdata: {}
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
app.register_blueprint(VIEW_SUBSCRIBER)
app.register_blueprint(VIEW_TRELLO)

if app.debug:
app.config['TEMPLATES_AUTO_RELOAD'] = True


NO_NEED_LOGIN_PATH = (
'/',
Expand Down
23 changes: 23 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM nginx:1.25.2-alpine

COPY ./nginx.conf /etc/nginx/nginx.conf

RUN apk update && \
apk upgrade && \
apk --update add logrotate

COPY logrotate/nginx /etc/logrotate.d

RUN apk add --no-cache curl

RUN mkdir /subscribe_cache

RUN set -x ; \
addgroup -g 82 -S www-data ; \
adduser -u 82 -D -S -G www-data www-data && exit 0 ; exit 1

RUN rm /etc/nginx/conf.d/default.conf

CMD [ "nginx" ]

EXPOSE 80 443
25 changes: 25 additions & 0 deletions nginx/logrotate/nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/var/log/nginx/*.log {
daily
missingok
rotate 3
compress
delaycompress
nodateext
notifempty
create 644 www-data root
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}

/var/log/apps/*.log {
daily
missingok
rotate 3
compress
delaycompress
nodateext
notifempty
create 644 root root
}
31 changes: 31 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
user www-data;
worker_processes 4;
pid /run/nginx.pid;
daemon off;

events {
worker_connections 2048;
multi_accept on;
use epoll;
}

http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
client_max_body_size 20M;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /dev/stdout;
error_log /dev/stderr;
gzip on;
gzip_disable "msie6";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*.conf;
open_file_cache off;
charset UTF-8;
}
61 changes: 61 additions & 0 deletions nginx/sites/subscribe-dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
upstream subscribe_web {
server web:5000;
}

upstream subscribe_cdn {
server secretary.coscup.org:443;
}

proxy_cache_path /subscribe_cache levels=1:2 keys_zone=subscribe_cdn:10m max_size=64m inactive=5m use_temp_path=off;

server {
listen 80 default_server;

location / {
proxy_pass http://subscribe_web/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-SSL-SESSION-ID $ssl_session_id;
}

location ~* /(js|css|faw|favicon.ico)(.*) {
proxy_pass https://subscribe_cdn/$1$2;
proxy_set_header Host secretary.coscup.org;
proxy_ssl_session_reuse on;

proxy_cache subscribe_cdn;
proxy_cache_revalidate on;
proxy_cache_use_stale timeout;
proxy_cache_lock on;
}
}

# Uncomment the following lines to enable HTTPS
# server {
# listen 443 ssl default_server;

# ssl_certificate /etc/nginx/ssl/server.crt;
# ssl_certificate_key /etc/nginx/ssl/server.key;

# location / {
# proxy_pass http://subscribe_web/;
# proxy_set_header Host $http_host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# proxy_set_header X-SSL-SESSION-ID $ssl_session_id;
# }

# location ~* /(js|css|faw|favicon.ico)(.*) {
# proxy_pass https://subscribe_cdn/$1$2;
# proxy_set_header Host secretary.coscup.org;
# proxy_ssl_session_reuse on;

# proxy_cache subscribe_cdn;
# proxy_cache_revalidate on;
# proxy_cache_use_stale timeout;
# proxy_cache_lock on;
# }
# }

0 comments on commit 8962a7d

Please sign in to comment.