Skip to content

Commit

Permalink
⬆️(core) upgrade edxapp to hawthorn.1
Browse files Browse the repository at this point in the history
The current work migrates Fonzie to our new edxapp images and a recent
release of edxapp, e.g. hawthorn.1

We've swiched our Docker image and compose environment to the standard
ones used in our projects.

Unused convenience scripts have been removed from the project.
  • Loading branch information
jmaupetit committed Apr 24, 2019
1 parent c3b5920 commit 9411b69
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 226 deletions.
18 changes: 18 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Django
SERVICE_VARIANT=lms
DJANGO_SETTINGS_MODULE=lms.envs.fun.docker_run_development

# Database
MYSQL_ROOT_PASSWORD=
MYSQL_ALLOW_EMPTY_PASSWORD=yes
MYSQL_DATABASE=edxapp
MYSQL_USER=edxapp_user
MYSQL_PASSWORD=password

# Email
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=mailcatcher
EMAIL_PORT=1025

# Python
PYTHONUNBUFFERED=1
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,3 @@ default.db
node_modules
yarn-error.log

# Local development environment
env.d/local
89 changes: 43 additions & 46 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
FROM fundocker/edxapp:ginkgo.1-1.0.3-dev
FROM fundocker/edxapp:hawthorn.1-2.6.0

# Disclaimer:
#
# This image is not intended to be used in production. For now, it has been
# designed to ease Fonzie's development. In a near future, we will cook a
# production-ready image and rename this Dockerfile as Dockerfile-dev.

# Dependencies
ENV DOCKERIZE_VERSION v0.6.0

# Get container user and group ids via build arguments
# Default: 0:0 (root:root)
ARG user=0
ARG group=0

# Add a non-privileged user to run the application if given as a build argument
RUN if [ ${user} -ne 0 -a ${group} -ne 0 ]; then \
groupadd --gid $group app ; \
useradd --uid $user --gid $group --home /app app ; \
fi

# Install dockerize
RUN curl -L \
--output dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && \
rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

# Add application sources
ADD . /app/fonzie/

# Install application and project requirements
RUN cd /app/fonzie && \
pip install --exists-action w -r requirements-dev.txt

# FIXME: pyopenssl seems to be linked with a wrong openssl release leading to
# bad handskake ssl errors. This looks ugly, but forcing pyopenssl
# re-installation solves this issue.
RUN pip install -U pyopenssl

# Run container with the $user:$group user
#
# We recommend to build the container with the following build arguments to map
# container user with the HOST user:
ARG USER_ID=1000
ARG GROUP_ID=1000

# Switch back to a priviledged user to perform base installation
USER root:root

# Install dockerize to wait for mysql before running the container command
# (and prevent connection issues)
ENV DOCKERIZE_VERSION v0.6.1
RUN python -c "import requests;open('dockerize-linux-amd64.tar.gz', 'wb').write(requests.get('https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/dockerize-linux-amd64-${DOCKERIZE_VERSION}.tar.gz', allow_redirects=True).content)" && \
tar -C /usr/local/bin -xzvf dockerize-linux-amd64.tar.gz && \
rm dockerize-linux-amd64.tar.gz

# Add the non-privileged user that will run the application
RUN groupadd -f --gid ${GROUP_ID} edx && \
useradd --uid ${USER_ID} --gid ${GROUP_ID} --home /edx edx

# Allow the edx user to create files in /edx/var (required to perform database
# migrations)
RUN mkdir /edx/var && \
chown edx:edx /edx/var

# FIXME: as mentionned in fun-platform and edx-platform bug tracker, this
# webpack-stats.json is required both in production and development in a static
# directory 😢
#
# docker build --build-arg user=$(id -u) --build-arg group=$(id -g)
USER $user:$group
# Also, the /edx/var tree should be writable by the running user to perform
# collectstatic and migrations.
RUN mkdir -p /edx/app/edxapp/staticfiles/studio && \
chown -R edx:edx /edx/var && \
cp /edx/app/edxapp/edx-platform/common/static/webpack-stats.json /edx/app/edxapp/staticfiles/ && \
cp /edx/app/edxapp/edx-platform/common/static/studio/webpack-stats.json /edx/app/edxapp/staticfiles/studio/

# Copy the app to the working directory
COPY --chown=edx:edx . /edx/app/fonzie/

# Install development dependencies and perform a base installation of the app
RUN cd /edx/app/fonzie/ && \
pip install --no-cache-dir -r requirements-dev.txt

# Switch to an un-privileged user matching the host user to prevent permission
# issues with volumes (host folders)
USER ${USER_ID}:${GROUP_ID}
34 changes: 20 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"

# Dockerized tools
# -- Docker
COMPOSE = bin/compose
COMPOSE_BUILD = bin/build
COMPOSE_RUN = bin/run
# Get local user ids
USER_ID = $(shell id -u)
GROUP_ID = $(shell id -g)

# Docker
COMPOSE = USER_ID=$(USER_ID) GROUP_ID=$(GROUP_ID) docker-compose
COMPOSE_RUN = $(COMPOSE) run --rm
COMPOSE_RUN_LMS = $(COMPOSE_RUN) lms
COMPOSE_RUN_FONZIE = $(COMPOSE_RUN) fonzie
COMPOSE_EXEC = $(COMPOSE) exec

# Django
MANAGE_LMS = $(COMPOSE_EXEC) lms dockerize -wait tcp://mysql:3306 -timeout 60s python manage.py lms

# -- Python
COVERAGE = $(COMPOSE_RUN) -e CODECOV_TOKEN lms coverage
DIFF-COVER = $(COMPOSE_RUN_FONZIE) diff-cover
PYTEST = $(COMPOSE_RUN_LMS) dockerize -wait tcp://mysql:3306 -timeout 60s \
pytest -c /edxapp/app/fonzie/setup.cfg
PYTEST = $(COMPOSE_RUN_LMS) dockerize -wait tcp://mysql:3306 -timeout 60s pytest -c /edx/app/fonzie/setup.cfg

#
# RULES
Expand All @@ -37,12 +40,11 @@ help: ## display this help message
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}'
.PHONY: help

bootstrap: build ## bootstrap the project
$(COMPOSE_RUN_LMS) python manage.py lms migrate
bootstrap: run migrate ## bootstrap the project
.PHONY: bootstrap

build: ## build project containers
$(COMPOSE_BUILD) lms
$(COMPOSE) build lms
.PHONY: build

clean: ## remove generated byte code, coverage reports, and build artifacts
Expand Down Expand Up @@ -75,6 +77,10 @@ docs: ## generate Sphinx HTML documentation, including API docs
$(BROWSER) docs/_build/html/index.html
.PHONY: docs

migrate: run ## run project migrations
$(MANAGE_LMS) migrate
.PHONY: migrate

quality: ## check coding style with pycodestyle and pylint
touch tests/__init__.py
$(COMPOSE_RUN_FONZIE) pylint fonzie tests test_utils
Expand All @@ -88,7 +94,7 @@ quality: ## check coding style with pycodestyle and pylint
.PHONY: quality

report: ## publish test coverage report
$(COVERAGE) --commit=${CIRCLE_SHA1}
$(COMPOSE_RUN) -e CODECOV_TOKEN lms codecov --commit=${CIRCLE_SHA1}
.PHONY: report

run: ## start development server
Expand All @@ -103,7 +109,7 @@ stop: ## stop development server
$(COMPOSE) stop
.PHONY: stop

test: clean ## run python tests suite
test: ## run python tests suite
# Create .pytest_cache directory with appropriate permissions. We cannot
# rely on docker-compose volume as if the directory does not exists, it will
# create one owned by root:root.
Expand Down
5 changes: 0 additions & 5 deletions bin/build

This file was deleted.

5 changes: 0 additions & 5 deletions bin/compose

This file was deleted.

90 changes: 0 additions & 90 deletions bin/config.sh

This file was deleted.

5 changes: 0 additions & 5 deletions bin/exec

This file was deleted.

5 changes: 4 additions & 1 deletion bin/pytest
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE[0]}")/config.sh"
declare -r USER_ID="$(id -u)"
export USER_ID
declare -r GROUP_ID="$(id -g)"
export GROUP_ID

docker-compose run --rm lms \
dockerize -wait tcp://mysql:3306 -timeout 60s \
Expand Down
5 changes: 0 additions & 5 deletions bin/run

This file was deleted.

0 comments on commit 9411b69

Please sign in to comment.