Skip to content

Commit

Permalink
feat: docker-based local work without lms
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnagro committed Sep 6, 2023
1 parent c5cfc5e commit ff8bf8d
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 1 deletion.
98 changes: 98 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Docker in this repo is only supported for running tests locally
# as an alternative to virtualenv natively - johnnagro 2023-09-06
FROM ubuntu:focal as app
LABEL org.opencontainers.image.authors="[email protected]"


# Packages installed:
# git; Used to pull in particular requirements from github rather than pypi,
# and to check the sha of the code checkout.

# build-essentials; so we can use make with the docker container

# language-pack-en locales; ubuntu locale support so that system utilities have a consistent
# language and time zone.

# python; ubuntu doesnt ship with python, so this is the python we will use to run the application

# python3-pip; install pip to install application requirements.txt files

# pkg-config
# mysqlclient>=2.2.0 requires this (https://github.com/PyMySQL/mysqlclient/issues/620)

# libmysqlclient-dev; to install header files needed to use native C implementation for
# MySQL-python for performance gains.

# libssl-dev; # mysqlclient wont install without this.

# python3-dev; to install header files for python extensions; much wheel-building depends on this

# gcc; for compiling python extensions distributed with python packages like mysql-client

# If you add a package here please include a comment above describing what it is used for
RUN apt-get update && apt-get -qy install --no-install-recommends \
language-pack-en \
locales \
python3.8 \
python3-pip \
python3.8-venv \
pkg-config \
libmysqlclient-dev \
libssl-dev \
python3-dev \
gcc \
build-essential \
git \
curl


RUN pip install --upgrade pip setuptools
# delete apt package lists because we do not need them inflating our image
RUN rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/python3 /usr/bin/python

RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV DJANGO_SETTINGS_MODULE test_settings

# Env vars: path
ENV VIRTUAL_ENV='/edx/app/venvs/edx-arch-experiments'
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
ENV PATH="/edx/app/edx-arch-experiments/node_modules/.bin:${PATH}"
ENV PATH="/edx/app/edx-arch-experiments/bin:${PATH}"
ENV PATH="/edx/app/nodeenv/bin:${PATH}"

RUN useradd -m --shell /bin/false app

WORKDIR /edx/app/edx-arch-experiments

RUN python3.8 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Copy the requirements explicitly even though we copy everything below
# this prevents the image cache from busting unless the dependencies have changed.
COPY requirements/ /edx/app/edx-arch-experiments/requirements/

# Dependencies are installed as root so they cannot be modified by the application user.
RUN pip install -r requirements/dev.txt
RUN pip install nodeenv

# Set up a Node environment and install Node requirements.
# Must be done after Python requirements, since nodeenv is installed
# via pip.
# The node environment is already 'activated' because its .../bin was put on $PATH.
RUN nodeenv /edx/app/nodeenv --node=18.15.0 --prebuilt

RUN mkdir -p /edx/var/log

# Code is owned by root so it cannot be modified by the application user.
# So we copy it before changing users.
USER app

# This line is after the requirements so that changes to the code will not
# bust the image cache
COPY . /edx/app/edx-arch-experiments

5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ dummy_translations: ## generate dummy translation (.po) files
build_dummy_translations: extract_translations dummy_translations compile_translations ## generate and compile dummy translation files

validate_translations: build_dummy_translations detect_changed_source_translations ## validate translations

## Docker in this repo is only supported for running tests locally
## as an alternative to virtualenv natively - johnnagro 2022-02-11
test-shell: ## Run a shell, as root, on the specified service container
docker-compose run -u 0 test-shell env TERM=$(TERM) /bin/bash
6 changes: 5 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ One Time Setup
Local testing
~~~~~~~~~~~~~
To test your changes locally, you will need to install the package from your local branch into edx-platform. For example, if using devstack, copy or clone your branch into <devstack-parent>/src/edx-arch-experiments. Then, in an lms or cms shell, run ``pip install -e /edx/src/edx-arch-experiments``. The plug-in configuration will automatically be picked up once installed, and changes will be hot reloaded.
Two options are available for testing changes locally:

First, via `make test-shell` a dockerized development envrionment can be launched to run `pytest` and do basic migration work.

Second, a local copy of the package can be installed into edx-platform. For example, if using devstack, copy or clone your branch into <devstack-parent>/src/edx-arch-experiments. Then, in an lms or cms shell, run ``pip install -e /edx/src/edx-arch-experiments``. The plug-in configuration will automatically be picked up once installed, and changes will be hot reloaded.


Every time you develop something in this repo
Expand Down
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Docker in this repo is only supported for running tests locally
# as an alternative to virtualenv natively - johnnagro 2022-02-11
version: "2.1"
services:
test-shell:
build:
context: .
dockerfile: Dockerfile
container_name: arch-experiments.test.app
hostname: app.test.arch-experiments
volumes:
- .:/edx/app/edx-arch-experiments

networks:
- devstack_default
# Allows attachment to this container using 'docker attach <containerID>'.
stdin_open: true
tty: true
environment:
DJANGO_SETTINGS_MODULE: test_settings

networks:
devstack_default:
external: true

0 comments on commit ff8bf8d

Please sign in to comment.