Skip to content

Commit

Permalink
Merge pull request #35 from 1tracy/containerize
Browse files Browse the repository at this point in the history
containerize backend and frontend
  • Loading branch information
1tracy authored Aug 7, 2021
2 parents 2e5eb59 + 32a5af8 commit 7396ef5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Mental Health Assistant

## Pre-requisites

- git
- python 3
- pip
Expand All @@ -10,50 +11,71 @@

Clone and cd to repo

Use developement .env file in **backend** folder

```bash
$ cp ./backend/example.env ./backend/.env
$ docker-compose up
```

OR if you don't have docker..

Create and python virtual environment

```bash
$ python -m venv venv
```

Start virtual environment using venv

Linux/MacOS:

```bash
$ source venv/bin/activate
```

Windows:

```cmd
> venv\Scripts\activate
```

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install all dependencies

```bash
$ pip install -r requirements.txt
```

## Usage

Use developement .env file
Linux/MacOS:

```bash
$ cp example.env .env
```

Windows:

```cmd
$ copy example.env .env
```

Start flask development server

```bash
$ flask run
```

Install node_modules

```bash
$ cd frontend
$ npm install
```

Run react

```bash
$ yarn start (for development)
$ yarn start (for production)
Expand Down
11 changes: 11 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.8-slim-buster

RUN mkdir /backend
COPY requirements.txt /backend
WORKDIR /backend
RUN pip3 install -r requirements.txt

COPY . .

RUN chmod u+x entrypoint.sh
ENTRYPOINT ["sh", "entrypoint.sh"]
4 changes: 4 additions & 0 deletions backend/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
flask db migrate
flask db upgrade
gunicorn wsgi:app -w 1 -b 0.0.0.0:5000 --capture-output --log-level debug
4 changes: 4 additions & 0 deletions backend/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from app import app

if __name__ == "__main__":
app.run()
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: "3"

services:
frontend:
build: frontend
command: ["npm", "start"]
volumes:
- ./frontend:/frontend
- node-modules:/frontend/node_modules
environment:
- NODE_ENV=development
ports:
- 3000:3000
depends_on:
- backend
backend:
container_name: backend
ports:
- 5000:5000
build: backend
restart: always
environment:
- FLASK_ENV=development
env_file:
- ./backend/.env
volumes:
- ./backend:/backend
depends_on:
- db
db:
container_name: postgres-db
image: postgres
restart: always
volumes:
- db:/var/lib/postgresql/data
env_file:
- ./backend/.env

volumes:
node-modules:
db:
5 changes: 5 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:10.15.2-alpine
RUN mkdir /frontend
WORKDIR /frontend
COPY package.json /frontend/package.json
RUN npm install

0 comments on commit 7396ef5

Please sign in to comment.