From 96d219dfe2e97fa8d79c10d41f18b9aa1f4c7cbb Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Thu, 29 Mar 2018 19:55:24 +0200
Subject: [PATCH] Local .env logic for webpack custom port

---
 .gitignore            |  1 +
 README.rst            | 13 +++++++++++++
 dev.yml               | 30 +++++++++++++++++++++---------
 front/config/index.js |  2 +-
 4 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/.gitignore b/.gitignore
index 1e1017c8..8b511703 100644
--- a/.gitignore
+++ b/.gitignore
@@ -86,3 +86,4 @@ front/selenium-debug.log
 docs/_build
 
 data/
+.env
diff --git a/README.rst b/README.rst
index 93281d26..2d5d2011 100644
--- a/README.rst
+++ b/README.rst
@@ -73,6 +73,19 @@ via the following command::
     docker-compose -f dev.yml build
 
 
+Creating your env file
+^^^^^^^^^^^^^^^^^^^^^^
+
+We provide a working .env.dev configuration file that is suitable for
+development. However, to enable customization on your machine, you should
+also create a .env file that will hold your personal environment
+variables (those will not be commited to the project).
+
+Create it like this::
+
+    touch .env
+
+
 Database management
 ^^^^^^^^^^^^^^^^^^^
 
diff --git a/dev.yml b/dev.yml
index dd3a55dd..19234f0f 100644
--- a/dev.yml
+++ b/dev.yml
@@ -1,27 +1,35 @@
-version: '2'
+version: '3'
 
 services:
-
   front:
     build: front
-    env_file: .env.dev
+    env_file:
+      - .env.dev
+      - .env
     environment:
       - "HOST=0.0.0.0"
+      - "WEBPACK_DEVSERVER_PORT=${WEBPACK_DEVSERVER_PORT-8080}"
     ports:
-      - "8080:8080"
+      - "${WEBPACK_DEVSERVER_PORT-8080}:${WEBPACK_DEVSERVER_PORT-8080}"
     volumes:
       - './front:/app'
 
   postgres:
-    env_file: .env.dev
+    env_file:
+      - .env.dev
+      - .env
     image: postgres
 
   redis:
-    env_file: .env.dev
+    env_file:
+      - .env.dev
+      - .env
     image: redis:3.0
 
   celeryworker:
-    env_file: .env.dev
+    env_file:
+      - .env.dev
+      - .env
     build:
       context: ./api
       dockerfile: docker/Dockerfile.test
@@ -41,7 +49,9 @@ services:
       - ./api:/app
       - ./data/music:/music
   api:
-    env_file: .env.dev
+    env_file:
+      - .env.dev
+      - .env
     build:
       context: ./api
       dockerfile: docker/Dockerfile.test
@@ -62,7 +72,9 @@ services:
       - redis
 
   nginx:
-    env_file: .env.dev
+    env_file:
+      - .env.dev
+      - .env
     image: nginx
     links:
       - api
diff --git a/front/config/index.js b/front/config/index.js
index 14cbe3e4..a2e99234 100644
--- a/front/config/index.js
+++ b/front/config/index.js
@@ -23,7 +23,7 @@ module.exports = {
   },
   dev: {
     env: require('./dev.env'),
-    port: 8080,
+    port: parseInt(process.env.WEBPACK_DEVSERVER_PORT),
     host: '127.0.0.1',
     autoOpenBrowser: true,
     assetsSubDirectory: 'static',
-- 
GitLab