How to: Create and Deploy a new Microfrontend inside edX
Create Your Microfrontend's Repository
Note that throughout this How-to we use XXX to represent the name of your repository/app, and YYY to represent the sub-domain you've chosen.
Pick a name. It should follow the convention:
frontend-app-XXX
.We have a GitHub template repository to help bootstrap your new application.
If you have permission to create new repositories:
Click the "Use this template" button.
Put in your chosen micro-frontend application name.
Make sure to create it in the edX organization.
If you do not have permission to create a new repository:
Get someone to do the above steps for you. You can read through How to request a new GitHub Repo to find a way to get someone to help you.
Do a find and replace in your new repository to replace frontend-template-application with frontend-app-XXX.
Similarly, there's an example module which demonstrates a basic module. Feel free to rename the "example" directory or delete it.
Add a link to your new repo to Frontend Repos.
If you are replacing an existing legacy frontend, update [Archive] MFE Rewrite Statusarchived accordingly.
Setup Automated Deployment
We serve our frontend applications from S3 through CloudFlare distributions. We deploy them with GoCD. We manage the creation of these resources/pipelines via configuration in edx/terraform and edx/edx-internal.
In this section you will be creating a series of pull requests for the following:
The AWS resources like the S3 Bucket and Route53 domain name
To add these you will need to open a PR to https://github.com/edx/terraform (e.g. https://github.com/edx/terraform/pull/2728/files)
The Route53 domain and S3 Bucket are created using the
frontend.hostname
variable (the creation of which you can see in the above PR)
The remote config blocks for Related Django services
To add these you will need to open a PR to https://github.com/edx/edx-internal and optionally https://github.com/edx/edge-internal (e.g. https://github.com/edx/edx-internal/pull/2374/files)
The GoCD deployment pipelines
Sandboxes
Beware of dragons, this will require a PR to GitHub - edx/configuration: A collection of edx configuration scripts and utilities that edx.org uses to deploy openedx. , please see How To Add an MFE to a Sandbox for more information.
After all your PRs are made, you will create an SRE Support ticket or a ticket to your eSRE for review.
1: edx/terraform
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. This repo contains terraform modules for deploying our applications on AWS, Cloudflare, NewRelic, Kubernetes and Snowflake.
Here we will leverage an existing frontend terraform module for provisioning new frontend infrastructure.
Create a branch/PR with the following changes:
In edx/terraform, create two files:
plans/edx/prod-frontends/frontend-app-XXXXX.tf
variable "frontend_app_XXXXX_hostname" { type = string description = "Hostname of the frontend-app-XXXXX used for bucket naming and routing" } module "frontend_app_XXXXX_frontend" { source = "../../../modules/frontends/frontend" cloudflare_record_name = "XXXXX" route53_zone_id = var.route53_zone_id_edx_org frontend_hostname = var.frontend_app_XXXXX_hostname internal_frontend_hostname = "${var.environment}-XXXXX.edx.org" aws_region = var.aws_region deployer_user = aws_iam_user.frontend_deployer_user.arn cloudflare_zone_id = var.cloudflare_zone_id_edx_org cdn_type = "cloudflare" }
plans/edx/stage-frontends/frontend-app-XXXXX.tfvariable "frontend_app_XXXXX_hostname" { type = string description = "Hostname of the frontend-app-XXXXX used for bucket naming and routing" } module "frontend_app_XXXXX_frontend" { source = "../../../modules/frontends/frontend" cloudflare_record_name = "XXXXX.stage" route53_zone_id = var.route53_zone_id_edx_org frontend_hostname = var.frontend_app_XXXXX_hostname internal_frontend_hostname = "${var.environment}-XXXXX.edx.org" aws_region = var.aws_region deployer_user = aws_iam_user.frontend_deployer_user.arn cloudflare_zone_id = var.cloudflare_zone_id_edx_org cdn_type = "cloudflare" }
Note the only difference between the stage plan and the prod plan is the
cloudflare_record_name
. For examples, see the existingplans/edx/prod-frontends/frontend-app-*
configurations.Add variables for your application for stage and prod:
plans/edx/prod-frontends/terraform.tfvars
... # frontend-app-XXXXX frontend_app_XXXXX_hostname = "YYYYY.edx.org"
plans/edx/stage-frontends/terraform.tfvarsOptional for edge deployment
2: edx/edx-internal (and edge-internal)
EdX Internal is a private configuration repo for the edx.org deployment. It contains private but not restricted/secure data. Here we will add configuration variable files for your frontend application to edx-internal/frontends.
Create a branch/PR with the following changes.
Create a subdirectory in edx-internal/frontends for your app:
edx-internal/frontends/frontend-app-XXX
Add the following two files:
prod_config.yml
stage_config.yml
For examples, see the existing
frontend-app-*
configurations in edx-internal/frontends.
If you're setting up NewRelic alerts, or Segment tracking there's additional configuration to define (NEW_RELIC_APP_ID
and SEGMENT_KEY
) in this repository that's described below. You may want to do it as part of the same PR to save time.
Add some variables for your application in
EDXAPP_XXX_MICROFRONTEND_URL
is used to let the LMS link to your frontend.EDXAPP_CORS_ORIGIN_WHITELIST
allows requests to LMS from your frontend.EDXAPP_LOGIN_REDIRECT_WHITELIST
allows the LMS login process to redirect to your frontend.edx-remote-config/prod/lms.yml
Do similarly in
Optional: ecommerce access
If you need to call ecommerce, you need to add your domain to the CORS_ORIGIN_WHITELIST variables
Add the following changes to your edx-remote-config PR/branch.
Add your domain in:
https://github.com/edx/edx-internal/blob/master/edx-remote-config/prod/ecommerce.yml
https://github.com/edx/edx-internal/blob/master/edx-remote-config/stage/ecommerce.yml
Also add it in ansible/vars/stage-edx.yml