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

Add docker compose file for local development #466

Merged
merged 6 commits into from
Apr 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
2 changes: 1 addition & 1 deletion .docker/run-celery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ done

sleep 5

while ! nc -vz $NEWARA_REDIS_ADDRESS 6379; do
while ! nc -vz $NEWARA_REDIS_ADDRESS $NEWARA_REDIS_PORT; do
>&2 echo "Redis is unavailable - sleeping"
sleep 1
done
Expand Down
2 changes: 1 addition & 1 deletion .docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ while ! nc -vz $NEWARA_DB_HOST $NEWARA_DB_PORT; do
sleep 1
done

while ! nc -vz $NEWARA_REDIS_ADDRESS 6379; do
while ! nc -vz $NEWARA_REDIS_ADDRESS $NEWARA_REDIS_PORT; do
>&2 echo "Redis is unavailable - sleeping"
sleep 1
done
Expand Down
38 changes: 30 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
DJANGO_ENV=development|production
SECRET_KEY=
# AWS S3
AWS_BUCKET_NAME=
AWS_BUCKET_NAME_STATIC=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

# SPARCS SSO
SSO_CLIENT_ID=
SSO_SECRET_KEY=
PORTAL_ID=
PORTAL_PASSWORD=
PORTAL_2FA_KEY=/[2-7A-Z]{16}/
DOCKERHUB_USERNAME=
DOCKERHUB_PASSWORD=
SENTRY_DSN=

# Django
DJANGO_ENV=development
SECRET_KEY=

# MySQL
NEWARA_DB_HOST=127.0.0.1
NEWARA_DB_PORT=3306
NEWARA_DB_USER=root
NEWARA_DB_PASSWORD=
NEWARA_DB_NAME=

# Redis
NEWARA_REDIS_ADDRESS=127.0.0.1
NEWARA_REDIS_PORT=6379

# Celery
C_FORCE_ROOT=true

# Elasticsearch
NEWARA_ELASTICSEARCH_HOST=127.0.0.1
NEWARA_ELASTICSEARCH_PORT=9200

# Logging
LOG_FILE_PATH=logs/http_access.log

# KAIST portal
PORTAL_JSESSIONID=
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ show_sql:

schema:
python3 manage.py spectacular --color --file schema.yml

local_env:
docker compose -f docker-compose.local.yml up -d

local_env_down:
docker compose -f docker-compose.local.yml down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pre-commit install --hook-type commit-msg
## How to Run

```bash
docker compose -f docker-compose.local.yml up -d
pipenv shell
make run
```
Expand Down
4 changes: 2 additions & 2 deletions ara/settings/cacheops.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from .redis import REDIS_HOST
from .redis import REDIS_HOST, REDIS_PORT

CACHEOPS_REDIS = {
"host": REDIS_HOST,
"port": 6379,
"port": REDIS_PORT,
"db": 1,
}

Expand Down
4 changes: 3 additions & 1 deletion ara/settings/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from os import environ as os_environ

REDIS_HOST = os_environ.get("NEWARA_REDIS_ADDRESS", "localhost")
REDIS_PORT = os_environ.get("NEWARA_REDIS_PORT", 6379)
REDIS_DATABASE = int(os_environ.get("NEWARA_REDIS_DATABASE", 0))
REDIS_URL = f"redis://{REDIS_HOST}:6379/{REDIS_DATABASE}"

REDIS_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DATABASE}"

CACHES_TIMEOUT = timedelta(days=14)

Expand Down
2 changes: 1 addition & 1 deletion ara/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

REDIS_DATABASE = int(environ.get("NEWARA_REDIS_DATABASE", 2))
REDIS_URL = f"redis://{REDIS_HOST}:6379/{REDIS_DATABASE}"
REDIS_URL = f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DATABASE}"

CELERY_TASK_ALWAYS_EAGER = True
ELASTICSEARCH_INDEX_NAME = "articles_test"
Expand Down
110 changes: 0 additions & 110 deletions docker-compose.example.yml

This file was deleted.

41 changes: 41 additions & 0 deletions docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: "3"

services:
db:
container_name: ara-db
image: mysql:8
ports:
- "${NEWARA_DB_PORT:?err}:3306"
environment:
- MYSQL_ROOT_PASSWORD=${NEWARA_DB_PASSWORD:?err}
- MYSQL_DATABASE=${NEWARA_DB_NAME:?err}
volumes:
- vol-db:/var/lib/mysql
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

redis:
container_name: ara-redis
image: redis:6
ports:
- "${NEWARA_REDIS_PORT:?err}:6379"
volumes:
- vol-redis:/data

elastic:
container_name: ara-elastic
image: elasticsearch:7.9.2
ports:
- "${NEWARA_ELASTICSEARCH_PORT:?err}:9200"
environment:
- discovery.type=single-node
command: >
bash -c "bin/elasticsearch-plugin list | grep -q analysis-nori || bin/elasticsearch-plugin install -b analysis-nori
&& /usr/local/bin/docker-entrypoint.sh"
volumes:
- ./ara/db/elasticsearch/synonym.txt:/usr/share/elasticsearch/config/analysis/synonym.txt
- vol-elastic:/usr/share/elasticsearch

volumes:
vol-db:
vol-redis:
vol-elastic:
41 changes: 18 additions & 23 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 테스트 환경에서만 사용
version: "3"

services:
api:
image: newara
depends_on:
- celery
- db
- redis
- celery_worker
- elasticsearch
- elastic
environment:
- DJANGO_SETTINGS_MODULE=ara.settings.test
- DJANGO_ENV=${DJANGO_ENV}
Expand All @@ -24,19 +24,19 @@ services:
- NEWARA_DB_PASSWORD=root-password
- NEWARA_DB_NAME=new_ara
- NEWARA_REDIS_ADDRESS=redis
- NEWARA_ELASTICSEARCH_HOST=elasticsearch
- NEWARA_REDIS_PORT=6379
- NEWARA_ELASTICSEARCH_HOST=elastic
- NEWARA_ELASTICSEARCH_PORT=9200
- PORTAL_2FA_KEY=${PORTAL_2FA_KEY}
entrypoint: /newara/www/.docker/run.sh
volumes:
- nori:/newara/www/ara/db/elasticsearch
- synonym:/newara/www/ara/db/elasticsearch

celery_worker:
celery:
image: newara
depends_on:
- db
- redis
- elasticsearch
- elastic
environment:
- DJANGO_SETTINGS_MODULE=main.settings.test
- DJANGO_ENV=${DJANGO_ENV}
Expand All @@ -53,42 +53,37 @@ services:
- NEWARA_DB_PASSWORD=root-password
- NEWARA_DB_NAME=new_ara
- NEWARA_REDIS_ADDRESS=redis
- NEWARA_ELASTICSEARCH_HOST=elasticsearch
- NEWARA_REDIS_PORT=6379
- NEWARA_ELASTICSEARCH_HOST=elastic
- NEWARA_ELASTICSEARCH_PORT=9200
- C_FORCE_ROOT=true
- PORTAL_2FA_KEY=${PORTAL_2FA_KEY}
entrypoint: /newara/www/.docker/run-celery.sh

db:
container_name: db
image: mysql:8.0
image: mysql:8
expose:
- 3306
environment:
- MYSQL_ROOT_PASSWORD=root-password
- MYSQL_DATABASE=new_ara
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

redis:
image: redis:6
expose:
- 6379

elasticsearch:
elastic:
image: elasticsearch:7.9.2
expose:
- 9200
- 9300
environment:
- discovery.type=single-node
command: bash -c "
bin/elasticsearch-plugin list | grep -q analysis-nori || bin/elasticsearch-plugin install --batch analysis-nori
&& /usr/local/bin/docker-entrypoint.sh
"
command: >
bash -c "bin/elasticsearch-plugin list | grep -q analysis-nori || bin/elasticsearch-plugin install --batch analysis-nori
&& /usr/local/bin/docker-entrypoint.sh"
volumes:
- nori:/usr/share/elasticsearch/config/analysis
- synonym:/usr/share/elasticsearch/config/analysis

volumes:
nori:
synonym:
Loading