Skip to content

Commit

Permalink
feat(docker) integrate fonzie in an Open edX stack (#3)
Browse files Browse the repository at this point in the history
** FEATURE DETAILS **

Switch to a docker-based environment using fun-platform docker images
[1] to integrate Fonzie in an Open edX dockerized stack. Here are the
steps we followed to implement this feature:

- use fun-platform base docker image
- override required settings to install fonzie app and its urls
- use docker containers for all Makefile targets
- add shortcut scripts in bin/ directory to ease running:
  - docker-compose
  - docker-compose build
  - docker-compose run
  - tox
  - ci
- use Fonzie's container in TravisCI

[1] https://github.com/openfun/fun-platform/

** FIXES **

- Update project baseline to: 'Fonzie, a FUN API for Open edX'

** REMARKS **

Stick fonzie dependencies to current edx-platform (ginkgo) pinned
releases for Django (1.8.18) and Django Rest Framework (aka DRF, 3.2.3).

These are temporary contraints. We will upgrade Django and DRF when Open
edX will switch to Django 1.11 for the upcoming release (Hawthorn). We
will then restore OpenAPI schema (thanks to drf_openapi).

** KNOWN ISSUES **

pyopenssl package needs to be rebuild in a supplementary step of our
Dockerfile to avoid SSL handbrake issues.
  • Loading branch information
jmaupetit committed Mar 9, 2018
1 parent 68e3313 commit 45cf27e
Show file tree
Hide file tree
Showing 37 changed files with 562 additions and 252 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.coverage
.coveragerc
.git
.tox
.tx
node_modules
venv
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ __pycache__
*.egg
*.egg-info
dist
build
build/
eggs
parts
bin
var
sdist
develop-eggs
Expand Down Expand Up @@ -82,3 +81,6 @@ default.db
# Node.js
node_modules
yarn-error.log

# Local development environment
env.d/local
39 changes: 14 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
# Config file for automatic testing at travis-ci.org
sudo: required

language: python

python:
- 2.7
- 3.6
cache:
directories:
- $HOME/.cache/db
- node_modules

env:
- TOXENV=django111
- TOXENV=django20

matrix:
exclude:
- python: 2.7
env: TOXENV=django20
include:
- python: 2.7
env: TOXENV=quality
- python: 2.7
env: TOXENV=docs
- python: 2.7
env: TOXENV=spec

cache:
- pip
- TOXENV=quality
- TOXENV=docs
- TOXENV=django18
- API_SPEC=1 OPENEDX_RELEASE=ginkgo.1

before_install:
- pip install --upgrade pip
# Upgrade docker-compose
- bin/ci before-install

install:
- pip install -r requirements/travis.txt
- yarn install
- bin/ci install

script:
- tox
- bin/ci script

after_success:
- codecov
- bin/ci after-success

# Set password via "travis encrypt --add deploy.password"; for details, see
# https://docs.travis-ci.com/user/deployment/pypi
Expand Down
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM fundocker/edxapp:ginkgo.1-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
RUN groupadd --gid $group app && \
useradd --uid $user --gid $group --home /app --create-home app

# 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

# Install project requirements
ADD ./requirements /app/fonzie/requirements
RUN pip install -q --exists-action w \
-r /app/fonzie/requirements/dev.txt \
-r /app/fonzie/requirements/private.*

# Add application sources
ADD . /app/fonzie/

# Install django application in development mode
RUN cd /app/fonzie && \
pip install -e .

# 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 recommand to build the container with the following build arguments to map container user
# with the HOST user:
# docker build --build-arg user=$(id -u) --build-arg group=$(id -g)
USER $user:$group
114 changes: 60 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: clean compile_translations coverage docs dummy_translations \
extract_translations fake_translations help pull_translations push_translations \
quality requirements selfcheck test test-all upgrade validate
quality requirements run selfcheck stop test test-all upgrade validate

.DEFAULT_GOAL := help

Expand All @@ -16,88 +16,94 @@ endef
export BROWSER_PYSCRIPT
BROWSER := python -c "$$BROWSER_PYSCRIPT"

# Auth
USER_ID = $(shell id -u)
GROUP_ID = $(shell id -g)

# Dockerized tools
# -- Docker
COMPOSE = docker-compose
COMPOSE_BUILD = $(COMPOSE) build --build-arg user=$(USER_ID) --build-arg group=$(GROUP_ID)
COMPOSE_RUN = $(COMPOSE) run --rm --user=$(USER_ID):$(GROUP_ID)
COMPOSE_RUN_LMS = $(COMPOSE_RUN) lms
COMPOSE_RUN_FONZIE = $(COMPOSE_RUN) fonzie
COMPOSE_RUN_NODE = $(COMPOSE_RUN) node

# -- Python
COVERAGE = $(COMPOSE_RUN_FONZIE) coverage
DIFF-COVER = $(COMPOSE_RUN_FONZIE) diff-cover
PIP = $(COMPOSE_RUN_FONZIE) pip
PIP-COMPILE = $(COMPOSE_RUN_FONZIE) pip-compile
PIP-SYNC = $(COMPOSE_RUN_FONZIE) pip-sync
PYTEST = $(COMPOSE_RUN_FONZIE) pytest
TOX = $(COMPOSE_RUN_FONZIE) tox

# -- Node
YARN = $(COMPOSE_RUN_NODE) yarn


help: ## display this help message
@echo "Please use \`make <target>' where <target> is one of"
@perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}'

clean: ## remove generated byte code, coverage reports, and build artifacts
find . -name '__pycache__' -exec rm -rf {} +
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
coverage erase
rm -fr build/
rm -fr dist/
rm -fr *.egg-info
$(COMPOSE_RUN_FONZIE) find . -name '__pycache__' -exec rm -rf {} +
$(COMPOSE_RUN_FONZIE) find . -name '*.pyc' -exec rm -f {} +
$(COMPOSE_RUN_FONZIE) find . -name '*.pyo' -exec rm -f {} +
$(COMPOSE_RUN_FONZIE) find . -name '*~' -exec rm -f {} +
$(COVERAGE) erase
$(COMPOSE_RUN_FONZIE) rm -fr build/
$(COMPOSE_RUN_FONZIE) rm -fr dist/
$(COMPOSE_RUN_FONZIE) rm -fr *.egg-info

coverage: clean ## generate and view HTML coverage report
py.test --cov-report html
$(PYTEST) --cov-report html
$(BROWSER) htmlcov/index.html

docs: ## generate Sphinx HTML documentation, including API docs
tox -e docs
$(TOX) -e docs
$(BROWSER) docs/_build/html/index.html

upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
pip install -q pip-tools
pip-compile --upgrade -o requirements/dev.txt requirements/base.in requirements/dev.in requirements/quality.in
pip-compile --upgrade -o requirements/doc.txt requirements/base.in requirements/doc.in
pip-compile --upgrade -o requirements/quality.txt requirements/quality.in
pip-compile --upgrade -o requirements/test.txt requirements/base.in requirements/test.in
pip-compile --upgrade -o requirements/travis.txt requirements/travis.in
$(PIP) install -q pip-tools
$(PIP-COMPILE) --upgrade -o requirements/dev.txt requirements/base.in requirements/dev.in requirements/quality.in
$(PIP-COMPILE) --upgrade -o requirements/doc.txt requirements/base.in requirements/doc.in
$(PIP-COMPILE) --upgrade -o requirements/quality.txt requirements/quality.in
$(PIP-COMPILE) --upgrade -o requirements/test.txt requirements/base.in requirements/test.in
$(PIP-COMPILE) --upgrade -o requirements/travis.txt requirements/travis.in
# Let tox control the Django version for tests
sed '/^django==/d' requirements/test.txt > requirements/test.tmp
mv requirements/test.tmp requirements/test.txt
$(COMPOSE_RUN_FONZIE) sed '/^django==/d' requirements/test.txt > requirements/test.tmp
$(COMPOSE_RUN_FONZIE) mv requirements/test.tmp requirements/test.txt

quality: ## check coding style with pycodestyle and pylint
tox -e quality
$(TOX) -e quality

requirements: ## install development environment requirements
pip install -qr requirements/dev.txt --exists-action w
pip-sync requirements/dev.txt requirements/private.* requirements/test.txt
yarn install
$(COMPOSE_BUILD) lms
$(COMPOSE_BUILD) fonzie
$(YARN) install

test: clean ## run tests in the current virtualenv
py.test
$(PYTEST)

diff_cover: test
diff-cover coverage.xml
$(DIFF-COVER) coverage.xml

test-all: ## run tests on every supported Python/Django combination
tox -e quality
tox -e spec
tox
$(TOX) -e quality
$(TOX)

test-spec: # run tests on API specification (API blueprint)
yarn dredd
test-spec: ## run tests on API specification (API blueprint)
$(COMPOSE) up -d lms
$(YARN) dredd

validate: quality test ## run tests and quality checks

selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."

## Localization targets

extract_translations: ## extract strings to be translated, outputting .mo files
rm -rf docs/_build
cd fonzie && ../manage.py makemessages -l en -v1 -d django
cd fonzie && ../manage.py makemessages -l en -v1 -d djangojs

compile_translations: ## compile translation files, outputting .po files for each supported language
cd fonzie && ../manage.py compilemessages

detect_changed_source_translations:
cd fonzie && i18n_tool changed

pull_translations: ## pull translations from Transifex
tx pull -af --mode reviewed

push_translations: ## push source translation files (.po) from Transifex
tx push -s

dummy_translations: ## generate dummy translation (.po) files
cd fonzie && i18n_tool dummy

build_dummy_translations: extract_translations dummy_translations compile_translations ## generate and compile dummy translation files
run: ## start develppment server
$(COMPOSE) up -d

validate_translations: build_dummy_translations detect_changed_source_translations ## validate translations
stop: ## stop development server
$(COMPOSE) stop
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Fonzie, an Open API for Open edX
================================
Fonzie, a FUN API for Open edX
==============================

|pypi-badge| |travis-badge| |codecov-badge| |doc-badge| |pyversions-badge|
|license-badge|
Expand Down
5 changes: 5 additions & 0 deletions bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

source "$(dirname "${BASH_SOURCE[0]}")/config.sh"

_dc_build "$@"

0 comments on commit 45cf27e

Please sign in to comment.