Skip to content

Commit

Permalink
fix(dev): use poetry shell in dev env
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwang44 committed Apr 9, 2024
1 parent 6fc8899 commit 965297f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
4 changes: 0 additions & 4 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,3 @@ ENV PATH="${WORKDIR}/.venv/bin:$PATH"

COPY --from=node_stage /node_modules ./node_modules
COPY --from=node_stage /usr/local/bin/node /usr/local/bin/node

# for entry point
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
3 changes: 1 addition & 2 deletions docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ services:
- DJANGO_SUPERUSER_USERNAME=admin
- DJANGO_SUPERUSER_PASSWORD=1234
- [email protected]
entrypoint: /docker-entrypoint.sh
command: python /app/src/manage.py runserver 0.0.0.0:8000
working_dir: /app/src
8 changes: 0 additions & 8 deletions docker-entrypoint.sh

This file was deleted.

24 changes: 23 additions & 1 deletion document/deploy_docker_dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,30 @@
DATABASE_URL=postgres://postgres:secretpostgres@db:5432/pycontw2016
```

2. Simply run the following command to install all dependencies, activate a containerized Postgres server, and run the Django server (<code>ctrl+c</code> to stop).
2. Simply run the following command to install all dependencies, activate a containerized Postgres server, and enter into a poetry shell inside the application container (<code>ctrl+c</code> to quit).

```
./enter_dev_env.sh
```

3. In the shell, you can run any commands as if you are in a local development environment. Here are some common Django commands:

```sh
# make migrations
python manage.py makemigrations

# apply migrations
python manage.py migrate

# create a superuser
python manage.py createsuperuser

# pull out strings for translations
python manage.py makemessages -l en_US -l zh_Hant

# compile translations
python manage.py compilemessages

# run the dev server
python manage.py runserver
```
4 changes: 2 additions & 2 deletions enter_dev_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ fi
if [ -n "$HASH" ];then
echo "found existing running container $CONTAINER, proceeding to exec another shell"
docker-compose -f $COMPOSE_FILE restart
docker exec -it $HASH $START_SHELL
docker exec -w /app/src -it $HASH bash -c "SHELL=bash poetry shell"
elif [ -n "$HASH_STOPPED" ];then
echo "found existing stopped container $CONTAINER, starting"
docker-compose -f $COMPOSE_FILE restart
docker start --attach -i $HASH_STOPPED
else
echo "existing container not found, creating a new one, named $CONTAINER"
docker-compose -f $COMPOSE_FILE pull
docker-compose -f $COMPOSE_FILE run -p 8000:8000 --name=$CONTAINER pycontw
docker-compose -f $COMPOSE_FILE run -p 8000:8000 --name=$CONTAINER pycontw bash -c "SHELL=bash poetry shell"
fi
echo "see you, use 'docker rm $CONTAINER' to kill the dev container or 'docker-compose -f $COMPOSE_FILE down' to kill both the postgres and the dev container if you want a fresh env next time"

0 comments on commit 965297f

Please sign in to comment.