/
How to: Create and Deploy a new Microfrontend inside edX

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.

  1. Pick a name.  It should follow the convention: frontend-app-XXX.

    1. The repo name may or may not correspond with the sub-domain.  Examples:

      1. frontend-app-profile is served at profile.edx.org

      2. frontend-app-ecommerce is served at orders.edx.org

      3. If you can keep it one word it will make things easier

  2. We have a GitHub template repository to help bootstrap your new application.

    1. If you have permission to create new repositories:

      1. Visit GitHub - openedx/frontend-template-application: A template repository for creating Open edX frontend applications. 💿➡️📀

      2. Click the "Use this template" button.

      3. Put in your chosen micro-frontend application name.

      4. Make sure to create it in the edX organization.

    2. If you do not have permission to create a new repository:

      1. 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.

    3. Do a find and replace in your new repository to replace frontend-template-application with frontend-app-XXX.

    4. Similarly, there's an example module which demonstrates a basic module.  Feel free to rename the "example" directory or delete it.

  3. Add a link to your new repo to Frontend Repos.

  4. 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:

  1. The AWS resources like the S3 Bucket and Route53 domain name

    1. 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)

    2. The Route53 domain and S3 Bucket are created using the frontend.hostname variable (the creation of which you can see in the above PR)

  2. The remote config blocks for Related Django services

    1. 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)

  3. The GoCD deployment pipelines

    1. See https://github.com/edx/edx-internal/blob/master/gocd/README#L31-L39

  4. Sandboxes

    1. 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:

  1. 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.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.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 existing plans/edx/prod-frontends/frontend-app-* configurations.

  2. 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.tfvars

     

  3. Optional 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.

Optional: ecommerce access

If you need to call ecommerce, you need to add your domain to the CORS_ORIGIN_WHITELIST variables

  1. Add the following changes to your edx-remote-config PR/branch.

  2. Add your domain in:

     

  3. Also add it in ansible/vars/stage-edx.yml

Optional: edge-internal configuration for edge deployment

Add configuration for edge deployments in https://github.com/edx/edge-internal

Create a branch/PR with the following changes.