Git Product home page Git Product logo

strapi-demo's Introduction

Strapi-Mongo Code Challenge Submission

This repo represents a two tier sytem that is composed of Strapi, a headless CMS, and MongoDB, a noSQL database. Both components have been architected for High Availability.

  • Strapi: 3 replica deployment config
  • Mongo: 3 replica statefulset (mongo replicaset)

Thought Process

My thought process was to create infrastruce and its automation that abstracted away operational specifics away into playbooks. In addition all infrastructure was decoupled (for example openshift templates are seperate from ansible playbooks) so that all individual components could be run individually.

This allows:

  1. devops folks to learn, interpret and run infra code as needed
  2. CI/CD pipelines to do the same (in the case ansible is not available)
  3. Developers to do what they do best

Quick Start Guide

Check out the ansible docs for all available playbooks.

To build and deploy strapi perform these steps:

  1. Open a PR (take not of PR num)
  2. Build Strapi using the build-strapi.yaml playbook
  3. Run the deploy-mongo.yaml playbook
  4. Run the deploy-strapi.yaml playbook when image is available and mongo is ready

Application Build and Deployment

The application build and deployments (onto Openshift) leverage several technologies to streamline the process.

  • ansible ansible
  • openshift templates openshift/templates

Together they deploy an instance of Strapi which is a Opensource headless CMS.

A Running version of the application can be found here http://strapi-pr-5-va3azs-patricksimonian-ocp201-tst-dev.pathfinder.gov.bc.ca/

Pull Request Based Deployments

This application (and its automation) leverages Github Flow (more info here).

TL;DR

  • Open Pull requests are utilzized as points to build and deploy code from
  • Pull requests are not closed until they reach a prod like environment (for our cases this would be the dev namespace)
  • You will require an OPEN PR in order to utilize the ansible playbooks to build and deploy this application.

Openshift Templates

There are a heavy use of Openshift Templates. I opted not to leverage tempaltes within ansible jinja templates so that they could be kept seperate and the templates run standalone.

Labeling

All components have a set of labels to organize seperate PR based deployments as well an easy way to group them up for cleaning.

  • app: identifies a label for a group of objects that belong to a Pull request. This includes the instance name plus a suffix. Such as strapi-pr-3 and mongo-pr-3

  • group: a generic label to get/delete all versions of an instance. Such as strapi and mongo

  • pr: identifies all objects that share the same Pull Request (allows you to grab strapi and mongo objects to gether)

Structure

architecture

Operational Plan

The operational plan describes the process for backing up and testing a restore of the mongo replicaset.

backup

Thought Process

The backup restore process is totally new to me and was indeed a big learning point. My mantra was

make it simple -> make it work -> make it right -> make it better

I comfortably covered up to make it work. My hope is to transfer the pod template into a cron job. This would require modification of the backup playbook to not delete the pod as a final task.

Performing a Strapi Upgrade

  1. Rebuild Strapi Image to latest version based off the build playbook *
  2. Perform Backup and Restore check of database *
  3. Redeploy Strapi and Mongo *
  4. Verify readiness and health of both services
  5. If Mongo is unhealthy scale both services down
  6. Restore Mongo
  7. Bring back up Mongo and Strapi and verify again
  • means playbooks exist, a missing * means a playbook needs to be written for these steps

Reducing Service Disruption

There are two ways that I'd reduce service disruption

  1. Perform upgrades outside of business hours
  2. Perform a blue-green deployment (this would be preferred)

Todos

  • combine strapi and mongo playbooks together
  • add readiness checks to strapi

Known Issues

  • #7 unable to run deploy mongo twice without deleting stateful set
  • #8 build strapi fails on github api check intermittently
  • #9 Deploy strapi playbook fails if you run it twice quickly on the first deploy

strapi-demo's People

Contributors

patricksimonian avatar

Watchers

 avatar

strapi-demo's Issues

Unable to run deploy mongo playbook twice without deleting the stateful set

This is a known bug with processing Openshift templates,

fatal: [localhost]: FAILED! => {"changed": true, "cmd": "oc process -n \"va3azs-patricksimonian-ocp201-tst-dev\" -f \"../openshift/templates/mongo/stateful-set.yaml\" -p MEMORY_REQUEST=256Mi \\\n-p MEMORY_LIMIT=512Mi \\\n-p CPU_REQUEST=500m \\\n-p CPU_LIMIT=1 \\\n-p VOLUME_CAPACITY=512Mi \\\n-p SC_MONGO=netapp-file-standard \\\n-p MONGODB_SERVICE_NAME=mongo-ha \\\n-p MONGODB_SECRET_NAME=mongo-ha \\\n-p MONGODB_REPLICAS=3 \\\n-p MONGODB_IMAGE=docker-registry.default.svc:5000/openshift/mongodb \\\n-p MONGODB_IMAGE_TAG=3.6 \\\n-p SUFFIX=pr-6 \\\n-p PULL_REQUEST_NUMBER=6 |  oc apply -n \"va3azs-patricksimonian-ocp201-tst-dev\" -f -\n", "delta": "0:00:00.653894", "end": "2020-07-13 11:34:51.015339", "msg": "non-zero return code", "rc": 1, "start": "2020-07-13 11:34:50.361445", "stderr": "Error from server: unrecognized type: int32", "stderr_lines": ["Error from server: unrecognized type: int32"], "stdout": "service/mongo-ha-pr-6 unchanged\nservice/mongo-ha-pr-6-internal unchanged\nsecret/mongo-ha-pr-6 configured", "stdout_lines": ["service/mongo-ha-pr-6 unchanged", "service/mongo-ha-pr-6-internal unchanged", "secret/mongo-ha-pr-6 configured"]}

Deploy strapi playbook fails if you run it twice quickly on the first deploy

If the strapi deployment was just triggered. Running it again will cause the error:

fatal: [localhost]: FAILED! => {"changed": true, "cmd": "oc rollout latest strapi-pr-6 -n va3azs-patricksimonian-ocp201-tst-dev", "delta": "0:00:00.370958", "end": "2020-07-13 11:37:38.516262", "msg": "non-zero return code", "rc": 1, "start": "2020-07-13 11:37:38.145304", "stderr": "error: #1 is already in progress (Pending).", "stderr_lines": ["error: #1 is already in progress (Pending)."], "stdout": "", "stdout_lines": []}

because it attempts to cancel the first rollout

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.