Skip to content

Commit

Permalink
configure docker dev setup
Browse files Browse the repository at this point in the history
- add start_container.sh
- if DEPLOYMENT=development, start reload server
  otherwise start gunicorn server
- use env variables to map host and port
- read PADDLES_URL from env variable instead
  of src/config.py

Signed-off-by: Vallari Agrawal <val.agl002@gmail.com>
  • Loading branch information
VallariAg committed Sep 26, 2023
1 parent 4370518 commit 6708201
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ RUN apt-get update && \

COPY .teuthology.yaml /root
WORKDIR /teuthology_api
COPY requirements.txt *.env /teuthology_api/
COPY requirements.txt *.env start_container.sh /teuthology_api/
RUN pip3 install -r requirements.txt
COPY . /teuthology_api/

WORKDIR /teuthology_api/src
ENTRYPOINT gunicorn -c /teuthology_api/gunicorn_config.py main:app
CMD sh /teuthology_api/start_container.sh
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth
build:
context: ../../../teuthology-api
ports:
- 8082:8082
- 8082:8080
environment:
TEUTHOLOGY_API_SERVER_HOST: 0.0.0.0
TEUTHOLOGY_API_SERVER_PORT: 8080
PADDLES_URL: http://localhost:8080
depends_on:
- teuthology
- paddles
Expand All @@ -32,7 +36,18 @@ A REST API to execute [teuthology commands](https://docs.ceph.com/projects/teuth
healthcheck:
test: [ "CMD", "curl", "-f", "http://0.0.0.0:8082" ]
```
5. Follow teuthology development setup instructions from [here](https://github.com/ceph/teuthology/tree/main/docs/docker-compose).

[optional] For developement use:
Add following things in `teuthology_api` container:
```
teuthology_api:
environment:
DEPLOYMENT: development
volumes:
- ../../../teuthology-api:/teuthology_api/:rw
```
`DEPLOYMENT: development` would run the server in `--reload` mode (server would restart when changes are made in `/src` dir) and `volumes` would mount host directory to docker's directory (local changes would reflect in docker container).
3. Follow teuthology development setup instructions from [here](https://github.com/ceph/teuthology/tree/main/docs/docker-compose).

## Documentation

Expand Down
9 changes: 7 additions & 2 deletions gh-actions/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ if [ ! -d "$folder" ] ; then
git clone https://github.com/ceph/teuthology.git
echo " teuthology_api:
build:
context: ../../../../
context: ../../../../
ports:
- 8082:8082
- 8082:8080
environment:
TEUTHOLOGY_API_SERVER_HOST: 0.0.0.0
TEUTHOLOGY_API_SERVER_PORT: 8080
depends_on:
- teuthology
- paddles
links:
- teuthology
- paddles
healthcheck:
test: [ "CMD", "curl", "-f", "http://0.0.0.0:8082" ]
" >> teuthology/docs/docker-compose/docker-compose.yml
fi
cd teuthology/docs/docker-compose
Expand Down
4 changes: 3 additions & 1 deletion gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
from multiprocessing import cpu_count


bind = '0.0.0.0:8082'
host = os.environ.get('TEUTHOLOGY_API_SERVER_HOST', '0.0.0.0')
port = os.environ.get('TEUTHOLOGY_API_SERVER_PORT', '8080')
bind = f'{host}:{port}'

workers = cpu_count()
worker_class = 'uvicorn.workers.UvicornWorker'
Expand Down
1 change: 0 additions & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class APISettings(BaseSettings):
"""

model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
PADDLES_URL: str = "http://paddles:8080"
# TODO: team names need to be changed below when created
admin_team: str = "ceph" # ceph's github team with *sudo* access to sepia
teuth_team: str = "teuth" # ceph's github team with access to sepia
Expand Down
2 changes: 1 addition & 1 deletion src/services/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import teuthology
import requests # Note: import requests after teuthology

PADDLES_URL = settings.PADDLES_URL
PADDLES_URL = os.getenv("PADDLES_URL")

log = logging.getLogger(__name__)

Expand Down
15 changes: 15 additions & 0 deletions start_container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -ex
trap exit TERM

HOST=${TEUTHOLOGY_API_SERVER_HOST:-"0.0.0.0"}
PORT=${TEUTHOLOGY_API_SERVER_PORT:-"8080"}


cd /teuthology_api/src/

if [ "$DEPLOYMENT" = "development" ]; then
uvicorn main:app --reload --port $PORT --host $HOST
else
gunicorn -c /teuthology_api/gunicorn_config.py main:app
fi

0 comments on commit 6708201

Please sign in to comment.