Closed ehmatthes closed 1 year ago
./integration_tests/test_deploy_process.sh -d pipenv -p heroku
./integration_tests/test_deploy_process.sh -d pipenv -p fly_io
Dockerfile
only refers to requirements.txt
../integration_tests/test_deploy_process.sh -d pipenv -p platform_sh
--skip-lock
, since there shouldn't be any reason to generate locks on the server. (No, this ignores the existing Pipfile.lock, which we definitely want to use.)Run
block in an if block, because the readability issue is about the overall block.
COPY Pipfile /tmp/Pipfile
RUN set -ex && \ pip install --upgrade pip && \ pip install pipenv && \ pipenv install --skip-lock && \ rm -rf /root/.cache/
Pipfile:
% cat tmp_django_simple_deploy_test/Pipfile [[source]] url = "https://pypi.org/simple" verify_ssl = true name = "pypi"
[packages] whitenoise = "" # Added by simple_deploy command. dj-database-url = "" # Added by simple_deploy command. psycopg2-binary = "" # Added by simple_deploy command. gunicorn = "" # Added by simple_deploy command. django = "" django-bootstrap5 = "" requests = "" django-simple-deploy = ""
[dev-packages]
[requires] python_version = "3.10"
Relevant output:
=> [4/7] COPY Pipfile /tmp/Pipfile 0.0s => [5/7] RUN set -ex && pip install --upgrade pip && pip install pipenv && pipenv install --skip-lock && rm 10.1s => [6/7] COPY . /code/ 0.0s => ERROR [7/7] RUN ON_FLYIO_SETUP="1" python manage.py collectstatic --noinput 0.3s
[7/7] RUN ON_FLYIO_SETUP="1" python manage.py collectstatic --noinput:
10 0.310 Traceback (most recent call last):
10 0.310 File "/code/manage.py", line 11, in main
10 0.310 from django.core.management import execute_from_command_line
10 0.311 ModuleNotFoundError: No module named 'django'
% cat tmp_django_simple_deploy_test/Pipfile
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages] whitenoise = "" # Added by simple_deploy command. dj-database-url = "" # Added by simple_deploy command. psycopg2 = "<2.9" # Added by simple_deploy command. gunicorn = "" # Added by simple_deploy command. django = "" django-bootstrap5 = "" requests = "" django-simple-deploy = "*"
[dev-packages]
[requires] python_version = "3.10"
- [x] Pass integration test.
- [ ] Unit test this approach.
% pipenv install --skip-lock
Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Installing dependencies from Pipfile...
An error occurred while installing django! Will try again.
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 8/8 — 00:00:08
Installing initially failed dependencies...
☤ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
(p_env) eric@Erics-MacBook-Pro-2 pipenv_trial % pip freeze
asgiref==3.5.2
certifi==2022.12.7
charset-normalizer==2.1.1
distlib==0.3.6
dj-database-url==1.1.0
Django==4.1.4
...
--skip-lock
, run fly deploy --verbose
, record screen to examine fly output that disappears.Locking [dev-packages] dependencies...
Updated Pipfile.lock...
...
To activate this project's virtualenv, run pipenv shell.
Alternatively run a command inside the virutalenv with pipenv run
https://user-images.githubusercontent.com/1886842/207141186-c51fdaac-ffa2-4ea6-81eb-51ec09404797.mov
pipenv shell
inside Docker" sourcecollectstatic
: pipenv run python manage.py collectstatic
Current Dockerfile, works through collectstatic stage but fails at migrate command:
ARG PYTHON_VERSION=3.10-slim-buster
FROM python:${PYTHON_VERSION}
ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 ENV PIPENV_PIPFILE /tmp/Pipfile
RUN mkdir -p /code
WORKDIR /code
COPY Pipfile /tmp/Pipfile
RUN set -ex && \ pip install --upgrade pip && \ pip install pipenv && \ pipenv install && \ rm -rf /root/.cache/
COPY . /code/
RUN ON_FLYIO_SETUP="1" pipenv run python manage.py collectstatic --noinput
EXPOSE 8000
CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "blog.wsgi"]
- [x] Use pipenv in fly.toml as well, for migrate command. This works.
- [x] May need to tweak final `CMD` in dockerfile?
- [x] Note: Fly may be incompatible with Pipenv, and maybe we should just generate requirements.txt. (nope)
2022-12-12T20:11:10.474 runner[1b0a7489] sea [info] Starting virtual machine
2022-12-12T20:11:10.758 app[1b0a7489] sea [info] Starting init (commit: f447594)...
2022-12-12T20:11:10.782 app[1b0a7489] sea [info] Preparing to run: `gunicorn --bind :8000 --workers 2 blog.wsgi` as root
2022-12-12T20:11:10.791 app[1b0a7489] sea [info] Error: UnhandledIoError(Os { code: 2, kind: NotFound, message: "No such file or directory" })
pipenv run gunicorn
?I've been tweaking a project that was initially deployed through the integration test. Process: modify Dockerfile and fly.toml, then run fly deploy --verbose
. It finally works, and I can make an account, and the site and admin home page have proper css. I do get this message at the release phase:
--> This release will not be available until the release command succeeds.
Starting instance
Configuring virtual machine
Pulling container image
Unpacking image
Preparing kernel init
Configuring firecracker
Starting virtual machine
Starting init (commit: f447594)...
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=bb945d0a-7089-4bf6-ac44-a55bba78ab63
Preparing to run: `pipenv run python manage.py migrate` as root
2022/12/12 20:19:54 listening on [fdaa:0:94e0:a7b:bbfb:8717:d0fb:2]:22 (DNS: [fdaa::3]:53)
System check identified some issues:
WARNINGS:
?: (staticfiles.W004) The directory '/code/static' in the STATICFILES_DIRS setting does not exist.
Operations to perform:
Apply all migrations: admin, auth, blogs, contenttypes, sessions
Running migrations:
No migrations to apply.
Starting clean up.
Dockerfile:
ARG PYTHON_VERSION=3.10-slim-buster
FROM python:${PYTHON_VERSION}
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIPENV_PIPFILE /tmp/Pipfile
RUN mkdir -p /code
WORKDIR /code
COPY Pipfile /tmp/Pipfile
RUN set -ex && \
pip install --upgrade pip && \
pip install pipenv && \
pipenv install && \
rm -rf /root/.cache/
COPY . /code/
RUN ON_FLYIO_SETUP="1" pipenv run python manage.py collectstatic --noinput
EXPOSE 8000
CMD ["pipenv", "run", "gunicorn", "--bind", ":8000", "--workers", "2", "blog.wsgi"]
fly.toml:
app = "ancient-bird-3980"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
PORT = "8000"
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8000
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
[[statics]]
guest_path = "/app/public"
url_prefix = "/static/"
[deploy]
release_command = "pipenv run python manage.py migrate"
using_pipenv
logic is moved to deploy.py, and we just have two separate, simple templates for the different dependency management systems. It's really not easy to read the current Dockerfile template.
Similar to #197, make sure Pipenv is supported across the three currently-supported platforms.