From dbc68de5f28d42ceea4ddc0a77246088b770b67d Mon Sep 17 00:00:00 2001 From: SamR1 Date: Sun, 14 Jan 2018 14:41:03 +0100 Subject: [PATCH] adding nginx --- .travis.yml | 4 ++-- Makefile.config | 2 +- docker-compose-ci.yml | 32 ++++++++++++++++++++++---------- docker-compose-dev.yml | 32 ++++++++++++++++++++++---------- mpwo_client/src/mpwoApi.js | 2 +- nginx/Dockerfile | 4 ++++ nginx/nginx.conf | 23 +++++++++++++++++++++++ 7 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 nginx/Dockerfile create mode 100644 nginx/nginx.conf diff --git a/.travis.yml b/.travis.yml index b1a32a39..c1cbe477 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,9 +30,9 @@ before_install: before_script: - export DATABASE_TEST_URL=postgres://postgres:@localhost:5432/mpwo_test - export APP_SETTINGS=mpwo_api.config.TestingConfig - - export REACT_APP_API_URL=http://127.0.0.1:5000/api/ + - export REACT_APP_API_URL=http://127.0.0.1 - export NODE_ENV=development - - export TEST_URL=http://127.0.0.1:3000 + - export TEST_URL=http://127.0.0.1 - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start - sleep 3 diff --git a/Makefile.config b/Makefile.config index 0dcdeb49..d5a5c193 100644 --- a/Makefile.config +++ b/Makefile.config @@ -2,7 +2,7 @@ HOST = 0.0.0.0 API_PORT = 5000 CLIENT_PORT = 3000 -export REACT_APP_API_URL = http://$(HOST):$(API_PORT)/api/ +export REACT_APP_API_URL = http://$(HOST):$(API_PORT) export FLASK_APP = $(PWD)/mpwo_api/server.py export TEST_URL = http://$(HOST):$(CLIENT_PORT) export REQUIREMENTS = $(PWD)/mpwo_api/requirements.txt diff --git a/docker-compose-ci.yml b/docker-compose-ci.yml index d9bb149b..839f7a35 100644 --- a/docker-compose-ci.yml +++ b/docker-compose-ci.yml @@ -2,8 +2,8 @@ version: '3.3' services: - api-db: - container_name: api-db + mpwo-db: + container_name: mpwo-db build: https://github.com/SamR1/mpwo.git#master:mpwo_api/db ports: - 5435:5432 @@ -11,8 +11,8 @@ services: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - api: - container_name: api + mpwo-api: + container_name: mpwo-api build: https://github.com/SamR1/mpwo.git#master:mpwo_api ports: - 5001:5000 @@ -23,12 +23,12 @@ services: - FLASK_DEBUG=1 - APP_SETTINGS=mpwo_api.config.TestingConfig depends_on: - - api-db + - mpwo-db links: - - api-db + - mpwo-db - client: - container_name: client + mpwo-client: + container_name: mpwo-client build: context: https://github.com/SamR1/mpwo.git dockerfile: ./mpwo_client/Dockerfile @@ -38,6 +38,18 @@ services: ports: - 3007:3000 depends_on: - - api + - mpwo-api links: - - api + - mpwo-api + + nginx: + container_name: nginx + build: ./nginx + restart: always + ports: + - 80:80 + depends_on: + - mpwo-api + - mpwo-client + links: + - mpwo-api diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index bebe9475..655d3112 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -2,8 +2,8 @@ version: '3.3' services: - api-db: - container_name: api-db + mpwo-db: + container_name: mpwo-db build: ./mpwo_api/db ports: - 5435:5432 @@ -11,8 +11,8 @@ services: - POSTGRES_USER=postgres - POSTGRES_PASSWORD=postgres - api: - container_name: api + mpwo-api: + container_name: mpwo-api build: ./mpwo_api ports: - 5001:5000 @@ -23,12 +23,12 @@ services: - FLASK_DEBUG=1 - APP_SETTINGS=mpwo_api.config.DevelopmentConfig depends_on: - - api-db + - mpwo-db links: - - api-db + - mpwo-db - client: - container_name: client + mpwo-client: + container_name: mpwo-client build: context: ./ dockerfile: ./mpwo_client/Dockerfile @@ -38,6 +38,18 @@ services: ports: - 3007:3000 depends_on: - - api + - mpwo-api links: - - api + - mpwo-api + + nginx: + container_name: nginx + build: ./nginx + restart: always + ports: + - 80:80 + depends_on: + - mpwo-api + - mpwo-client + links: + - mpwo-api diff --git a/mpwo_client/src/mpwoApi.js b/mpwo_client/src/mpwoApi.js index c2438af7..73d83fb4 100644 --- a/mpwo_client/src/mpwoApi.js +++ b/mpwo_client/src/mpwoApi.js @@ -1,4 +1,4 @@ -const apiUrl = `${process.env.REACT_APP_API_URL}` +const apiUrl = `${process.env.REACT_APP_API_URL}/api/` export default class MpwoApi { static login(email, password) { diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 00000000..743e91ac --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx:1.13.0 + +RUN rm /etc/nginx/conf.d/default.conf +ADD /nginx.conf /etc/nginx/conf.d diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 00000000..fdc9ac50 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,23 @@ +server { + + listen 80; + + location / { + proxy_pass http://mpwo-client:3000; + proxy_redirect default; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } + + location /api { + proxy_pass http://mpwo-api:5000; + proxy_redirect default; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + } + +}