Giter Site home page Giter Site logo

serverless-monorepo-app's Introduction

Serverless Monorepo App

License: MIT CircleCI

This application is structured as a monorepo which means all the different packages sits under the same GitHub repository.

It makes it easier to have CI/CD and automate dependency management.

For example, under frontend sits the React application which consumes the services under services.

Since the endpoint urls for the services change between environments (dev/qa/prod) we need to setup the frontend app correctly.

Since all of our code sits in the same repository, we can update the frontend app environment based on the services deployment with ease.

This application uses Auth0 for authentication, Sendgrid for sending emails, CircleCI for deployment and AWS as a cloud provider.

Resources Used

Prerequisites

Nodejs (at least version 8)

Yarn

Amazon AWS account and awscli installed and configured: https://aws.amazon.com/getting-started/

CircleCI account

Serverless CLI

Auth0 account

Sendgrid account for the email service

Repository structure

This repository uses lerna and yarn workspaces to handle dependencies.

The React frontend app sits under frontend/.

The Serverless services sit under services/.

Shared services code is under services/common/ (e.g. both api-service and email-service use the same authentication handler).

Typescript is used across the repository.

Setup

Install Dependencies

yarn install

CI/CD is setup for 3 different environments: dev (for local development), qa (for integration tests) and prod (production).

Setup Environments

This part can be a bit tedious, but you only have to do it once.

Sendgrid

Open Sendgrid settings

For sending emails you'll need a Sendgrid API key for each environment you'll want to have (3 keys if you want dev,qa and prod).

Login into your Sendgrid account and create an API key (with email sending permissions) for each environment (you can name them Serverless App Dev, Serverless App QA, etc.).

Make sure to copy the API keys somewhere as you'll only see them once.

Auth0

Open Auth0 management dashboard

The way to create different environments in Auth0 is to use something called Tenants.

You should create a tenant for each environment you'd like to use (you do it by clicking the icon for your account and choosing Create tenant).

A common setup is to have tenants named mydomain-dev for development, mydomain-qa for QA and mydomain for production.

After creating the relevant tenants you'll need to create an application (you can name it Serverless Test App or something similar).

You'll need your application's Domain, Client ID, Audience and the public key of the signing certificate.

Domain and Client ID are under applications->${YOUR_APP_NAME}->settings.

Audience is usually https://YOUR_DOMAIN/userinfo and to get the certificate you'll need to scroll down, go to Show Advanced Settings->Certificates->DOWNLOAD CERTIFICATE.

You should save the certificate in PEM format.

Setup Dev Environments Files

Run the following command to create the dev config files (make sure to update your_certificate.pem)

cp frontend/.env.example.local frontend/.env.local
cp services/common/environment/config.example.json services/common/environment/config.dev.json
cp services/email-service/config.example.json services/email-service/config.dev.json
mv your_certificate.pem services/common/environment/public_key.dev.pem

Update frontend/.env.local, services/common/environment/config.dev.json and services/email-service/config.dev.json with the relevant values.

Setup CircleCI

You'll need to add your project in CircleCI. In order to do it you'll probably need to fork this repository.

After you've done that you should add your AWS credentials under Settings->AWS Permissions (you should create a separate IAM User for that)

The last part left is to setup qa and prod environment variables for your project.

Under Settings->Environment Variables add the following items (update the values):

PROD_AUTH0_AUDIENCE
PROD_AUTH0_CLIENT_ID
PROD_AUTH0_DOMAIM
PROD_AUTH0_PUBLIC_KEY # This value should be base64 encoded, run `base64 ${LOCATION_TO_PEM_FILE}` to get the value
PROD_REGION # You can use `us-east-1` at the moment
PROD_SENDGRID_API_KEY
QA_AUTH0_AUDIENCE
QA_AUTH0_CLIENT_ID
QA_AUTH0_DOMAIM
QA_AUTH0_PUBLIC_KEY # This value should be base64 encoded, run `base64 ${LOCATION_TO_PEM_FILE}` to get the value
QA_REGION # You can use `us-east-1` at the moment
QA_SENDGRID_API_KEY

Deployment

Development environment

yarn deploy:dev # deploys services and updates frontend configuration
yarn build:frontend # builds frontend application
yarn publish:frontend:dev # deploys frontend application

QA environment will be deployed automatically on each commit to master

Production environment will be deployed automatically on each version tag push, for example the following will trigger a production deployment:

git tag "v0.0.1"
git push --tags

Post Deployment Setup

After deploying there is one last step to get Auth0 to work.

Open Auth0 management dashboard and go to applications->${YOUR_APP_NAME}->settings.

Update Allowed Callback URLs with:

http://localhost:3000/callback,http://localhost:5000/callback,https://YOUR_CLOUDFRONT_DOMAIN/callback

Update Allowed Web Origins with:

http://localhost:3000,http://localhost:5000,https://YOUR_CLOUDFRONT_DOMAIN

You can get the domain value from here: https://console.aws.amazon.com/cloudfront/home

Run Tests

yarn test
yarn coverage

serverless-monorepo-app's People

Contributors

dependabot[bot] avatar erezrokah avatar julbrs avatar kodiakhq[bot] avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

serverless-monorepo-app's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • fix(deps): update dependency react-redux to v7.2.9
  • chore(deps): update dependency webpack to v5.91.0
  • fix(deps): update dependency auth0-js to v9.25.0 (auth0-js, @types/auth0-js)
  • fix(deps): update dependency aws-sdk to v2.1608.0
  • fix(deps): update dependency aws-xray-sdk to v3.6.0
  • fix(deps): update dependency react-router-dom to v6.23.0
  • fix(deps): update dependency redux-saga to v1.3.0
  • chore(deps): update dependency @types/jsonwebtoken to v9
  • chore(deps): update dependency @types/node to v20
  • chore(deps): update dependency @types/puppeteer to v7
  • chore(deps): update dependency axios to v1
  • chore(deps): update dependency chai to v5
  • chore(deps): update dependency fs-extra to v11
  • chore(deps): update dependency jest-junit to v16
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency puppeteer to v22
  • chore(deps): update dependency typescript to v5
  • chore(deps): update react monorepo to v18 (major) (@types/react, @types/react-dom, react, react-dom, react-test-renderer)
  • fix(deps): update dependency @sendgrid/mail to v8
  • fix(deps): update dependency react-redux to v9
  • fix(deps): update dependency redux to v5
  • fix(deps): update dependency redux-actions to v3
  • fix(deps): update dependency reselect to v5
  • fix(deps): update dependency styled-components to v6
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

circleci
.circleci/config.yml
npm
frontend/package.json
  • auth0-js ^9.7.3
  • connected-react-router ^6.0.0
  • react ^17.0.0
  • react-dom ^17.0.0
  • react-loadable ^5.5.0
  • react-redux ^7.0.0
  • react-router-dom ^6.0.0
  • react-scripts ^5.0.0
  • redux ^4.0.0
  • redux-actions ^2.6.1
  • redux-auth-wrapper ^3.0.0
  • redux-ignore ^1.2.5
  • redux-logger ^3.0.6
  • redux-saga ^1.0.0
  • reselect ^4.0.0
  • semantic-ui-css ^2.4.0
  • semantic-ui-react ^2.0.0
  • styled-components ^5.0.0
  • @anttiviljami/serverless-stack-output ^0.3.1
  • @types/auth0-js ^9.13.4
  • @types/enzyme ^3.10.5
  • @types/jest ^27.0.0
  • @types/node ^16.0.0
  • @types/react ^17.0.0
  • @types/react-dom ^17.0.0
  • @types/react-loadable ^5.4.1
  • @types/react-redux ^7.0.0
  • @types/react-router-dom ^5.0.0
  • @types/react-test-renderer ^17.0.0
  • @types/redux-actions ^2.3.0
  • @types/redux-auth-wrapper ^2.0.8
  • @types/redux-mock-store ^1.0.0
  • enzyme ^3.9.0
  • enzyme-adapter-react-16 ^1.12.1
  • jest-styled-components ^7.0.0
  • mockdate ^3.0.0
  • react-test-renderer ^17.0.0
  • redux-mock-store ^1.5.3
  • serverless-s3-remover ^0.6.0
  • source-map-explorer ^2.0.0
  • tslint ^6.0.0
  • tslint-config-prettier ^1.18.0
  • tslint-react ^5.0.0
  • typescript ^4.0.0
frontend/serverless-single-page-app-plugin/package.json
package.json
  • jest-junit ^13.0.0
  • lerna ^4.0.0
  • prettier ^2.0.0
  • @types/react 17.0.80
services/api-service/package.json
  • jsonwebtoken ^8.5.1
  • @anttiviljami/serverless-stack-output ^0.3.1
  • @types/aws-lambda ^8.10.62
  • @types/chai ^4.2.12
  • @types/jest ^27.0.0
  • @types/jsonwebtoken ^8.5.0
  • @types/node ^16.0.0
  • @types/puppeteer ^5.0.0
  • aws-testing-library ^2.0.0
  • axios ^0.28.0
  • chai ^4.2.0
  • jest 27.5.1
  • puppeteer ^13.0.0
  • serverless-plugin-tracing ^2.0.0
  • serverless-webpack ^5.2.0
  • ts-jest 27.1.5
  • ts-loader ^9.0.0
  • tslint ^6.0.0
  • tslint-config-prettier ^1.18.0
  • typescript ^4.0.0
  • webpack ^5.0.0
  • webpack-node-externals ^3.0.0
services/common/package.json
  • jsonwebtoken ^8.5.1
  • @types/aws-lambda ^8.10.62
  • @types/jest ^27.0.0
  • @types/jsonwebtoken ^8.5.0
  • @types/node ^16.0.0
  • jest 27.5.1
  • ts-jest 27.1.5
  • ts-loader ^9.0.0
  • tslint ^6.0.0
  • tslint-config-prettier ^1.18.0
  • typescript ^4.0.0
services/db-service/package.json
  • aws-sdk ^2.449.0
  • uuid ^8.0.0
  • @anttiviljami/serverless-stack-output ^0.3.1
  • @types/aws-lambda ^8.10.62
  • @types/chai ^4.2.12
  • @types/jest ^27.0.0
  • @types/node ^16.0.0
  • @types/uuid ^8.0.0
  • aws-testing-library ^2.0.0
  • chai ^4.2.0
  • dotenv ^16.0.0
  • jest 27.5.1
  • mockdate ^3.0.0
  • serverless-plugin-tracing ^2.0.0
  • serverless-webpack ^5.2.0
  • ts-jest 27.1.5
  • ts-loader ^9.0.0
  • tslint ^6.0.0
  • tslint-config-prettier ^1.18.0
  • typescript ^4.0.0
  • webpack ^5.0.0
  • webpack-node-externals ^3.0.0
services/email-service/package.json
  • @sendgrid/mail ^7.0.0
  • aws-xray-sdk ^3.0.0
  • source-map-support ^0.5.12
  • @types/aws-lambda ^8.10.62
  • @types/jest ^27.0.0
  • @types/node ^16.0.0
  • dotenv ^16.0.0
  • fs-extra ^10.0.0
  • jest 27.5.1
  • serverless-plugin-tracing ^2.0.0
  • @anttiviljami/serverless-stack-output ^0.3.1
  • serverless-webpack ^5.2.0
  • ts-jest 27.1.5
  • ts-loader ^9.0.0
  • tslint ^6.0.0
  • tslint-config-prettier ^1.18.0
  • typescript ^4.0.0
  • webpack ^5.0.0
  • webpack-node-externals ^3.0.0
services/file-service/package.json
  • aws-sdk ^2.449.0
  • node-fetch ^3.0.0
  • @anttiviljami/serverless-stack-output ^0.3.1
  • @types/aws-lambda ^8.10.62
  • @types/chai ^4.2.12
  • @types/jest ^27.0.0
  • @types/node ^16.0.0
  • @types/node-fetch ^3.0.0
  • aws-testing-library ^2.0.0
  • chai ^4.2.0
  • jest 27.5.1
  • serverless-plugin-tracing ^2.0.0
  • serverless-webpack ^5.2.0
  • ts-jest 27.1.5
  • ts-loader ^9.0.0
  • tslint ^6.0.0
  • tslint-config-prettier ^1.18.0
  • typescript ^4.0.0
  • webpack ^5.0.0
  • webpack-node-externals ^3.0.0
services/kinesis-service/package.json
  • aws-sdk ^2.449.0
  • uuid ^8.0.0
  • @anttiviljami/serverless-stack-output ^0.3.1
  • @types/aws-lambda ^8.10.62
  • @types/chai ^4.2.12
  • @types/jest ^27.0.0
  • @types/node ^16.0.0
  • @types/node-fetch ^3.0.0
  • aws-testing-library ^2.0.0
  • chai ^4.2.0
  • jest 27.5.1
  • mockdate ^3.0.0
  • serverless-plugin-tracing ^2.0.0
  • serverless-webpack ^5.2.0
  • ts-jest 27.1.5
  • ts-loader ^9.0.0
  • tslint ^6.0.0
  • tslint-config-prettier ^1.18.0
  • typescript ^4.0.0
  • webpack ^5.0.0
  • webpack-node-externals ^3.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

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.