Upgrade to Pro — share decks privately, control downloads, hide ads and more …

poetryでパッケージ管理 on Docker

mizzsugar
August 08, 2019
670

poetryでパッケージ管理 on Docker

mizzsugar

August 08, 2019
Tweet

More Decks by mizzsugar

Transcript

  1. ディレクトリ構成 ├── app │ ├── poetry.lock │ ├── project │

    │ ├── アプリケーションコード諸々 │ └── pyproject.toml ├── docker │ ├── app │ │ ├── Dockerfile │ │ └── start-server.sh │ ├── etc │ │ └── gunicorn.conf │ ├── db │ └── Dockerfile └── docker-compose.yaml
  2. docker-compose.yaml version: "3" services: app: build: context: ./docker/app dockerfile: Dockerfile

    env_file: .env volumes: - ./app:/home/app - ./docker/app:/home/docker - ./docker/etc/gunicorn.conf:/etc/gunicorn.conf - ./docker/var/log/gunicorn:/var/log/gunicorn working_dir: /home/app entrypoint: "/bin/sh" command: "/home/docker/start-server.sh" ports: - "8080:8080" tty: true depends_on: - db db: build: context: ./docker/db dockerfile: Dockerfile env_file: .env ports: - 5432:5432 volumes: - ./docker/postgres/pgsql-data:/var/lib/postgresql/data PythonコンテナとDBコンテナの 2つでアプリケーションを動かすとい う設定です。
  3. シェルスクリプトにやってもらう #!/bin/bash cd /home/app poetry install cd project if [

    "${DJANGO_ENV}" = 'production' ]; then poetry run python manage.py migrate --settings config.settings poetry run python manage.py collectstatic --noinput poetry run gunicorn config.wsgi:application -c /etc/gunicorn.conf -b :8080 else poetry run python manage.py migrate poetry run python manage.py runserver 0.0.0.0:8000 fi
  4. シェルスクリプトにやってもらう #!/bin/bash cd /home/app poetry install cd project if [

    "${DJANGO_ENV}" = 'production' ]; then poetry run python manage.py migrate --settings config.settings poetry run python manage.py collectstatic --noinput poetry run gunicorn config.wsgi:application -c /etc/gunicorn.conf -b :8080 else poetry run python manage.py migrate poetry run python manage.py runserver 0.0.0.0:8000 fi poetryでインストールしたパッ ケージをインストールします。 poetry run を頭につけると poetryが作ってくれる仮想環境で 操作がされる動きになります。
  5. docker-compose.yaml version: "3" services: app: build: context: ./docker/app dockerfile: Dockerfile

    env_file: .env volumes: - ./app:/home/app - ./docker/app:/home/docker - ./docker/etc/gunicorn.conf:/etc/gunicorn.conf - ./docker/var/log/gunicorn:/var/log/gunicorn working_dir: /home/app entrypoint: "/bin/sh" command: "/home/docker/start-server.sh" ports: - "8080:8080" tty: true depends_on: - db db: build: context: ./docker/db dockerfile: Dockerfile env_file: .env ports: - 5432:5432 volumes: - ./docker/postgres/pgsql-data:/var/lib/postgresql/data
  6. docker-compose exec app bash まずPythonコンテナに入って cd project poetry run python

    manage.py shell poetryが作成してくれる仮想環境にて実行! poetry shell cd project poetry run python manage.py shell こちらでも可