build(joyent-cp-frontend): build for demo

This commit is contained in:
Sérgio Ramos 2017-06-01 23:32:58 +01:00
parent af899f353d
commit 2ce47eb669
17 changed files with 187 additions and 102 deletions

View File

@ -65,9 +65,9 @@ cp-frontend:
- com.docker.swarm.affinities=["container!=~*cp-frontend*"]
environment:
- CONSUL_AGENT=1
- PORT=3069
- PORT=5000
ports:
- 3069
- 5000
#############################################################################
# BACKEND

View File

@ -1,16 +1,17 @@
# todo change to 7
FROM quay.io/yldio/alpine-node-containerpilot:latest
RUN npm install lerna@^2.0.0-rc.5 \
RUN yarn global add lerna@^2.0.0-rc.5 serve \
&& ./node_modules/.bin/lerna clean --yes --scope joyent-cp-frontend --include-filtered-dependencies \
&& ./node_modules/.bin/lerna bootstrap --scope joyent-cp-frontend --include-filtered-dependencies
WORKDIR /home/node/app/packages/cp-frontend
COPY packages/cp-frontend/etc/containerpilot.json /etc/
RUN yarn run build
ARG CIRCLE_BRANCH
ENV REACT_APP_GQL_HOSTNAME gql-mock-server-$CIRCLE_BRANCH.svc.f4b20699-b323-4452-9091-977895896da6.eu-ams-1.triton.zone
EXPOSE 3069
CMD ["/bin/containerpilot", "yarn", "run", "start"]
EXPOSE 5000
CMD ["/bin/containerpilot", "serve", "-s", "build"]

View File

@ -3,8 +3,8 @@
[![Docker Repository on Quay](https://quay.io/repository/yldio/joyent-cp-frontend/status)](https://quay.io/repository/yldio/joyent-cp-frontend)
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-brightgreen.svg)](https://opensource.org/licenses/MPL-2.0)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg)](https://github.com/RichardLitt/standard-readme)
[![demo master](https://img.shields.io/badge/demo-master-3B47CC.svg)](http://cp-frontend-master.svc.f4b20699-b323-4452-9091-977895896da6.eu-ams-1.triton.zone:3069)
[![demo staging](https://img.shields.io/badge/demo-staging-3B47CC.svg)](http://cp-frontend-staging.svc.f4b20699-b323-4452-9091-977895896da6.eu-ams-1.triton.zone:3069)
[![demo master](https://img.shields.io/badge/demo-master-3B47CC.svg)](http://cp-frontend-master.svc.f4b20699-b323-4452-9091-977895896da6.eu-ams-1.triton.zone:5000)
[![demo staging](https://img.shields.io/badge/demo-staging-3B47CC.svg)](http://cp-frontend-staging.svc.f4b20699-b323-4452-9091-977895896da6.eu-ams-1.triton.zone:5000)
## Table of Contents

View File

@ -20,11 +20,10 @@
},
"dependencies": {
"apollo": "^0.2.2",
"babel-plugin-inline-react-svg": "^0.4.0",
"babel-plugin-styled-components": "^1.1.4",
"constant-case": "^2.0.0",
"graphql-tag": "^2.0.0",
"joyent-ui-toolkit": "^1.1.0",
"lodash.isstring": "^4.0.1",
"normalized-styled-components": "^1.0.5",
"prop-types": "^15.5.10",
"react": "^15.5.4",
@ -46,6 +45,7 @@
"unitcalc": "^1.0.5"
},
"devDependencies": {
"apr-for-each": "^1.0.6",
"apr-main": "^1.0.7",
"babel-plugin-inline-react-svg": "^0.4.0",
"babel-plugin-styled-components": "^1.1.4",

View File

@ -0,0 +1,70 @@
const isString = require('lodash.isstring');
const fs = require('fs');
const path = require('path');
const FRONTEND_ROOT = process.cwd();
const FRONTEND = path.join(FRONTEND_ROOT, 'src');
module.exports = config => {
config.resolve.plugins = [];
config.module.rules = config.module.rules
.reduce((loaders, loader, index) => {
if (!isString(loader.loader)) {
return loaders.concat([loader]);
}
if (loader.loader.match(/babel-loader/)) {
return loaders.concat([
{
test: loader.test,
include: loader.include,
loader: loader.loader,
options: {
babelrc: true,
cacheDirectory: true
}
}
]);
}
if (loader.loader.match(/file-loader/)) {
return loaders.concat([
{
exclude: loader.exclude.concat([/\.(graphql|gql)$/]),
loader: loader.loader,
options: loader.options
}
]);
}
return loaders.concat([loader]);
}, [])
.concat([
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: require.resolve('graphql-tag/loader')
}
]);
config.resolve.alias = Object.assign(
{},
config.resolve.alias,
fs
.readdirSync(FRONTEND)
.map(name => path.join(FRONTEND, name))
.filter(fullpath => fs.statSync(fullpath).isDirectory())
.reduce(
(aliases, fullpath) =>
Object.assign(aliases, {
[`@${path.basename(fullpath)}`]: fullpath
}),
{
'@root': FRONTEND
}
)
);
return config;
};

View File

@ -1,30 +1,42 @@
const { readFile, writeFile, exists } = require('mz/fs');
const main = require('apr-main');
const forEach = require('apr-for-each');
const path = require('path');
// TODO: this will need to happen for prod and test too
const ROOT = path.join(__dirname, '../node_modules/react-scripts/config');
const enhancedConfigPath = path.join(__dirname, './webpack.config.dev.js');
const configs = ['webpack.config.dev', 'webpack.config.prod'];
const configPath = path.join(
__dirname,
'../node_modules/react-scripts/config/webpack.config.dev.js'
);
const orignalConfigPath = path.join(
__dirname,
'../node_modules/react-scripts/config/webpack.config.dev.original.js'
);
const toCopy = [
'patch-webpack-config',
'webpack.config.dev',
'webpack.config.prod'
];
const backup = async file => {
const backupPath = path.join(ROOT, `${file}.original.js`);
const backupExists = await exists(backupPath);
if (backupExists) {
return;
}
const originalPath = path.join(ROOT, `${file}.js`);
const orignalConfig = await readFile(originalPath, 'utf-8');
return writeFile(backupPath, orignalConfig);
};
const copy = async file => {
const srcPath = path.join(__dirname, `${file}.js`);
const destPath = path.join(ROOT, `${file}.js`);
const src = await readFile(srcPath, 'utf-8');
return writeFile(destPath, src);
};
main(
(async () => {
const orignalConfigPathExists = await exists(orignalConfigPath);
if (!orignalConfigPathExists) {
const orignalConfig = await readFile(configPath, 'utf-8');
await writeFile(orignalConfigPath, orignalConfig);
}
const enhancedConfig = await readFile(enhancedConfigPath);
await writeFile(configPath, enhancedConfig);
await forEach(configs, backup);
await forEach(toCopy, copy);
})()
);

View File

@ -1,61 +1,4 @@
const fs = require('fs');
const path = require('path');
const originalConfig = require('./webpack.config.dev.original');
const patch = require('./patch-webpack-config');
const FRONTEND_ROOT = process.cwd();
const FRONTEND = path.join(FRONTEND_ROOT, 'src');
const rules = originalConfig.module.rules.reduce((loaders, loader, index) => {
if (index === 3) {
loaders.push({
test: loader.test,
include: loader.include,
loader: loader.loader,
options: {
babelrc: true,
cacheDirectory: true
}
});
} else if (index === 1) {
loaders.push({
exclude: loader.exclude.concat([/\.(graphql|gql)$/]),
loader: loader.loader,
options: loader.options
});
} else if (loader.include) {
loaders.push(Object.assign({}, loader, { include: loader.include }));
} else {
loaders.push(loader);
}
return loaders;
}, []);
rules.push({
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: require.resolve('graphql-tag/loader')
});
const aliases = Object.assign(
{},
originalConfig.resolve.alias,
fs
.readdirSync(FRONTEND)
.map(name => path.join(FRONTEND, name))
.filter(fullpath => fs.statSync(fullpath).isDirectory())
.reduce(
(aliases, fullpath) =>
Object.assign(aliases, {
[`@${path.basename(fullpath)}`]: fullpath
}),
{
'@root': FRONTEND
}
)
);
originalConfig.module.rules = rules;
originalConfig.resolve.alias = aliases;
originalConfig.resolve.plugins = [];
module.exports = originalConfig;
module.exports = patch(originalConfig);

View File

@ -0,0 +1,4 @@
const originalConfig = require('./webpack.config.prod.original');
const patch = require('./patch-webpack-config');
module.exports = patch(originalConfig);

View File

@ -1,7 +1,7 @@
# todo change to 7
FROM quay.io/yldio/alpine-node-containerpilot:latest
RUN npm install lerna@^2.0.0-rc.5 \
RUN yarn global add lerna@^2.0.0-rc.5 \
&& ./node_modules/.bin/lerna clean --yes --scope joyent-cp-gql-mock-server --include-filtered-dependencies \
&& ./node_modules/.bin/lerna bootstrap --scope joyent-cp-gql-mock-server --include-filtered-dependencies

View File

@ -1,2 +1,3 @@
.nyc_output
coverage
dist

View File

@ -12,12 +12,17 @@
"pixel"
],
"repository": "github:yldio/joyent-portal",
"main": "src/index.js",
"main": "dist/remcalc.umd.js",
"jsnext:main": "dist/remcalc.es.js",
"module": "dist/remcalc.es.js",
"entry": "src/index.js",
"scripts": {
"lint": "eslint . --fix",
"lint-ci": "eslint . --format junit --output-file $CIRCLE_TEST_REPORTS/lint/remcalc.xml",
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ava",
"test-ci": "cross-env NODE_ENV=test nyc --report-dir=$CIRCLE_ARTIFACTS/remcalc --reporter=lcov --reporter=text ava --tap | tap-xunit > $CIRCLE_TEST_REPORTS/test/remcalc.xml"
"test": "bup && cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ava",
"test-ci": "cross-env NODE_ENV=test nyc --report-dir=$CIRCLE_ARTIFACTS/remcalc --reporter=lcov --reporter=text ava --tap | tap-xunit > $CIRCLE_TEST_REPORTS/test/remcalc.xml",
"build": "bup",
"prepublish": "bup"
},
"dependencies": {
"lodash.flatten": "^4.4.0"
@ -25,7 +30,12 @@
"devDependencies": {
"ava": "0.19.1",
"babel-plugin-istanbul": "^4.1.3",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-parameters": "^6.24.1",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
"babel-register": "^6.24.1",
"bup": "^1.0.8",
"cross-env": "^5.0.0",
"eslint": "^3.19.0",
"eslint-config-joyent-portal": "1.0.0",
@ -38,6 +48,12 @@
},
"babel": {
"sourceMaps": "inline",
"plugins": [
"transform-es2015-parameters",
"transform-es2015-template-literals",
"transform-es2015-arrow-functions",
"transform-es2015-spread"
],
"env": {
"test": {
"plugins": [

View File

@ -1,2 +1,3 @@
.nyc_output
coverage
dist

View File

@ -8,12 +8,17 @@
"alphabetical"
],
"repository": "github:yldio/joyent-portal",
"main": "src/index.js",
"main": "dist/rnd-id.umd.js",
"jsnext:main": "dist/rnd-id.es.js",
"module": "dist/rnd-id.es.js",
"entry": "src/index.js",
"scripts": {
"lint": "eslint . --fix",
"lint-ci": "eslint . --format junit --output-file $CIRCLE_TEST_REPORTS/lint/rnd-id.xml",
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ava",
"test-ci": "cross-env NODE_ENV=test nyc --report-dir=$CIRCLE_ARTIFACTS/rnd-id --reporter=lcov --reporter=text ava --tap | tap-xunit > $CIRCLE_TEST_REPORTS/test/rnd-id.xml"
"test": "bup && cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ava",
"test-ci": "cross-env NODE_ENV=test nyc --report-dir=$CIRCLE_ARTIFACTS/rnd-id --reporter=lcov --reporter=text ava --tap | tap-xunit > $CIRCLE_TEST_REPORTS/test/rnd-id.xml",
"build": "bup",
"prepublish": "bup"
},
"dependencies": {
"random-natural": "^1.0.3"
@ -21,7 +26,10 @@
"devDependencies": {
"ava": "0.19.1",
"babel-plugin-istanbul": "^4.1.3",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
"babel-register": "^6.24.1",
"bup": "^1.0.8",
"cross-env": "^5.0.0",
"eslint": "^3.19.0",
"eslint-config-joyent-portal": "1.0.0",
@ -35,6 +43,10 @@
},
"babel": {
"sourceMaps": "inline",
"plugins": [
"transform-es2015-arrow-functions",
"transform-es2015-template-literals"
],
"env": {
"test": {
"plugins": [

View File

@ -29,6 +29,10 @@
"devDependencies": {
"ava": "0.19.1",
"babel-plugin-istanbul": "^4.1.3",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-parameters": "^6.24.1",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-es2015-template-literals": "^6.22.0",
"babel-register": "^6.24.1",
"bup": "^1.0.7",
"cross-env": "^5.0.0",
@ -50,6 +54,12 @@
},
"babel": {
"sourceMaps": "inline",
"plugins": [
"transform-es2015-parameters",
"transform-es2015-template-literals",
"transform-es2015-arrow-functions",
"transform-es2015-spread"
],
"env": {
"test": {
"plugins": [

View File

@ -1,7 +1,7 @@
# todo change to 7
FROM quay.io/yldio/alpine-node-containerpilot:latest
RUN npm install lerna@^2.0.0-rc.5 \
RUN yarn global add lerna@^2.0.0-rc.5 \
&& ./node_modules/.bin/lerna clean --yes --scope joyent-ui-toolkit --include-filtered-dependencies \
&& ./node_modules/.bin/lerna bootstrap --scope joyent-ui-toolkit --include-filtered-dependencies

View File

@ -1,2 +1,3 @@
.nyc_output
coverage
dist

View File

@ -14,12 +14,17 @@
"unit"
],
"repository": "github:yldio/joyent-portal",
"main": "src/index.js",
"main": "dist/unitcalc.umd.js",
"jsnext:main": "dist/unitcalc.es.js",
"module": "dist/unitcalc.es.js",
"entry": "src/index.js",
"scripts": {
"lint": "eslint . --fix",
"lint-ci": "eslint . --format junit --output-file $CIRCLE_TEST_REPORTS/lint/unitcalc.xml",
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ava",
"test-ci": "cross-env NODE_ENV=test nyc --report-dir=$CIRCLE_ARTIFACTS/unitcalc --reporter=lcov --reporter=text ava --tap | tap-xunit > $CIRCLE_TEST_REPORTS/test/unitcalc.xml"
"test": "bup && cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text ava",
"test-ci": "cross-env NODE_ENV=test nyc --report-dir=$CIRCLE_ARTIFACTS/unitcalc --reporter=lcov --reporter=text ava --tap | tap-xunit > $CIRCLE_TEST_REPORTS/test/unitcalc.xml",
"build": "bup",
"prepublish": "bup"
},
"dependencies": {
"lodash.flatten": "^4.4.0",
@ -28,7 +33,11 @@
"devDependencies": {
"ava": "0.19.1",
"babel-plugin-istanbul": "^4.1.3",
"babel-plugin-transform-es2015-arrow-functions": "^6.22.0",
"babel-plugin-transform-es2015-parameters": "^6.24.1",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-register": "^6.24.1",
"bup": "^1.0.8",
"cross-env": "^5.0.0",
"eslint": "^3.19.0",
"eslint-config-joyent-portal": "1.0.0",
@ -41,6 +50,11 @@
},
"babel": {
"sourceMaps": "inline",
"plugins": [
"transform-es2015-parameters",
"transform-es2015-arrow-functions",
"transform-es2015-spread"
],
"env": {
"test": {
"plugins": [