Skip to content

Commit

Permalink
ci(openshift): Move back to using S3 as deployment target for the doc…
Browse files Browse the repository at this point in the history
…s site.

Integrate the S3 deploy with OpenShift and Jenkins. Add the s3-website npm package for simpler
uploading to the bucket.
  • Loading branch information
ryanoglesby08 committed Aug 2, 2017
1 parent 90fbb41 commit cd18dd3
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 20 deletions.
14 changes: 10 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ try {

stage('Deploy Staging') {
deploy(
name: 'tds',
buildVersion: buildVersion,
environment: 'staging',
numReplicas: 1
environment: 'staging'
)
}

Expand All @@ -74,9 +74,9 @@ try {

stage('Deploy Production') {
deploy(
name: 'tds',
buildVersion: buildVersion,
environment: 'production',
numReplicas: 1
environment: 'production'
)
}

Expand Down Expand Up @@ -157,6 +157,12 @@ def test(Map attrs) {
}

def deploy(Map attrs) {
// WIP -- Waiting on AWS keys and a bucket to deploy to.
// node {
// unstash 'scripts'
// sh("./openshift/run-deploy-docs.sh ${attrs.name} ${attrs.buildVersion} ${attrs.environment}")
// }

node {
String dockerRegistry = sh(
returnStdout: true,
Expand Down
4 changes: 4 additions & 0 deletions openshift/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ oc create secret generic npmrc-secret --from-literal=.npmrc=$(vault read -field=
# SonarQube
oc create secret generic sonarqube-token-secret --from-literal=sonar.login=$(vault read -field=sonar_token secret/common/sonarqube) --dry-run -o yaml | oc apply -f -

# AWS -- WIP. Need AWS Access Key and Secret key in Vault.
#oc create secret generic aws-access-key-secret --from-literal=aws.accesskey=$(vault read -field=sonar_token secret/common/sonarqube) --dry-run -o yaml | oc apply -f -
#oc create secret generic aws-secret-key-secret --from-literal=aws.secretkey=$(vault read -field=sonar_token secret/common/sonarqube) --dry-run -o yaml | oc apply -f -

# Install templates
oc apply -f openshift-template.yml

Expand Down
42 changes: 42 additions & 0 deletions openshift/run-deploy-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

## Runs `yarn deploy:docs` against a container on OpenShift. Used by the Deploy stage of the Jenkinsfile.
## Usage: ./run-deploy-docs.sh tds latest staging

NAME=${1}
VERSION=${2:-latest}
ENV=${3:-staging}
IMAGESTREAM=`oc get imagestream ${NAME} -o='jsonpath={.status.dockerImageRepository}'`

oc run ${NAME}-${VERSION} \
--image=${IMAGESTREAM}:${VERSION} \
--rm=true \
--attach=true \
--restart=Never \
--overrides='{
"apiVersion":"v1",
"spec":{
"containers":[{
"name": "'${NAME}'-'${VERSION}'",
"image": "'${IMAGESTREAM}':'${VERSION}'",
"env":[{
"name":"AWS_ACCESS_KEY_ID",
"valueFrom":{
"secretKeyRef":{
"key": "aws.accesskey",
"name":"aws-access-key-secret"
}
}
},{
"name":"AWS_SECRET_ACCESS_KEY",
"valueFrom":{
"secretKeyRef":{
"key": "aws.secretkey",
"name":"aws-secret-key-secret"
}
}
}]
"command":["yarn", "deploy:docs", "--", "'${ENV}'"]
}]
}
}'
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
],
"scripts": {
"precommit": "yarn lint && yarn test && yarn build",
"release": "scripts/release.sh",
"release:changelog": "changelog",
"lint": "yarn lint:js && yarn lint:scss",
"lint:js": "eslint src --ext '.js,.jsx' --config config/.eslintrc.json",
"lint:scss": "stylelint 'src/scss/**/*.scss' --config config/.stylelintrc.json",
Expand All @@ -28,7 +26,10 @@
"build:scss": "sh ./scripts/cp-scss.sh",
"build:styleguide": "styleguidist build --config config/styleguide.config.js",
"start": "node styleguide.js",
"start:dev": "styleguidist server --config config/styleguide.config.js"
"start:dev": "styleguidist server --config config/styleguide.config.js",
"release": "scripts/release.sh",
"release:changelog": "changelog",
"deploy:docs": "node ./scripts/deploy-docs.js"
},
"repository": {
"type": "git",
Expand All @@ -41,7 +42,6 @@
"homepage": "http://tds.telus.com",
"devDependencies": {
"@telusdigital/redux-contentful": "^3.0.0",
"aws-sdk": "^2.7.3",
"babel-cli": "^6.24.1",
"babel-loader": "^7.1.1",
"babel-plugin-external-helpers": "^6.22.0",
Expand Down Expand Up @@ -75,6 +75,7 @@
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-sass": "^0.5.3",
"s3-website": "^3.1.0",
"sass-loader": "^6.0.6",
"sinon": "^2.3.8",
"style-loader": "^0.18.2",
Expand Down
29 changes: 29 additions & 0 deletions scripts/deploy-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node

// Arguments
// 1 = The environment to deploy. Determines which S3 bucket to use.

const resolvePath = require('path').resolve;
const execSync = require('child_process').execSync;

const s3Website = resolvePath('node_modules/.bin/s3-website');
const uploadDir = resolvePath('styleguide/');

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' }
);
};


if (env === 'production') {
deployToS3(`prod/v${version}`);
deployToS3("prod/latest");
}
else {
deployToS3('staging');
}
Loading

0 comments on commit cd18dd3

Please sign in to comment.