-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from bcgov/70-backend-docker
feat: Dockerfile for backend
- Loading branch information
Showing
7 changed files
with
117 additions
and
8 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
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,7 @@ | ||
.venv | ||
.git | ||
.gitignore | ||
.vscode | ||
**/__pycache__ | ||
**/*.pyc | ||
python_cache |
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,3 +1,3 @@ | ||
python 3.9.18 | ||
poetry 1.6.1 | ||
poetry 1.7.1 | ||
postgres 14.0 |
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,52 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.9.18 AS main | ||
|
||
# Install system dependencies and clean up | ||
RUN apt-get update && \ | ||
apt-get upgrade -y && \ | ||
apt-get install -y git gnupg curl build-essential && \ | ||
apt-get clean | ||
|
||
# Set environment variables | ||
ENV PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 \ | ||
USER_ID=1001 \ | ||
HOME=/root | ||
|
||
WORKDIR ${HOME} | ||
# Make everything in the home group-writable to support OpenShift's restricted SCC | ||
# Needs to be done as root to chown | ||
RUN useradd -ms /bin/bash -d ${HOME} --uid ${USER_ID} -g root server | ||
|
||
COPY ./ ${HOME}/ | ||
|
||
# Install asdf | ||
RUN git clone https://github.com/asdf-vm/asdf.git ${HOME}/asdf --depth 1 --branch v0.14.0 | ||
|
||
ENV BASH_ENV="${HOME}/asdf/asdf.sh" | ||
# Because asdf is loaded via BASH_ENV, all commands using adsf need to be executed using /usr/bin/env bash -c | ||
SHELL ["/usr/bin/env", "bash", "-c"] | ||
|
||
RUN sed -i -nr '/python|poetry/p' ${HOME}/.tool-versions && \ | ||
cat ${HOME}/.tool-versions | cut -f 1 -d ' ' | xargs -n 1 asdf plugin-add && \ | ||
asdf plugin-update --all && \ | ||
asdf install && \ | ||
asdf reshim | ||
|
||
# Add Poetry's bin directory to PATH | ||
ENV PATH="${HOME}/.asdf/installs/poetry/1.7.1/bin:${PATH}" | ||
|
||
# Configuring poetry to behave properly with asdf | ||
RUN poetry config virtualenvs.prefer-active-python true | ||
|
||
# Change ownership and permissions | ||
RUN chown -R server:0 ${HOME} && \ | ||
chmod -R g+rwX ${HOME} | ||
|
||
# Expose the port your Django application will run on (change as needed) | ||
EXPOSE 8000 | ||
|
||
# Install project dependencies using Poetry | ||
RUN poetry install --without dev | ||
USER ${USER_ID} | ||
CMD ["/usr/bin/env", "bash", "-c", "poetry run python manage.py collectstatic --noinput && poetry run python manage.py migrate && poetry run gunicorn --access-logfile - server.wsgi:application --timeout 200 --workers 8 --bind '0.0.0.0:8000'"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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