Skip to content

Commit

Permalink
Merge 0b22f12 into 8f681f4
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanLovely authored Dec 15, 2018
2 parents 8f681f4 + 0b22f12 commit c6b1fc7
Show file tree
Hide file tree
Showing 14 changed files with 477 additions and 362 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
dist
vendor
/.idea
/.vscode
/example-integrations
/www
/apps/bolt-site/cache
/apps/pattern-lab/cache
45 changes: 30 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
sudo: false
sudo: required
dist: trusty

services:
- docker

language: php
php:
- 7.1

addons:
sauce_connect: true
#addons:
# sauce_connect: true

before_install:
- nvm install # version lifted from `.nvmrc`
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.4
- export PATH="$HOME/.yarn/bin:$PATH"

before_script:
- phpenv config-rm xdebug.ini
# - nvm install # version lifted from `.nvmrc`
# - curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.4
# - export PATH="$HOME/.yarn/bin:$PATH"

install:
- yarn run setup
# - yarn run setup

before_script:
- yarn run lint
#before_script:
# - yarn run lint
#- phpenv config-rm xdebug.ini

# Can't do deploy on `after_success` b/c if deploy fails, the build still reports success. Can't use `deploy` step b/c Travis skips that on PRs.
script:
- bash ./travis.sh # time command already run inside the travis.sh script
- npx nightwatch@0.9.20 --config nightwatch.js --env chrome,ie11
- docker --log-level error pull boltdesignsystem/bolt || true
- docker --log-level error build --quiet --pull --cache-from boltdesignsystem/bolt --tag boltdesignsystem/bolt .
- docker images
- echo $DOCKER_HUB_PASS | docker login --username $DOCKER_HUB_USER --password-stdin
- GIT_SHA="$(git rev-parse --short HEAD)"
- docker tag boltdesignsystem/bolt boltdesignsystem/bolt:latest
- docker tag boltdesignsystem/bolt boltdesignsystem/bolt:${GIT_SHA}
- docker --log-level error push boltdesignsystem/bolt:latest && docker --log-level error push boltdesignsystem/bolt:${GIT_SHA}

# @todo reconsider script deps install process; need them for following script since we don't `yarn install` (it all happens inside Docker build)
after_script:
- cd scripts && npm install
- npm run deploy
# - npm run nightwatch
- cd ..
- time ./scripts/update-read-only-git-repos.sh

cache:
apt: true
Expand All @@ -35,7 +50,7 @@ cache:
notifications:
email:
on_success: never
on_failure: always
on_failure: never # @todo re-enable
slack:
secure: cNto+gWAoK1JM9jBNG4i4rMSybv3twMbqlFSCohQFBDMwKFMdlyWqFDX6iYKtHxWEDzrZyRz3qiJ8/S44mgjeKJ/xHbHDtPchp/KL2P1htipvwD2EZXobcBEGl83v2rmtFO1WNJUPB3RIJE2yt1wJsX7NIXpDw82hePmaIvNJmtbLpK/J5uaFqGNHIsctmULgVmGSNSTyK4nYxxjNNLd0EvO37Y6VN8FhsKNu2NHMKeeQxinEvETDUh8XuqXZYNWE3PBvVa4OiDhgnr5K27jsnWX+wEmqg0xY+CMf7mUSTqVN61fA7LnHyM0qcGGmB6YTv4QYLMwPydp+nsjDcm3St9D+KOTsQ4ExOaEAL/6EnAEpl8GtxST+ytdqswhCC4yMCO61Hy+M5AoXgDSGrrXHgZakDMAcEVcJdH38791hRxcuM3ldVmHAlAWFdgRLG5rRMVh3qoXz7jbraoTdjyKMegQIQdKR2SX7O9Dv0EEtLz4lTFN2RENvAjLggUPPU+ESoUHmSbwmPGnt7jy3ra2AI3nnYpfn/0e6Op/A3z7HLbdm3XyuNWoTPhy1mc4Adca+HosJ37UPv7nDRIGds1sKYAeWq94+rEk+/6IQ/oRIDRhSYsQbLLWnU6DH4o7iOj7D+X/ngjqmF75nW2s5+7rtdBHFvNzOJalCKHiDTMfdlQ=

10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM boltdesignsystem/bolt-docker:latest
WORKDIR /app
COPY . .
EXPOSE 3123
RUN yarn setup
RUN yarn lint
RUN yarn build
RUN yarn test

CMD yarn serve
1 change: 1 addition & 0 deletions now.json → Xnow.old.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"COMMENT": "@todo ensure these rewrites work in new setup",
"version": 1,
"static": {
"trailingSlash": true,
Expand Down
4 changes: 4 additions & 0 deletions deploys/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM boltdesignsystem/bolt:${DOCKER_TAG:-latest}
RUN echo "Using DOCKER_TAG: ${DOCKER_TAG:-latest}"
# tag being built from will be env var `$DOCKER_TAG` if set, else it will be `latest`
EXPOSE 3123
14 changes: 14 additions & 0 deletions deploys/now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": 1,
"name": "boltdesignsystem",
"type": "docker",
"scale": {
"sfo1": {
"min": 1,
"max": 1
}
},
"features": {
"cloud": "v1"
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@
"test:js:watch": "jest --watch",
"test:php": "cd packages/core-php && composer run test",
"test": "npm-run-all --parallel test:*",
"serve": "node server.js",
"watch:icons": "lerna exec --scope @bolt/components-icons -- yarn run watch"
},
"dependencies": {
"sassdoc": "^2.5.0"
},
"devDependencies": {
"editorconfig-checker": "^1.3.3",
"express": "^4.16.3",
"husky": "^0.14.3",
"jest": "^23.5.0",
"lerna": "^3.4.3",
"node-fetch": "^2.2.0",
"now": "^12.1.0",
"npm-run-all": "^4.1.5",
"yaml-lint": "^1.2.4",
"git-semver-tags": "^2.0.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/build-tools/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ async function handleRequest(req, res, next) {
// }
// @todo test with `GET` requests
// @todo test with empty body
console.log(`api request received at ${pathname}`); // remove once we're sure this works on server
switch (pathname) {
case '/':
res.json({
ok: true,
message: `Welcome to the Bolt Design System API! Have a nice day!`,
});
break;
case '/render-twig':
try {
/** @var renderResponse {Response} */
Expand Down Expand Up @@ -72,7 +79,7 @@ async function handleRequest(req, res, next) {
res.end(
JSON.stringify({
ok: false,
message: `Not api route found at: ${url}`,
message: `No api route found at: ${pathname}`,
}),
'utf8',
() =>
Expand Down
26 changes: 21 additions & 5 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const url = require('url');
const { resolve } = require('path');
const querystring = require('querystring');
const fetch = require('node-fetch');
const {spawnSync} = require('child_process');
Expand Down Expand Up @@ -30,8 +31,13 @@ async function init() {
TRAVIS_REPO_SLUG,
// If the current build is for a git tag, this variable is set to the tag’s name
TRAVIS_TAG,
TRAVIS_BUILD_WEB_URL,
} = process.env;

// also made in `.travis.yml` during docker tag
const gitSha = spawnSync('git', ['rev-parse', '--short', 'HEAD'], {
encoding: 'utf8',
}).stdout.trim();

console.log({
TRAVIS,
Expand All @@ -40,6 +46,8 @@ async function init() {
TRAVIS_PULL_REQUEST,
TRAVIS_REPO_SLUG,
TRAVIS_TAG,
TRAVIS_BUILD_WEB_URL,
gitSha,
});

let branchName = 'detached-HEAD';
Expand All @@ -64,21 +72,29 @@ async function init() {
const baseNowArgs = [
'--platform-version=1',
'--team=boltdesignsystem',
'--local-config=../now.json',
];

if (NOW_TOKEN) baseNowArgs.push(`--token=${NOW_TOKEN}`);

console.log('Starting deploy...');
const deployOutput = spawnSync('now', [
'deploy',
'./www',
'--name=boltdesignsystem',
'--static',
'--force',
'--meta',
`TRAVIS_BUILD_WEB_URL="${TRAVIS_BUILD_WEB_URL}"`,
'--env',
`DOCKER_TAG=${gitSha}`,
'--build-env',
`DOCKER_TAG=${gitSha}`,
...baseNowArgs,
], {encoding: 'utf8'});
], {
encoding: 'utf8',
cwd: resolve(__dirname, '../deploys'),
});
if (deployOutput.status !== 0) {
console.error('Error deploying:');
console.log(deployOutput.stdout, deployOutput.stderr);
process.exit(1);
}
console.log(deployOutput.stdout, deployOutput.stderr);
const deployedUrl = deployOutput.stdout.trim();
Expand Down
29 changes: 29 additions & 0 deletions scripts/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Start in this directory even if ran elsewhere
cd "$(dirname "$0")"
# Up to root of repo
cd ..
# Show all commands ran
set -x
# Exit this script if anything else exits
set -e

# Error messages are redirected to stderr
function handle_error {
echo "$(basename $0): ERROR! An error was encountered executing line $1." 1>&2;
# cleanup
echo 'Exiting with error.' 1>&2;
exit 1
}

function handle_exit {
# cleanup
echo 'Exiting without error.' 1>&2;
exit
}

# Exit the script with a helpful error message when any error is encountered
trap 'set +x; handle_error $LINENO $BASH_COMMAND' ERR

# --oom-kill-disable -memory=2000m
time docker build --tag boltdesignsystem/bolt:latest .
12 changes: 12 additions & 0 deletions scripts/docker-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# Start in this directory even if ran elsewhere
cd "$(dirname "$0")"
# Up to root of repo
cd ..

# Show all commands ran
set -x
# Exit this script if anything else exits
set -e

time docker run -p 3123:3123 --tty --rm boltdesignsystem/bolt:latest
18 changes: 18 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "@bolt/scripts",
"version": "2.2.0",
"description": "Deps for CI scripts",
"main": "deploy.js",
"scripts": {
"deploy": "./deploy.js",
"nightwatch": "nightwatch --config ../nightwatch.js --env chrome,ie11"
},
"dependencies": {
"nightwatch": "0.9.20",
"node-fetch": "^2.3.0",
"git-semver-tags": "^2.0.2",
"now": "latest"
},
"author": "",
"license": "ISC"
}
13 changes: 13 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const express = require('express');
const { join } = require('path');
const { handleRequest } = require('@bolt/build-tools/api');
const app = express();

const port = process.env.PORT || 3123;

app.use('/api', handleRequest);
app.use(express.static(join(__dirname, './www')));

app.listen(port, () => {
console.log(`Express listening on http://localhost:${port}`);
});
Loading

0 comments on commit c6b1fc7

Please sign in to comment.