Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
Update Config vars - Improve docker prod image (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
remstos committed May 9, 2017
1 parent a5b6e61 commit 9105cef
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 44 deletions.
11 changes: 7 additions & 4 deletions .eslintrc
Expand Up @@ -13,10 +13,13 @@
"browser" : true
},
"globals": {
"__DEV__" : false,
"__TEST__" : false,
"__PROD__" : false,
"__COVERAGE__" : false
"__DEV__" : false,
"__TEST__" : false,
"__PROD__" : false,
"__COVERAGE__" : false,
"__SERVER_HOST__" : false,
"__SERVER_PORT__" : false,
"__CORS_PROXY_PORT__" : false
},
"rules": {
"key-spacing" : 0,
Expand Down
10 changes: 7 additions & 3 deletions Dockerfile-prod
@@ -1,4 +1,4 @@
FROM node:6.9
FROM bitnami/node

ENV TERM=xterm
ENV ROOT /var/www/kubeless-ui
Expand All @@ -9,8 +9,12 @@ RUN mkdir -p $ROOT/dist && \
COPY package.json $ROOT/src/

WORKDIR $ROOT/src
RUN npm install --global yarn

RUN install_packages apt-transport-https
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
RUN install_packages yarn

# build & test
COPY . $ROOT/src/
RUN rm -rf node_modules && yarn install && yarn cache clean
RUN yarn cache clean && npm cache clean && rm -rf /tmp/*
17 changes: 0 additions & 17 deletions bin/dev-server.js

This file was deleted.

19 changes: 19 additions & 0 deletions bin/server.js
@@ -0,0 +1,19 @@
const config = require('../config/project.config')
const server = require('../server/main')
const debug = require('debug')('app:bin:server')
const corsProxy = require('cors-anywhere')

if (config.env === 'development') {
corsProxy.createServer({
// originWhitelist: [], // Allow all origins
// requireHeader: [],
// setHeaders: { },
// removeHeaders: []
}).listen(config.cors_proxy_port, config.server_host, () => {
debug(`\n\n ⚠️ CORS proxy running on ${config.server_host}:${config.cors_proxy_port}`)
})
}

server.listen(config.server_port, () => {
debug(`\n\n 💻 Server is now running at ${config.server_host}:${config.server_port}.`)
})
8 changes: 4 additions & 4 deletions config/environments.config.js
Expand Up @@ -8,9 +8,9 @@ module.exports = {
// NOTE: In development, we use an explicit public path when the assets
// are served webpack by to fix this issue:
// http://stackoverflow.com/questions/34133808/webpack-ots-parsing-error-loading-fonts/34133809#34133809
// development : (config) => ({
// compiler_public_path : `/`
// }),
development : (config) => ({
compiler_public_path : `/`
}),

// ======================================================
// Overrides when NODE_ENV === 'production'
Expand All @@ -19,7 +19,7 @@ module.exports = {
compiler_public_path : '/',
compiler_fail_on_warning : false,
compiler_hash_type : 'chunkhash',
compiler_devtool : null,
compiler_devtool : false,
compiler_stats : {
chunks : true,
chunkModules : true,
Expand Down
15 changes: 9 additions & 6 deletions config/project.config.js
Expand Up @@ -78,12 +78,15 @@ config.globals = {
'process.env' : {
'NODE_ENV' : JSON.stringify(config.env)
},
'NODE_ENV' : config.env,
'__DEV__' : config.env === 'development',
'__PROD__' : config.env === 'production',
'__TEST__' : config.env === 'test',
'__COVERAGE__' : !argv.watch && config.env === 'test',
'__BASENAME__' : JSON.stringify(process.env.BASENAME || '')
'NODE_ENV' : config.env,
'__DEV__' : config.env === 'development',
'__PROD__' : config.env === 'production',
'__TEST__' : config.env === 'test',
'__COVERAGE__' : !argv.watch && config.env === 'test',
'__BASENAME__' : JSON.stringify(process.env.BASENAME || ''),
'__SERVER_HOST__' : JSON.stringify(config.server_host),
'__SERVER_PORT__' : config.server_port,
'__CORS_PROXY_PORT__' : config.cors_proxy_port
}

// ------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -30,7 +30,7 @@
}
},
"dev": {
"command": "nodemon bin/dev-server --ignore dist --ignore coverage --ignore tests --ignore src",
"command": "nodemon bin/server --ignore dist --ignore coverage --ignore tests --ignore src",
"env": {
"NODE_ENV": "development",
"DEBUG": "app:*"
Expand All @@ -57,7 +57,7 @@
}
},
"start": {
"command": "node bin/dev-server",
"command": "node bin/server",
"env": {
"DEBUG": "app:*"
}
Expand All @@ -84,6 +84,7 @@
"babel-plugin-module-alias": "^1.6.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.14.0",
"babel-preset-flow": "^6.23.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.3.13",
"babel-runtime": "^6.11.6",
Expand Down Expand Up @@ -134,7 +135,6 @@
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.2",
"babel-plugin-istanbul": "^4.1.1",
"babel-preset-flow": "^6.23.0",
"cheerio": "^0.22.0",
"codecov": "^2.1.0",
"enzyme": "^2.8.2",
Expand Down
18 changes: 11 additions & 7 deletions src/utils/Api.js
Expand Up @@ -17,17 +17,21 @@ limitations under the License.
import StatusCodes from 'utils/StatusCodes'
import Qs from 'qs'
import _ from 'lodash'
const CONFIG = { // TODO: take that from config
server_host: 'http://localhost',
cors_proxy_port: '3001'
const CONFIG = {
server_host: __SERVER_HOST__,
cors_proxy_port: __CORS_PROXY_PORT__
}

export default class Api {

static apiFetch({ url, method, body, dataUrl, cluster, entity }) {
const { url: URL, headers } = this.updateParams({ url, method, body, dataUrl, cluster, entity })
const proxiedURL = `${CONFIG.server_host}:${CONFIG.cors_proxy_port}/${encodeURI(URL)}`
return fetch(proxiedURL, {
let { url: URL, headers } = this.updateParams({ url, method, body, dataUrl, cluster, entity })

URL = encodeURI(URL)
if (__DEV__) {
URL = `${'http://'}${CONFIG.server_host}:${CONFIG.cors_proxy_port}/${URL}` // proxied url for CORS
}

return fetch(URL, {
method,
headers,
body: _.isEmpty(body) ? undefined : JSON.stringify(body)
Expand Down

0 comments on commit 9105cef

Please sign in to comment.