Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Support multiple Open edX devstacks #88

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,46 @@ help:

VIRTUAL_ENV?=/blockstore/venv
PYTHON_VERSION=3.8
CONTAINER_NAME=edx.devstack.blockstore
VENV_BIN=${VIRTUAL_ENV}/bin

# Blockstore Docker configuration
BLOCKSTORE_PROJECT_NAME?=blockstore${PYTHON_VERSION}
BLOCKSTORE_DOCKER_COMPOSE_OPTS=-p ${BLOCKSTORE_PROJECT_NAME} -f docker-compose-${PYTHON_VERSION}.yml

# Blockstore test server Docker configuration
BLOCKSTORE_TESTSERVER_PROJECT_NAME?=blockstore-testserver${PYTHON_VERSION}
BLOCKSTORE_TESTSERVER_DOCKER_COMPOSE_OPTS=-p ${BLOCKSTORE_TESTSERVER_PROJECT_NAME} -f docker-compose-testserver-${PYTHON_VERSION}.yml

# Open edX Docker configuration
OPENEDX_PROJECT_NAME?=devstack

dev.build: # Start Blockstore container
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} build --no-cache

dev.up: # Start Blockstore container
docker-compose --project-name "blockstore${PYTHON_VERSION}" -f "docker-compose-${PYTHON_VERSION}.yml" up -d
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} up -d

dev.provision: # Provision Blockstore service
docker exec -t edx.devstack.mysql57 /bin/bash -c 'mysql -uroot <<< "create database if not exists blockstore_db;"'
docker exec -t ${CONTAINER_NAME} /bin/bash -c 'source ~/.bashrc && make requirements && make migrate'
docker exec -t edx.${OPENEDX_PROJECT_NAME}.mysql57 /bin/bash -c 'mysql -uroot <<< "create database if not exists blockstore_db;"'
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} exec blockstore /bin/bash -c 'source ~/.bashrc && make requirements && make migrate'

dev.run: dev.up # Run the service in the foreground
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} exec blockstore /blockstore/venv/bin/python /blockstore/app/manage.py runserver 0.0.0.0:18250

dev.run-detached: dev.up # Run the service in the background
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} exec -d blockstore /blockstore/venv/bin/python /blockstore/app/manage.py runserver 0.0.0.0:18250

stop: # Stop Blockstore container
docker-compose --project-name blockstore${PYTHON_VERSION} -f docker-compose-${PYTHON_VERSION}.yml stop
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} stop

pull: # Update docker images that this depends on.
docker pull python:3.8.5-alpine3.12

destroy: # Remove Blockstore container, network and volumes. Destructive.
docker-compose --project-name "blockstore${PYTHON_VERSION}" -f "docker-compose-${PYTHON_VERSION}.yml" down -v
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} down -v

blockstore-shell: # Open a shell on the running Blockstore container
docker exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" -it ${CONTAINER_NAME} /bin/bash
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} exec -e COLUMNS="`tput cols`" -e LINES="`tput lines`" blockstore /bin/bash

clean: ## Remove all generated files
find . -name '*.pyc' -delete
Expand All @@ -52,7 +71,7 @@ requirements-test: ## Install requirements for testing
${VENV_BIN}/pip install -r requirements/test.txt --exists-action w

production-requirements:
pip install -r requirements/production.txt --exists-action w
${VENV_BIN}/pip install -r requirements/production.txt --exists-action w

migrate: ## Apply database migrations
${VENV_BIN}/python manage.py migrate --no-input
Expand All @@ -71,19 +90,19 @@ test: clean ## Run tests and generate coverage report

easyserver: dev.up dev.provision # Start and provision a Blockstore container and run the server until CTRL-C, then stop it
# Now run blockstore until the user hits CTRL-C:
docker-compose --project-name "blockstore${PYTHON_VERSION}" -f "docker-compose-${PYTHON_VERSION}.yml" exec blockstore /blockstore/venv/bin/python /blockstore/app/manage.py runserver 0.0.0.0:18250
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} exec blockstore /blockstore/venv/bin/python /blockstore/app/manage.py runserver 0.0.0.0:18250
# Then stop the container:
docker-compose --project-name blockstore${PYTHON_VERSION} -f docker-compose-${PYTHON_VERSION}.yml stop
docker-compose ${BLOCKSTORE_DOCKER_COMPOSE_OPTS} stop

testserver: # Run an isolated ephemeral instance of Blockstore for use by edx-platform tests
docker-compose --project-name "blockstore-testserver${PYTHON_VERSION}" -f "docker-compose-testserver-${PYTHON_VERSION}.yml" up -d
docker exec -t edx.devstack.mysql57 /bin/bash -c 'mysql -uroot <<< "create database if not exists blockstore_test_db;"'
docker exec -t ${CONTAINER_NAME}-test /bin/bash -c 'source ~/.bashrc && make requirements && make migrate && ./manage.py shell < provision-testserver-data.py'
docker-compose ${BLOCKSTORE_TESTSERVER_DOCKER_COMPOSE_OPTS} up -d
docker exec -t edx.${OPENEDX_PROJECT_NAME}.mysql57 /bin/bash -c 'mysql -uroot <<< "create database if not exists blockstore_test_db;"'
docker-compose ${BLOCKSTORE_TESTSERVER_DOCKER_COMPOSE_OPTS} exec blockstore /bin/bash -c 'source ~/.bashrc && make requirements && make migrate && ./manage.py shell < provision-testserver-data.py'
# Now run blockstore until the user hits CTRL-C:
docker-compose --project-name "blockstore-testserver${PYTHON_VERSION}" -f "docker-compose-testserver-${PYTHON_VERSION}.yml" exec blockstore /blockstore/venv/bin/python /blockstore/app/manage.py runserver 0.0.0.0:18251
docker-compose ${BLOCKSTORE_TESTSERVER_DOCKER_COMPOSE_OPTS} exec blockstore /blockstore/venv/bin/python /blockstore/app/manage.py runserver 0.0.0.0:18251
# And destroy everything except the virtualenv volume (which we want to reuse to save time):
docker-compose --project-name "blockstore-testserver${PYTHON_VERSION}" -f "docker-compose-testserver-${PYTHON_VERSION}.yml" down
docker exec -t edx.devstack.mysql57 /bin/bash -c 'mysql -uroot <<< "drop database blockstore_test_db;"'
docker-compose ${BLOCKSTORE_TESTSERVER_DOCKER_COMPOSE_OPTS} down
docker exec -t edx.${OPENEDX_PROJECT_NAME}.mysql57 /bin/bash -c 'mysql -uroot <<< "drop database blockstore_test_db;"'

html_coverage: ## Generate HTML coverage report
${VENV_BIN}/coverage html
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ Prerequisite: Have your Open edX `Devstack <https://github.com/edx/devstack>`_ p
#. In ``private.py``, set ``SOCIAL_AUTH_EDX_OAUTH2_SECRET`` to the random "Client secret" value.
#. Now you can login at http://localhost:18250/login/

#. Optional: If running an Open edX devstack under a project name different
than the default (support for which was introduced
[here](https://github.com/edx/devstack/pull/532)), simply export
``OPENEDX_PROJECT_NAME`` and substitute the container names in the commands
above accordingly.

Running Tests
=============
Expand Down
10 changes: 6 additions & 4 deletions docker-compose-3.8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:

blockstore:
container_name: edx.devstack.blockstore
container_name: edx.${OPENEDX_PROJECT_NAME:-devstack}.blockstore
image: opencraft/blockstore:latest
build:
context: .
Expand All @@ -12,8 +12,10 @@ services:
tty: true
entrypoint: ["/bin/bash"]
networks:
- default
- devstack
default:
devstack:
aliases:
- edx.devstack.blockstore
ports:
- "18250:18250"
volumes:
Expand All @@ -29,7 +31,7 @@ services:
networks:
devstack:
external:
name: devstack_default
name: ${OPENEDX_PROJECT_NAME:-devstack}_default

volumes:
blockstore_venv_3_8_5:
10 changes: 6 additions & 4 deletions docker-compose-testserver-3.8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: '3'
services:

blockstore:
container_name: edx.devstack.blockstore-test
container_name: edx.${OPENEDX_PROJECT_NAME:-devstack}.blockstore-test
image: opencraft/blockstore:latest
build:
context: .
Expand All @@ -15,8 +15,10 @@ services:
tty: true
entrypoint: ["/bin/bash"]
networks:
- default
- devstack
default:
devstack:
aliases:
- edx.devstack.blockstore-test
ports:
- "18251:18251"
volumes:
Expand All @@ -32,7 +34,7 @@ services:
networks:
devstack:
external:
name: devstack_default
name: ${OPENEDX_PROJECT_NAME:-devstack}_default

volumes:
blockstore_venv_3_8_5:
Expand Down