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

dev2stg #48

Merged
merged 7 commits into from
Oct 7, 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
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SECRET_KEY=secret-key

DATABASE_URL=psql://postgres:postgres@db:5432/postgres
CACHE_DEFAULT=redis://redis:6379/0
STATIC_URL=/static/
STATIC_ROOT=/var/static/

POSTGRES_DB=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=db
13 changes: 12 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
[flake8]
max-complexity = 20
max-line-length = 120
exclude = ~*
exclude =
~*
.venv,
venv,
.git,
__pycache__,
build,
dist,
migrations,
snapshots,
__pypackages__,

ignore = E401,W391,E128,E261,E731,Q000,W504,W606,W503,E203
;putty-ignore =
; tests/test_choice_as_instance.py : E501
Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/docker.yml

This file was deleted.

36 changes: 20 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ on:
pull_request:

jobs:
# lint:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# - uses: actions/setup-python@v2
#
# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip pre-commit
# - name:
# run: pre-commit run --all-files

test:
runs-on: ubuntu-latest
services:
Expand All @@ -36,7 +24,7 @@ jobs:
fail-fast: false
matrix:
django-version: [ "4.2", ]
python-version: [ "3.11", ]
python-version: [ "3.12", ]
experimental: [ false ]
# include:
# - django-version: "5.0"
Expand Down Expand Up @@ -68,8 +56,24 @@ jobs:
pdm sync

- name: Run tests
run: pdm run pytest tests/ --create-db
run: pdm run pytest tests/ --create-db --cov --cov-report xml --junit-xml junit.xml

- name: Upload pytest test results
uses: actions/upload-artifact@v4
with:
name: pytest-results
path: junit.xml
if: ${{ always() }}

- uses: codecov/codecov-action@v4
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
if: matrix.python-version == 3.12
continue-on-error: true
with:
verbose: false # optional (default = false)
env_vars: OS,PYTHON
fail_ci_if_error: true
flags: unittests
files: ./coverage.xml
verbose: false
token: ${{ secrets.CODECOV_TOKEN }}
name: codecov-${{env.GITHUB_REF_NAME}}
2 changes: 1 addition & 1 deletion .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3.12'

- name: Install pdm
run: python -m pip install --upgrade pdm
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ docker/conf/nginx.conf
docker/conf/redis.conf
src/aurora/staticfiles

.pdm-python
.pdm-python
29 changes: 4 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
# Aurora

Aurora is an open source project to collect and register data.
It is focused mainly on performance and security.
[![Test](https://github.com/unicef/hope-aurora/actions/workflows/test.yml/badge.svg)](https://github.com/unicef/hope-aurora/actions/workflows/test.yml)


### Run the code
Aurora is the official HOPE online registration tool, it is released as open source project, feel free to contribute and use it.

- Option 1: with local machine services (redis, postgres) with `direnv`
It has be development taking performance and security as main key points

First configure your `.envrc` and run

```shell
python manage.py runserver
````

- Option 2: using docker-composer

For the first time you need to run in root project directory

```shell
./manage env --comment --defaults > .env
docker-compose build
docker-compose up
```

each next time

```shell
docker-compose up
```
Please read more about Aurora and HOPE in the [official documentation](https://unicef.github.io/hope-documentation/)
60 changes: 60 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
volumes:
db:

services:
app:
stdin_open: true
tty: true
environment:
- [email protected]
- ADMIN_PASSWORD=password
- ALLOWED_HOSTS=app,localhost,127.0.0.1
- CACHE_URL=redis://redis:6379/1?client_class=django_redis.client.DefaultClient
- CACHE_DEFAULT=redis://redis:6379/2
- CELERY_BROKER_URL=redis://redis:6379/9
- CSRF_COOKIE_SECURE=False
- CSRF_TRUSTED_ORIGINS=http://localhost:8000,http://localhost
- DATABASE_URL=postgres://aurora:password@db:5432/aurora
- DEBUG=true
- DJANGO_ADMIN_URL=admin/
- FERNET_KEY=3bfbbad7d5e149e9b313fd47d33db5e6
- MEDIA_ROOT=/var/storage/media/
- SECRET_KEY=super_secret_key_just_for_development_that_needs_to_be_more_than_fifty_characters
- SECURE_HSTS_PRELOAD=0
- SECURE_SSL_REDIRECT=False
- SESSION_COOKIE_DOMAIN=localhost:8000
- SESSION_COOKIE_SECURE=False
- SOCIAL_AUTH_REDIRECT_IS_HTTPS=False
- STORAGE_STATIC=django.core.files.storage.FileSystemStorage
- STORAGE_MEDIA=django.core.files.storage.FileSystemStorage
- STORAGE_DEFAULT=django.core.files.storage.FileSystemStorage
- STATIC_ROOT=/var/storage/static/
- STATIC_URL=/static/
- USE_HTTPS=false
- USE_X_FORWARDED_HOST=false
build:
context: ./
dockerfile: ./docker/Dockerfile
target: dev
ports:
- "8000:80" # expose nginx here
# - "8000:8000"
depends_on:
- db
- redis

db:
image: postgres:16
environment:
- PGUSER=aurora
- POSTGRES_USER=aurora
- POSTGRES_PASSWORD=password
- POSTGRES_DB=aurora
volumes:
- db:/var/lib/postgresql/data

redis:
image: redis:7
restart: unless-stopped
# expose:
# - "6379"
32 changes: 0 additions & 32 deletions docker-compose.yml

This file was deleted.

19 changes: 15 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim-bullseye
FROM python:3.12-slim-bookworm AS base
ARG BUILD_DATE
ARG VERSION

Expand All @@ -24,13 +24,16 @@ RUN apt-get update \
&& locale-gen --no-purge uk_UA.UTF-8 \
&& apt-get clean

ENV PATH="${PATH}:/root/.local/bin:/code/__pypackages__/3.11/bin" \
ENV PATH="${PATH}:/root/.local/bin:/code/__pypackages__/3.12/bin" \
ADMINS="" \
BUILD_DATE=${BUILD_DATE} \
CACHE_DEFAULT="redis://127.0.0.1/0" \
CONSTANCE_DATABASE_CACHE_BACKEND="" \
CSRF_TRUSTED_ORIGINS="" \
CSRF_COOKIE_NAME="aurora" \
CSRF_COOKIE_SECURE="true" \
DATABASE_URL="" \
DEFAULT_ORGANIZATION="UNICEF"\
DEBUG="false"\
DJANGO_SETTINGS_MODULE="aurora.config.settings" \
IPSTACK_KEY="" \
LOG_LEVEL="ERROR" \
Expand All @@ -40,7 +43,7 @@ ENV PATH="${PATH}:/root/.local/bin:/code/__pypackages__/3.11/bin" \
REDIS_LOGLEVEL="warning" \
REDIS_MAXMEMORY="100Mb" \
REDIS_MAXMEMORY_POLICY="volatile-ttl" \
PYTHONPATH="/code/src/:/code/__pypackages__/3.11/lib" \
PYTHONPATH="/code/src/:/code/__pypackages__/3.12/lib" \
PYTHONUNBUFFERED=1 \
SECRET_KEY="secret-key-just-for-build" \
SENTRY_DSN="" \
Expand All @@ -63,4 +66,12 @@ ADD ./docker/conf/* /conf/
ADD ./docker/bin/* /usr/local/bin/

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["run"]

EXPOSE 80
EXPOSE 8000

FROM base AS dev
RUN pdm sync --dev

FROM base AS dist
2 changes: 1 addition & 1 deletion docker/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim-bullseye
FROM python:3.12-slim-bookworm
ARG BUILD_DATE
ARG VERSION

Expand Down
7 changes: 3 additions & 4 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ WORKER?='??'
CONTAINER_NAME?=flex-form-cnt
LAZO?=$(shell which lazo)

DOCKER_REGISTRY=ghcr.io
DOCKER_IMAGE_NAME=saxix/aurora
DOCKER_REGISTRY?=ghcr.io
DOCKER_IMAGE_NAME?=saxix/aurora
DOCKER_IMAGE=${DOCKER_IMAGE_NAME}:${VERSION}
DOCKER_TARGET=${DOCKER_REGISTRY}/${DOCKER_IMAGE}
DOCKERFILE?=Dockerfile
Expand Down Expand Up @@ -91,9 +91,8 @@ dev:
-e ALLOWED_HOSTS="*" \
-e DATABASE_URL="${DATABASE_URL}" \
-e DEBUG="0" \
-e DJANGO_SETTINGS_MODULE="aurora.config.settings" \
-e SENTRY_DSN="${SENTRY_DSN}" \
-e REDIS_CONNSTR="192.168.66.66" \
-e REDIS_CONNSTR="127.0.0.1" \
-e VERSION="${VERSION}" \
-v ${PWD}/conf/:/conf/ \
-v ${PWD}/bin/entrypoint.sh:/usr/local/bin/entrypoint.sh \
Expand Down
38 changes: 21 additions & 17 deletions docker/bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,38 @@ export REDIS_MAXMEMORY="${REDIS_MAXMEMORY:-100Mb}"
export REDIS_MAXMEMORY_POLICY="${REDIS_MAXMEMORY_POLICY:-volatile-ttl}"
export AURORA_VERSION=${VERSION}
export AURORA_BUILD=${BUILD_DATE}
export PYTHONPATH="/code/src/:/code/__pypackages__/3.11/lib"
#export PYTHONPATH="/code/src/:/code/__pypackages__/3.12/lib"

export DOLLAR='$'

mkdir -p /var/run /var/nginx ${NGINX_CACHE_DIR} ${MEDIA_ROOT} ${STATIC_ROOT}
echo "created support dirs /var/run ${MEDIA_ROOT} ${STATIC_ROOT}"

if [ $# -eq 0 ]; then
envsubst < /conf/nginx.conf.tpl > /conf/nginx.conf && nginx -tc /conf/nginx.conf
envsubst < /conf/redis.conf.tpl > /conf/redis.conf
case "$1" in
"run")
envsubst < /conf/nginx.conf.tpl > /conf/nginx.conf && nginx -tc /conf/nginx.conf
envsubst < /conf/redis.conf.tpl > /conf/redis.conf

django-admin upgrade --no-input
django-admin upgrade --no-input

nginx -c /conf/nginx.conf
redis-server /conf/redis.conf
exec uwsgi --ini /conf/uwsgi.ini
# exec gunicorn aurora.config.wsgi -c /conf/gunicorn_config.py
else
case "$1" in
"dev")
nginx -c /conf/nginx.conf
redis-server /conf/redis.conf
exec uwsgi --ini /conf/uwsgi.ini

;;
"dev")
until pg_isready -h db -p 5432;
do echo "waiting for database"; sleep 2; done;
django-admin collectstatic --no-input
django-admin migrate
django-admin runserver 0.0.0.0:8000
;;
*)
exec "$@"
;;
esac
fi
"setup")
until pg_isready -h db -p 5432;
do echo "waiting for database"; sleep 2; done;
django-admin upgrade --no-input
;;
*)
exec "$@"
;;
esac
2 changes: 2 additions & 0 deletions docker/conf/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nginx.conf
redis.conf
Loading
Loading