Skip to content

Commit

Permalink
Merge pull request #15 from Studio-Yandex-Practicum/docker/docker_com…
Browse files Browse the repository at this point in the history
…pose

Docker/docker compose
  • Loading branch information
Raidzin authored Nov 4, 2023
2 parents 0173423 + cce3bbf commit dea7cc6
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,6 @@ cython_debug/
# PyCharm
.idea/

# Static
static/

3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ RUN python -m pip install --no-cache-dir poetry==1.6.1 \

FROM python:3.11-slim-bullseye

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
COPY --from=builder /app /app
COPY adaptive_hockey_federation/ ./
ENTRYPOINT ["/entrypoint.sh"]

CMD ["/app/.venv/bin/gunicorn", "adaptive_hockey_federation.wsgi:application", "--bind", "0:8000" ]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ docker run --name adaptive-hockey-federation -it -p 8000:8000 adaptive-hockey-fe
cd adaptive_hockey_federation
python manage.py runserver
```

## Собрать приложения в контейнеры при помощи Docker-compose:

```shell
docker-compose up -d --build
```

Django-проект и Nginx запустятся в контейнерах, при помощи инструкций в entrypoint.sh через 10 секунд добавится статика
47 changes: 5 additions & 42 deletions adaptive_hockey_federation/adaptive_hockey_federation/settings.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
"""
Django settings for adaptive_hockey_federation project.
Generated by 'django-admin startproject' using Django 4.2.6.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.2/ref/settings/
"""
import os

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-))v)^p&_y!_-dsc7p)v%b@yi+#)k^34mp^ai8jc^9v)jpu2xn1'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS: list = []

ALLOWED_HOSTS: list = ['*']

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
Expand Down Expand Up @@ -73,21 +52,13 @@

WSGI_APPLICATION = 'adaptive_hockey_federation.wsgi.application'


# Database
# https://docs.djangoproject.com/en/4.2/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
Expand All @@ -103,10 +74,6 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/

LANGUAGE_CODE = 'ru'

TIME_ZONE = 'UTC'
Expand All @@ -115,15 +82,11 @@

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

# Default primary key field type
# https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
26 changes: 26 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3.8'

services:
site:
build: .
restart: always
volumes:
- static_value:/app/static/
- media_value:/app/media/
env_file:
- ./.env

nginx:
image: nginx:1.21.3-alpine
ports:
- "80:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- static_value:/var/html/static/
- media_value:/var/html/media/
depends_on:
- site

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

sleep 10
app/.venv/bin/python manage.py collectstatic --noinput
mv /static/* /app/static/

exec "$@"
17 changes: 17 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server {
listen 80;

server_name 127.0.0.1;

location /static/ {
root /var/html/;
}

location /media/ {
root /var/html/;
}

location / {
proxy_pass http://site:8000;
}
}
1 change: 1 addition & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ exclude =
per-file-ignores =
*/settings.py:E501
max-complexity = 10

0 comments on commit dea7cc6

Please sign in to comment.