Commit 45f2edf8 authored by Vladimir Kiryakov's avatar Vladimir Kiryakov
Browse files

cli scripts

parent c2c0565d
### run in develop mode
### Deploy to AWS
- configure AWS cli sdk
- install node js and yarn
- execute
```bash
yarn install
yarn install
yarn run deploy --key <Name of an existing EC2 KeyPair>
```
- wait for CloudFormation Stack creation
```bash
yarn run publish
```
### Run in develop mode
- install node js and yarn
- execute
```bash
yarn start
yarn install
yarn start
```
\ No newline at end of file
......@@ -30,20 +30,22 @@ prog
}).then((data) => {
console.log(JSON.stringify(data))
}).catch((err) => {
console.error(err, err.message)
console.error(err.message)
});
});
prog
.command('publish', 'Sync Web to s3')
.option('--bucket <bucket>', 'static website bucket', NO_VALIDATE, null, false)
.option('--stackName <stackName>', 'Stack Name', NO_VALIDATE, DEFAULT_STACK_NAME)
.action((args, options) => {
syncUI(options.bucket).then(({stdout, stderr}) => {
console.log(`stdout: ${stdout}`);
console.error(`stderr: ${stderr}`);
syncUI(options.stackName).then(({stdout, stderr, websiteURL}) => {
console.log(`${stdout}`);
console.error(`${stderr}`);
console.log(`build has been synced to s3 bucket`);
console.log(`website URL: ${websiteURL}`);
}).catch((err) => {
console.error(err, err.message)
console.error(err.message)
});
});
......@@ -62,7 +64,7 @@ prog
console.log(JSON.stringify(data))
})
.catch((err) => {
console.error(err, err.message)
console.error(err.message)
});
});
......@@ -81,7 +83,7 @@ prog
console.log(JSON.stringify(data))
})
.catch((err) => {
console.error(err, err.message)
console.error(err.message)
});
});
......
......@@ -31,21 +31,21 @@ const describeStacks = (stackName) => {
});
};
const syncUI = (bucket) => {
return new Promise((resolve, reject) => {
if (!bucket) {
describeStacks(DEFAULT_STACK_NAME)
.then((data) => {
const stackOutputs = _.get(data, 'Stacks[0].Outputs', []);
const s3BucketNameOutput = _.find(stackOutputs, {OutputKey: 'S3BucketName'});
const S3BucketName = _.get(s3BucketNameOutput, 'OutputValue');
if (!S3BucketName) reject('no S3BucketSecureURL in template output');
return sync(`${__dirname}/../build`, S3BucketName);
})
} else {
return sync(`${__dirname}/../build`, bucket);
}
});
const syncUI = (stackName) => {
return describeStacks(stackName)
.then((data) => {
const stackOutputs = _.get(data, 'Stacks[0].Outputs', []);
const s3BucketNameOutput = _.find(stackOutputs, {OutputKey: 'S3BucketName'});
const websiteURLOutpup = _.find(stackOutputs, {OutputKey: 'WebsiteURL'});
const websiteURL = _.get(websiteURLOutpup, 'OutputValue');
const S3BucketName = _.get(s3BucketNameOutput, 'OutputValue');
if (!S3BucketName) return Promise.reject('no S3BucketSecureURL in template output');
return sync(`${__dirname}/../build`, S3BucketName).then(({stdout, stderr}) => {
return {stdout, stderr, websiteURL}
});
})
};
......@@ -61,22 +61,19 @@ const sync = (dirPath, bucket) => {
};
const createOrUpdateStack = ({stackName, key, instanceType, template}) => {
return new Promise((resolve, reject) => {
describeStacks(stackName)
.then((data) => {
return updateStack({stackName, key, instanceType, template});
})
.catch((err) => {
if (_.includes(err.message, 'does not exist')) {
createStack({stackName, key, instanceType, template});
} else {
return reject(err);
}
});
});
return describeStacks(stackName)
.then((data) => {
return updateStack({stackName, key, instanceType, template});
})
.catch((err) => {
if (_.includes(err.message, 'does not exist')) {
return createStack({stackName, key, instanceType, template});
} else {
return Propmise.reject(err);
}
});
};
const createStack = ({stackName, key, instanceType, template}) => {
return new Promise((resolve, reject) => {
const params = {
......@@ -90,7 +87,6 @@ const createStack = ({stackName, key, instanceType, template}) => {
}],
TemplateBody: template
};
cloudformation.createStack(params, (err, data) => {
if (err) reject(err);
resolve(data);
......@@ -111,6 +107,7 @@ const updateStack = ({stackName, key, instanceType, template}) => {
}],
TemplateBody: template,
};
cloudformation.updateStack(params, (err, data) => {
if (err) reject(err);
resolve(data);
......
......@@ -36,12 +36,17 @@
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"deploy": "react-scripts build"
"deploy": "node cli/app.js deploy",
"publish": "react-scripts build && node cli/app.js publish",
"describe-stacks": "node cli/app.js describe-stacks"
},
"devDependencies": {
"stylelint": "^9.2.0",
"stylelint-config-recommended": "^2.1.0",
"stylelint-config-styled-components": "^0.1.1",
"stylelint-processor-styled-components": "^1.3.1"
},
"eslintConfig": {
}
}
{
"extends": [
"plugin:react/recommended"
],
"plugins": [
"react"
],
"rules": {
"react/jsx-uses-vars": 1,
"react/react-in-jsx-scope": 1
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment