diff --git a/Makefile b/Makefile index cd797e15..6b78eab7 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 diff --git a/docker-compose-3.8.yml b/docker-compose-3.8.yml index 4b739653..5636be92 100644 --- a/docker-compose-3.8.yml +++ b/docker-compose-3.8.yml @@ -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: . @@ -12,8 +12,10 @@ services: tty: true entrypoint: ["/bin/bash"] networks: - - default - - devstack + default: + devstack: + aliases: + - edx.devstack.blockstore ports: - "18250:18250" volumes: @@ -29,7 +31,7 @@ services: networks: devstack: external: - name: devstack_default + name: ${OPENEDX_PROJECT_NAME:-devstack}_default volumes: blockstore_venv_3_8_5: diff --git a/docker-compose-testserver-3.8.yml b/docker-compose-testserver-3.8.yml index 70741772..c5ba245f 100644 --- a/docker-compose-testserver-3.8.yml +++ b/docker-compose-testserver-3.8.yml @@ -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: . @@ -15,8 +15,10 @@ services: tty: true entrypoint: ["/bin/bash"] networks: - - default - - devstack + default: + devstack: + aliases: + - edx.devstack.blockstore-test ports: - "18251:18251" volumes: @@ -32,7 +34,7 @@ services: networks: devstack: external: - name: devstack_default + name: ${OPENEDX_PROJECT_NAME:-devstack}_default volumes: blockstore_venv_3_8_5: