Commit b5db19a2 authored by Volkov Gherman's avatar Volkov Gherman

Merge branch 'feature/add_docker' into 'develop'

Create docker configs for docusign_app, postgres & nginx

See merge request !3
parents 15fe8568 25300385
POSTGRES_USER='databse user'
POSTGRES_PASSWORD='database password'
POSTGRES_DB='database name'
\ No newline at end of file
...@@ -113,6 +113,7 @@ celerybeat.pid ...@@ -113,6 +113,7 @@ celerybeat.pid
# Environments # Environments
.env .env
.env.db
.venv .venv
env/ env/
venv/ venv/
...@@ -152,4 +153,4 @@ cython_debug/ ...@@ -152,4 +153,4 @@ cython_debug/
.idea/ .idea/
.DS_Store .DS_Store
private.key private.key
.bash_history
FROM python:3.10
WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY requirements /app/requirements
RUN pip install --upgrade pip
RUN pip install -r requirements/dev.txt
COPY ./entrypoint.sh /
ENTRYPOINT ["sh", "/entrypoint.sh"]
COPY . .
...@@ -40,13 +40,18 @@ ...@@ -40,13 +40,18 @@
<script> <script>
const sendForm = (e) => { const sendForm = (e) => {
e.preventDefault(); e.preventDefault();
fetch('http://localhost:8000/api/v1/', { fetch(`${window.location.protocol + '//' + window.location.host}/api/v1/`, {
method: 'POST', method: 'POST',
body: new FormData(form) body: new FormData(form)
}).then(form.reset()) }).then(form.reset())
} }
const form = document.querySelector('#form'); const form = document.querySelector('#form');
try {
form.addEventListener('submit', sendForm); form.addEventListener('submit', sendForm);
} catch (e) {
throw e
}
</script> </script>
</html> </html>
\ No newline at end of file
...@@ -30,7 +30,7 @@ SECRET_KEY = os.getenv('SECRET_KEY') ...@@ -30,7 +30,7 @@ SECRET_KEY = os.getenv('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = ['*']
# Application definition # Application definition
...@@ -42,13 +42,14 @@ INSTALLED_APPS = [ ...@@ -42,13 +42,14 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'rest_framework', 'rest_framework',
'corsheaders',
'api', 'api',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
...@@ -115,10 +116,15 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -115,10 +116,15 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = [ CORS_ALLOWED_ORIGINS = [
'http://loaclhost:8000/api/v1/', 'http://localhost:8000',
'http://127.0.0.1:8000/api/v1/' 'http://0.0.0.0:8000',
]
CSRF_TRUSTED_ORIGINS = [
'http://localhost:8000',
'http://0.0.0.0:8000',
] ]
# Internationalization # Internationalization
...@@ -136,6 +142,8 @@ USE_TZ = True ...@@ -136,6 +142,8 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.2/howto/static-files/ # https://docs.djangoproject.com/en/4.2/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [BASE_DIR / "api/docusign_app/static"]
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
MEDIA_ROOT = os.path.join(BASE_DIR, 'api/docusign_app/static') MEDIA_ROOT = os.path.join(BASE_DIR, 'api/docusign_app/static')
MEDIA_URL = '/api/docusign_app/static/' MEDIA_URL = '/api/docusign_app/static/'
......
version: '3'
services:
docusign:
build:
context: .
dockerfile: ./Dockerfile
container_name: docusign
image: docusign_image
command: gunicorn core.wsgi:application --bind 0.0.0.0:8000 --workers 3
restart: always
volumes:
- static_volume:/app/static
expose:
- 8000
env_file:
- ./.env
depends_on:
- postgres
postgres:
container_name: postgres
image: postgres:14
restart: always
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env.db
environment:
POSTGRES_USER: ${DATABASE_USER}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
nginx:
build: ./nginx
container_name: nginx
restart: always
volumes:
- static_volume:/app/static
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
ports:
- "80:80"
depends_on:
- docusign
volumes:
static_volume:
postgres_data:
#!/bin/sh
if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."
while ! nc -z $DATABASE_HOST $DATABASE_PORT; do
sleep 0.1
done
echo "PostgreSQL started"
fi
python manage.py migrate --noinput
python manage.py collectstatic --no-input --clear
exec "$@"
\ No newline at end of file
FROM nginx:latest
RUN rm /etc/nginx/conf.d/default.conf
COPY default.conf /etc/nginx/conf.d/
\ No newline at end of file
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream wsgiserver {
server docusign:8000;
}
server {
listen 80;
server_name localhost;
location / {
try_files $uri @proxy_api;
}
location @proxy_api {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://wsgiserver;
}
location /static/ {
root /app/;
expires 1M;
access_log off;
add_header Cache-Control "public";
}
}
\ No newline at end of file
...@@ -3,3 +3,5 @@ djangorestframework==3.14.* ...@@ -3,3 +3,5 @@ djangorestframework==3.14.*
psycopg2-binary==2.9.* psycopg2-binary==2.9.*
python-dotenv==1.0.* python-dotenv==1.0.*
docusign-esign==3.22.* docusign-esign==3.22.*
django-cors-headers==4.0.*
gunicorn==20.1.*
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment