Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Antibioticvz committed Mar 21, 2018
1 parent b000785 commit 7e3d804
Show file tree
Hide file tree
Showing 96 changed files with 4,272 additions and 19,929 deletions.
28 changes: 17 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules
cognito/node_modules

# testing
/coverage
cognito/coverage

# production
/build
cognito/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
cognito/.DS_Store
cognito/.env.local
cognito/.env.development.local
cognito/.env.test.local
cognito/.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
cognito/npm-debug.log*
cognitoyarn-debug.log*
cognitoyarn-error.log*

api/schema.gql
api/schema.json

api/dist/*
api/node_modules
477 changes: 377 additions & 100 deletions .idea/workspace.xml

Large diffs are not rendered by default.

64 changes: 22 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
# aws-cognito-react

Reference implementation / boilerplate for AWS Cognito user management
### Config cluster cli

![signin](https://s3-us-west-2.amazonaws.com/union25-public/aws-cognito-login.png)

## Introduction

I would like to start every project knowing user management is taken care of so I can focus on making a great app. I want a service that will scale and not require extra back-end management / development. I want to be able to customize the look for new apps and control the state a flow
```
ecs-cli configure --cluster test --region us-east-1 --config-name test
aws-cognito-react primary goal is to provide user management services for a web app in a scalable serverless way.
# Create cluster and cloud formation
ecs-cli up --cluster gr --keypair gramm --capability-iam --size 1 --port 443 --instance-type c4.large -f
# or
ecs-cli up --cluster gr --keypair gramm --capability-iam --size 1 --port 443 --instance-type t2.micro -f
## Install
# Compose
ecs-cli compose --verbose --project-name mygr --file ecs.yml up --create-log-groups --cluster mygr
```bash
git clone [email protected]:dbroadhurst/aws-cognito-react.git
cd aws-cognito-react
npm install
npm run start
```

Your browser should open at
### Run Docker

```
http://localhost:3000
```

## AWS Cognito Setup

Once your AWS Cognito account is setup update the config file in src/components/Auth/Auth.js

## Description
# Start docker Dev
./run.sh
My original idea was to provide user management as a package but it became clear adding user management to an existing project is tricky. If you are in the position where you need to retro fit user management into an existing project then this project will help but the cleanest path is to start with this project as a boilerplate. The project has been setup using create-react-app which is currently the most robust way to setup a react project.
# Build docker prod and push to s3
cd api/cognito
./build.sh
The stack has 3 layers that help provide an opportunity to extend and even replace sections of the stack.
# Docker test ready prod build
docker run --rm -p 3000:3000 CONTAINER_NAME
[aws-cognito-react](https://github.com/dbroadhurst/aws-cognito-react) front-end boilerplate

[aws-cognito-redux-saga](https://github.com/dbroadhurst/aws-cognito-redux-saga) asynchronous code management

[aws-cognito-promise](https://github.com/dbroadhurst/aws-cognito-promises) promise wrappers for the AWS Cognito SDK

The AWS guide can be found [here](http://docs.aws.amazon.com/cognito/latest/developerguide/setting-up-the-javascript-sdk.html)

You can find a working example [here](http://cognito.dbroadhurst.net)

## Road map
```
> Frontend
http://localhost:3000

* Password update - Done
* Social identity integration
* Authenticated routes
* Authorized routes
* Get help from contributors
* Provide ability for administrators to add new users - Done
> Graphiql
http://localhost:5000/graphiql
6 changes: 6 additions & 0 deletions api/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
.git
coverage/
.dockerignore
Dockerfile
.gitignore
Binary file added api/.yarn-cache.tgz
Binary file not shown.
12 changes: 4 additions & 8 deletions dockerize-me/Dockerfile → api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:8.5.0-alpine
FROM node:8.9.4-alpine

MAINTAINER Victor Zadorozhnyy <[email protected]>

Expand All @@ -22,11 +22,7 @@ RUN mkdir -p /opt/app && cd /opt/app && ln -s /tmp/node_modules
# Copy the code
ADD . /opt/app

RUN yarn build --production
RUN yarn build

# Install `serve` to run the application.
RUN npm install -g serve

EXPOSE 3000

CMD serve -s build -p 3000
EXPOSE 5000
CMD ["node", "dist/index.js"]
22 changes: 22 additions & 0 deletions api/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

touch yarn.lock

# Init empty cache file
if [ ! -f .yarn-cache.tgz ]; then
echo "Init empty .yarn-cache.tgz"
tar cvzf .yarn-cache.tgz --files-from /dev/null
fi

docker build . -t api
docker tag api:latest 079659954133.dkr.ecr.us-east-1.amazonaws.com/api:latest

docker run --rm --entrypoint cat api:latest /tmp/yarn.lock > /tmp/yarn.lock
if ! diff -q yarn.lock /tmp/yarn.lock > /dev/null 2>&1; then
echo "Saving Yarn cache"
docker run --rm --entrypoint tar api:latest czf - /root/.yarn-cache/ > .yarn-cache.tgz
echo "Saving yarn.lock"
cp /tmp/yarn.lock yarn.lock
fi

docker push 079659954133.dkr.ecr.us-east-1.amazonaws.com/api:latest
File renamed without changes.
16 changes: 16 additions & 0 deletions api/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**/node_modules",
"schema.json"
],
"verbose": true,
"execMap": {
"js": "node --harmony"
},
"watch": [
"/opt/app"
],
"ext": "js json"
}
27 changes: 27 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "api",
"version": "0.0.1",
"private": true,
"description": "RPG Boilerplate API",
"author": "Chad Furman <[email protected]>",
"main": "src/index.js",
"scripts": {
"start": "nodemon src/index.js --exec babel-node --presets es2015,stage-2",
"build": "babel src -d dist --presets es2015,stage-2",
"lint": "standard --fix ./**/*.js"
},
"dependencies": {
"babel-cli": "^6.26.0",
"config": "^1.26.2",
"cookie-parser": "^1.4.3",
"dotenv": "^4.0.0",
"express": "^4.13.3",
"node-fetch": "^1.7.3",
"postgraphile": "^4.0.0-alpha2.20"
},
"devDependencies": {
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"nodemon": "^1.12.1"
}
}
43 changes: 43 additions & 0 deletions api/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
import express from 'express'
import postgraphile from 'postgraphile'
// import PluginName from './plugins/PluginName'
// const plugins = [
// PluginName
// ]
const app = express()
const pgConnectionString = 'postgresql://postgres:[email protected]:5432/mygramm'
const pgSchemasGramm = 'public'
const pgOptions = {"watchPg": true, "graphiql": true, "exportJsonSchemaPath": "./schema.json", "exportGqlSchemaPath": "./schema.gql", "showErrorStack": true, "pgDefaultRole": "postgres"}
// pgOptions.appendPlugins = plugins
//app.use(postgraphile(pgConnectionString, [...pgSchemas, ...pgSchemasGramm], pgOptions))
app.use(postgraphile(pgConnectionString, pgSchemasGramm, pgOptions))
app.listen(3000, ()=> console.info('Postgraphile API started.\n'))
*/
import express from 'express'
import postgraphile from 'postgraphile'

const app = express();

const pgConnectionString = 'postgresql://postgres:[email protected]:5432/mygramm'
//const pgConnectionString = 'postgresql://rpg_app:localdev@localhost:8001/localdb'

app.use(postgraphile(pgConnectionString, 'public',
{
"watchPg": true,
"graphiql": true,
"exportJsonSchemaPath": "./schema.json",
"exportGqlSchemaPath": "./schema.gql",
"showErrorStack": true
}
))

app.listen(5000, ()=> console.info('Postgraphile API started.\n'));
23 changes: 23 additions & 0 deletions api/src/plugins/PluginName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export default function PluginName (builder) {

builder.hook('GraphQLObjectType:fields',
(
fields,
{ extend, getTypeByName },
context
) => {
const { scope: { isMutationPayload }, GraphQLObjectType} = context
if (!isMutationPayload) {
return fields
}
const String = getTypeByName('String')

return extend(fields, {
anExtraFieldOnMutations: {
type: String,
resolve: () => "An extra field!"
},
})
}
)
}
Loading

0 comments on commit 7e3d804

Please sign in to comment.