├── .gitignore ├── .gitmodules ├── README.md ├── config └── nginx │ └── local.conf ├── docker-compose.yml └── env.example /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "fastapi-template"] 2 | path = backend 3 | url = https://github.com/gsc2001/fastapi-template.git 4 | [submodule "vuejs-template"] 5 | path = frontend 6 | url = https://github.com/gsc2001/vuejs-template.git 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### FastAPI / VueJS docker template 2 | 3 | fastapi and vuejs application in docker-compose 4 | 5 | ##### Steps 6 | 7 | Needs docker and docker-compose 8 | 9 | - Copy .env 10 | 11 | ```bash 12 | $ cp -rv env.example .env 13 | ``` 14 | 15 | - Populate .env 16 | 17 | - Docker 18 | 19 | ```bash 20 | $ docker-compose up -d 21 | ``` 22 | -------------------------------------------------------------------------------- /config/nginx/local.conf: -------------------------------------------------------------------------------- 1 | upstream backend_server { 2 | server backend:5000; 3 | } 4 | 5 | upstream frontend_server { 6 | server frontend:8080; 7 | } 8 | 9 | upstream db_interface { 10 | server db_interface:8081; 11 | } 12 | 13 | # now we declare our main server 14 | server { 15 | 16 | listen 80; 17 | server_name localhost; 18 | client_max_body_size 8M; 19 | 20 | location /static/ { 21 | proxy_pass http://backend_server/static/; 22 | } 23 | 24 | location /db_interface/ { 25 | proxy_pass http://db_interface; 26 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 27 | proxy_set_header Host $host; 28 | proxy_redirect off; 29 | } 30 | 31 | location /api/ { 32 | proxy_pass http://backend_server/; 33 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 34 | proxy_set_header Host $host; 35 | proxy_redirect off; 36 | } 37 | 38 | location / { 39 | proxy_pass http://frontend_server/; 40 | proxy_redirect off; 41 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 42 | proxy_set_header Host $host; 43 | proxy_http_version 1.1; 44 | proxy_set_header Upgrade $http_upgrade; 45 | proxy_set_header Connection "upgrade"; 46 | } 47 | 48 | 49 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.1' 2 | services: 3 | db: 4 | image: mongo 5 | restart: always 6 | networks: 7 | - db_network # for api reqs 8 | environment: 9 | MONGO_INITDB_ROOT_USERNAME: $DB_USERNAME 10 | MONGO_INITDB_ROOT_PASSWORD: $DB_PASSWORD 11 | MONGO_INITDB_DATABASE: $MONGO_INITDB_DATABASE 12 | volumes: 13 | - db_vol:/data/db 14 | 15 | db_interface: 16 | image: mongo-express 17 | restart: always 18 | environment: 19 | ME_CONFIG_MONGODB_ADMINUSERNAME: $DB_USERNAME 20 | ME_CONFIG_MONGODB_ADMINPASSWORD: $DB_PASSWORD 21 | ME_CONFIG_SITE_BASEURL: /db_interface/ 22 | ME_CONFIG_MONGODB_SERVER: db 23 | networks: 24 | - db_network # for db 25 | - web_network # for interface 26 | depends_on: 27 | - db 28 | 29 | backend: 30 | build: ./backend 31 | command: --log-level debug 32 | restart: always 33 | volumes: 34 | - ./backend:/app 35 | environment: 36 | PORT: 5000 37 | DEBUG: $DEBUG 38 | SECRET_KEY: $SECRET_KEY 39 | DATABASE_URL: $DATABASE_URL 40 | depends_on: 41 | - db 42 | networks: 43 | - db_network 44 | - web_network 45 | 46 | frontend: 47 | build: 48 | context: ./frontend 49 | args: 50 | DEBUG: $DEBUG 51 | NODE_ENV: $NODE_ENV 52 | entrypoint: ./entrypoint.sh 53 | restart: unless-stopped 54 | volumes: 55 | - ./frontend:/home/node/app 56 | - /home/node/app/node_modules 57 | environment: 58 | NODE_ENV: $NODE_ENV 59 | PORT: 8080 60 | DEBUG: $DEBUG 61 | depends_on: 62 | - backend 63 | networks: 64 | - web_network 65 | 66 | nginx: 67 | image: nginx:latest 68 | ports: 69 | - 8000:80 70 | volumes: 71 | - web-root:/var/www/html 72 | - ./config/nginx:/etc/nginx/conf.d/ 73 | depends_on: 74 | - frontend 75 | - backend 76 | - db_interface 77 | networks: 78 | - web_network 79 | 80 | networks: 81 | web_network: 82 | driver: bridge 83 | db_network: 84 | driver: bridge 85 | 86 | volumes: 87 | web-root: 88 | db_vol: 89 | -------------------------------------------------------------------------------- /env.example: -------------------------------------------------------------------------------- 1 | COMPOSE_PROJECT_NAME='fastapi-template' 2 | DB_USERNAME=root 3 | DB_PASSWORD=password 4 | MONGO_INITDB_DATABASE=core 5 | DATABASE_URL=mongodb://root:password@db:27017 6 | NODE_ENV=development 7 | DEBUG=1 8 | SECRET_KEY=change-this-key 9 | --------------------------------------------------------------------------------