-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(Jenkins): Add stages for deploying docs to s3 and publishing to npm.
- Loading branch information
1 parent
e2bd3e8
commit 2b04d6f
Showing
8 changed files
with
111 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,84 @@ | ||
#!/usr/bin/env node | ||
|
||
// Environment: These variables must be available in the environment. | ||
// AWS_ACCESS_KEY_ID | ||
// AWS_SECRET_ACCESS_KEY | ||
|
||
// Arguments | ||
// 1 = The environment to deploy. Determines which S3 bucket to use. | ||
// 1 = staging|production; The environment to deploy. Determines which S3 bucket to use. Defaults to "staging" | ||
|
||
// Dependencies | ||
// s3-website: https://github.com/klaemo/s3-website | ||
|
||
|
||
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) { | ||
console.error("'AWS_ACCESS_KEY_ID' and 'AWS_SECRET_ACCESS_KEY' must be available in the environment."); | ||
process.exit(1); | ||
} | ||
|
||
|
||
const resolvePath = require('path').resolve; | ||
const execSync = require('child_process').execSync; | ||
const relativePath = require('path').relative; | ||
const readDirSync = require('fs').readdirSync; | ||
const deploy = require('s3-website').deploy; | ||
const AWS = require('aws-sdk'); | ||
|
||
const s3Website = resolvePath('node_modules/.bin/s3-website'); | ||
const uploadDir = resolvePath('styleguide/'); | ||
|
||
const version = require(resolvePath('package.json')).version; | ||
// Holding off on using the version for now. Will need DNS changes to properly get versioned folders in the bucket. | ||
// const version = require(resolvePath('package.json')).version; | ||
const env = process.argv[2] || 'staging'; | ||
|
||
const deployToS3 = (prefix) => { | ||
execSync( | ||
`${s3Website} deploy ${uploadDir} --prefix ${prefix} --domain cdn.telus-digital.tds-docs`, | ||
{ stdio: 'inherit' } | ||
); | ||
const config = { | ||
region: 'us-east-1', | ||
domain: `cdn.telus-thorium-doc-${env}`, | ||
uploadDir: uploadDir, | ||
lockConfig: true | ||
}; | ||
const s3 = new AWS.S3({region: config.region}); | ||
|
||
|
||
if (env === 'production') { | ||
deployToS3(`prod/v${version}`); | ||
deployToS3("prod/latest"); | ||
} | ||
else { | ||
deployToS3('staging'); | ||
} | ||
const deployToS3 = (onDeploy) => { | ||
deploy(s3, config, (err, website) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
console.log(website); | ||
|
||
onDeploy(s3); | ||
}); | ||
}; | ||
|
||
const grandReadPermissions = (directory) => { | ||
readDirSync(directory) | ||
.filter((file) => file !== 'build') | ||
.forEach((file) => { | ||
const absoluteFilePath = resolvePath(directory, file); | ||
|
||
putObjectAcl(relativePath(uploadDir, absoluteFilePath)) | ||
}); | ||
}; | ||
|
||
const putObjectAcl = (key) => { | ||
const params = { | ||
Bucket: config.domain, | ||
ACL: 'public-read', | ||
Key: key | ||
}; | ||
|
||
s3.putObjectAcl(params, (err, data) => { | ||
if (err) { | ||
throw err; | ||
} | ||
|
||
console.log(data); | ||
}); | ||
}; | ||
|
||
|
||
deployToS3(() => { | ||
// FIXME: There seems to be something wrong with the permissions when uploading via s3-website. Objects are not public readable by default. | ||
grandReadPermissions(uploadDir); | ||
grandReadPermissions(resolvePath(uploadDir, 'build')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
set -o nounset -o errexit | ||
|
||
## Used by the Publish stage of the Jenkinsfile | ||
## Publishes a package to npm | ||
|
||
echo -n ${NPM_PUBLISH_TOKEN} > .npmrc | ||
|
||
npm publish | ||
|
||
npm access grant read-write telusdigital:developers @telusdigital/tds | ||
npm access grant read-only telusdigital:read-only @telusdigital/tds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env bash | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
|