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

updated deploy to take in alternative aws profile #307

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion bin/mastarm-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ commander
.option('-e, --env <environment>', 'Environment to use.')
.option('-m, --minify', 'Minify built files.')
.option('-O, --outdir <dir>', 'Publish directory', '')
.option('-c, --credProfile <dir>', 'Alternative AWS Credentials in .aws dir defaults to "default"', '')
.option('--cloudfront <id>', 'CloudFront Distribution ID to invalidate.')
.option('--s3bucket <bucket>', 'S3 Bucket to push to.')
.option('--static-file-directory <dir>', 'Directory of static files to deploy in lieu of building')
.parse(process.argv)

// each of these variables are also used in the logToMsTeams function and
// these need to be defined after potentially decoding a sops-encoded file
let cloudfront, config, env, minify, s3bucket, tag, url
let cloudfront, config, env, minify, s3bucket, tag, url, credProfile

async function deploy () {
// get information about the directory that the config is in
Expand Down Expand Up @@ -89,6 +90,7 @@ async function deploy () {
minify = get('minify')
cloudfront = get('cloudfront')
s3bucket = get('s3bucket')
credProfile = get('cred') || 'default'

const pushToS3 = createPushToS3({
cloudfront,
Expand Down
8 changes: 6 additions & 2 deletions lib/push-to-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ const uuid = require('uuid')

const logger = require('./logger')

module.exports = ({ s3bucket, cloudfront }) => ({ body, outfile }) =>
upload({ body, cloudfront, outfile, s3bucket })
module.exports = ({ s3bucket, cloudfront, credProfile }) => ({ body, outfile }) =>
upload({ body, cloudfront, outfile, s3bucket, credProfile })

/**
*
* Upload the contents of a file to s3.
* Also, invalidate the respective cloudfront path if instructed to do so.
*/
function upload ({ body, s3bucket, cloudfront, outfile }) {
const bucketUrl = `https://s3.amazonaws.com/${s3bucket}`
const credentials = new AWS.SharedIniFileCredentials({profile: credProfile});
return new Promise((resolve, reject) => {
const s3object = new AWS.S3({
params: {
Expand All @@ -23,6 +25,7 @@ function upload ({ body, s3bucket, cloudfront, outfile }) {
Key: outfile
}
})
s3bucket.credentials = credentials

const bytes = bytesToSize(body.byteLength || body.length)
const bucketLink = `<${bucketUrl}/${outfile}|${s3bucket}/${outfile}>`
Expand All @@ -38,6 +41,7 @@ function upload ({ body, s3bucket, cloudfront, outfile }) {
}
if (cloudfront) {
const cf = new AWS.CloudFront()
cf.credentials = credentials
logger
.log(`:lightning: *cloudfront:* invalidating path ${outfile}`)
.then(() => {
Expand Down