diff --git a/.env_templates/infrastructure.template.env b/.env_templates/infrastructure.template.env
index 8ae2afb..61dcafb 100644
--- a/.env_templates/infrastructure.template.env
+++ b/.env_templates/infrastructure.template.env
@@ -3,10 +3,12 @@
# run this app locally, not host it to the public.
ENVIRONMENT=
+# AWS credentials and region
AWS_DEFAULT_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
+# Route53 Configurations
AWS_ROUTE53_HOSTED_ZONE_ID=
SITE_SUB_DOMAIN=
SITE_DOMAIN=
diff --git a/.env_templates/local.template.env b/.env_templates/local.template.env
index 3fb5530..41a84cd 100644
--- a/.env_templates/local.template.env
+++ b/.env_templates/local.template.env
@@ -6,17 +6,17 @@ ENVIRONMENT=local
CLIENT_UI_URL=http://localhost:4200
API_URL=http://localhost:3000
-# AWS Credentials and regions
+# AWS credentials and region
AWS_DEFAULT_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
-# AWS Cognito configurations
+# Cognito configurations
COGNITO_CLIENT_ID=
COGNITO_AUTH_URL=
COGNITO_JWKS_BASE64=
-# Bucket where application data is saved
+# Folder path where application data is saved
SHEET_DATA_S3_BUCKET=
# AWS Layer ARN, with necessary dependencies for the Python3.7 API
@@ -27,5 +27,5 @@ LAMBDA_LAYER=
# Tell SAM Local the Path of the API, so it can properly mount volumes
SAM_LOCAL_ABSOLUTE_PATH=
-# Comment this out if your okay with SAM sending data
+# Comment this out if you are okay with SAM sending data
SAM_CLI_TELEMETRY=0
diff --git a/.env_templates/remote.template.env b/.env_templates/remote.template.env
index f4248be..b261f66 100644
--- a/.env_templates/remote.template.env
+++ b/.env_templates/remote.template.env
@@ -2,28 +2,31 @@
# This should match the environment of infrastructure it is going to
# be deployed to.
ENVIRONMENT=
-SITE_SUB_DOMAIN=
+
+# Should be the same as infrastructure.env
+SITE_SUB_DOMAIN
SITE_DOMAIN=
# The Base url for the Frontend and Backend
CLIENT_UI_URL=
API_URL=
-# AWS Credentials and regions
+# AWS credentials and region
AWS_DEFAULT_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
-# Cognito
+# Cognito configurations
COGNITO_CLIENT_ID=
COGNITO_AUTH_URL=
COGNITO_JWKS_BASE64=
-# Where application data is saved
+# Folder path where application data is saved
SHEET_DATA_S3_BUCKET=
# AWS IAM Role ARN for Lambda function. The minimum requirement is for:
# - Read and Write Access to the Sheet Data S3 Bucket
+# - Write logs to Cloud Watch
# - The ability to invoke itself
LAMBDA_IAM_ROLE=
@@ -35,5 +38,5 @@ LAMBDA_LAYER=
# Bucket that facilatates SAM deployments of the Api
API_DEPLOYMENT_S3_BUCKET=
-# Comment this out if your okay with SAM sending data
+# Comment this out if you are okay with SAM sending data
SAM_CLI_TELEMETRY=0
diff --git a/.utils/create-env.js b/.utils/create-env.js
index 680fd6e..cfecfee 100644
--- a/.utils/create-env.js
+++ b/.utils/create-env.js
@@ -7,13 +7,14 @@ const util = require('util');
var request = require('request-promise-native');
var AWS = require('aws-sdk');
-// Template for the infrastructure.env file generated
+// Template for the remote.env file generated
const generateRemoteEnvString = (params) => {
return `` +
`# What unique environment is this code will be deployed to.
# This should match the environment of infrastructure it is going to
# be deployed to.
ENVIRONMENT=${params.ENVIRONMENT || ''}
+
SITE_SUB_DOMAIN=${params.SITE_SUB_DOMAIN || ''}
SITE_DOMAIN=${params.SITE_DOMAIN || ''}
@@ -21,21 +22,22 @@ SITE_DOMAIN=${params.SITE_DOMAIN || ''}
CLIENT_UI_URL=${params.CLIENT_UI_URL || ''}
API_URL=${params.API_URL || ''}
-# AWS Credentials and regions
+# AWS credentials and region
AWS_DEFAULT_REGION=${params.AWS_DEFAULT_REGION || ''}
AWS_ACCESS_KEY_ID=${params.AWS_ACCESS_KEY_ID || ''}
AWS_SECRET_ACCESS_KEY=${params.AWS_SECRET_ACCESS_KEY || ''}
-# Cognito
+# Cognito configurations
COGNITO_CLIENT_ID=${params.COGNITO_CLIENT_ID || ''}
COGNITO_AUTH_URL=${params.COGNITO_AUTH_URL || ''}
COGNITO_JWKS_BASE64=${params.COGNITO_JWKS_BASE64 || ''}
-# Where application data is saved
+# Folder path where application data is saved
SHEET_DATA_S3_BUCKET=${params.SHEET_DATA_S3_BUCKET || ''}
# AWS IAM Role ARN for Lambda function. The minimum requirement is for:
# - Read and Write Access to the Sheet Data S3 Bucket
+# - Write logs to Cloud Watch
# - The ability to invoke itself
LAMBDA_IAM_ROLE=${params.LAMBDA_IAM_ROLE || ''}
@@ -44,13 +46,14 @@ LAMBDA_IAM_ROLE=${params.LAMBDA_IAM_ROLE || ''}
# - cryptography==2.8
LAMBDA_LAYER=${params.LAMBDA_LAYER || ''}
-# SHEET_DATA_S3_BUCKET: S3 bucket that stores all sheets
+# Bucket that facilatates SAM deployments of the Api
API_DEPLOYMENT_S3_BUCKET=${params.API_DEPLOYMENT_S3_BUCKET || ''}
-# Comment this out if your okay with SAM sending data
+# Comment this out if you are okay with SAM sending data
SAM_CLI_TELEMETRY=0
`}
+// Template for the local.env file generated
const generateLocalEnvString = (params) => {
return `` +
`# This env file does not deploy anything. It is only used for local
@@ -61,12 +64,12 @@ ENVIRONMENT=${params.ENVIRONMENT || ''}
CLIENT_UI_URL=${params.CLIENT_UI_URL || ''}
API_URL=${params.API_URL || ''}
-# AWS Credentials and regions
+# AWS credentials and region
AWS_DEFAULT_REGION=${params.AWS_DEFAULT_REGION || ''}
AWS_ACCESS_KEY_ID=${params.AWS_ACCESS_KEY_ID || ''}
AWS_SECRET_ACCESS_KEY=${params.AWS_SECRET_ACCESS_KEY || ''}
-# AWS Cognito configurations
+# Cognito configurations
COGNITO_CLIENT_ID=${params.COGNITO_CLIENT_ID || ''}
COGNITO_AUTH_URL=${params.COGNITO_AUTH_URL || ''}
COGNITO_JWKS_BASE64=${params.COGNITO_JWKS_BASE64 || ''}
@@ -82,30 +85,11 @@ LAMBDA_LAYER=${params.LAMBDA_LAYER || ''}
# Tell SAM Local the Path of the API, so it can properly mount volumes
SAM_LOCAL_ABSOLUTE_PATH=${params.SAM_LOCAL_ABSOLUTE_PATH || ''}
-# Comment this out if your okay with SAM sending data
+# Comment this out if you are okay with SAM sending data
SAM_CLI_TELEMETRY=0
`
}
-
-
-const createEnv = (environment) => {
- if(environment === 'local') {
- var params = {
- };
- dotenv.config({path: '../infrastructure.env'});
- AWS.config.region = 'us-east-1'
- AWS.config.credentials = new AWS.Credentials(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY);
- const cloudformation = new AWS.CloudFormation({
- apiVersion: '2010-05-15'
- });
- cloudformation.listExports(params, function(err, data) {
- if (err) console.log(err, err.stack); // an error occurred
- else console.log(data); // successful response
- });
- }
-}
-
/**
* These are the question propmts for this CLI command
*/
@@ -123,12 +107,7 @@ const questions = [
];
-
-// const describeStacksPromise = util.promisify(cloudformation.describeStacks);
-
-// - Get Stack outputs
-
-
+// Turn file writer into a promise
const writeFilePromise = util.promisify(fs.writeFile);
// Export CLI Command
@@ -178,9 +157,6 @@ module.exports = () => {
AWS.config.credentials = new AWS.Credentials(answers.AWS_ACCESS_KEY_ID, answers.AWS_SECRET_ACCESS_KEY);
const cloudformation = new AWS.CloudFormation({ apiVersion: '2010-05-15' });
-
-
-
// Read exports from CloudFormation
return cloudformation.describeStacks({ StackName: infrastructureStackName }).promise()
.then((data) => {
diff --git a/.utils/create-infra-env.js b/.utils/create-infra-env.js
index 5f1846a..61dbd5a 100644
--- a/.utils/create-infra-env.js
+++ b/.utils/create-infra-env.js
@@ -15,11 +15,12 @@ return `` +
# run this app locally, not host it to the public.
ENVIRONMENT=${params.ENVIRONMENT || ''}
-# AWS Creds
+# AWS credentials and region
AWS_DEFAULT_REGION=${params.AWS_DEFAULT_REGION || ''}
AWS_ACCESS_KEY_ID=${params.AWS_ACCESS_KEY_ID || ''}
AWS_SECRET_ACCESS_KEY=${params.AWS_SECRET_ACCESS_KEY || ''}
+# Route53 Configurations
AWS_ROUTE53_HOSTED_ZONE_ID=${params.AWS_ROUTE53_HOSTED_ZONE_ID || ''}
SITE_SUB_DOMAIN=${params.SITE_SUB_DOMAIN || ''}
SITE_DOMAIN=${params.SITE_DOMAIN || ''}
diff --git a/README.md b/README.md
index 79d50b1..a7a3900 100644
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@
Cheet Sheet is an open source Content Management System for developers and development teams to Create, Edit and Share code snippets. This accelerates software engineering by having a centralized place where one can see how they or teammates have solved common problems in the past.
-Setting up Cheet Sheet for you or your organization is simple. All you need is Docker, node and an AWS account. It's 100% Serverless so your costs and infrastructure will automatically grow and shrink based on your needs with minimal effort on your part. ***Read [Getting Started](/docs/getting-started.md)***
+Setting up Cheet Sheet for you or your organization is simple. All you need is Docker, Node and an AWS account. It's 100% Serverless so your costs and infrastructure will automatically grow and shrink based on your needs with minimal effort on your part. ***Read [Getting Started](/docs/getting-started.md)***
Here is my own instance of the application: https://cheet-sheet.gugz.net/
@@ -25,7 +25,7 @@ If you use the app and like it please leave a star. If you find bugs feel free t
width="700"
/>
@@ -57,9 +57,9 @@ You can enter Edit mode by manually toggling it on and off. When on, you can add />
-Team workspaces are also available for logged in users. Everything you can do on a Personal workspace applies here except that this workspace can be viewed and edited by anyone who is on your team. To create a new workspace all you need to do is simply make a group in the Cognito user pool and add users to it. The name of the group is the name of team. +Team workspaces are also available for logged in users. Everything you can do on a Personal workspace applies here, except that this workspace can be viewed and edited by anyone who is on your team. To create a new Team workspace all you need to do is make a group in the Cognito user pool and add users to it. The name of the group is the name of team.@@ -78,7 +78,7 @@ Other things to note: />
-This repo also supports local development. This is so we can develop and test new features on our own machine before deploying it. To do this the Api and the UI are dockerized. Both services use mounted volumes so code changes can be reflected in real time. +This repo also supports local development. This is so we can develop and test new features on our own machine before deploying them. To do this the Api and the UI are dockerized. Both services use mounted volumes so code changes can be reflected in real time. The Api Service uses SAM local. Anytime a request is sent to the Api, SAM will run a temporary Docker container to simulate the Lambda function. diff --git a/docs/environment-variable-glossary.md b/docs/environment-variable-glossary.md index 71b7853..cc08d5b 100644 --- a/docs/environment-variable-glossary.md +++ b/docs/environment-variable-glossary.md @@ -12,20 +12,20 @@ This README tries to break down what each of these variables are. | --------------------------------- | ------------------------------------------------------------------------- | | ENVIRONMENT | This describes what unique environment is this app for. For example, prod, staging, dev, etc. This should be alphabetical and have no spaces. If set to "local", this will configure the app specifically for running on your machine and not for deploying it to AWS. | | AWS_DEFAULT_REGION | This is AWS region you want to deploy the app to. Ex: us-east-1, us-west-2, etc. | -| AWS_ACCESS_KEY_ID | This is for the IAM Credentials with which we gain the authentication provision infrastructure and deploy the app to AWS with. You need this for local development too, because some resources like S3 will sill run in the cloud. | -| AWS_SECRET_ACCESS_KEY | This is another IAM Credential (pairs with AWS_ACCESS_KEY_ID) with which we gain the authentication provision infrastructure and deploy the app to AWS with. You need this for local development too, because some resources like S3 will sill run in the cloud. | -| SITE_SUB_DOMAIN | This is the subdomain to which your app will be deployed to. For example, if you wish to have the app on https://cheet-sheet.mydomain.com this variable is set to `cheet-sheet`. For local environments this is not used for networking. Only for Naming conventions for S3 resources. | -| SITE_DOMAIN | This is the subdomain to which your app will be deployed to. For example, if you wish to have the app on https://cheet-sheet.mydomain.com this variable is set to `mydomain.com`. You must own this domain on Route53 if you are deploying the app to the internet. For local environments this is not used for networking. Only for Naming conventions for S3 resources. | +| AWS_ACCESS_KEY_ID | This is for the IAM Credentials with which we gain access to AWS with. You need this for local development too, because some resources like S3 will sill run in the cloud. | +| AWS_SECRET_ACCESS_KEY | This is another IAM Credential (pairs with AWS_ACCESS_KEY_ID) with which we gain access to AWS with. You need this for local development too, because some resources like S3 will sill run in the cloud. | +| SITE_SUB_DOMAIN | This is the subdomain to which your app will be deployed to. For example, if you wish to have the app on https://cheet-sheet.mydomain.com this variable is set to `cheet-sheet`. For local environments this is not used for networking, but still used for naming conventions of S3 resources. | +| SITE_DOMAIN | This is the subdomain to which your app will be deployed to. For example, if you wish to have the app on https://cheet-sheet.mydomain.com this variable is set to `mydomain.com`. You must own this domain on Route53 if you are deploying the app to the internet. For local environments this is not used for networking, but still used for naming conventions of S3 resources. | | AWS_ACM_CERTIFICATE_ARN | Not need for `ENVIRONMENT=local`. This is the AWS ACM ARN for the SSL certificate of the website, so we can use https. The certificate must valid for both these domains: `{SITE_SUB_DOMAIN}`.`{SITE_DOMAIN}`, `{SITE_SUB_DOMAIN}`.api.`{SITE_DOMAIN}` | | AWS_ROUTE53_HOSTED_ZONE_ID | This is the Zone Id for `SITE_DOMAIN` | | CLIENT_UI_URL | https://`{SITE_SUB_DOMAIN}`.`{SITE_DOMAIN}` if `ENVIRONMENT!=local`, `http://localhost:4200` if `ENVIRONMENT=local`| | API_URL | https://`{SITE_SUB_DOMAIN}`.api.`{SITE_DOMAIN}` if `ENVIRONMENT!=local`, `http://localhost:3000` if `ENVIRONMENT=local`| -| COGNITO_CLIENT_ID | This is the Id of the Cognito User Pool Client. We provision a different user pool for every different Environment. You can find this on your Infrastructure stack Outputs after it is deployed. | -| COGNITO_AUTH_URL | This is the Cognito Domain, that handles our authentication and hosts the login page. You can find this on your Infrastructure stack Outputs after it is deployed.| -| COGNITO_JWKS_BASE64 | In order to verify web tokens on the backend for login users we need a public. AWS hosts these keys as a Json Web Key Set on https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json. You can find the User Pool Id on your Infrastructure stack Outputs after it is deployed. | +| COGNITO_CLIENT_ID | This is the Id of the Cognito User Pool Client. We provision a different user pool for every different Environment. You can find this on your Infrastructure stack's Outputs after it is deployed. | +| COGNITO_AUTH_URL | This is the Cognito Domain, that handles our authentication and hosts the login page. You can find this on your Infrastructure stack's Outputs after it is deployed.| +| COGNITO_JWKS_BASE64 | In order to verify web tokens on the backend for login users we need a public key. AWS hosts these keys as a Json Web Key Set on https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json. You can find the User Pool Id on your Infrastructure stack's Outputs after it is deployed. | | SHEET_DATA_S3_BUCKET | This is the S3 bucket name where the different sheets and index cards are saved. You can find this on your Infrastructure stack Outputs after it is deployed. | -| LAMBDA_IAM_ROLE | This is the IAM role that gives the Lambda function that's behind our api, the necessary permissions to communicate with other AWS resources. You can find this on your Infrastructure stack Outputs after it is deployed. | -| LAMBDA_LAYER | AWS ARN for the Layer. AWS Lambda Layers are for you to save dependencies for the Lambda function that's behind our api. By default Lambda comes with several libraries out of the box, but we still need 2 more. They are pyjwt==1.7.1 and cryptography==2.8. You will need to make one yourself you don't have on. You can look at https://github.com/gugzkumar/my-python-lambda-layers for guidance. | -| API_DEPLOYMENT_S3_BUCKET | This is the S3 bucket name that SAM leverages to deploy the backend code of our app. You can find this on your Infrastructure stack Outputs after it is deployed. | -| SAM_LOCAL_ABSOLUTE_PATH | Absolute path of the `api` folder on your machine. In order for local development to work SAM needs to know where it is located. | +| LAMBDA_IAM_ROLE | This is the IAM role that gives the Lambda function behind our api, the necessary permissions to communicate with other AWS resources. You can find this on your Infrastructure stack's Outputs after it is deployed. | +| LAMBDA_LAYER | AWS ARN for the Layer. AWS Lambda Layers are for you to provide dependencies for the Lambda function behind our api. Lambda comes with several libraries out of the box, but we still need 2 more. They are pyjwt==1.7.1 and cryptography==2.8. You will need to make one yourself if you don't have one. You can look at https://github.com/gugzkumar/my-python-lambda-layers for guidance. | +| API_DEPLOYMENT_S3_BUCKET | This is the S3 bucket name that SAM leverages to deploy the backend code of our app. You can find this on your Infrastructure stack's Outputs after it is deployed. | +| SAM_LOCAL_ABSOLUTE_PATH | Absolute path of the `api` folder on your machine. In order for local development to work, SAM needs to know where it is located. | | SAM_CLI_TELEMETRY | Set this to 0 if you don't want to send AWS logistics about your use of SAM. Set to 1 if you're okay with it. This can help AWS make improvements to SAM. | diff --git a/docs/getting-started.md b/docs/getting-started.md index 295f183..902cf05 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -3,7 +3,7 @@ This document and the following ones will help you set up Cheet Sheet. ### Preliminary Setup -Click [here](/docs/setting-up-preliminary-tools.md) to read the necessary prep to run the app locally and deploy it AWS. +Click [here](/docs/setting-up-preliminary-tools.md) to read the necessary prep to run the app locally and/or deploy it to AWS. ### Set Up and Run Locally Click [here](/docs/setting-up-locally.md) to learn how to setup and run the app on your local machine. This is good for development and testing. diff --git a/docs/setting-up-ci-cd.md b/docs/setting-up-ci-cd.md index 9321edd..3a5145a 100644 --- a/docs/setting-up-ci-cd.md +++ b/docs/setting-up-ci-cd.md @@ -1,6 +1,6 @@ # Setting Up Continuous Deployment Via CircleCI -Continuous Deployment automates the updating of new code in our Api and UI so that we can focus on building features rather than how t launch them. CircleCI is easy to use, has a free tier, and takes away the hassle of have to set up infrastructure for it. +Continuous Deployment automates the updating of new code in our Api and UI so that we can focus on building features rather than worrying about how to launch them. CircleCI is easy to use, has a free tier, and takes away the hassle of have to set up infrastructure for it. ## STEP 1: Connect CircleCI to your repo @@ -9,9 +9,10 @@ Continuous Deployment automates the updating of new code in our Api and UI so th ## STEP 2: Create the ENVIRONMENT variable out of your remote.env -1. In [Setting Up And Launching The App On AWS](/docs/setting-up-remote.md) you create an `remote.env` file for code deploys -1. From the .utils folder run `node main.js create-infra-env` generate-base64-env. This will encode all contents of the `.env` file as base64 and spit it out. -1. The way we do continuous deployment is by mapping a branch in your repo to environment variable that has the contents of `remote.env` (base 64 encoded). Outbox the following deployment strategies are provided. If you want change the branch name, environment variable name, or add a new strategy follow **STEP 3**. +1. In [Setting Up And Launching The App On AWS](/docs/setting-up-remote.md) find the `remote.env` file you made for code deploys +1. From the `.utils` folder run `node main.js create-infra-env` generate-base64-env. This will encode all contents of the `.env` file as base64 and spit it out. +1. The way we do continuous deployment is by mapping a branch in your repo to an environment variable that has the contents of `remote.env` (base 64 encoded). Out of the box, the following deployment strategies are provided. If you want to change the branch name, environment variable name, or add a new strategy, follow **STEP 3**. + | Branch | CircleCI Environment Variable | | ------ | ----------------------------- | | master | PROD_ENV_FILE | @@ -21,7 +22,7 @@ Continuous Deployment automates the updating of new code in our Api and UI so th 1. Copy the output of the cli command, and set it as the desired Environment Variable. -## STEP 3: Update .circleci/config.yml if needed (Optional) +## STEP 3: Update `.circleci/config.yml` if needed (Optional) If you want to add more environments than supported out of the the box, modify the `load-env` command: @@ -47,5 +48,3 @@ load-env: exit 1 fi ``` - -# diff --git a/docs/setting-up-locally.md b/docs/setting-up-locally.md index 6d6e89d..c9b6989 100644 --- a/docs/setting-up-locally.md +++ b/docs/setting-up-locally.md @@ -1,18 +1,18 @@ # Setting Up And Running The App On Your Local Machine -This guide is for you to have a working version of Cheet Sheet deployed to your machine. This is useful for testing the app before you use it, and develop new features. All commands, unless otherwise noted, should be ran from the root of the project folder. +This guide is for you to have a working version of Cheet Sheet running on your computer. This is useful for testing the app before you use it, and develop new features. All commands, unless otherwise noted, should be ran from the root project folder. ## STEP 1: Create Your infrastructure.env File -**Warning: if you've already made infrastructure.env before, it will be overridden. So save it if you don't want to lose it** +**Warning: if you've already made an infrastructure.env before, it will be overridden. So save it if you don't want to lose it** -1. From the .utils folder run `node main.js create-infra-env` +1. From the `.utils` folder run `node main.js create-infra-env` 2. Follow the guided prompt to create `infrastructure.env` 3. Confirm you now have a file in your root folder called `infrastructure.env`