Parcourir la source

Add of dynamic PORT use for client and back/client; Docker's separation

Jérôme BUISINE il y a 5 ans
Parent
commit
f6d86c40dc
7 fichiers modifiés avec 36 ajouts et 29 suppressions
  1. 1 0
      .dockerignore
  2. 6 1
      Dockerfile_back
  3. 0 7
      Makefile
  4. 9 4
      README.md
  5. 3 3
      config.js
  6. 11 0
      docker-compose.frontapp_only.yml
  7. 6 14
      docker-compose.yml

+ 1 - 0
.dockerignore

@@ -1,2 +1,3 @@
 node_modules
 npm-debug.log
+.git

+ 6 - 1
Dockerfile_back

@@ -1,7 +1,12 @@
 FROM node:11.7.0-alpine
 
 # Back docker image
+COPY . /usr/src/app
 
 WORKDIR /usr/src/app
 
-EXPOSE 5000
+EXPOSE ${PORT}
+
+RUN yarn install
+CMD yarn run api:start
+

+ 0 - 7
Makefile

@@ -1,7 +0,0 @@
-compose:
-	yarn install
-	yarn run app:build
-	docker-compose up --scale web=3 &
-	sleep 5
-
-

+ 9 - 4
README.md

@@ -3,16 +3,21 @@ Travaux développés par Antoine dans le cadre de son stage de DUT2.
 
 
 ## Run as a Docker instance
-### Run the server + client version
+### Run server + client
 ```sh
-docker-compose up
+PORT=8080 SERVE_CLIENT=true docker-compose up
+```
+### Run only the server
+```sh
+PORT=8080 SERVE_CLIENT=false docker-compose up
 ```
 
-### Run the client only version
+### Run only the client
 ```sh
-docker-compose up front_vue
+PORT=8080 docker-compose -f docker-compose.frontapp_only.yml up
 ```
 
+To change the port the server is running on set the environnements variables if necessary (see project setup part).
 
 ## Run on the file system
 ### Project setup

+ 3 - 3
config.js

@@ -8,10 +8,10 @@ export const PRODUCTION_MODE = process.env.NODE_ENV === 'production'
 export const apiPrefix = '/api'
 
 // The port used by the server
-export const serverPort = 5000
+export const serverPort = parseInt(process.env.PORT, 10) || 5000
 
-// The directory where the images are stored
+// The directory where the images are stored (do not edit it)
 export const imagesPath = path.resolve(__dirname, 'images')
 
 // Should the server serve client files from the `/dist` directory
-export const serveClient = true
+export const serveClient = process.env.SERVE_CLIENT === 'true'

+ 11 - 0
docker-compose.frontapp_only.yml

@@ -0,0 +1,11 @@
+version: '3'
+
+services:
+
+   frontapp_only:
+      build:
+          context: .
+          dockerfile: Dockerfile_front
+      image: frontwebapp
+      ports:
+          - "${PORT}:80"

+ 6 - 14
docker-compose.yml

@@ -2,25 +2,17 @@ version: '3'
 
 services:
 
-  back_node:
+  backapp:
       build:
           context: .
           dockerfile: Dockerfile_back
-      command:    
-          sh -c "yarn install && yarn run api:start"
       image: backapp
       ports:
-          - "5000:5000"
-      volumes:
-          - ./:/usr/src/app
+          - "${PORT}:${PORT}"
       environment:
           NODE_ENV: production
           SERVE_CLIENT: $SERVE_CLIENT
-
-  front_vue:
-      build:
-          context: .
-          dockerfile: Dockerfile_front 
-      image: frontwebapp
-      ports:
-          - "80:80"
+          PORT: $PORT
+      volumes:
+          - ./images:/usr/src/app/images
+