-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor django container build with poetry dependency management
- Loading branch information
Showing
3 changed files
with
32 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
# start from an official image | ||
# Download and install python dependencies in a container | ||
FROM python:3.9 as dependency-install-container | ||
ARG PROJECT_ENVIRONMENT | ||
COPY ./poetry.lock ./pyproject.toml ./django/install-packages.sh /code/ | ||
WORKDIR /code | ||
RUN chmod u+x /code/install-packages.sh && \ | ||
/code/install-packages.sh $PROJECT_ENVIRONMENT | ||
|
||
# Copy our dependencies into the base image | ||
FROM python:3.9 | ||
COPY --from=dependency-install-container /code/.venv /code/.venv | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
EXPOSE 8000 | ||
|
||
WORKDIR /code/django/cantusdb_project | ||
|
||
COPY cantusdb_project/requirements.txt /code/django/cantusdb_project | ||
|
||
RUN pip3 install -r requirements.txt | ||
WORKDIR /code/cantusdb_project | ||
|
||
COPY cantusdb_project . | ||
# Add our python environment binaries and package files to the path | ||
ENV PATH="$PATH:/code/.venv/bin/" \ | ||
PYTHONPATH="$PYTHONPATH:/code/.venv/lib/python3.9/site-packages/" | ||
|
||
# define the default command to run when starting the container | ||
CMD ["gunicorn", "--chdir", "cantusdb", "--bind", ":8000", "cantusdb.wsgi:application", "--workers", "5"] | ||
CMD ["gunicorn", "--bind", ":8000", "cantusdb.wsgi:application", "--workers", "5"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
pip install poetry==1.8.2 | ||
|
||
poetry config virtualenvs.in-project true # Creates a virtualenv in the project directory | ||
poetry config virtualenvs.options.always-copy true # Ensures no symlinking in the virtualenv | ||
poetry config virtualenvs.options.no-pip true # Don't install pip in the virtualenv | ||
poetry config virtualenvs.options.no-setuptools true # Don't install setuptools in the virtualenv | ||
|
||
if [ $1 = "DEVELOPMENT" ]; then | ||
poetry install --no-cache --with debug,test | ||
else | ||
poetry install --no-cache | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters