Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datanar 2.0.0 - Docker edition #46

Merged
merged 14 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/*.sqlite3
**/*.mo
**/static
**/media
40 changes: 27 additions & 13 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
DJANGO_DEBUG=False
DJANGO_SECRET_KEY=this_is_test_key_-_some_very_dummy_secret_key
DJANGO_ALLOWED_HOSTS=*
COMPOSE_PROFILES=dev

DJANGO_MAIL_HOST=smtp.mail.ru
DJANGO_MAIL_PORT=2525
DJANGO_MAIL_USER=webmaster@localhost
DJANGO_MAIL_PASSWORD=this_very_secret_password_for_smtp_mail
DATANAR_DJANGO_DEBUG=False
DATANAR_SECRET_KEY=this_is_test_key_-_some_very_dummy_secret_key
DJANGO_LOG_FILE_PATH=./logs/django.log
DATANAR_ALLOWED_HOSTS=*

DJANGO_DEFAULT_USER_IS_ACTIVE=True
DATANAR_MAIL_HOST=smtp.mail.ru
DATANAR_MAIL_PORT=2525
DATANAR_MAIL_USER=webmaster@localhost
DATANAR_MAIL_PASSWORD=this_very_secret_password_for_smtp_mail

DJANGO_USE_SIMPLE_DATABASE=True
DJANGO_DATABASE_NAME=database
DJANGO_DATABASE_USER=webmaster
DJANGO_DATABASE_PASSWORD=this_very_secret_password_for_database
DATANAR_DEFAULT_USER_IS_ACTIVE=False
DATANAR_SUPERUSER_NAME=admin
DATANAR_SUPERUSER_EMAIL=webmaster@localhost
DATANAR_SUPERUSER_PASSWORD=this_very_secret_password_for_superuser

DJANGO_LOG_FILE_PATH=/path/to/log/file
DATANAR_USE_FILE_DATABASE=False
DATANAR_DATABASE_NAME=database
DATANAR_DATABASE_USER=webmaster
DATANAR_DATABASE_PASSWORD=this_very_secret_password_for_database
DATANAR_DATABASE_HOST=postgres
DATANAR_DATABASE_PORT=5432

DATANAR_REDIS_HOST=redis
DATANAR_REDIS_PORT=6379
DATANAR_REDIS_DB=0

DATANAR_CERTBOT_DEBUG=1
DATANAR_CERTBOT_STAGING=1
DATANAR_CERTBOT_EMAIL=webmaster@localhost
45 changes: 4 additions & 41 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Python application
name: Datanar

on:
push:
Expand Down Expand Up @@ -42,35 +42,6 @@ jobs:
cd ./datanar
python manage.py test

test-deploy:
if: github.ref == 'refs/heads/dev'
needs: [black-test, flake8-test, django-test]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
sudo supervisorctl stop test_gunicorn test_celery
cd ~/test_datanar
git reset --hard origin/dev
git pull origin dev
source venv/bin/activate
pip install -r requirements/dev.txt
cd ~/test_datanar/datanar
python manage.py migrate
python manage.py compilemessages
python manage.py collectstatic --no-input
deactivate
cd ~
sudo supervisorctl start test_gunicorn test_celery

prod-deploy:
if: github.ref == 'refs/heads/main'
needs: [black-test, flake8-test, django-test]
Expand All @@ -86,16 +57,8 @@ jobs:
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
sudo supervisorctl stop gunicorn celery
cd ~/datanar
git reset --hard origin/main
git reset --hard origin/main
git pull origin main
source venv/bin/activate
pip install -r requirements/dev.txt
cd ~/datanar/datanar
python manage.py migrate
python manage.py compilemessages
python manage.py collectstatic --no-input
deactivate
cd ~
sudo supervisorctl start gunicorn celery
docker compose down -v
docker compose up --build -d
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ __pycache__/
*.pyc
*$py.class

for_docker/nginx_certificates
for_docker/postgres_data
for_docker/logs
static/
media/
logs/

*.so
db.sqlite3
*.sqlite3
.Python
build/
develop-eggs/
Expand All @@ -13,7 +20,6 @@ eggs/
.eggs/
lib/
lib64/
media/
parts/
sdist/
var/
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.12.4-slim

RUN apt update
RUN apt install gettext -y

COPY ./requirements /requirements
RUN pip install -r requirements/dev.txt
RUN rm -rf requirements

COPY ./datanar /datanar/
WORKDIR /datanar

CMD python manage.py migrate \
&& python manage.py init_superuser \
&& python manage.py compilemessages \
&& python manage.py collectstatic --no-input \
&& gunicorn datanar.wsgi:application \
--workers $(nproc) \
--bind 0.0.0.0:8000 \
--access-logfile /datanar/logs/gunicorn_access.log \
--error-logfile /datanar/logs/gunicorn_error.log
Loading
Loading