Skip to content

Commit 16c7713

Browse files
authored
Merge pull request #293 from conveyal/dev
Next release
2 parents 5be1b1f + f34e5b0 commit 16c7713

File tree

4 files changed

+74
-45
lines changed

4 files changed

+74
-45
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,20 @@ Utilize best practices when forming a commit message using [Commitzen](http://co
130130

131131
### `deploy`
132132

133-
Build, push to S3, and invalidate CloudFront in one command.
133+
Build, push to S3, and invalidate CloudFront in one command. If the static-file-directory flag is set, then mastarm will not build any files with browserify, and instead it will just upload all files in the base level of the specified directory.
134134

135135
```shell
136136
$ mastarm deploy --help
137137

138-
Usage: deploy [options] [entries...]
139-
140-
Bundle & Deploy JavaScript & CSS
138+
Usage: mastarm-deploy [options]
141139

142140
Options:
143-
144-
-h, --help output usage information
145-
--cloudfront CloudFront Distribution ID to invalidate.
146-
--s3bucket S3 Bucket to push to.
141+
-m, --minify Minify built files.
142+
-O, --outdir <dir> Publish directory (default: "")
143+
--cloudfront <id> CloudFront Distribution ID to invalidate.
144+
--s3bucket <bucket> S3 Bucket to push to.
145+
--static-file-directory <dir> Directory of static files to deploy in lieu of building
146+
-h, --help output usage information
147147
```
148148

149149
#### Slack Notifications

bin/mastarm-deploy

+64-36
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require('path')
44

55
const commander = require('commander')
66
const execa = require('execa')
7+
const fs = require('fs-extra')
78
const gitRepoIsUpToDate = require('git-repo-is-up-to-date')
89
const commit = require('this-commit')()
910
const username = require('username')
@@ -26,8 +27,9 @@ commander
2627
.option('-e, --env <environment>', 'Environment to use.')
2728
.option('-m, --minify', 'Minify built files.')
2829
.option('-O, --outdir <dir>', 'Publish directory', '')
29-
.option('--cloudfront', 'CloudFront Distribution ID to invalidate.')
30-
.option('--s3bucket', 'S3 Bucket to push to.')
30+
.option('--cloudfront <id>', 'CloudFront Distribution ID to invalidate.')
31+
.option('--s3bucket <bucket>', 'S3 Bucket to push to.')
32+
.option('--static-file-directory <dir>', 'Directory of static files to deploy in lieu of building')
3133
.parse(process.argv)
3234

3335
// each of these variables are also used in the logToMsTeams function and
@@ -52,18 +54,21 @@ async function deploy () {
5254
process.exit(1)
5355
}
5456

55-
// decrypt env file using sops to make sure old file is overwritten with
56-
// data from encoded sops file
57-
const configPath = path.resolve(commander.config)
58-
console.log('decrypting env file with sops')
59-
const {stdout} = await execa(
60-
'sops',
61-
[
62-
'-d',
63-
path.join(configPath, 'env.enc.yml')
64-
]
65-
)
66-
await writeFile(path.join(configPath, 'env.yml'), stdout)
57+
// no decryption needed during workflow to upload just static files
58+
if (!commander.staticFileDirectory) {
59+
// decrypt env file using sops to make sure old file is overwritten with
60+
// data from encoded sops file
61+
const configPath = path.resolve(commander.config)
62+
console.log('decrypting env file with sops')
63+
const {stdout} = await execa(
64+
'sops',
65+
[
66+
'-d',
67+
path.join(configPath, 'env.enc.yml')
68+
]
69+
)
70+
await writeFile(path.join(configPath, 'env.yml'), stdout)
71+
}
6772
// at this point, we can be certain that the local configurations repo
6873
// directory matches what has been committed and pushed to the remote repo
6974
}
@@ -80,19 +85,8 @@ async function deploy () {
8085
})
8186
}
8287

83-
const files = util.parseEntries([...commander.args, ...(get('entries') || [])])
84-
util.assertEntriesExist(files)
85-
const sourceFiles = files.map(f => f[0])
86-
const outfiles = [...files.map(f => f[1]), ...files.map(f => `${f[1]}.map`)]
87-
8888
env = get('env') || 'development'
8989
minify = get('minify')
90-
const buildOpts = {
91-
config,
92-
env,
93-
files,
94-
minify
95-
}
9690
cloudfront = get('cloudfront')
9791
s3bucket = get('s3bucket')
9892

@@ -108,18 +102,52 @@ async function deploy () {
108102
:hash: *commit:* ${commit}
109103
:seedling: *env:* ${env}
110104
:compression: *minify:* ${minify}
111-
:package: *s3bucket:* ${s3bucket}
112-
:hammer_and_wrench: *building:* ${sourceFiles.join(', ')}`
105+
:package: *s3bucket:* ${s3bucket}`
113106
)
114-
107+
let outfiles
115108
try {
116-
await build(buildOpts)
117-
await logger.log(`:rocket: *uploading:* ${sourceFiles.length * 2} file(s)`)
109+
// If the flag staticFileDirectory is set, upload all files found in
110+
// the base level of the given directory.
111+
if (commander.staticFileDirectory) {
112+
const staticDirPath = path.resolve(commander.staticFileDirectory)
113+
process.chdir(staticDirPath)
114+
outfiles = []
115+
const files = await fs.readdir(staticDirPath)
116+
await Promise.all(files.map(async file => {
117+
const fileStats = await fs.stat(file)
118+
if (!fileStats.isDirectory()) {
119+
outfiles.push(file)
120+
}
121+
}))
122+
await logger.log(`:rocket: *uploading:* ${outfiles.length} file(s)`)
123+
} else {
124+
// Otherwise, upload the files specified with the entries arg.
125+
const files = util.parseEntries([...commander.args, ...(get('entries') || [])])
126+
// assert that the files exist if not uploading from static file directory
127+
util.assertEntriesExist(files)
128+
// build files using mastarm build
129+
outfiles = [...files.map(f => f[1]), ...files.map(f => `${f[1]}.map`)]
130+
const sourceFiles = files.map(f => f[0])
131+
await logger.log(`:hammer_and_wrench: *building:* ${sourceFiles.join(', ')}`)
132+
const buildOpts = {
133+
config,
134+
env,
135+
files,
136+
minify
137+
}
138+
await build(buildOpts)
139+
await logger.log(`:rocket: *uploading:* ${sourceFiles.length * 2} file(s)`)
140+
}
141+
142+
// upload files to s3 and invalid cloudfront if needed
118143
await Promise.all(
119-
outfiles.map(outfile =>
120-
readFile(outfile).then(body => pushToS3({body, outfile}))
121-
)
144+
outfiles.map(async outfile => {
145+
const body = await readFile(outfile)
146+
await pushToS3({body, outfile})
147+
})
122148
)
149+
150+
// pronounce success!
123151
await logger.log(
124152
`:tada: :confetti_ball: :tada: *deploy ${tag} complete* :tada: :confetti_ball: :tada:`
125153
)
@@ -152,7 +180,7 @@ function logToMsTeams ({ configCommit, configDir, configRemoteUrl, error }) {
152180

153181
const potentialAction = [{
154182
'@type': 'OpenUri',
155-
name: `View Commit on Github`,
183+
name: 'View Commit on Github',
156184
targets: [
157185
{
158186
os: 'default',
@@ -163,7 +191,7 @@ function logToMsTeams ({ configCommit, configDir, configRemoteUrl, error }) {
163191
if (configCommit && configRemoteUrl) {
164192
potentialAction.push({
165193
'@type': 'OpenUri',
166-
name: `View Config Commit on Github`,
194+
name: 'View Config Commit on Github',
167195
targets: [
168196
{
169197
os: 'default',
@@ -185,7 +213,7 @@ function logToMsTeams ({ configCommit, configDir, configRemoteUrl, error }) {
185213
📦 **s3bucket:** ${s3bucket}\n
186214
${error
187215
? `🚨 🚨 **error deploying ${error.message || error}**`
188-
: `🎉 🎊 🎉 **deploy successful!** 🎉 🎊 🎉`}`
216+
: '🎉 🎊 🎉 **deploy successful!** 🎉 🎊 🎉'}`
189217

190218
return logger.notifyMsTeams({
191219
potentialAction,

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"exorcist": "^1.0.1",
8989
"flow-bin": "0.84.0",
9090
"flow-runtime": "^0.17.0",
91+
"fs-extra": "^8.1.0",
9192
"git-repo-is-up-to-date": "^1.1.0",
9293
"glob": "^7.1.3",
9394
"isomorphic-fetch": "^2.2.1",

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -4283,7 +4283,7 @@ fs-extra@^7.0.0:
42834283
jsonfile "^4.0.0"
42844284
universalify "^0.1.0"
42854285

4286-
fs-extra@^8.0.0:
4286+
fs-extra@^8.0.0, fs-extra@^8.1.0:
42874287
version "8.1.0"
42884288
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
42894289
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==

0 commit comments

Comments
 (0)