Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"allow": ["_id"]
}
],
"no-console": "off",
"import/no-named-as-default": "off"
}
}
1 change: 0 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
4 changes: 2 additions & 2 deletions src/createCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
64 changes: 32 additions & 32 deletions src/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dotenv from 'dotenv';
import fs from 'fs';
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
Expand All @@ -12,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;
};

Expand All @@ -48,12 +49,9 @@ 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 \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(
'error: 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');
return false;
}
return true;
Expand All @@ -70,19 +68,27 @@ 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',
);
console.error(
'error: 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',
`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;
}
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;

Expand All @@ -92,7 +98,7 @@ const deploy = async (opts) => {
return false;
}

// load environment
// load environment variables
dotenv.config({ path: env });

// validate environment variables
Expand All @@ -112,17 +118,11 @@ const deploy = async (opts) => {
DISTRIBUTION,
} = process.env;

console.log(
console.info(
`publishing app ${REACT_APP_GRAASP_APP_ID} version ${REACT_APP_VERSION}`,
);

// 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}`;

Expand Down Expand Up @@ -158,15 +158,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;
}
Expand All @@ -190,7 +190,7 @@ const deploy = async (opts) => {
console.error(err, err.stack);
} else {
// successful response
console.log(data);
console.info(data);
}
});

Expand Down
9 changes: 2 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3360,21 +3360,16 @@ 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.19, lodash@^4.0.0:
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==

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==

loose-envify@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
Expand Down