Skip to content

Commit d80a611

Browse files
authored
Merge pull request #458 from nursoltan-s/feature/es-db-compare
Report ES/DB - Upload to AWS S3
2 parents 633672c + 3ff964d commit d80a611

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

config/default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@
7474
"BUDGET": 123
7575
}
7676
},
77-
"DEFAULT_M2M_USERID": -101
77+
"DEFAULT_M2M_USERID": -101,
78+
"REPORT_S3_BUCKET": "S3 BUCKET NAME"
7879
}

scripts/es-db-compare/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ during the comparation. You may need to modify/add/delete items in the list.
2020

2121
- `PROJECT_START_ID` and `PROJECT_END_ID` must exist together.
2222
- At least one of `PROJECT_START_ID` with `PROJECT_END_ID` or `PROJECT_LAST_ACTIVITY_AT` needs be set before running the script.
23+
- If you want to upload report to AWS S3 You need to Set `REPORT_S3_BUCKET`, `ACCESS_KEY_ID`, `SECRET_ACCESS_KEY` keys to `config/default.js` file.
24+
- Report file will uploaded to `REPORT_S3_BUCKET` in `es-db-report-<NODE_ENV>-<DD-MM-YYYY-HH-MM-SS>.html` format.
25+
`<NODE_ENV>` - replace with the value for `NODE_ENV` env variable
26+
`<DD-MM-YYYY-HH-MM-SS>` - current date and time in such format
27+
- If `REPORT_S3_BUCKET` variable is not set. Report will be stored in local filesystem.
2328

2429
## Usage
2530

scripts/es-db-compare/index.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import Joi from 'joi';
99
import lodash from 'lodash';
1010
import config from 'config';
11+
import AWS from 'aws-sdk';
12+
import moment from 'moment';
1113

1214
import models from '../../src/models';
1315
import util from '../../src/util';
@@ -298,8 +300,35 @@ async function main() {
298300
metadata: dataForMetadata,
299301
project: dataForProject,
300302
});
301-
fs.writeFileSync(reportPathname, report);
302-
console.log(`report is written to ${reportPathname}`);
303+
304+
if (config.has('REPORT_S3_BUCKET')) {
305+
// Make sure set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY in Environment Variables
306+
const s3 = new AWS.S3();
307+
308+
const fileName =
309+
`es-db-report-${process.env.NODE_ENV || 'development'}-${moment().format('DD-MM-YYYY-HH-MM-SS')}.html`;
310+
311+
const params = {
312+
Bucket: config.get('REPORT_S3_BUCKET'),
313+
Key: fileName,
314+
Body: report,
315+
ContentType: 'text/html',
316+
};
317+
318+
await new Promise((resolve, reject) => {
319+
s3.putObject(params, (error) => {
320+
if (error) {
321+
reject(error);
322+
} else {
323+
console.log(`Report uploaded successfully on S3. FileName is: ${fileName}`);
324+
resolve();
325+
}
326+
});
327+
});
328+
} else {
329+
fs.writeFileSync(reportPathname, report);
330+
console.log(`Report is written to local file ${reportPathname}`);
331+
}
303332
}
304333

305334
main().then(() => {

scripts/es-db-compare/verification/Verification.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Verification
22

33
## Steps
4+
- Set `REPORT_S3_BUCKET`, `ACCESS_KEY_ID`, `SECRET_ACCESS_KEY` keys to `config/default.js` file. If you don't set report will be generated in local file
45
- Start ES and DB services: `docker-compose -f local/docker-compose.yml up`
56
- Insert ES and DB data:
67

@@ -17,4 +18,4 @@
1718
PROJECT_LAST_ACTIVITY_AT=0 npm run es-db-compare
1819
```
1920

20-
- See `./report.html` under the root project directory.
21+
- See uploaded file in AWS Console or See `./report.html` under the root project directory.

0 commit comments

Comments
 (0)