From 3769273f691da2b2155e11a2e7698901606b756e Mon Sep 17 00:00:00 2001 From: Muhammad Soban Javed Date: Thu, 21 Nov 2024 02:27:12 +0500 Subject: [PATCH] feat: add enterprise-access to devstack --- check.sh | 6 ++++ docker-compose-host.yml | 7 ++++ docker-compose.yml | 63 ++++++++++++++++++++++++++++++++++ docs/service_list.rst | 3 ++ options.mk | 4 +-- provision-enterprise-access.sh | 28 +++++++++++++++ provision-mysql80.sql | 4 +++ provision.sh | 1 + provision.sql | 3 ++ repo.sh | 2 ++ 10 files changed, 119 insertions(+), 2 deletions(-) create mode 100755 provision-enterprise-access.sh diff --git a/check.sh b/check.sh index 3c0781f025..c85a204217 100755 --- a/check.sh +++ b/check.sh @@ -114,6 +114,12 @@ if should_check ecommerce; then "curl --fail -L http://localhost:18130/health/" fi +if should_check enterprise_access; then + echo "Checking enterprise-access health:" + run_check enterprise_access_heartbeat enterprise-access \ + "curl --fail -L http://localhost:18130/health/" +fi + if should_check discovery; then echo "Checking discovery health:" run_check discovery_heartbeat discovery \ diff --git a/docker-compose-host.yml b/docker-compose-host.yml index 5941bfbdc2..17c62b85f0 100644 --- a/docker-compose-host.yml +++ b/docker-compose-host.yml @@ -18,6 +18,13 @@ services: - ecommerce_node_modules:/edx/app/ecommerce/ecommerce/node_modules - ecommerce_tox:/edx/app/ecommerce/ecommerce/.tox - ${DEVSTACK_WORKSPACE}/src:/edx/src + enterprise-access: + volumes: + - ${DEVSTACK_WORKSPACE}/enterprise-access:/edx/app/enterprise-access/ + - ${DEVSTACK_WORKSPACE}/src:/edx/src + enterprise-access-worker: + volumes: + - ${DEVSTACK_WORKSPACE}/enterprise-access:/edx/app/enterprise-access/ forum: volumes: - ${DEVSTACK_WORKSPACE}/cs_comments_service:/edx/app/forum/cs_comments_service diff --git a/docker-compose.yml b/docker-compose.yml index a165a6bf22..e2a3116276 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -386,6 +386,69 @@ services: ELASTICSEARCH_URL: "http://edx.devstack.elasticsearch710:9200" ELASTICSEARCH_DSL: "http://edx.devstack.elasticsearch710:9200" + enterprise-access: + image: edxops/enterprise-access-dev + container_name: "edx.${COMPOSE_PROJECT_NAME:-devstack}.enterprise-access" + hostname: enterprise-access.devstack.edx + command: bash -c 'while true; do python /edx/app/enterprise-access/manage.py runserver 0.0.0.0:18270; sleep 2; done' + ports: + - "18270:18270" + depends_on: + - mysql80 + - memcached + - enterprise-access-worker + networks: + default: + aliases: + - edx.devstack.enterprise-access + stdin_open: true + tty: true + environment: + CELERY_ALWAYS_EAGER: 'false' + CELERY_BROKER_TRANSPORT: redis + CELERY_BROKER_HOSTNAME: edx.devstack.redis:6379 + CELERY_BROKER_VHOST: 0 + CELERY_BROKER_PASSWORD: password + DJANGO_SETTINGS_MODULE: enterprise_access.settings.devstack + DJANGO_WATCHMAN_TIMEOUT: 30 + ENABLE_DJANGO_TOOLBAR: 1 + DB_HOST: edx.devstack.mysql80 + DB_NAME: enterprise_access + DB_PORT: 3306 + DB_USER: enterprise_access001 + DB_PASSWORD: password + + enterprise-access-worker: + image: edxops/enterprise-access-dev + command: bash -c 'cd /edx/app/enterprise-access/ && celery -A enterprise_access worker -l DEBUG' + container_name: "edx.${COMPOSE_PROJECT_NAME:-devstack}.enterprise-access-worker" + hostname: enterprise-access-worker.devstack.edx + depends_on: + - mysql80 + - memcached + environment: + CELERY_ALWAYS_EAGER: 'false' + CELERY_BROKER_TRANSPORT: redis + CELERY_BROKER_HOSTNAME: edx.devstack.redis:6379 + CELERY_BROKER_VHOST: 0 + CELERY_BROKER_PASSWORD: password + DJANGO_SETTINGS_MODULE: enterprise_access.settings.devstack + COLUMNS: 80 + DB_HOST: edx.devstack.mysql80 + DB_NAME: enterprise_access + DB_PORT: 3306 + DB_USER: enterprise_access001 + DB_PASSWORD: password + networks: + default: + aliases: + - edx.devstack.enterprise-access-worker + ports: + - "18271:18271" + restart: always + stdin_open: true + tty: true + forum: command: bash -c 'source /edx/app/forum/ruby_env && source /edx/app/forum/devstack_forum_env && cd /edx/app/forum/cs_comments_service && bundle install && while true; do ./bin/unicorn -c config/unicorn_tcp.rb -I .; sleep 2; done' container_name: "edx.${COMPOSE_PROJECT_NAME:-devstack}.forum" diff --git a/docs/service_list.rst b/docs/service_list.rst index 092b8028c6..b4d405f4df 100644 --- a/docs/service_list.rst +++ b/docs/service_list.rst @@ -63,6 +63,8 @@ Instead of a service name or list, you can also run commands like ``make dev.pro +------------------------------------+-------------------------------------+----------------+--------------+ | `frontend-app-ora-grading`_ | http://localhost:1993 | MFE (React.js) | Extra | +------------------------------------+-------------------------------------+----------------+--------------+ +| `enterprise-access`_ | http://localhost:18270 | Python/Django | Extra | ++------------------------------------+-------------------------------------+----------------+--------------+ Some common service combinations include: @@ -95,3 +97,4 @@ Some common service combinations include: .. _frontend-app-ora-grading: https://github.com/edx/frontend-app-ora-grading .. _insights: https://github.com/edx/edx-analytics-dashboard .. _analyticsapi: https://github.com/edx/edx-analytics-data-api +.. _enterprise-access: https://github.com/openedx/enterprise-access diff --git a/options.mk b/options.mk index 5a4d9b4e2c..9d4903a0d1 100644 --- a/options.mk +++ b/options.mk @@ -67,7 +67,7 @@ credentials+discovery+ecommerce+edx_notes_api+forum+frontend-app-authn+frontend- # Separated by plus signs. # Separated by plus signs. Listed in alphabetical order for clarity. EDX_SERVICES ?= \ -analyticsapi+credentials+cms+cms-worker+cms_watcher+discovery+ecommerce+edx_notes_api+forum+frontend-app-account+frontend-app-learner-dashboard+frontend-app-learner-record+frontend-app-profile+frontend-app-authn+frontend-app-course-authoring+frontend-app-gradebook+frontend-app-ora-grading+frontend-app-learning+frontend-app-library-authoring+frontend-app-payment+frontend-app-program-console+frontend-app-publisher+insights+lms+lms-worker+lms_watcher+registrar+registrar-worker+xqueue+xqueue_consumer +analyticsapi+credentials+cms+cms-worker+cms_watcher+discovery+ecommerce+edx_notes_api+enterprise-access+forum+frontend-app-account+frontend-app-learner-dashboard+frontend-app-learner-record+frontend-app-profile+frontend-app-authn+frontend-app-course-authoring+frontend-app-gradebook+frontend-app-ora-grading+frontend-app-learning+frontend-app-library-authoring+frontend-app-payment+frontend-app-program-console+frontend-app-publisher+insights+lms+lms-worker+lms_watcher+registrar+registrar-worker+xqueue+xqueue_consumer # Services with database migrations. # Should be a subset of $(EDX_SERVICES). @@ -76,7 +76,7 @@ analyticsapi+credentials+cms+cms-worker+cms_watcher+discovery+ecommerce+edx_note # Note: This list should contain _all_ db-backed services, even if not # configured to run; the list will be filtered later against $(DEFAULT_SERVICES). DB_SERVICES ?= \ -credentials+cms+discovery+ecommerce+lms+registrar +credentials+cms+discovery+ecommerce+enterprise-access+lms+registrar # Services with static assets to be built. # Should be a subset of $(EDX_SERVICES). diff --git a/provision-enterprise-access.sh b/provision-enterprise-access.sh new file mode 100755 index 0000000000..4874ce1d93 --- /dev/null +++ b/provision-enterprise-access.sh @@ -0,0 +1,28 @@ +set -euf -o pipefail + +. scripts/colors.sh + +name="enterprise-access" +port="18270" + +docker-compose up -d $name + +# Run migrations +echo -e "${GREEN}Running migrations for ${name}...${NC}" +docker compose exec -T ${name} bash -e -c "cd /edx/app/enterprise-access/ && make migrate" -- "$name" +# docker compose exec -T ${name} bash -e -c 'source /edx/app/credentials/credentials_env && cd /edx/app/credentials/credentials && make migrate' -- "$name" + +# Create superuser +echo -e "${GREEN}Creating super-user for ${name}...${NC}" +docker compose exec -T ${name} bash -e -c "echo 'from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser(\"edx\", \"edx@example.com\", \"edx\") if not User.objects.filter(username=\"edx\").exists() else None' | python /edx/app/enterprise-access/manage.py shell" -- "$name" + +./provision-ida-user.sh ${name} ${name} ${port} + +# Create system wide enterprise role assignment +# TODO: this is a pretty complex oneline, we should probably eventually convert this to a management command. +echo -e "${GREEN}Creating system wide enterprise user role assignment for ${name}...${NC}" +docker compose exec -T lms bash -e -c "source /edx/app/edxapp/edxapp_env && echo 'from django.contrib.auth import get_user_model; from enterprise.models import SystemWideEnterpriseUserRoleAssignment, SystemWideEnterpriseRole; User = get_user_model(); worker_user = User.objects.get(username=\"${name}_worker\"); operator_role = SystemWideEnterpriseRole.objects.get(name=\"enterprise_openedx_operator\"); assignment = SystemWideEnterpriseUserRoleAssignment.objects.get_or_create(user=worker_user, role=operator_role, applies_to_all_contexts=True);' | /edx/app/edxapp/venvs/edxapp/bin/python /edx/app/edxapp/edx-platform/manage.py lms shell" -- lms + +# Restart enterprise.catalog app and worker containers +# docker-compose restart app +make dev.restart-devserver.enterprise-access \ No newline at end of file diff --git a/provision-mysql80.sql b/provision-mysql80.sql index 19b32e0ebd..44238a1086 100644 --- a/provision-mysql80.sql +++ b/provision-mysql80.sql @@ -14,6 +14,10 @@ CREATE DATABASE IF NOT EXISTS ecommerce; CREATE USER IF NOT EXISTS 'ecomm001'@'%' IDENTIFIED BY 'password'; GRANT ALL ON ecommerce.* TO 'ecomm001'@'%'; +CREATE DATABASE IF NOT EXISTS enterprise_access; +CREATE USER IF NOT EXISTS 'enterprise_access001'@'%' IDENTIFIED BY 'password'; +GRANT ALL ON enterprise_access.* TO 'enterprise_access001'@'%'; + CREATE DATABASE IF NOT EXISTS notes; CREATE USER IF NOT EXISTS 'notes001'@'%' IDENTIFIED BY 'password'; GRANT ALL ON notes.* TO 'notes001'@'%'; diff --git a/provision.sh b/provision.sh index cde27b6fcd..a630391e8a 100755 --- a/provision.sh +++ b/provision.sh @@ -49,6 +49,7 @@ xqueue \ coursegraph \ insights \ analyticsapi \ +enterprise-access \ " # What should we provision? diff --git a/provision.sql b/provision.sql index 0b672c9986..7f55c25eca 100644 --- a/provision.sql +++ b/provision.sql @@ -7,6 +7,9 @@ GRANT ALL ON discovery.* TO 'discov001'@'%' IDENTIFIED BY 'password'; CREATE DATABASE IF NOT EXISTS ecommerce; GRANT ALL ON ecommerce.* TO 'ecomm001'@'%' IDENTIFIED BY 'password'; +CREATE DATABASE IF NOT EXISTS enterprise_access; +GRANT ALL ON enterprise_access.* TO 'enterprise_access001'@'%' IDENTIFIED BY 'password'; + CREATE DATABASE IF NOT EXISTS notes; GRANT ALL ON notes.* TO 'notes001'@'%' IDENTIFIED BY 'password'; diff --git a/repo.sh b/repo.sh index cb93108f63..4f8e2af003 100755 --- a/repo.sh +++ b/repo.sh @@ -36,6 +36,7 @@ repos=( "https://github.com/openedx/frontend-app-publisher.git" "https://github.com/edx/edx-analytics-dashboard.git" "https://github.com/edx/edx-analytics-data-api.git" + "https://github.com/openedx/enterprise-access.git" ) non_release_repos=( @@ -66,6 +67,7 @@ ssh_repos=( "git@github.com:openedx/frontend-app-publisher.git" "git@github.com:edx/edx-analytics-dashboard.git" "git@github.com:edx/edx-analytics-data-api.git" + "git@github.com:openedx/enterprise-access.git" ) non_release_ssh_repos=(