-
Notifications
You must be signed in to change notification settings - Fork 1
build: Improve Docker image and add version in hash.txt #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,54 @@ | ||
# hadolint global ignore=DL3008,SC2046 | ||
FROM python:3.13.2 | ||
LABEL maintainer "ODL DevOps <[email protected]>" | ||
LABEL org.opencontainers.image.authors="ODL DevOps <[email protected]>" | ||
|
||
# Set shell to bash with pipefail | ||
SHELL ["/bin/bash", "-o", "pipefail", "-c"] | ||
|
||
# Add package files, install updated node and pip | ||
WORKDIR /tmp | ||
|
||
# Install packages | ||
COPY apt.txt /tmp/apt.txt | ||
RUN apt-get update | ||
RUN apt-get install -y $(grep -vE "^\s*#" apt.txt | tr "\n" " ") | ||
RUN apt-get update && apt-get install libpq-dev postgresql-client -y | ||
|
||
# pip | ||
RUN curl --silent --location https://bootstrap.pypa.io/get-pip.py | python3 - | ||
RUN apt-get update \ | ||
&& apt-get install -y \ | ||
--no-install-recommends \ | ||
libpq-dev \ | ||
postgresql-client \ | ||
$(grep -vE '^\s*#' apt.txt | tr '\n' ' ') \ | ||
&& apt-get clean \ | ||
&& apt-get purge \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Add, and run as, non-root user. | ||
RUN mkdir /src | ||
RUN adduser --disabled-password --gecos "" mitodl | ||
RUN mkdir /var/media && chown -R mitodl:mitodl /var/media | ||
RUN mkdir /src \ | ||
&& adduser --disabled-password --gecos "" mitodl \ | ||
&& mkdir /var/media && chown -R mitodl:mitodl /var/media | ||
|
||
## Set some poetry config | ||
ENV \ | ||
POETRY_VERSION=1.7.1 \ | ||
PYTHON_UNBUFFERED=1 \ | ||
POETRY_VERSION=1.8.5 \ | ||
POETRY_VIRTUALENVS_CREATE=true \ | ||
POETRY_CACHE_DIR='/tmp/cache/poetry' \ | ||
POETRY_HOME='/home/mitodl/.local' \ | ||
VIRTUAL_ENV="/opt/venv" | ||
ENV PATH="$VIRTUAL_ENV/bin:$POETRY_HOME/bin:$PATH" | ||
|
||
# Install poetry | ||
RUN pip install "poetry==$POETRY_VERSION" | ||
RUN pip install --no-cache-dir "poetry==$POETRY_VERSION" | ||
|
||
COPY pyproject.toml /src | ||
COPY poetry.lock /src | ||
RUN chown -R mitodl:mitodl /src | ||
RUN mkdir ${VIRTUAL_ENV} && chown -R mitodl:mitodl ${VIRTUAL_ENV} | ||
RUN chown -R mitodl:mitodl /src && \ | ||
mkdir ${VIRTUAL_ENV} && \ | ||
chown -R mitodl:mitodl ${VIRTUAL_ENV} | ||
|
||
## Install poetry itself, and pre-create a venv with predictable name | ||
USER mitodl | ||
RUN curl -sSL https://install.python-poetry.org \ | ||
| \ | ||
POETRY_VERSION=${POETRY_VERSION} \ | ||
POETRY_HOME=${POETRY_HOME} \ | ||
python3 -q | ||
WORKDIR /src | ||
RUN python3 -m venv $VIRTUAL_ENV | ||
RUN poetry install | ||
RUN python3 -m venv $VIRTUAL_ENV && \ | ||
poetry install | ||
|
||
# Add project | ||
USER root | ||
|
@@ -53,28 +57,12 @@ WORKDIR /src | |
|
||
# Generate commit hash file | ||
ARG GIT_REF | ||
RUN mkdir -p /src/static | ||
RUN echo $GIT_REF >> /src/static/hash.txt | ||
|
||
# Run collectstatic | ||
ENV DATABASE_URL="postgres://postgres:postgres@localhost:5433/postgres" | ||
ENV MITOL_SECURE_SSL_REDIRECT="False" | ||
ENV MITOL_DB_DISABLE_SSL="True" | ||
ENV MITOL_FEATURES_DEFAULT="True" | ||
ENV CELERY_TASK_ALWAYS_EAGER="True" | ||
ENV CELERY_BROKER_URL="redis://localhost:6379/4" | ||
ENV CELERY_RESULT_BACKEND="redis://localhost:6379/4" | ||
ENV MITOL_APP_BASE_URL="http://localhost:8002/" | ||
ENV MAILGUN_KEY="fake_mailgun_key" | ||
ENV MAILGUN_SENDER_DOMAIN="other.fake.site" | ||
ENV MITOL_COOKIE_DOMAIN="localhost" | ||
ENV MITOL_COOKIE_NAME="cookie_monster" | ||
RUN python3 manage.py collectstatic --noinput --clear | ||
|
||
RUN apt-get clean && apt-get purge | ||
ARG RELEASE_VERSION | ||
Comment on lines
59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
RUN mkdir -p /src/static \ | ||
&& echo "{\"version\": \"$RELEASE_VERSION\", \"hash\": \"$GIT_REF\"}" >> /src/static/hash.txt | ||
blarghmatey marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using
Comment on lines
+61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line creates the
|
||
|
||
USER mitodl | ||
|
||
EXPOSE 8888 | ||
EXPOSE 8001 | ||
ENV PORT 8001 | ||
ENV PORT=8001 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
hadolint-docker
to theci
section is a good step to ensure Dockerfile linting in CI. However, it's worth noting that this hook might not run locally unless the necessary environment is set up. Consider adding a comment to clarify this for developers.