Skip to content

Commit c69e77b

Browse files
committed
build: Improve Docker image and add version in hash.txt
In mitodl/release-script#400 Doof gains the ability to parse versions. This adds the necessary information in the hash.txt to allow Doof to properly detect production deployments of this app.
1 parent 013bb99 commit c69e77b

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ci:
77
# Because these are local hooks it seems like they won't easily run in pre-commit CI
88
- eslint
99
- style-lint
10+
- hadolint-docker
1011
repos:
1112
- repo: https://github.com/pre-commit/pre-commit-hooks
1213
rev: v5.0.0
@@ -89,3 +90,7 @@ repos:
8990
hooks:
9091
- id: shellcheck
9192
args: ["--severity=warning"]
93+
- repo: https://github.com/hadolint/hadolint
94+
rev: v2.12.0
95+
hooks:
96+
- id: hadolint-docker

Dockerfile

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,54 @@
1+
# hadolint global ignore=DL3008,SC2046
12
FROM python:3.12.6
2-
LABEL maintainer "ODL DevOps <[email protected]>"
3+
LABEL org.opencontainers.image.authors="ODL DevOps <[email protected]>"
4+
5+
# Set shell to bash with pipefail
6+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
37

48
# Add package files, install updated node and pip
59
WORKDIR /tmp
610

711
# Install packages
812
COPY apt.txt /tmp/apt.txt
9-
RUN apt-get update
10-
RUN apt-get install -y $(grep -vE "^\s*#" apt.txt | tr "\n" " ")
11-
RUN apt-get update && apt-get install libpq-dev postgresql-client -y
12-
13-
# pip
14-
RUN curl --silent --location https://bootstrap.pypa.io/get-pip.py | python3 -
13+
RUN apt-get update \
14+
&& apt-get install -y \
15+
--no-install-recommends \
16+
libpq-dev \
17+
postgresql-client \
18+
$(grep -vE '^\s*#' apt.txt | tr '\n' ' ') \
19+
&& apt-get clean \
20+
&& apt-get purge \
21+
&& rm -rf /var/lib/apt/lists/*
1522

1623
# Add, and run as, non-root user.
17-
RUN mkdir /src
18-
RUN adduser --disabled-password --gecos "" mitodl
19-
RUN mkdir /var/media && chown -R mitodl:mitodl /var/media
24+
RUN mkdir /src \
25+
&& adduser --disabled-password --gecos "" mitodl \
26+
&& mkdir /var/media && chown -R mitodl:mitodl /var/media
2027

2128
## Set some poetry config
2229
ENV \
23-
POETRY_VERSION=1.7.1 \
30+
PYTHON_UNBUFFERED=1 \
31+
POETRY_VERSION=1.8.5 \
2432
POETRY_VIRTUALENVS_CREATE=true \
2533
POETRY_CACHE_DIR='/tmp/cache/poetry' \
2634
POETRY_HOME='/home/mitodl/.local' \
2735
VIRTUAL_ENV="/opt/venv"
2836
ENV PATH="$VIRTUAL_ENV/bin:$POETRY_HOME/bin:$PATH"
2937

3038
# Install poetry
31-
RUN pip install "poetry==$POETRY_VERSION"
39+
RUN pip install --no-cache-dir "poetry==$POETRY_VERSION"
3240

3341
COPY pyproject.toml /src
3442
COPY poetry.lock /src
35-
RUN chown -R mitodl:mitodl /src
36-
RUN mkdir ${VIRTUAL_ENV} && chown -R mitodl:mitodl ${VIRTUAL_ENV}
43+
RUN chown -R mitodl:mitodl /src && \
44+
mkdir ${VIRTUAL_ENV} && \
45+
chown -R mitodl:mitodl ${VIRTUAL_ENV}
3746

3847
## Install poetry itself, and pre-create a venv with predictable name
3948
USER mitodl
40-
RUN curl -sSL https://install.python-poetry.org \
41-
| \
42-
POETRY_VERSION=${POETRY_VERSION} \
43-
POETRY_HOME=${POETRY_HOME} \
44-
python3 -q
4549
WORKDIR /src
46-
RUN python3 -m venv $VIRTUAL_ENV
47-
RUN poetry install
50+
RUN python3 -m venv $VIRTUAL_ENV && \
51+
poetry install
4852

4953
# Add project
5054
USER root
@@ -53,28 +57,12 @@ WORKDIR /src
5357

5458
# Generate commit hash file
5559
ARG GIT_REF
56-
RUN mkdir -p /src/static
57-
RUN echo $GIT_REF >> /src/static/hash.txt
58-
59-
# Run collectstatic
60-
ENV DATABASE_URL="postgres://postgres:postgres@localhost:5433/postgres"
61-
ENV MITOL_SECURE_SSL_REDIRECT="False"
62-
ENV MITOL_DB_DISABLE_SSL="True"
63-
ENV MITOL_FEATURES_DEFAULT="True"
64-
ENV CELERY_TASK_ALWAYS_EAGER="True"
65-
ENV CELERY_BROKER_URL="redis://localhost:6379/4"
66-
ENV CELERY_RESULT_BACKEND="redis://localhost:6379/4"
67-
ENV MITOL_APP_BASE_URL="http://localhost:8002/"
68-
ENV MAILGUN_KEY="fake_mailgun_key"
69-
ENV MAILGUN_SENDER_DOMAIN="other.fake.site"
70-
ENV MITOL_COOKIE_DOMAIN="localhost"
71-
ENV MITOL_COOKIE_NAME="cookie_monster"
72-
RUN python3 manage.py collectstatic --noinput --clear
73-
74-
RUN apt-get clean && apt-get purge
60+
ARG RELEASE_VERSION
61+
RUN mkdir -p /src/static \
62+
&& echo "{\"version\": \"$RELEASE_VERSION\", \"hash\": \"$GIT_REF\"}" >> /src/static/hash.txt
7563

7664
USER mitodl
7765

7866
EXPOSE 8888
7967
EXPOSE 8001
80-
ENV PORT 8001
68+
ENV PORT=8001

0 commit comments

Comments
 (0)