From e2bd3b6dbcdc1672a6e71026d7a03bb0ee4302bb Mon Sep 17 00:00:00 2001 From: ONS-Tom Date: Tue, 13 Mar 2018 12:33:29 +0000 Subject: [PATCH] Feature/dockerfile (#31) * Add Dockerfile and .dockerignore file * Add env var to apiGateway config - Use passed in env var for server url, so that we can pass in a docker url * Remove misc notes from dockerfile * Update README with better running instructions * Update Jenkinsfile shared pipeline branch --- .dockerignore | 3 +++ Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ README.md | 23 +++++++++++++++++++---- server/config/urls.js | 2 +- 4 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..38f3e49 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +log \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0739608 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +# https://nodejs.org/en/docs/guides/nodejs-docker-webapp/ + +FROM node:6.11.5 + +# Create app directory +WORKDIR /usr/src/app + +# Install app dependencies +# A wildcard is used to ensure both package.json AND package-lock.json are copied +# where available (npm@5+) +COPY package*.json ./ + +RUN npm install + +# Bundle app source +COPY . . + +EXPOSE 3001 + +ENV NODE_ENV development +ENV SERVE_HTML true +ENV NPM_CONFIG_LOGLEVEL info +ENV SERVER_AUTH_URL http://localhost:3002/auth +ENV SERVER_API_GW_URL http://localhost:3002 +ENV API_URL http://localhost:9000 +ENV BI_UI_TEST_ADMIN_USERNAME admin +ENV BI_UI_TEST_ADMIN_PASSWORD admin +ENV BI_UI_TEST_USER_USERNAME test +ENV BI_UI_TEST_USER_PASSWORD test +ENV REACT_APP_ENV local +ENV REACT_APP_AUTH_URL http://localhost:3001 +ENV REACT_APP_API_URL http://localhost:3001/api + +# 'npm start' will create the static build files and then serve them +CMD [ "npm", "start" ] + +# Useful Docker Commands: +# docker build -t bi-ui . +# docker images +# docker run -p 3001:3001 -d bi-ui +# docker ps +# docker logs +# docker attach diff --git a/README.md b/README.md index eba0bdf..57871c0 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Install NPM, it is included with Node.js ([Download](https://nodejs.org/en/)) ## Running the UI: -1. Clone this repo and install dependencies +Clone this repo and install dependencies ```shell git clone https://github.com/ONSdigital/bi-ui.git @@ -32,18 +32,33 @@ cd bi-ui npm install ``` -2. Start the `Node.js` server +### Development Setup + +1. Start the `React.js` development server (which uses hot reloading): + +```shell +npm run start:react +``` + +2. Start the `Node.js` server: ```shell npm run start:server ``` -3. Start the `React.js` development server (with hot reloading) +3. Go to [localhost:3000](http://localhost:3000) to see bi-ui. + +### Docker Setup + +1. Build and run the UI inside a Docker container. ```shell -npm run start:react +docker build -t bi-ui . +docker run -p 3001:3001 bi-ui ``` +2. Go to [localhost:3001](http://localhost:3001) to see bi-ui. + ## Running the API * [business-index-api](https://github.com/ONSdigital/business-index-api): diff --git a/server/config/urls.js b/server/config/urls.js index 2fc0047..baac595 100644 --- a/server/config/urls.js +++ b/server/config/urls.js @@ -1,7 +1,7 @@ const urls = { AUTH_URL: process.env.SERVER_AUTH_URL, API_GW: process.env.SERVER_API_GW_URL, - API_URL: 'http://localhost:9000', + API_URL: process.env.API_URL, API_VERSION: 'v1', };