From a7aa57bebaab6d1fc639a0c6c0ff14455aa112e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Jul 2020 01:27:21 +0000 Subject: [PATCH 1/8] build(deps): bump lodash from 4.17.15 to 4.17.19 Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19) Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 402473f..67c7419 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "fs-extra": "7.0.1", "hosted-git-info": "2.7.1", "inquirer": "6.2.2", - "lodash": "4.17.15", + "lodash": "4.17.19", "yargs": "12.0.5" } } diff --git a/yarn.lock b/yarn.lock index 95daabb..a08f6a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3246,15 +3246,15 @@ lodash.templatesettings@^4.0.0: dependencies: lodash._reinterpolate "^3.0.0" -lodash@4.17.15, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15: +lodash@4.17.15: version "4.17.15" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== -lodash@^4.17.11, lodash@^4.2.1: - version "4.17.13" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.13.tgz#0bdc3a6adc873d2f4e0c4bac285df91b64fc7b93" - integrity sha512-vm3/XWXfWtRua0FkUyEHBZy8kCPjErNBT9fJx8Zvs+U6zjqPbTUOpkaoum3O5uiA8sm+yNMHXfYkTUHFoMxFNA== +lodash@4.17.19, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.2.1: + version "4.17.19" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" + integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== loose-envify@^1.0.0: version "1.4.0" From e85ac364209ec57c325ab7839fcb484ab28cef83 Mon Sep 17 00:00:00 2001 From: Uchendu Nwachukwu Date: Sat, 18 Jul 2020 15:50:44 +0200 Subject: [PATCH 2/8] chore: enable linting warning for console log --- .eslintrc | 1 - 1 file changed, 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 0c89313..91b2eaa 100644 --- a/.eslintrc +++ b/.eslintrc @@ -12,7 +12,6 @@ "allow": ["_id"] } ], - "no-console": "off", "import/no-named-as-default": "off" } } From 2338ead532f028319a64d87de9cbb73cd9a5c96d Mon Sep 17 00:00:00 2001 From: Uchendu Nwachukwu Date: Sun, 26 Jul 2020 13:35:53 +0200 Subject: [PATCH 3/8] chore: try out promisify --- src/deploy.js | 33 +++++++++++++++++++++++++++++++-- yarn.lock | 2 +- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/deploy.js b/src/deploy.js index d10e366..b112432 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -1,9 +1,10 @@ import aws from 'aws-sdk'; -import s3 from 's3-node-client'; +// import s3 from 's3-node-client'; import dotenv from 'dotenv'; import fs from 'fs'; -import cliProgress from 'cli-progress'; +// import cliProgress from 'cli-progress'; import _ from 'lodash'; +import { promisify } from './utils'; const validateTag = (tag) => { // Both compilation hints because of backslashes used in RegExp but unecessary by conception in JS Strings @@ -103,6 +104,10 @@ const deploy = async (opts) => { return false; } + const { REACT_APP_GRAASP_APP_ID, REACT_APP_VERSION } = process.env; + + /* + const { REACT_APP_GRAASP_DEVELOPER_ID, REACT_APP_GRAASP_APP_ID, @@ -112,10 +117,33 @@ const deploy = async (opts) => { DISTRIBUTION, } = process.env; +*/ + console.log( `publishing app ${REACT_APP_GRAASP_APP_ID} version ${REACT_APP_VERSION}`, ); + const getAwsCredentialsPromise = promisify(aws.config.getCredentials); + console.log('Before promise'); + getAwsCredentialsPromise() + .then((err) => { + console.log('In then promises'); + if (err) { + // credentials not loaded + console.error(err.stack); + } + }) + .catch((err) => { + console.log('In catch promises'); + if (err) { + // credentials not loaded + console.error(err.stack); + } + }); + console.log('After promise'); + + return false; + /* // configure the deployment aws.config.getCredentials((err) => { if (err) { @@ -195,6 +223,7 @@ const deploy = async (opts) => { }); return true; + */ }; export default deploy; diff --git a/yarn.lock b/yarn.lock index e3ce6e9..6b50296 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3365,7 +3365,7 @@ lodash@4.17.15: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== -lodash@4.17.19, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.2.1: +lodash@4.17.19, lodash@^4.0.0, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.2.1: version "4.17.19" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== From 449109249e87ab0c28aa3c26802d93519b705292 Mon Sep 17 00:00:00 2001 From: Uchendu Nwachukwu Date: Sun, 26 Jul 2020 13:38:02 +0200 Subject: [PATCH 4/8] chore: force commit with eslint errors --- src/deploy.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/deploy.js b/src/deploy.js index b112432..5141379 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -1,8 +1,8 @@ import aws from 'aws-sdk'; -// import s3 from 's3-node-client'; +import s3 from 's3-node-client'; import dotenv from 'dotenv'; import fs from 'fs'; -// import cliProgress from 'cli-progress'; +import cliProgress from 'cli-progress'; import _ from 'lodash'; import { promisify } from './utils'; @@ -104,10 +104,6 @@ const deploy = async (opts) => { return false; } - const { REACT_APP_GRAASP_APP_ID, REACT_APP_VERSION } = process.env; - - /* - const { REACT_APP_GRAASP_DEVELOPER_ID, REACT_APP_GRAASP_APP_ID, @@ -117,8 +113,6 @@ const deploy = async (opts) => { DISTRIBUTION, } = process.env; -*/ - console.log( `publishing app ${REACT_APP_GRAASP_APP_ID} version ${REACT_APP_VERSION}`, ); @@ -143,7 +137,7 @@ const deploy = async (opts) => { console.log('After promise'); return false; - /* + // configure the deployment aws.config.getCredentials((err) => { if (err) { @@ -223,7 +217,6 @@ const deploy = async (opts) => { }); return true; - */ }; export default deploy; From 62ea0f8f538c7a31f7d86e220917085687046330 Mon Sep 17 00:00:00 2001 From: Uchendu Nwachukwu Date: Sun, 26 Jul 2020 14:53:24 +0200 Subject: [PATCH 5/8] feat: load sync aws credentials --- src/deploy.js | 82 +++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 48 deletions(-) diff --git a/src/deploy.js b/src/deploy.js index 5141379..4f1f351 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -4,7 +4,7 @@ import dotenv from 'dotenv'; import fs from 'fs'; import cliProgress from 'cli-progress'; import _ from 'lodash'; -import { promisify } from './utils'; +// import { promisify } from './utils'; const validateTag = (tag) => { // Both compilation hints because of backslashes used in RegExp but unecessary by conception in JS Strings @@ -13,28 +13,28 @@ const validateTag = (tag) => { // eslint-disable-next-line no-useless-escape const pattern = new RegExp('^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z]*)?$') if (tag === 'latest' || pattern.test(tag)) { - console.log(`info: validated tag ${tag}`); + console.info(`validated tag ${tag}`); return true; } - console.error(`error: unable to validate version '${tag}'`); + console.error(`unable to validate version '${tag}'`); return false; }; const validateEnv = (env) => { if (fs.existsSync(env)) { - console.log(`info: validated environment file ${env}`); + console.info(`validated environment file ${env}`); return true; } - console.log(`error: environment file '${env}' does not exist`); + console.error(`environment file '${env}' does not exist`); return false; }; const validateBuild = (build) => { if (fs.existsSync(build)) { - console.log(`info: validated build directory ${build}`); + console.info(`validated build directory ${build}`); return true; } - console.log(`error: build directory '${build}' does not exist`); + console.error(`build directory '${build}' does not exist`); return false; }; @@ -49,12 +49,12 @@ const validateAppVariables = ({ _.isUndefined(REACT_APP_GRAASP_APP_ID) ) { console.error( - 'error: environment variables REACT_APP_GRAASP_APP_ID, REACT_APP_GRAASP_DEVELOPER_ID and/or REACT_APP_HOST are not defined', + 'environment variables REACT_APP_GRAASP_APP_ID, REACT_APP_GRAASP_DEVELOPER_ID and/or REACT_APP_HOST are not defined', ); console.error( - 'error: you can specify them through a .env file in the app root folder', + 'you can specify them through a .env file in the app root folder', ); - console.error('error: or through another file specified with the -e flag'); + console.error('or through another file specified with the -e flag'); return false; } return true; @@ -71,19 +71,32 @@ const validateAwsCredentialsVariables = ({ _.isUndefined(AWS_SECRET_ACCESS_KEY) ) { console.error( - 'error: environment variables BUCKET, AWS_ACCESS_KEY_ID and/or AWS_SECRET_ACCESS_KEY are not defined', + 'environment variables BUCKET, AWS_ACCESS_KEY_ID and/or AWS_SECRET_ACCESS_KEY are not defined', ); console.error( - 'error: make sure you setup your credentials file correctly using the scripts/setup.sh script', + 'make sure you setup your credentials file correctly using the scripts/setup.sh script', ); console.error( - 'error: and contact your favourite Graasp engineer if you keep running into trouble', + 'and contact your favourite Graasp engineer if you keep running into trouble', ); return false; } return true; }; +const loadAwsCredentials = async () => { + const awsCredentials = new aws.Credentials(); + await awsCredentials.getPromise().then( + async () => true, + (err) => { + console.error(err.stack); + return false; + }, + ); + // set the AWS credentials into the global object + aws.config.credentials = awsCredentials; +}; + const deploy = async (opts) => { const { tag, env, build } = opts; @@ -93,7 +106,7 @@ const deploy = async (opts) => { return false; } - // load environment + // load environment variables dotenv.config({ path: env }); // validate environment variables @@ -113,38 +126,11 @@ const deploy = async (opts) => { DISTRIBUTION, } = process.env; - console.log( + console.info( `publishing app ${REACT_APP_GRAASP_APP_ID} version ${REACT_APP_VERSION}`, ); - const getAwsCredentialsPromise = promisify(aws.config.getCredentials); - console.log('Before promise'); - getAwsCredentialsPromise() - .then((err) => { - console.log('In then promises'); - if (err) { - // credentials not loaded - console.error(err.stack); - } - }) - .catch((err) => { - console.log('In catch promises'); - if (err) { - // credentials not loaded - console.error(err.stack); - } - }); - console.log('After promise'); - - return false; - - // configure the deployment - aws.config.getCredentials((err) => { - if (err) { - // credentials not loaded - console.error(err.stack); - } - }); + loadAwsCredentials(); const APP_PATH = `${REACT_APP_GRAASP_DEVELOPER_ID}/${REACT_APP_GRAASP_APP_ID}/${REACT_APP_VERSION}`; @@ -180,15 +166,15 @@ const deploy = async (opts) => { // e.g. invalidate cache }); - console.log( - `info: published app to https://${REACT_APP_HOST}/${APP_PATH}/index.html`, + console.info( + `published app to https://${REACT_APP_HOST}/${APP_PATH}/index.html`, ); // ensure the correct distribution variables are defined if (_.isUndefined(DISTRIBUTION)) { - console.error('error: environment variable DISTRIBUTION is not defined'); + console.error('environment variable DISTRIBUTION is not defined'); console.error( - 'error: contact your favourite Graasp engineer if you keep running into trouble', + 'contact your favourite Graasp engineer if you keep running into trouble', ); return false; } @@ -212,7 +198,7 @@ const deploy = async (opts) => { console.error(err, err.stack); } else { // successful response - console.log(data); + console.info(data); } }); From 89e88212f644c5b9a783259500d239ea32732bbe Mon Sep 17 00:00:00 2001 From: Uchendu Nwachukwu Date: Sun, 26 Jul 2020 14:56:30 +0200 Subject: [PATCH 6/8] chore: update flag descriptions --- src/createCli.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/createCli.js b/src/createCli.js index 2a8389d..fcca0d4 100644 --- a/src/createCli.js +++ b/src/createCli.js @@ -68,13 +68,13 @@ const createCli = (argv) => { .option('e', { alias: 'env', type: 'string', - describe: 'Environment used to load variables from', + describe: 'Environment file used to load variables from', }) .option('b', { alias: 'build', type: 'string', default: DEFAULT_BUILD_DIR, - describe: 'Path to the build directory that is deployed', + describe: 'Path to the build directory that will be deployed', }), handler: deploy, }) From 7a288e8b7be432b995a731bf6800b664382eb68a Mon Sep 17 00:00:00 2001 From: Uchendu Nwachukwu Date: Sun, 26 Jul 2020 14:59:56 +0200 Subject: [PATCH 7/8] chore: assemble error outputs in together --- src/deploy.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/deploy.js b/src/deploy.js index 4f1f351..b5b3dc6 100644 --- a/src/deploy.js +++ b/src/deploy.js @@ -49,12 +49,9 @@ const validateAppVariables = ({ _.isUndefined(REACT_APP_GRAASP_APP_ID) ) { console.error( - 'environment variables REACT_APP_GRAASP_APP_ID, REACT_APP_GRAASP_DEVELOPER_ID and/or REACT_APP_HOST are not defined', + `environment variables REACT_APP_GRAASP_APP_ID, REACT_APP_GRAASP_DEVELOPER_ID and/or REACT_APP_HOST are not defined \n + you can specify them through a .env file in the app root folder or through another file specified with the -e flag`, ); - console.error( - 'you can specify them through a .env file in the app root folder', - ); - console.error('or through another file specified with the -e flag'); return false; } return true; @@ -71,13 +68,8 @@ const validateAwsCredentialsVariables = ({ _.isUndefined(AWS_SECRET_ACCESS_KEY) ) { console.error( - 'environment variables BUCKET, AWS_ACCESS_KEY_ID and/or AWS_SECRET_ACCESS_KEY are not defined', - ); - console.error( - 'make sure you setup your credentials file correctly using the scripts/setup.sh script', - ); - console.error( - 'and contact your favourite Graasp engineer if you keep running into trouble', + `environment variables BUCKET, AWS_ACCESS_KEY_ID and/or AWS_SECRET_ACCESS_KEY are not defined. \n + make sure you setup your credentials file correctly using the scripts/setup.sh script and contact your favourite Graasp engineer if you keep running into trouble`, ); return false; } From 28a0dc57aca9c7c6be40d20ee51bf38865597d99 Mon Sep 17 00:00:00 2001 From: Uchendu Nwachukwu Date: Sun, 26 Jul 2020 15:05:07 +0200 Subject: [PATCH 8/8] chore: remove obsolete default env variable --- src/config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config.js b/src/config.js index 89bb429..9e2d689 100644 --- a/src/config.js +++ b/src/config.js @@ -18,4 +18,3 @@ export const GRAASP_IGNORE_FILE = '.graaspignore'; // deploy settings export const DEFAULT_BUILD_DIR = './build'; export const DEFAULT_APP_VERSION = 'latest'; -export const DEFAULT_ENV = '.env.dev';