Skip to content

Commit

Permalink
Initial release of cirrus-dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Woodruff committed Mar 2, 2022
0 parents commit fc09825
Show file tree
Hide file tree
Showing 54 changed files with 2,049 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# dotenv environment variables file
.env

# gatsby files
.cache/
public

# Mac files
.DS_Store

# Yarn
yarn-error.log
.pnp/
.pnp.js
# Yarn Integrity file
.yarn-integrity
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright ©2022. Element 84, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Cirrus Dashboard

Dashboard for Cirrus processing pipeline.

## Getting Started

### Requirements
* node
* yarn*
* Environment files

*If you don't have yarn installed, you should be okay running the project with npm, but keep in mind the dependencies should be updated using yarn.

#### Environment Files
For local development, you should include an `.env.development` file with the proper configuration.

For production builds, you should include an `.env.production` file with the proper configuration.

```
CIRRUS_API_ENDPOINT="[Endpoint]"
```

### Installing Depdencies
```
yarn install
```

### Development
```
yarn develop
```

### Production Builds
```
yarn build
```

### Deploying cirrus-dashboard into AWS
```
export ENVIRONMENT=Development
export AWS_REGION=us-east-1
export AWS_DEFAULT_REGION=us-east-1
TARGET_ENVIRONMENT=$(echo $ENVIRONMENT | tr '[:upper:]' '[:lower:]')
TARGET_BUCKET="cirrus-dashboard-${TARGET_ENVIRONMENT}"
S3_BUCKET="http://${target_bucket}.s3-website-${AWS_REGION}.amazonaws.com"
rm -rf public
cd build-deploy && sh ./build-environment.sh $ENVIRONMENT && \
source ./.env.production && npm run build && \
sh ./create-bucket.sh "${TARGET_ENVIRONMENT}" && \
echo "Syncing deployment to S3 ..." && \
aws s3 rm s3://${TARGET_BUCKET} --recursive && \
aws s3 cp ./public s3://${TARGET_BUCKET}/ --recursive && \
echo "Updating metadata ..." && \
sh ./update-metadata.sh "${TARGET_ENVIRONMENT}" && \
echo "Done"
```
30 changes: 30 additions & 0 deletions build-deploy/build-environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

set -o pipefail

if [[ "$#" -lt 1 ]]; then
echo "Requires environment name as a parameter"
exit 1
fi

ENVIRONMENT=$1
ENVIRONMENT_CONFIG_PATH="../.env.production"
SECRET_ENV="${ENVIRONMENT}"

shift
ARGS=$@

rm -f "${ENVIRONMENT_CONFIG_PATH}"
echo "Setting up .env.production configuration"

CIRRUS_API_ENDPOINT=$(aws cloudformation $ARGS describe-stacks --stack-name cirrus-$ENVIRONMENT| jq -c -r '.Stacks[0].Outputs[] | select(.OutputKey | test("^ServiceEndpoint$")) | .OutputValue')

if [[ "$CIRRUS_API_ENDPOINT" == "" ]]; then
echo "Unable to determine CIRRUS_API_ENDPOINT"
exit 1
fi

echo "Using CIRRUS_API_ENDPOINT=${CIRRUS_API_ENDPOINT}"
echo "Building .env.production at ${ENVIRONMENT_CONFIG_PATH}"
echo CIRRUS_API_ENDPOINT=${CIRRUS_API_ENDPOINT} >> "${ENVIRONMENT_CONFIG_PATH}"
cat "${ENVIRONMENT_CONFIG_PATH}"
57 changes: 57 additions & 0 deletions build-deploy/create-bucket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

set -o pipefail

if [[ "$#" -lt 1 ]]; then
echo "Requires environment name as a parameter"
exit 1
fi

ENVIRONMENT=$1
shift

ARGS=$@

BUCKET="cirrus-dashboard-${ENVIRONMENT}"
BUCKET_ARN="arn:aws:s3:::$BUCKET/*"
echo "Checking to see if ${BUCKET} exists"

aws s3api head-bucket --bucket "$BUCKET"
if [[ $? -eq 0 ]]; then
echo "Bucket exists"
else
echo "Bucket does not exist"
echo "Creating ${BUCKET}"
echo "$(aws s3 mb s3://"$BUCKET" --region ${AWS_REGION})"
echo "$(aws s3 website s3://"$BUCKET" --index-document index.html --error-document index.html)"
fi

# ensure default encryption-at-rest is enabled
echo "S3 Bucket: $BUCKET - ApplyServerSideEncryptionByDefault ..."
aws s3api put-bucket-encryption --bucket $BUCKET --server-side-encryption-configuration \
'{"Rules": [{"ApplyServerSideEncryptionByDefault": {"SSEAlgorithm": "AES256"}}]}'

# If you ever want to put cloudfront in front of the s3 bucket you can set a
# s3 bucket policy to restrict access by using this version of RESTRICT_CF
#RESTRICT_CF=', "Condition": { "StringLike": { "aws:UserAgent": "*Amazon CloudFront*" }}'
RESTRICT_CF=''

echo "Checking to see if ${BUCKET} has a policy"
aws s3api get-bucket-policy-status --bucket "$BUCKET"
if [[ $? -eq 0 ]]; then
echo "Bucket has a policy"
else
echo "Bucket policy not found, adding bucket policy"
touch policy.json
echo '{"Version": "2012-10-17","Statement": [{"Sid": "PublicReadGetObject","Effect": "Allow","Principal": "*","Action": "s3:GetObject","Resource": "'"${BUCKET_ARN}"'"'"$RESTRICT_CF"'}]}' > policy.json
cat policy.json
echo "$(aws s3api put-bucket-policy --bucket "$BUCKET" --policy file://policy.json)"
fi

aws s3api get-bucket-website --bucket "$BUCKET" |jq -e '.ErrorDocument.Key'
if [[ $? -eq 0 ]]; then
echo "Bucket has error page"
else
echo "Updating bucket website"
echo "$(aws s3 website s3://"$BUCKET" --index-document index.html --error-document index.html)"
fi
82 changes: 82 additions & 0 deletions build-deploy/update-metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
#
# Example usage:
# ./update-metadata.sh Development --profile my-dev --region $AWS_REGION
#

set -o pipefail

if [ "$#" -lt 1 ]; then
echo "Requires environment name as a parameter"
exit 1
fi

ENVIRONMENT=$1
shift

ARGS=$@

BUCKET="cirrus-dashboard-${ENVIRONMENT}"
echo "Checking to see if ${BUCKET} exists"

aws s3api head-bucket --bucket "$BUCKET" $ARGS
if [ $? -eq 0 ]; then
echo "Bucket exists"
else
echo "Bucket does not exist"
break
fi

# Caching policy recommendations per https://www.gatsbyjs.org/docs/caching/

cacheControlNever="public, max-age=0, must-revalidate"
cacheControlForever="public, max-age=31536000, immutable"

# page-data.json files require the content-type to function appropriately
# due to a bug / restriction in Gatsby's page lookup engine
aws s3 cp "s3://${BUCKET}/page-data" "s3://${BUCKET}/page-data" \
--recursive \
--content-type "application/json" \
--metadata-directive REPLACE --exclude "*" --include "*.json" $ARGS
if [ $? -eq 0 ]; then
echo "Updated page-data JSON files to content type application/json"
else
echo "Failed to update page-data JSON files to content type application/json"
fi

# Page data controls Gatby's lookups and page management, it should
# not get cached ever
aws s3 cp "s3://${BUCKET}/page-data" "s3://${BUCKET}/page-data" \
--recursive \
--cache-control "${cacheControlNever}" \
--metadata-directive REPLACE $ARGS
if [ $? -eq 0 ]; then
echo "Updated page-data directory metadata"
else
echo "Failed to update page-data directory metadata"
fi

# Update all and any files in the static directory to cache forever
aws s3 cp "s3://${BUCKET}/static" "s3://${BUCKET}/static" \
--recursive \
--cache-control "${cacheControlForever}" \
--metadata-directive REPLACE $ARGS
if [ $? -eq 0 ]; then
echo "Updated static directory metadata"
else
echo "Failed to update static directory metadata"
fi

# Update all CSS and JS files to cache forever
# We specifically exclude sw.js, which is used in some
# Gatsby functionality for service workers
aws s3 cp "s3://${BUCKET}/" "s3://${BUCKET}/" \
--recursive \
--cache-control "${cacheControlForever}" \
--metadata-directive REPLACE \
--exclude "*" --include "*.css" --include "*.js" --exclude "sw.js" $ARGS
if [ $? -eq 0 ]; then
echo "Updated all CSS and JS file metadata"
else
echo "Failed to update all CSS and JS file metadata"
fi
22 changes: 22 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
plugins: [
'gatsby-plugin-resolve-src',
'gatsby-plugin-sass',
'gatsby-plugin-react-helmet',
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/assets/images`,
},
},
{
resolve: 'gatsby-plugin-create-client-paths',
options: {
prefixes: [
'/collections/*'
]
}
}
],
}
47 changes: 47 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "cirrus-dashboard",
"description": "a dashboard for cirrus",
"license": "Apache-2.0",
"version": "0.4.0",
"author": "Element 84, Inc. <[email protected]>",
"dependencies": {
"@material-ui/core": "^4.10.2",
"axios": "^0.19.2",
"gatsby": "^2.23.4",
"gatsby-plugin-create-client-paths": "^2.3.4",
"gatsby-plugin-react-helmet": "^3.3.4",
"gatsby-plugin-resolve-src": "^2.1.0",
"gatsby-plugin-sass": "^2.3.4",
"gatsby-source-filesystem": "^2.3.11",
"node-sass": "^4.14.1",
"numeral": "^2.0.6",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-helmet": "^6.1.0",
"react-icons": "^3.10.0"
},
"devDependencies": {},
"keywords": [
"gatsby",
"sass",
"scss"
],
"scripts": {
"build": "gatsby build",
"sonar": "sonar-scanner -Dsonar.projectVersion=$npm_package_version",
"develop": "gatsby develop",
"lint": "Get started linting your code with Eslint and stylelint",
"format": "Get started formatting your code with Eslint, Prettier, and stylelint",
"start": "yarn develop",
"serve": "gatsby serve",
"test": "echo 'Write tests! -> https://gatsby.dev/unit-testing'"
},
"repository": {
"type": "git",
"url": "https://github.com/cirrus-geo/cirrus-dashboard"
},
"bugs": {
"url": "https://github.com/cirrus-geo/cirrus-dashboard/issues"
}
}
8 changes: 8 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Config Parameters Can Be Found Here:
# https://docs.sonarqube.org/latest/analysis/analysis-parameters/
sonar.host.url=https://sonar.example.com/
sonar.projectKey=cirrus-geo:cirrus-dashboard
sonar.projectName=cirrus-dashboard

sonar.sources=.
sonar.sourceEncoding=UTF-8
1 change: 1 addition & 0 deletions src/assets/images/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Remove when images exist in this directory
Loading

0 comments on commit fc09825

Please sign in to comment.