Skip to content

Commit

Permalink
Reduce the prod image size by 83%
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhiek187 committed May 6, 2023
1 parent 2ffc69f commit e903c47
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ venv/
*/*/*.swp
*/*/*/*.swp

# Django stuff:
# Django stuff
*.log
local_settings.py
db.sqlite3
Expand Down
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# Start with a python 3 base image
ARG PYTHON_VERSION=3-alpine

FROM python:${PYTHON_VERSION}

RUN \
apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev

RUN mkdir -p /app
WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt
RUN apk --purge del .build-deps

# Install dependencies
RUN \
apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \
pip install -r requirements.txt --no-cache-dir && \
apk --purge del .build-deps

COPY . .
ENV SECRET_KEY=$SECRET_KEY FMP_API_KEY=$FMP_API_KEY

# Initialize the Postgres database, load the flashcards data, and collect all static files
RUN \
python stockhelper/manage.py migrate && \
python stockhelper/manage.py loaddata cards.json && \
python stockhelper/manage.py collectstatic --noinput

# Start an HTTP server
EXPOSE 8080

CMD ["gunicorn", "--bind", ":8080", "--workers", "2", "--chdir", "stockhelper", "stockhelper.wsgi"]
4 changes: 0 additions & 4 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ RUN \

COPY . /code
WORKDIR /code/stockhelper
# Initialize the SQLite databases
RUN python manage.py migrate
# Load the flashcards data
RUN python manage.py loaddata cards.json
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ services:
build:
context: .
dockerfile: Dockerfile.dev
# Initialize the SQLite database, load the flashcards data, and start the server
command: >
sh -c "python manage.py migrate &&
python manage.py loaddata cards.json &&
Expand Down

0 comments on commit e903c47

Please sign in to comment.