docker-compose.yml 3.77 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
volumes:
  # Create some local volume (should be stored in some directory on your computer)
  postgres_data:
Florent Chehab's avatar
Florent Chehab committed
13
  media_files:
14 15 16 17

networks:
  backend-nginx:
  backend-db:
18
  map-nginx:
19

Florent Chehab's avatar
Florent Chehab committed
20
services:
21

22
  # Service for the backend app.
Florent Chehab's avatar
Florent Chehab committed
23
  backend:
24
    # Get the image from the registry
25
    image: registry.gitlab.utc.fr/rex-dri/rex-dri/backend:v0.2.1
26
    # To use a locally built one, comment above, uncomment bellow.
Florent Chehab's avatar
Florent Chehab committed
27
    # build: ./backend
28
    restart: on-failure
Florent Chehab's avatar
Florent Chehab committed
29
    volumes: [".:/usr/src/app/", "media_files:/usr/src/app/backend/media"]  # "Copy" the repo to the workdir and store media files on volume.
30
    networks: [backend-nginx, backend-db]
Florent Chehab's avatar
Florent Chehab committed
31
    environment:
32
      WAIT_HOSTS: database:5432  # For the 'wait' script, so that we are sure the db is up and running
33
    env_file: [./server/envs/db.env, ./server/envs/django.env, ./server/envs/external_data.env]
34
    # Run the django developpement server on image startup.
35 36 37 38 39 40 41 42 43 44 45 46
    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
Florent Chehab's avatar
Florent Chehab committed
47
      - media_files:/usr/src/media:ro
48
    networks: [backend-nginx, map-nginx]
49 50 51 52
    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
53
    depends_on: [backend, map]
54

55
  # Service for the postgres database
Florent Chehab's avatar
Florent Chehab committed
56
  database:
57
    # Use of classic image
Florent Chehab's avatar
Florent Chehab committed
58
    image: postgres:10.5-alpine
59 60 61 62
    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.
63

64
  # Service to handle frontend live developpments and building
Florent Chehab's avatar
Florent Chehab committed
65
  frontend:
66
    # Get the image from the registry
67
    image: registry.gitlab.utc.fr/rex-dri/rex-dri/frontend:v0.5.0
68 69 70 71
    # 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
72
    volumes:
73
      # "Copy" the repo to the workdir.
Florent Chehab's avatar
Florent Chehab committed
74
      - .:/usr/src/app/
75 76
      # 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
77
    ports:
78
      # Replicate the node server port (used for live/hot reloading). More info in ./frontend/server.js
79
      - 3000:3000
80 81
      # replicate the view stats port
      - "8888:8888"
82

83 84 85 86 87 88 89 90
  # Service to host map tiles
  map:
    image: floawfloaw/light-world-tileserver:2019-05-21--zoom-8
    networks: [map-nginx]
    volumes: ["./server/map:/data/custom:ro"]
    entrypoint: ["node", "/usr/src/app/", "-p", "8080", "--config", "/data/custom/config.json", "--public_url", "http://localhost:8000/map-server/", "--silent"]
    restart: always

91
  # Service to provide a local documentation
92 93
  documentation:
    build: ./documentation
94
    volumes: ["./documentation:/usr/src/app"]
95
    # Start a simple python folder
96
    command: /bin/sh -c "python -m http.server 5000"
97
    ports: ["5000:5000"]  # replicate the server port
98 99 100

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