diff --git a/dev.Dockerfile b/dev.Dockerfile index 8112a1435..7190fdf06 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -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 diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index 5eb827e2c..0f1143373 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -26,5 +26,4 @@ services: - DJANGO_SUPERUSER_USERNAME=admin - DJANGO_SUPERUSER_PASSWORD=1234 - DJANGO_SUPERUSER_EMAIL=admin@pycon.tw - entrypoint: /docker-entrypoint.sh - command: python /app/src/manage.py runserver 0.0.0.0:8000 + working_dir: /app/src diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh deleted file mode 100644 index 8ed33cc8e..000000000 --- a/docker-entrypoint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -echo 'Run migration' -python3 /app/src/manage.py migrate -echo 'Create super user' -python3 /app/src/manage.py createsuperuser --noinput || echo "Super user already created" -echo 'Compile localized translation' -python3 /app/src/manage.py compilemessages -exec "$@" diff --git a/document/deploy_docker_dev.md b/document/deploy_docker_dev.md index a56a216bc..198145bda 100644 --- a/document/deploy_docker_dev.md +++ b/document/deploy_docker_dev.md @@ -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 (ctrl+c 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 (ctrl+c 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 + ``` diff --git a/enter_dev_env.sh b/enter_dev_env.sh index 5f7bd16b4..468310702 100755 --- a/enter_dev_env.sh +++ b/enter_dev_env.sh @@ -16,7 +16,7 @@ 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 @@ -24,6 +24,6 @@ elif [ -n "$HASH_STOPPED" ];then 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"