Skip to content

Commit

Permalink
Initial docker files
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebrownlee committed Jul 19, 2024
1 parent 1649d9a commit ba9b4b9
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ setup
learning.service
logs/
.env
.env*
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3
RUN mkdir /api
RUN mkdir -p /var/www/learning.nss.team
WORKDIR /api
ADD . /api/
RUN pip install -r requirements.txt
ADD entrypoint.sh /entrypoint.sh
RUN chmod a+x /entrypoint.sh
COPY config/nginx/nginx.conf /etc/nginx/nginx.conf

ENTRYPOINT [ "/entrypoint.sh" ]
45 changes: 45 additions & 0 deletions config/nginx/conf.d/api.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
upstream learningapicontainer {
server apihost:8000;
}

server {
if ($host = learningapi.nss.team) {
return 301 https://$host$request_uri;
}

listen 80;
server_name learningapi.nss.team;
return 404;
}

server {
listen 443 ssl;
server_name learningapi.nss.team;

location /static/ {
autoindex off;
root /var/www/learning.nss.team;
}

location / {
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;

include proxy_params;
proxy_pass http://learningapicontainer;

# Preflighted requests
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, PUT, DELETE, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}

if ($request_method ~* "(GET|POST|PUT|DELETE)") {
add_header "Access-Control-Allow-Origin" *;
}
}
}
66 changes: 66 additions & 0 deletions config/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
worker_connections 768;
}


http {
##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 40m;
# server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

default_type application/octet-stream;

## Caching Settings
# proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=512m;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

}
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
certbot:
image: certbot/certbot
volumes:
- ./certs:/etc/letsencrypt
command: certonly --webroot --webroot-path=/var/www/learning.nss.team --email [email protected] --agree-tos --non-interactive --domains -d learning.nss.team
nginx:
image: nginx:latest
container_name: ng01
ports:
- "80:80"
- "443:443"
volumes:
- .:/api
- ./config/nginx/conf.d:/etc/nginx/conf.d
- ./certs:/etc/nginx/ssl
depends_on:
- certbot
apihost:
build: .
container_name: learningapi
command: gunicorn -w 3 -b 0.0.0.0:8000 LearningPlatform.wsgi
volumes:
- .:/api
env_file:
- .env
depends_on:
- nginx

7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic

exec gunicorn -w 3 -b 0.0.0.0:8000 LearningPlatform.wsgi

0 comments on commit ba9b4b9

Please sign in to comment.