Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Flask dev server in docker-compose #119

Merged
merged 3 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files that shouldn't be copied into the api image
frontend
.vscode
.pytest_cache
.env
**/__pycache__
6 changes: 5 additions & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ FROM python:3.8-slim-buster AS base

RUN apt-get update && apt-get install curl -y

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.7.3/wait /wait
RUN chmod +x /wait

FROM base
WORKDIR /app/

Expand All @@ -12,4 +15,5 @@ RUN pip3 install -r requirements/dev_unix.txt
COPY . .

ENV PORT=5000
CMD ["/bin/bash", "run_prod.sh"]

CMD /wait && ./run_dev.sh
13 changes: 8 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@ services:
web:
restart: always
build:
context: .
dockerfile: ./frontend/Dockerfile
context: ./frontend
volumes:
- ./frontend/pages:/usr/src/app/pages
- ./frontend/public:/usr/src/app/public
- ./frontend/styles:/usr/src/app/styles
- ./frontend:/app
# Prevents the host node_modules from clobbering the image's
- /app/node_modules
ports:
- 3000:3000
api:
restart: always
build:
context: .
dockerfile: ./backend/Dockerfile
volumes:
- .:/app
depends_on:
- db
environment:
POSTGRES_HOST: db
FLASK_ENV: development
WAIT_HOSTS: db:5432
ports:
- 5000:5000

Expand Down
3 changes: 3 additions & 0 deletions frontend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Files that shouldn't be copied into the web image
node_modules
.next
3 changes: 3 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ yarn-error.log*

# vercel
.vercel

# Non-UI frontend code
!lib
11 changes: 5 additions & 6 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
FROM node:lts-buster
RUN npm install --global npm@latest

WORKDIR /usr/src/app
WORKDIR /app/

USER root

COPY frontend/package*.json /usr/src/app/
RUN npm install --no-optional --quiet 1>/dev/null
COPY package*.json ./
RUN npm ci --no-optional --quiet 1>/dev/null

COPY .git/hooks/ .git/hooks/
RUN npm run prepare
COPY frontend/ ./
COPY . .

ENV POSTGRES_HOST=$DATABASE
ENV PORT=3000
Expand Down
7 changes: 7 additions & 0 deletions run_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

export FLASK_ENV=development

flask psql create
flask psql init
flask run --host=0.0.0.0