Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Nov 17, 2019
0 parents commit 1ac32c0
Show file tree
Hide file tree
Showing 28 changed files with 527 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
sites/*/node_modules
packages/*/node_modules
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated Marko Files
*.marko.js
# Build assets
**/dist/
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
extends: 'airbnb-base',
plugins: [
'import'
],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.marko'],
},
},
},
};
88 changes: 88 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless

# FuseBox cache
.fusebox/
.DS_Store

# Marko
*.marko.js
.marko-cli
.marko-devtools

.bash_history
.node-gyp

# Build assets
**/dist/
2 changes: 2 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Build products
dist
8 changes: 8 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
extends: [
'stylelint-config-twbs-bootstrap/scss',
],
rules: {
'scss/dollar-variable-default': null,
},
};
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
language: node_js
node_js: "10.15"
cache: yarn

stages:
- name: test
- name: notify_start
if: tag is present
- name: deploy
if: tag is present
- name: notify
if: tag is present

jobs:
include:
- stage: test
env:
- NODE_ENV=test

- stage: notify_start
script: deploy/notify-start.sh
install: skip

- stage: notify
script: deploy/notify.sh
install: skip

- stage: deploy
name: Industry Week
script: deploy/index.js industryweek gemenon
install: skip
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"emmet.includeLanguages": {
"marko": "html"
},
"editor.tabSize": 2,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.trimTrailingWhitespace": true,
"eslint.validate": [ "javascript", "javascriptreact", { "language": "vue", "autoFix": true } ]
}
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:10.15 as build
WORKDIR /root
ENV NODE_ENV production
ARG SITE

ADD package.json yarn.lock /root/
ADD packages /root/packages
ADD sites/$SITE /root/sites/$SITE
RUN yarn --production --pure-lockfile

WORKDIR /root/sites/$SITE
RUN node_modules/.bin/basecms-website build

FROM node:10.15-alpine
ENV NODE_ENV production
ENV PORT 80
ARG SITE
COPY --from=build /root /root
WORKDIR /root/sites/$SITE
ENTRYPOINT [ "node", "index.js" ]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Endeavor Business Media

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# BaseCMS Websites for Endeavor Business Media (Former Informa Sites)
This monorepo contains the codebase for websites managed by Endeavor Business Media. All sites within this repository utilize the [@base-cms/base-cms](https://github.com/base-cms/base-cms) packages, most notably the `marko-web` and `web-cli`.
9 changes: 9 additions & 0 deletions deploy/image.sh
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 -t "$1:$2" --build-arg SITE=$1 .

docker tag "$1:$2" "basecmswebsites/$1:$2"
docker push "basecmswebsites/$1:$2"
docker image rm "$1:$2"
110 changes: 110 additions & 0 deletions deploy/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env node

//
// @todo MOVE DEPLOYMENT SCRIPTS TO OWN REPOSITORY AND IMPORT!!
//

/**
* Deployment tool for website containers
* Requirements:
* - Argument 1: the folder name of the sit to deploy
* - ENV
* - DOCKERHUB_USERNAME
* - DOCKERHUB_PASSWORD
* - TRAVIS_TAG
* - RANCHER_URL
* - RANCHER_TOKEN
* - RANCHER_CLUSTERID
* - NR_APIKEY
* - NR_APPID
*/

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 } = process.env;

const version = `v${lerna.version}`;
const site = process.argv[2];
const namespace = process.argv[3];
const sitePath = join('sites', site, 'package.json');
const image = `basecmswebsites/${site}`;

const error = async (message) => {
log(`ERROR: ${message}`);
await spawnSync('bash', ['deploy/notify-fail.sh', message], { stdio: 'inherit' });
process.exit(1);
};

if (TRAVIS_TAG !== version) error(`Tagged version ${TRAVIS_TAG} differs from lerna version ${version}, aborting!`);
if (!site) error('You must specify the site folder to deploy.');
if (!existsSync(sitePath)) error(`Could not read ${sitePath}!`);

// eslint-disable-next-line import/no-dynamic-require
const pkg = require(`../${sitePath}`);

if (version !== `v${pkg.version}`) {
log(`Site ${site} is at version ${pkg.version}. Skipping deployment.`);
process.exit(0);
}

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)));
return null;
}).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', ['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', ['deploy/k8s.sh', site, version, namespace], { 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(error);
6 changes: 6 additions & 0 deletions deploy/k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

IMAGE=basecmswebsites/$1:$2
yarn global add @endeavorb2b/rancher2cli
r2 dl basecms-website $1 $IMAGE --namespace=$3
11 changes: 11 additions & 0 deletions deploy/notify-fail.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -e
[[ $RANCHER_CLUSTERID = "c-rc5kp" ]] && ENVIRONMENT="staging" || ENVIRONMENT="production"

payload="{
\"attachments\": [{
\"color\": \"danger\",
\"text\": \"Deployment of \`$TRAVIS_REPO_SLUG\` @ \`$TRAVIS_TAG\` to \`$ENVIRONMENT\` has FAILED!\n$1\"
}]
}"
curl -f -X POST --data "$payload" -H 'Content-type: application/json' $SLACK_WEBHOOK_URL
23 changes: 23 additions & 0 deletions deploy/notify-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e
[[ $RANCHER_CLUSTERID = "c-rc5kp" ]] && ENVIRONMENT="staging" || ENVIRONMENT="production"

payload="{
\"attachments\": [{
\"color\": \"#1d9bd1\",
\"text\": \"Deployment of \`$TRAVIS_REPO_SLUG\` @ \`$TRAVIS_TAG\` to \`$ENVIRONMENT\` has started.\"
}]
}"
curl -f -X POST --data "$payload" -H 'Content-type: application/json' $SLACK_WEBHOOK_URL

payload="{
\"deployment\": {
\"revision\": \"\`$TRAVIS_TAG\`\",
\"description\": \"Started\",
\"user\": \"TravisCD\"
}
}"
curl -f -X POST --data "$payload" \
-H 'Content-type: application/json' \
-H "X-Api-Key:$NR_APIKEY" \
https://api.newrelic.com/v2/applications/$NR_APPID/deployments.json
Loading

0 comments on commit 1ac32c0

Please sign in to comment.