docker-compose.yml 3.88 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

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

10 11 12
volumes:
  # Create some local volume (should be stored in some directory on your computer)
  postgres_data:
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
  # Service for the backend app.
Florent Chehab's avatar
Florent Chehab committed
22
  backend:
23
    # Get the image from the registry
24
    image: registry.gitlab.utc.fr/rex-dri/rex-dri/backend:v0.2.1
25
    # To use a locally built one, comment above, uncomment bellow.
Florent Chehab's avatar
Florent Chehab committed
26
    # build: ./backend
27
    restart: on-failure
28
    volumes: [".:/usr/src/app/", "media_files:/usr/src/app/backend/media"] # "Copy" the repo to the workdir and store media files on volume.
29
    networks: [backend-nginx, backend-db]
Florent Chehab's avatar
Florent Chehab committed
30
    environment:
31 32 33 34 35 36 37
      WAIT_HOSTS: database:5432 # For the 'wait' script, so that we are sure the db is up and running
    env_file:
      [
        ./server/envs/db.env,
        ./server/envs/django.env,
        ./server/envs/external_data.env,
      ]
38
    # Run the django developpement server on image startup.
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
51
      - media_files:/usr/src/media:ro
52
    networks: [backend-nginx, map-nginx]
53 54 55 56
    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
57
    depends_on: [backend, map]
58

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

68
  # Service to handle frontend live developpments and building
Florent Chehab's avatar
Florent Chehab committed
69
  frontend:
70
    # Get the image from the registry
71
    image: registry.gitlab.utc.fr/rex-dri/rex-dri/frontend:v2.0.0
72 73 74
    # 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
75
    command: /bin/sh -c "cd frontend && mv -f /usr/src/deps/node_modules/* ./node_modules/ && yarn dev"
Florent Chehab's avatar
Florent Chehab committed
76
    volumes:
77
      # "Copy" the repo to the workdir.
Florent Chehab's avatar
Florent Chehab committed
78
      - .:/usr/src/app/
79 80
      # 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
81
    ports:
82
      # Replicate the node server port (used for live/hot reloading). More info in ./frontend/server.js
83
      - 3000:3000
84 85
      # replicate the view stats port
      - "8888:8888"
86

87 88 89 90 91
  # 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"]
92 93 94 95 96 97 98 99 100 101 102 103
    entrypoint:
      [
        "node",
        "/usr/src/app/",
        "-p",
        "8080",
        "--config",
        "/data/custom/config.json",
        "--public_url",
        "http://localhost:8000/map-server/",
        "--silent",
      ]
104 105
    restart: always

106
  # Service to provide a local documentation
107 108
  documentation:
    build: ./documentation
109
    volumes: ["./documentation:/usr/src/app"]
110
    # Start a simple python folder
111
    command: python run_server.py
112
    ports: ["5000:5000"] # replicate the server port
113 114 115

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