Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup Cognito user pool and copy it to S3 #2

Merged
merged 18 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": [["babel-plugin-dotenv", {
"replacedModuleName": "babel-dotenv"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to make babel and dotenv play nicely together.

}]],
"presets": [
"@babel/preset-env"
]
}
72 changes: 72 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#

defaults: &defaults
docker:
- image: circleci/node:10.15.3
working_directory: ~/sinopia_user_backup

version: 2
jobs:
build:
<<: *defaults
steps:
- checkout
- setup_remote_docker
- restore_cache:
keys:
- dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- dependencies-
- run:
name: Install dependencies
command: npm install
- save_cache:
paths:
- node_modules
key: dependencies-{{ checksum "package.json" }}
- run:
name: Run linter
command: npm run lint
- run:
name: Setup Code Climate test-reporter
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
- run:
name: Run unit tests
command: |
./cc-test-reporter before-build
npm test
./cc-test-reporter after-build --exit-code $?
register_image:
<<: *defaults
steps:
- checkout
- setup_remote_docker
- restore_cache:
key: dependencies-{{ checksum "package.json" }}
- attach_workspace:
at: .
- run:
name: Build & push docker image
# NOTE: the env variables holding docker credentials are stored in the CircleCI dashboard
command: |
docker build -t ld4p/sinopia_user_backup:latest .
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
docker push ld4p/sinopia_user_backup:latest

workflows:
version: 2
build:
jobs:
- build
- register_image:
requires:
- build
filters:
branches:
only:
- master
21 changes: 21 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "2"

exclude_patterns:
- "__tests__/"
- 'eslintrc.js'
- 'jest.config.js'
- '**/node_modules/'

plugins:
eslint:
enabled: true
config:
config: .eslintrc.js
channel: "eslint-5"
duplication:
enabled: true
config:
languages:
- javascript:
nodesecurity:
enabled: true
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.dockerignore
.env
.git
.node-version
Dockerfile
__tests__
node_modules
npm-debug.log
40 changes: 40 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
plugins: [
"import",
"jest",
"security"
],
extends: [
"eslint:recommended",
"plugin:node/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:security/recommended",
"plugin:jest/recommended"
],
env: {
"es6": true,
"jest": true,
"node": true
},
parser: "babel-eslint",
parserOptions: {
ecmaVersion: 2019,
sourceType: "module"
},
overrides: [
{
"files": ["**/*.js"],
"rules": {
// See https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-unsupported-features/es-syntax.md
// rule supposedly matches ECMA version with node
// we get: "Import and export declarations are not supported yet"
"node/no-unsupported-features/es-syntax": "off",
// Avoiding: "warning Found fs.readFileSync with non literal argument ..."
"security/detect-non-literal-fs-filename": "off",
// this is a CLI tool; we DO want to send output to console
"no-console": "off",
}
}
]
}
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM circleci/node:10.15

WORKDIR /home/circleci

COPY . .

RUN npm install

# TODO: Add CMD later once JavaScript package is in place
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
[![CircleCI](https://circleci.com/gh/LD4P/sinopia_indexing_pipeline.svg?style=svg)](https://circleci.com/gh/LD4P/sinopia_indexing_pipeline)
[![Code Climate](https://codeclimate.com/github/LD4P/sinopia_indexing_pipeline/badges/gpa.svg)](https://codeclimate.com/github/LD4P/sinopia_indexing_pipeline)
[![Code Climate Test Coverage](https://codeclimate.com/github/LD4P/sinopia_indexing_pipeline/badges/coverage.svg)](https://codeclimate.com/github/LD4P/sinopia_indexing_pipeline/coverage)

# sinopia_user_backup
A Node component for backing up the Cognito user pool for Sinopia

A Node application that backs up Cognito user pools for the Sinopia project.

## Testing

### Run the linter

```shell
$ npm run lint
```

### Run unit tests

```shell
$ npm test
```

## Build and push image

The CircleCI build is configured to perform these steps automatically on any successful build on the `master` branch. If you need to manually build and push an image, you can do this:

```shell
$ docker build -t ld4p/sinopia_user_backup:latest .
$ docker push ld4p/sinopia_user_backup:latest
```
5 changes: 5 additions & 0 deletions __tests__/backupUsers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('backupUsers', () => {
test('dummy test', () => {
expect(true).toEqual(true)
})
})
3 changes: 3 additions & 0 deletions bin/backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

npx babel-node src/backupUsers.js
10 changes: 10 additions & 0 deletions config/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Allow populating ENV variables using not-check-in .env file (for secrets)
require('dotenv').config()

module.exports = {
awsAccessKey: process.env.AWS_ACCESS_KEY_ID || '',
awsAccessSecret: process.env.AWS_SECRET_ACCESS_KEY || '',
awsRegion: process.env.AWS_REGION || 'us-west-2',
s3BucketUri: process.env.S3_BUCKET_URI || '',
userPoolId: process.env.COGNITO_USER_POOL_ID || 'us-west-2_CGd9Wq136'
}
Loading