-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
713626e
commit 6531299
Showing
8 changed files
with
157 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,20 @@ | ||
language: node_js | ||
node_js: "10.15" | ||
cache: yarn | ||
|
||
stages: | ||
- name: test | ||
- name: deploy | ||
if: tag is present | ||
- name: notify | ||
if: tag is present | ||
|
||
jobs: | ||
include: | ||
- stage: test | ||
- stage: notify | ||
script: scripts/deploy-notify.sh | ||
|
||
- stage: deploy | ||
name: Deploy Package | ||
script: scripts/deploy.js |
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,7 @@ | ||
FROM node:10.15 | ||
|
||
ENV NODE_ENV production | ||
WORKDIR /root | ||
|
||
ADD ./ /root | ||
RUN yarn --production |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
set -e | ||
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin | ||
|
||
docker build -q -t "body-import-parser:$1" . | ||
|
||
docker tag "body-import-parser:$1" "basecms/body-import-parser:$1" | ||
docker push "basecms/body-import-parser:$1" | ||
docker image rm "body-import-parser:$1" |
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,6 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
IMAGE=basecms/body-import-parser:$1 | ||
yarn global add @endeavorb2b/rancher2cli | ||
r2 dl basecms-service body-import-parser $IMAGE --namespace=imports |
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,10 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
payload="{ | ||
\"attachments\": [{ | ||
\"color\": \"good\", | ||
\"text\": \"Deployment of \`$TRAVIS_REPO_SLUG\` @ \`$TRAVIS_TAG\` to production has finished successfully.\" | ||
}] | ||
}" | ||
curl -X POST -H 'Content-type: application/json' --data "$payload" https://hooks.slack.com/services/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 |
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,102 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* Deployment tool for project | ||
* Requirements: | ||
* - ENV | ||
* - DOCKERHUB_USERNAME | ||
* - DOCKERHUB_PASSWORD | ||
* - TRAVIS_TAG | ||
* - RANCHER_URL | ||
* - RANCHER_TOKEN | ||
* - RANCHER_CLUSTERID | ||
*/ | ||
|
||
const { existsSync } = require('fs'); | ||
const { join } = require('path'); | ||
const { spawnSync } = require('child_process'); | ||
const https = require('https'); | ||
const lerna = require('../lerna.json'); | ||
|
||
const { log } = console; | ||
const { TRAVIS_TAG: version } = process.env; | ||
const image = `basecms/body-import-parser`; | ||
|
||
const error = (message) => { | ||
log(`ERROR: ${message}`); | ||
const text = `Deployment of \`${image}\` @ \`${version}\` to production FAILED!\n${message}`; | ||
const payload = JSON.stringify({ attachments: [{ color: 'danger', text }] }); | ||
const req = https.request({ | ||
hostname: 'hooks.slack.com', | ||
path: '/services/TDA6JTAKC/BGCT0SNGY/vJSPL4S2NQN8SDAjCPilP773', | ||
port: 443, | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Content-Length': payload.length, | ||
} | ||
}, (res) => { | ||
res.on('data', () => { | ||
log('Slack notified.'); | ||
process.exit(1); | ||
}); | ||
}); | ||
|
||
req.on('error', e => log(e)); | ||
req.write(payload); | ||
req.end(); | ||
|
||
} | ||
|
||
const getJson = (url, reqHeaders) => new Promise((resolve, reject) => { | ||
const headers = { ...reqHeaders, 'Content-Type': 'application/json; charset=utf-8' }; | ||
https.get(url, { headers }, (resp) => { | ||
let data = ''; | ||
const { statusCode, statusMessage } = resp; | ||
if (statusCode >= 500) return reject(statusMessage); | ||
resp.on('data', chunk => data += chunk); | ||
resp.on('end', () => resolve(JSON.parse(data))); | ||
}).on('error', reject); | ||
}); | ||
|
||
const getVersions = async () => { | ||
const authUrl = `https://auth.docker.io/token?service=registry.docker.io&scope=repository:${image}:pull`; | ||
const { token } = await getJson(authUrl); | ||
const url = `https://registry.hub.docker.com/v2/${image}/tags/list`; | ||
const list = await getJson(url, { Authorization: `Bearer ${token}`}); | ||
return Array.isArray(list.tags) ? list.tags : []; | ||
}; | ||
|
||
const shouldBuild = async () => { | ||
log(`\nChecking ${image}:${version} on DockerHub`); | ||
const versions = await getVersions(); | ||
return !versions.includes(version); | ||
} | ||
|
||
/** | ||
* Build docker image and push to docker hub | ||
*/ | ||
const build = async () => { | ||
log(`Building ${image}:${version}...\n`); | ||
const { status } = await spawnSync('bash', ['scripts/deploy-image.sh', site, version], { stdio: 'inherit' }); | ||
if (status !== 0) error('Image build failed!'); | ||
} | ||
|
||
const deploy = async () => { | ||
log(`Deploying ${image}:${version} on Kubernertes`); | ||
const { status } = await spawnSync('bash', ['scripts/deploy-k8s.sh', site, version], { stdio: 'inherit' }); | ||
if (status !== 0) error('Image deploy failed!'); | ||
}; | ||
|
||
const main = async () => { | ||
if (await shouldBuild()) { | ||
log(` Image was not found, building.`) | ||
await build(); | ||
log(' Build complete.'); | ||
} else { | ||
log(` Image found, skipping build.`); | ||
} | ||
await deploy(); | ||
log(' Deploy complete.\n'); | ||
}; | ||
|
||
main().catch(e => error); |