Skip to content

Commit

Permalink
build(app): dockerize full app for development
Browse files Browse the repository at this point in the history
Fixes part of #116
  • Loading branch information
brijsiyag authored and Samy-33 committed Jul 14, 2022
1 parent bd0b200 commit 85b5b1d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
24 changes: 15 additions & 9 deletions api/Dockerfile → api/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# base image
FROM python:3.8
FROM python:3.8

# setup environment variable for work directory
ENV API_HOME=/home/app/webapp
ENV API_HOME=/home/app/api

# make work directory
RUN mkdir -p $API_HOME
RUN mkdir -p $API_HOME

# set work directory
WORKDIR $API_HOME
WORKDIR $API_HOME

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONUNBUFFERED 1

# copy requirements file
COPY requirements.txt $API_HOME
Expand All @@ -21,13 +21,19 @@ COPY requirements.txt $API_HOME
RUN pip install --upgrade pip && pip install -r requirements.txt

# copy api directory to docker's work directory.
COPY . $API_HOME
COPY . $API_HOME

# make migrations
RUN chmod +x scripts/makemigrations.sh && ./scripts/makemigrations.sh && python manage.py migrate
RUN chmod +x scripts/makemigrations.sh && ./scripts/makemigrations.sh

# Migrate all migrations
RUN python manage.py migrate

# Populate Database with dummy data
RUN chmod +x scripts/populate_db.sh && scripts/populate_db.sh

# port where the Django app runs
EXPOSE 8000
EXPOSE 8000

# start server
ENTRYPOINT ["python", "manage.py", "runserver", "0.0.0.0:8000"]
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
1 change: 1 addition & 0 deletions api/scripts/populate_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python manage.py loaddata user_data
21 changes: 21 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3.9"
services:
api:
build:
context: ./api
dockerfile: Dockerfile.dev
volumes:
- ./api:/home/app/api
ports:
- 8000:8000
command: python manage.py runserver 0.0.0.0:8000
ui:
build:
context: ./ui
dockerfile: Dockerfile.dev
volumes:
- ./ui:/home/app/ui
- /home/app/ui/node_modules
ports:
- 3000:3000
command: npm run dev -- --host
24 changes: 24 additions & 0 deletions ui/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM node:alpine3.16

# Set working DIE
WORKDIR /home/app/ui

# Upgrade Alpine Packages
RUN apk -U upgrade

# Add bash to run tests and other scripts
RUN apk add --no-cache bash

# Copy package.json and package-lock.json
COPY package*.json .

# Install node packages
RUN npm ci

# Copy rest of code
COPY . .

# PORT where UI will run in browser
EXPOSE 3000

CMD ["npm","run","dev","--","--host"]

0 comments on commit 85b5b1d

Please sign in to comment.