docker-compose.yml 3.29 KB
Newer Older
1 2 3
# Main docker-compose file for the project to coordinate all the docker related stuff.
# To build from local image, use the `build: ...` attibute and not the `image` attribute.

4 5 6 7
# Main ports summary:
# - 8000: main app
# - 5000: documentation

Florent Chehab's avatar
Florent Chehab committed
8 9
version: '3.7'

10 11 12 13 14 15 16 17
volumes:
  # Create some local volume (should be stored in some directory on your computer)
  postgres_data:

networks:
  backend-nginx:
  backend-db:

Florent Chehab's avatar
Florent Chehab committed
18
services:
19

20
  # Service for the backend app.
Florent Chehab's avatar
Florent Chehab committed
21
  backend:
22
    # Get the image from the registry
23
    image: registry.gitlab.utc.fr/rex-dri/rex-dri/backend:v0.2.1
24
    # To use a locally built one, comment above, uncomment bellow.
Florent Chehab's avatar
Florent Chehab committed
25
    # build: ./backend
26
    restart: on-failure
27 28
    volumes: [".:/usr/src/app/"]  # "Copy" the repo to the workdir.
    networks: [backend-nginx, backend-db]
Florent Chehab's avatar
Florent Chehab committed
29
    environment:
Florent Chehab's avatar
Florent Chehab committed
30
      WAIT_HOSTS: database:5432  # For the 'wait' script, so that we are sure the db is up and running
31
    env_file: [./server/envs/db.env, ./server/envs/django.env]
32
    # Run the django developpement server on image startup.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
    command: /bin/sh -c "/wait && cd backend && ./entry.sh && ./manage.py runserver 0.0.0.0:8000 --nostatic"
    # Required that the `database` and `frontend` service are up and running.
    depends_on: [database, frontend]

  # Serve through nginx just like in a production env
  nginx:
    build:
      context: ./server/nginx
      dockerfile: dev.Dockerfile
    restart: always
    volumes:
      - ./backend/static/:/usr/src/static:ro
      - ./backend/media/:/usr/src/media:ro
    networks: [backend-nginx]
    ports:
      # The port 8000 of the host is redirected to the port 80 of the container
      # which then redirect it to the port 8000 of the backend container
      - 8000:80
Florent Chehab's avatar
Florent Chehab committed
51
    depends_on:
52
      - backend
53

54
  # Service for the postgres database
Florent Chehab's avatar
Florent Chehab committed
55
  database:
56
    # Use of classic image
Florent Chehab's avatar
Florent Chehab committed
57
    image: postgres:10.5-alpine
58 59 60 61
    networks: [backend-db]
    ports: ["5432:5432"]
    env_file: [./server/envs/db.env]
    volumes: ["postgres_data:/var/lib/postgresql/data/"]  # Add a volume to store the DB data.
62

63
  # Service to handle frontend live developpments and building
Florent Chehab's avatar
Florent Chehab committed
64
  frontend:
65
    # Get the image from the registry
66
    image: registry.gitlab.utc.fr/rex-dri/rex-dri/frontend:v0.2.0
67 68 69 70
    # To use a locally built one, comment above, uncomment bellow.
    # build: ./frontend
    # On startup, we retrieve the dependencies from the image and start the developpement server
    command: /bin/sh -c "cd frontend && cp -R /usr/src/deps/node_modules . && npm run dev"
Florent Chehab's avatar
Florent Chehab committed
71
    volumes:
72
      # "Copy" the repo to the workdir.
Florent Chehab's avatar
Florent Chehab committed
73
      - .:/usr/src/app/
74 75
      # Ignore local node_modules: we will use the one from the docker image
      - /usr/src/app/frontend/node_modules
Florent Chehab's avatar
Florent Chehab committed
76
    ports:
77
      # Replicate the node server port (used for live/hot reloading). More info in ./frontend/server.js
78
      - 3000:3000
79 80
      # replicate the view stats port
      - "8888:8888"
81 82

  # Service to provide a local documentation
83 84
  documentation:
    build: ./documentation
85
    volumes: ["./documentation:/usr/src/app"]
86
    # Start a simple python folder
87
    command: /bin/sh -c "python -m http.server 5000"
88
    ports: ["5000:5000"]  # replicate the server port
89 90 91

  # service to generate the UML of the backend
  gen_doc_uml:
92
    image: floawfloaw/plantuml
93
    volumes: [".:/usr/src/app"]
94
    command: tail -F anything # keep the container alive