Skip to content

Commit

Permalink
fix: docker build deprecation warnings
Browse files Browse the repository at this point in the history
With the latest Docker upgrade, we got the following warnings during
build:

    FromAsCasing: 'as' and 'FROM' keywords' casing do not match
    LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format
  • Loading branch information
regisb committed Jun 21, 2024
1 parent 617a2a8 commit d9a2c24
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ COPY --from=docker/compose:1.24.0 /usr/local/bin/docker-compose /usr/bin/docker-

RUN pip install tutor
RUN mkdir /opt/tutor
ENV TUTOR_ROOT /opt/tutor
ENV TUTOR_ROOT=/opt/tutor

EXPOSE 80
EXPOSE 443
Expand Down
1 change: 1 addition & 0 deletions changelog.d/20240621_172314_regis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- [Bugfix] Fix legacy warnings during Docker build. (by @regisb)
2 changes: 1 addition & 1 deletion tutor/hooks/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def your_filter_callback(some_data):
#: Python-based Docker image as well. The Dockerfile must declare mounted layers::
#:
#: {% for name in iter_mounted_directories(MOUNTS, "yourimage") %}
#: FROM scratch as mnt-{{ name }}
#: FROM scratch AS mnt-{{ name }}
#: {% endfor %}
#:
#: Then, Python packages are installed with::
Expand Down
60 changes: 30 additions & 30 deletions tutor/templates/build/openedx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# syntax=docker/dockerfile:1
###### Minimal image with base system requirements for most stages
FROM docker.io/ubuntu:20.04 as minimal
FROM docker.io/ubuntu:20.04 AS minimal
LABEL maintainer="Overhang.io <contact@overhang.io>"

ENV DEBIAN_FRONTEND=noninteractive
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt update && \
apt install -y build-essential curl git language-pack-en
ENV LC_ALL en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
{{ patch("openedx-dockerfile-minimal") }}

###### Install python with pyenv in /opt/pyenv and create virtualenv in /openedx/venv
FROM minimal as python
FROM minimal AS python
# https://github.com/pyenv/pyenv/wiki/Common-build-problems#prerequisites
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
Expand All @@ -25,7 +25,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
# https://www.python.org/downloads/
# https://github.com/pyenv/pyenv/releases
ARG PYTHON_VERSION=3.11.8
ENV PYENV_ROOT /opt/pyenv
ENV PYENV_ROOT=/opt/pyenv
RUN git clone https://github.com/pyenv/pyenv $PYENV_ROOT --branch v2.3.36 --depth 1

# Install Python
Expand All @@ -35,7 +35,7 @@ RUN $PYENV_ROOT/bin/pyenv install $PYTHON_VERSION
RUN $PYENV_ROOT/versions/$PYTHON_VERSION/bin/python -m venv /openedx/venv

###### Checkout edx-platform code
FROM minimal as code
FROM minimal AS code
ARG EDX_PLATFORM_REPOSITORY={{ EDX_PLATFORM_REPOSITORY }}
ARG EDX_PLATFORM_VERSION={{ EDX_PLATFORM_VERSION }}
RUN mkdir -p /openedx/edx-platform
Expand All @@ -61,19 +61,19 @@ RUN git config --global user.email "tutor@overhang.io" \
##### Empty layer with just the repo at the root.
# This is useful when overriding the build context with a host repo:
# docker build --build-context edx-platform=/path/to/edx-platform
FROM scratch as edx-platform
FROM scratch AS edx-platform
COPY --from=code /openedx/edx-platform /

{# Create empty layers for all bind-mounted directories #}
{% for name in iter_mounted_directories(MOUNTS, "openedx") %}
FROM scratch as mnt-{{ name }}
FROM scratch AS mnt-{{ name }}
{% endfor %}

###### Install python requirements in virtualenv
FROM python as python-requirements
ENV PATH /openedx/venv/bin:${PATH}
ENV VIRTUAL_ENV /openedx/venv/
ENV XDG_CACHE_HOME /openedx/.cache
FROM python AS python-requirements
ENV PATH=/openedx/venv/bin:${PATH}
ENV VIRTUAL_ENV=/openedx/venv/
ENV XDG_CACHE_HOME=/openedx/.cache

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
Expand Down Expand Up @@ -112,8 +112,8 @@ RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared \
{% endfor %}

###### Install nodejs with nodeenv in /openedx/nodeenv
FROM python as nodejs-requirements
ENV PATH /openedx/nodeenv/bin:/openedx/venv/bin:${PATH}
FROM python AS nodejs-requirements
ENV PATH=/openedx/nodeenv/bin:/openedx/venv/bin:${PATH}

# Install nodeenv with the version provided by edx-platform
# https://github.com/openedx/edx-platform/blob/master/requirements/edx/base.txt
Expand All @@ -130,7 +130,7 @@ RUN --mount=type=bind,from=edx-platform,source=/package.json,target=/openedx/edx
npm clean-install --no-audit --registry=$NPM_REGISTRY

###### Production image with system and python requirements
FROM minimal as production
FROM minimal AS production

# Install system requirements
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
Expand Down Expand Up @@ -163,11 +163,11 @@ COPY --link --chown=$APP_USER_ID:$APP_USER_ID --from=nodejs-requirements /opened
# Symlink node_modules such that we can bind-mount the edx-platform repository
RUN ln -s /openedx/node_modules /openedx/edx-platform/node_modules

ENV PATH /openedx/venv/bin:./node_modules/.bin:/openedx/nodeenv/bin:${PATH}
ENV VIRTUAL_ENV /openedx/venv/
ENV COMPREHENSIVE_THEME_DIRS /openedx/themes
ENV STATIC_ROOT_LMS /openedx/staticfiles
ENV STATIC_ROOT_CMS /openedx/staticfiles/studio
ENV PATH=/openedx/venv/bin:./node_modules/.bin:/openedx/nodeenv/bin:${PATH}
ENV VIRTUAL_ENV=/openedx/venv/
ENV COMPREHENSIVE_THEME_DIRS=/openedx/themes
ENV STATIC_ROOT_LMS=/openedx/staticfiles
ENV STATIC_ROOT_CMS=/openedx/staticfiles/studio

WORKDIR /openedx/edx-platform

Expand All @@ -185,9 +185,9 @@ RUN pip install -e .
# the tutor-specific settings files.
RUN mkdir -p /openedx/config ./lms/envs/tutor ./cms/envs/tutor
COPY --chown=app:app revisions.yml /openedx/config/
ENV LMS_CFG /openedx/config/lms.env.yml
ENV CMS_CFG /openedx/config/cms.env.yml
ENV REVISION_CFG /openedx/config/revisions.yml
ENV LMS_CFG=/openedx/config/lms.env.yml
ENV CMS_CFG=/openedx/config/cms.env.yml
ENV REVISION_CFG=/openedx/config/revisions.yml
COPY --chown=app:app settings/lms/*.py ./lms/envs/tutor/
COPY --chown=app:app settings/cms/*.py ./cms/envs/tutor/

Expand All @@ -208,7 +208,7 @@ RUN ./manage.py cms --settings=tutor.i18n compilejsi18n
# Copy scripts
COPY --chown=app:app ./bin /openedx/bin
RUN chmod a+x /openedx/bin/*
ENV PATH /openedx/bin:${PATH}
ENV PATH=/openedx/bin:${PATH}

{{ patch("openedx-dockerfile-pre-assets") }}

Expand Down Expand Up @@ -240,15 +240,15 @@ RUN echo \
> bindmount-canary

# service variant is "lms" or "cms"
ENV SERVICE_VARIANT lms
ENV DJANGO_SETTINGS_MODULE lms.envs.tutor.production
ENV SERVICE_VARIANT=lms
ENV DJANGO_SETTINGS_MODULE=lms.envs.tutor.production

{{ patch("openedx-dockerfile") }}

EXPOSE 8000

###### Intermediate image with dev/test dependencies
FROM production as development
FROM production AS development

# Install useful system requirements (as root)
USER root
Expand Down Expand Up @@ -285,12 +285,12 @@ RUN rm -r /openedx/staticfiles && \
{{ patch("openedx-dev-dockerfile-post-python-requirements") }}

# Default django settings
ENV DJANGO_SETTINGS_MODULE lms.envs.tutor.development
ENV DJANGO_SETTINGS_MODULE=lms.envs.tutor.development

CMD ./manage.py $SERVICE_VARIANT runserver 0.0.0.0:8000
CMD ["./manage.py", "$SERVICE_VARIANT", "runserver", "0.0.0.0:8000"]

###### Final image with production cmd
FROM production as final
FROM production AS final

# Default amount of uWSGI processes
ENV UWSGI_WORKERS=2
Expand All @@ -299,7 +299,7 @@ ENV UWSGI_WORKERS=2
COPY --chown=app:app settings/uwsgi.ini .

# Run server
CMD uwsgi uwsgi.ini
CMD ["uwsgi", "uwsgi.ini"]

{{ patch("openedx-dockerfile-final") }}

0 comments on commit d9a2c24

Please sign in to comment.