Skip to content

Commit

Permalink
Support multiple Open edX devstacks
Browse files Browse the repository at this point in the history
This allows for multiple edX devstacks (introduced via
https://github.com/edx/devstack/pull/532) by letting the user specify
which compose project to target.
  • Loading branch information
Adolfo R. Brandes authored and arbrandes committed Sep 30, 2020
1 parent aeb7265 commit 0103e22
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
51 changes: 31 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,45 @@ help:
@echo ""

VIRTUAL_ENV?=/blockstore/venv
OLD_VERSION=3.5
PYTHON_VERSION?=3.8
ifeq ($(PYTHON_VERSION), $(OLD_VERSION))
CONTAINER_NAME=edx.devstack.blockstore.old
else
CONTAINER_NAME=edx.devstack.blockstore
endif
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.yml

# Open edX Docker configuration
OPENEDX_PROJECT_NAME?=devstack

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.mysql /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}.mysql /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 -f docker-compose.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
docker pull python:3.5.7-alpine3.9

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 Down Expand Up @@ -75,19 +86,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.mysql /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}.mysql /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.mysql /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}.mysql /bin/bash -c 'mysql -uroot <<< "drop database blockstore_test_db;"'

html_coverage: ## Generate HTML coverage report
${VENV_BIN}/coverage html
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

0 comments on commit 0103e22

Please sign in to comment.