Skip to content

cookiecutter-openedx/cookiecutter-openedx-devops

Repository files navigation

Cookiecutter Open edX Devops Tools

Hack.d Lawrence McDaniel

Forums

Documentation

Terraform

AWS

Docker

Kubernetes

OPEN edX

Tutor logo

Powered by Cookiecutter, Cookiecutter Open edX Devops Tools is a community maintained project template for jumpstarting production-ready, Kubernetes-based installations of the Open edX online learning management system running on AWS cloud infrastructure that is built and managed with fully parameterized Terraform and Github Actions automation scripts. The template offers a number of generation options, we invite you to check the dedicated docs pages to learn more about each of them.

Cookiecutter Workflow

Usage

You use a popular command-line tool named Cookiecutter to generate your git code repository using this repo as a template.

First, get Cookiecutter. Trust me, it's awesome:

$ pip install "cookiecutter>=2.1.1"

Now run it against this repo, using the following example usage pattern:

GITHUB_REPO="gh:cookiecutter-openedx/cookiecutter-openedx-devops"
GITHUB_BRANCH="main"
OUTPUT_FOLDER="./"

cookiecutter --checkout $GITHUB_BRANCH \
            --output-dir $OUTPUT_FOLDER \
            --overwrite-if-exists \
            --no-input \
            $GITHUB_REPO \
            global_platform_name=prod \
            global_platform_region=usa \
            global_aws_region=us-east-1 \
            global_account_id=012345678912 \
            global_root_domain=schoolofrock.edu \
            global_aws_route53_hosted_zone_id=Z123456789ABCDEFGHIJK \
            environment_name=prod \
            environment_subdomain=courses \
            stack_add_remote_mysql=Y \
            stack_add_remote_mongodb=Y \
            stack_add_remote_redis=Y \
            stack_add_bastion=Y \
            stack_add_k8s_dashboard=Y \
            stack_add_k8s_kubeapps=Y \
            stack_add_k8s_kubecost=Y \
            stack_add_k8s_karpenter=Y \
            stack_add_k8s_prometheus=Y \
            wordpress_add_site=N \
            ci_openedx_release_tag=olive.1 \
            ci_deploy_install_backup_plugin=N \
            ci_deploy_install_credentials_server=N \
            ci_deploy_install_discovery_service=N \
            ci_deploy_install_notes_service=N \
            ci_deploy_install_ecommerce_service=N \
            ci_deploy_install_forum_service=Y \
            ci_deploy_install_xqueue_service=N \
            ci_deploy_install_license_manager_service=N \

There are lots more Cookiecutter parameters here.

Alternatively, you can run Cookiecutter without providing any prompts, which will result in it generating a questionnaire that includes all of the 75 or so input parameters. You'll be prompted for some values. Provide them, then a complete git repository will be created for you, with Github Actions workflows to automate the build and deployment of your Tutor Open edX platform, and Terraform scripts to automate the build of your AWS backend. Answer the prompts with your own desired options. For example:

$ cookiecutter https://github.com/cookiecutter-openedx/cookiecutter-openedx-devops

Cloning into 'cookiecutter-openedx-devops'...
remote: Counting objects: 550, done.
remote: Compressing objects: 100% (310/310), done.
remote: Total 550 (delta 283), reused 479 (delta 222)
Receiving objects: 100% (550/550), 127.66 KiB | 58 KiB/s, done.
Resolving deltas: 100% (283/283), done.
github_account_name [lpm0073]:
github_repo_name [openedx_devops]:
global_platform_name [yourschool]:
global_platform_description [Your School]:
global_platform_region [virginia]:
global_root_domain [yourschool.edu]:
# lots more questions .....

Enter the project and take a look around:

cd openedx_devops/
ls

Create a Github repo and push it there:

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/youraccount/{{ cookiecutter.github_repo_name }}.git
git push -u origin main

Now take a look at your repo. Don't forget to carefully look at the generated README. Awesome, right?

Features and functionality

Automated AWS Infrastructure Management with Terraform

Your new repository includes Terraform modules that have been optimized for running Open edX at scale on AWS EKS and RDS. The modules are organized to ease your implementation of additional environments for dev, test and qa. These modules will additionally configure all Open edX credentials (Django secret key, JWT, admin user, IAM keypairs, MySQL users and passwords, etcetera) on a per-environment basis, and will store these in Kubernetes Secrets. This configuration scales automatically, reliably supporting anywhere from a few hundred to as many as several hundred thousand learners. This Terraform configuration is also designed to support your additional external systems. Your custom legacy systems and microservices can safely deploy to this same Kubernetes cluster and RDS MySQL cluster.

Scalable and Secure Cloud Infrastructure

Builds a fully functional Docker-based, horizontally-scaled Open edX installation running on AWS infrastructure.

K9S Console Screenshot

Complete Kubernetes Auto scaling

Your new Kubernetes infrastructure platform leverages Prometheus and metrics-server to provide you with fully self-maintained auto-scaling features:

  • Vertical Pod Auto-scaling: a set of Kubernetes components that automatically adjust the amount of CPU and memory requested by your running pods based on performance metrics collected real-time by prometheus and metrics-server.
  • Horizontal Pod Auto-scaling: a built-in Kubernetes feature that automatically updates the pod count of your application deployments with the aim of automatically scaling the workload to match demand.
  • Karpenter: automatically launches just the right number of AWS EC2 compute node (ie application server instance) resources to handle your cluster's applications. It is designed to let you take full advantage of the cloud with fast and simple compute provisioning for Kubernetes clusters.

Kubernetes Management Tools

Your new Kubernetes cluster includes preconfigured, state of the art systems to help you keep things running securely, reliably and efficiently.

Github Workflows for Build and Deploy

Your new repository will be preconfigured to accept a collection of Github secrets parameters for your AWS IAM keypair, SMTP email host credentials, and oAuth provider credentials.

  • CI workflows for building your customized Docker images for the Open edX platform and its optional modules.
  • Built entirely from reusable Open edX Github Actions community-supported components that are purpose designed to support Open edX software running on Kubernetes.
  • Deployment workflows for deploying your Open edX platform to your new AWS EKS Kubernetes cluster. The deployment workflow installs the latest stable versions of the following:
    • Open edX LMS and Course Management Studio
    • scaffolding to add Open edX custom themes, plugins, and Xblocks to your build
    • Tutor plugins for all Open edX optional services: Discovery, Micro Front-end, Credentials, Xqueue, Ecommerce, Discussion Forums, Notes, SMTP email
    • Hastexo Tutor plugin for AWS S3 integration

Quick Start

See: Getting Started Guide

About The Open edX Platform Back End

The scripts in the terraform folder of your new repo will provide 1-click functionality to create and manage all resources in your AWS account. These scripts generally follow current best practices for implementing a large Python Django web platform like Open edX in a secure, cloud-hosted environment. Besides reducing human error, there are other tangible improvements to managing your cloud infrastructure with Terraform as opposed to creating and managing your cloud infrastructure resources manually from the AWS console. For example, all AWS resources are systematically tagged which in turn facilitates use of CloudWatch and improved consolidated logging and AWS billing expense reporting.

The Terraform scripts in your new repository will allow you to automatically create the following resources in your AWS account:

  • Compute Cluster. uses AWS EC2 behind a Classic Load Balancer.
  • Kubernetes. Uses AWS Elastic Kubernetes Service to implement a Kubernetes cluster onto which all applications and scheduled jobs are deployed as pods.
  • MySQL. uses AWS RDS for all MySQL data, accessible inside the vpc as mysql.courses.yourschool.edu:3306. Instance size settings are located in the environment configuration file, and other common configuration settings are located here. Passwords are stored in Kubernetes Secrets accessible from the EKS cluster.
  • MongoDB. uses either the default MongoDB service installed by tutor, or alternatively, a remote MongoDB server running on an EC2 instance. Regardless of the configuration option that you choose, the MongoDB service will be accessible inside the vpc as mongodb.master.courses.yourschool.edu:27017 and mongodb.reader.courses.yourschool.edu. Instance size settings are located in the environment configuration file, and other common configuration settings are located here. Passwords are stored in Kubernetes Secrets accessible from the EKS cluster.
  • Redis. uses AWS ElastiCache for all Django application caches, accessible inside the vpc as cache.courses.yourschool.edu. Instance size settings are located in the environment configuration file. This is necessary in order to make the Open edX application layer completely ephemeral. Most importantly, user's login session tokens are persisted in Redis and so these need to be accessible to all app containers from a single Redis cache. Common configuration settings are located here. Passwords are stored in Kubernetes Secrets accessible from the EKS cluster.
  • Container Registry. uses this automated Github Actions workflow to build your tutor Open edX container and then register it in Amazon Elastic Container Registry (Amazon ECR). Uses this automated Github Actions workflow to deploy your container to AWS Amazon Elastic Kubernetes Service (EKS). EKS worker instance size settings are located in the environment configuration file. Note that tutor provides out-of-the-box support for Kubernetes. Terraform leverages Elastic Kubernetes Service to create a Kubernetes cluster onto which all services are deployed. Common configuration settings are located here
  • User Data. uses AWS S3 for storage of user data. This installation makes use of a Tutor plugin to offload object storage from the Ubuntu file system to AWS S3. It creates a public read-only bucket named of the form courses-yourschool-virginia-storage, with write access provided to edxapp so that app-generated static content like user profile images, xblock-generated file content, application badges, e-commerce pdf receipts, instructor grades downloads and so on will be saved to this bucket. This is not only a necessary step for making your application layer ephemeral but it also facilitates the implementation of a CDN (which Terraform implements for you). Terraform additionally implements a completely separate, more secure S3 bucket for archiving your daily data backups of MySQL and MongoDB. Common configuration settings are located here
  • CDN. uses AWS Cloudfront as a CDN, publicly acccessible as https://cdn.courses.yourschool.edu. Terraform creates Cloudfront distributions for each of your enviornments. These are linked to the respective public-facing S3 Bucket for each environment, and the requisite SSL/TLS ACM-issued certificate is linked. Terraform also automatically creates all Route53 DNS records of form cdn.courses.yourschool.edu. Common configuration settings are located here
  • Password & Secrets Management uses Kubernetes Secrets in the EKS cluster. Open edX software relies on many passwords and keys, collectively referred to in this documentation simply as, "secrets". For all back services, including all Open edX applications, system account and root passwords are randomly and strongluy generated during automated deployment and then archived in EKS' secrets repository. This methodology facilitates routine updates to all of your passwords and other secrets, which is good practice these days. Common configuration settings are located here
  • SSL Certs. Uses AWS Certificate Manager and LetsEncrypt. Terraform creates all SSL/TLS certificates. It uses a combination of AWS Certificate Manager (ACM) as well as LetsEncrypt. Additionally, the ACM certificates are stored in two locations: your aws-region as well as in us-east-1 (as is required by AWS CloudFront). Common configuration settings are located here
  • DNS Management uses AWS Route53 hosted zones for DNS management. Terraform expects to find your root domain already present in Route53 as a hosted zone. It will automatically create additional hosted zones, one per environment for production, dev, test and so on. It automatically adds NS records to your root domain hosted zone as necessary to link the zones together. Configuration data exists within several modules but the highest-level settings are located here
  • System Access uses AWS Identity and Access Management (IAM) to manage all system users and roles. Terraform will create several user accounts with custom roles, one or more per service.
  • Network Design. uses Amazon Virtual Private Cloud (Amazon VPC) based on the AWS account number provided in the global configuration file to take a top-down approach to compartmentalize all cloud resources and to customize the operating enviroment for your Open edX resources. Terraform will create a new virtual private cloud into which all resource will be provisioned. It creates a sensible arrangment of private and public subnets, network security settings and security groups. See additional VPC documentation here
  • Proxy Access to Backend Services. uses an Amazon EC2 t2.micro Ubuntu instance publicly accessible via ssh as bastion.courses.yourschool.edu:22 using the ssh key specified in the global configuration file. For security as well as performance reasons all backend services like MySQL, Mongo, Redis and the Kubernetes cluster are deployed into their own private subnets, meaning that none of these are publicly accessible. See additional Bastion documentation here. Terraform creates a t2.micro EC2 instance to which you can connect via ssh. In turn you can connect to services like MySQL via the bastion. Common configuration settings are located here. Note that if you are cost conscious then you could alternatively use AWS Cloud9 to gain access to all backend services.

FAQ

See: FAQ

License

The code in this repository is licensed under version 3 of the AGPL unless otherwise noted. Please see the LICENSE file for details.

Important Considerations

  • this Cookiecutter can only generate a GitHub repository.
  • the Terraform code and Github Actions workflows in your new repository will only work for AWS.
  • the application domain for your Open edX installation (ie courses.yourschool.edu) must be hosted in AWS Route53. Terraform will create several DNS entries inside of this hosted zone, and it will optionally create additional hosted zones (one for each additional optional environment) that will be linked to the hosted zone of your application domain.
  • the Github Actions workflows in your new repository will depend on secrets located in the repository settings page. Look for further instructions in the README of your new repository.
  • the Github Actions workflows in your new repository will use an AWS IAM key pair from an IAM user named ci that you must manually create.
  • the collection of resources created by these scripts will generate AWS costs of around $0.41 USD per hour ($10.00 USD per day) while the platform is in a mostly-idle pre-production state. This cost will grow proportionally to your production work loads.
  • BE ADVISED that MySQL RDS, MongoDB and Redis ElastiCache are vertically scaled manually and therefore require some insight and potential adjustments on your part. All of these services are defaulted to their minimum instance sizes which you can modify in the environment configuration file.
  • TO DO: NSA Updated: Kubernetes Hardening Guide

Get Involved!

Cookiecutter is Used By These Organizations
Organization Organization
UK Cabinet Office Stepwise Math
Turn The Bus University of South Florida MUMA College of Business
MRI Online University of British Columbia Learn ExL
blend-ed YAM

Contributors are welcome. Contact me here: lawrencemcdaniel.com if you're interested in becoming a contributor to this project.

Local Development Quick Start

# clone this repository
git clone https://github.com/cookiecutter-openedx/cookiecutter-openedx-devops

# install the pre-commit command-line tools
pip install pre-commit
pre-commit install
npm install -g markdown-link-check

# Lint your Terraform code
terraform fmt -recursive
pre-commit run --all-files

# make some improvements and then create a pull request!!!!

Special Thanks

Special thanks go out to several folks in the open source community who've already made signficant contributions to this project, even if they're not actually aware.