Skip to content

Commit

Permalink
fixed docker
Browse files Browse the repository at this point in the history
  • Loading branch information
u-shev committed Jan 4, 2024
1 parent bf5ea9a commit 5c1c9de
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 56 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ __pycache__
coverage.xml
*.sqlite3
db.sqlite3

/myenv
users/__pycache__/
posts/__pycache__/
10 changes: 3 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
FROM python:3.9-alpine3.18

COPY requirements.txt /temp/requirements.txt
COPY space-app /space-app
WORKDIR /space-app
COPY . /space_app/
WORKDIR /space_app/
EXPOSE 8000

RUN apk add postgresql-client build-base postgresql-dev

RUN pip install -r /temp/requirements.txt

RUN adduser --disabled-password gagarin

USER gagarin
RUN pip install --upgrade pip -r /temp/requirements.txt
19 changes: 12 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ services:
ports:
- "8000:8000"
volumes:
- ./space-app:/space-app:ro
- ./space_app:/space_app
env_file:
- ./space_app/.env

command: >
sh -c "python manage.py makemigrations &&
python manage.py migrate &&
gunicorn -w 5 -b 90.156.225.192:8000 space_app.wsgi"
gunicorn -w 5 -b 0.0.0.0:8000 space_app.wsgi"
depends_on:
- database
Expand All @@ -31,21 +31,26 @@ services:
context: .
command: celery -A space_app worker -l info
volumes:
- ./project/:/usr/src/app/:ro
- ./space_app:/space_app
env_file:
- ./space_app/.env
links:
- redis
depends_on:
- redis
- database


celery-beat:
build:
context: .
command: celery -A space_app beat -l info
volumes:
- ./space-app/:/usr/src/app/:ro
env_file:
- ./space_app/.env
- ./space_app:/space_app
links:
- redis
depends_on:
- redis
- database
- database
env_file:
- ./space_app/.env
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ install:
poetry install

migrate:
poetry run python3 manage.py makemigrations
poetry run python3 manage.py migrate
poetry run python3 space_app/manage.py makemigrations
poetry run python3 space_app/manage.py migrate

lint:
poetry run flake8 space_app

start:
poetry run uvicorn space_app.asgi:application
poetry run gunicorn -w 5 -b 0.0.0.0:8000 space_app.wsgi

worker:
celery -A space_app worker -l info
Expand Down
26 changes: 13 additions & 13 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
python==">=3.8.1,<4.0"
django=="^4.2.7"
python-dotenv=="^1.0.0"
django-bootstrap5=="^23.3"
aiohttp=="^3.9.1"
requests=="^2.31.0"
celery=="^5.3.6"
redis=="^5.0.1"
flake8=="^6.1.0"
coverage=="^7.3.2"
django-redis=="^5.4.0"
django-debug-toolbar=="^4.2.0"
gunicorn=="^21.2.0"
django==4.2.7
python-dotenv==1.0.0
django-bootstrap5==23.3
aiohttp==3.9.1
requests==2.31.0
flake8==6.1.0
coverage==7.3.2
django-redis==5.4.0
django-debug-toolbar==4.2.0
gunicorn==21.2.0
psycopg2-binary==2.9.9
celery[redis]==5.2.7
celery==5.2.7
9 changes: 0 additions & 9 deletions space_app/.env.example

This file was deleted.

Binary file added space_app/celerybeat-schedule
Binary file not shown.
File renamed without changes.
2 changes: 1 addition & 1 deletion space_app/posts/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class PostsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'space_app.posts'
name = 'posts'
2 changes: 1 addition & 1 deletion space_app/posts/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from space_app.users.models import User
from users.models import User


'''Standart post model, connected to author, file can be added'''
Expand Down
2 changes: 1 addition & 1 deletion space_app/posts/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.core.mail import send_mail
from django.contrib.auth import get_user_model
from space_app.celery import app
from space_app.posts.models import Post
from posts.models import Post


REPORT_TEMPLATE = """
Expand Down
2 changes: 1 addition & 1 deletion space_app/posts/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.urls import path
from space_app.posts import views
from posts import views
from .views import PostCreateView, PostUpdateView, PostDeleteView


Expand Down
1 change: 0 additions & 1 deletion space_app/__init__.py → space_app/space_app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from .celery import app as celery_app

__all__ = ('celery_app',)
6 changes: 6 additions & 0 deletions space_app/space_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class PostsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'space_app'
File renamed without changes.
5 changes: 4 additions & 1 deletion space_app/celery.py → space_app/space_app/celery.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import os
from celery import Celery
from celery.schedules import crontab
from django.conf import settings


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'space_app.settings')
app = Celery('space_app')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.conf.broker_url = settings.CELERY_BROKER_URL
app.autodiscover_tasks()


'''Sending letters every Monday at 8:30'''
app.conf.beat_schedule = {
'send-report-every-single-minute': {
'task': 'space_app.posts.tasks.send_view_count_report',
'task': 'posts.tasks.send_view_count_report',
'schedule': crontab(hour=8, minute=30, day_of_week=1)
},
}
2 changes: 1 addition & 1 deletion space_app/helpers.py → space_app/space_app/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from dotenv import load_dotenv
from space_app.posts.models import Post
from posts.models import Post
import aiohttp


Expand Down
File renamed without changes.
13 changes: 9 additions & 4 deletions space_app/settings.py → space_app/space_app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',

'space_app',
'space_app.users',
'space_app.posts',
'users',
'posts',

'django_bootstrap5',
'debug_toolbar',
]
Expand Down Expand Up @@ -160,8 +162,11 @@


BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600}
CELERY_BROKER_URL = "redis://90.156.225.192:6379/0"
CELERY_RESULT_BACKEND = "redis://90.156.225.192:6379/0"
CELERY_BROKER_URL = 'redis://redis:6379/0'
CELERY_RESULT_BACKEND = "redis://redis:6379/0"
# BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 3600}
# CELERY_BROKER_URL = "redis://127.0.0.1:6379/0"
# CELERY_RESULT_BACKEND = "redis://127.0.0.1:6379/0"


EMAIL_HOST ='smtp.mail.ru'
Expand Down
4 changes: 2 additions & 2 deletions space_app/urls.py → space_app/space_app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.index_view, name='home'),
path('users/', include('space_app.users.urls')),
path('users/', include('users.urls')),
path('login/', views.UserLoginView.as_view(), name='login'),
path('logout/', views.UserLogoutView.as_view(), name='logout'),
path('posts/', include('space_app.posts.urls')),
path('posts/', include('posts.urls')),
path("__debug__/", include("debug_toolbar.urls")),
]

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions space_app/users/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin
from space_app.users.models import User
from space_app.posts.models import Post
from users.models import User
from posts.models import Post


admin.site.register(User)
Expand Down
2 changes: 1 addition & 1 deletion space_app/users/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class UsersConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'space_app.users'
name = 'users'

0 comments on commit 5c1c9de

Please sign in to comment.