Skip to content

Commit

Permalink
incorporate review
Browse files Browse the repository at this point in the history
i.e.
* switch to prebuilt gdal image
* multistaged docker build
* allow superuser creation via flag
* use bash for script execution
* set -euo pipefial for entrypoint.sh
  • Loading branch information
hbruch committed Sep 22, 2024
1 parent 12593aa commit f908a0a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.dockerignore
.gitignore
.env
docker-compose.yml
Dockerfile
env/
Expand Down
35 changes: 24 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
FROM python:3.11
FROM ghcr.io/osgeo/gdal:alpine-small-3.9.2 AS builder
LABEL maintainer="Holger Bruch <[email protected]>"

ENV RUN_MIGRATION=false
RUN apk add --no-cache build-base python3-dev py3-pip postgresql-client libpq-dev geos-dev

RUN apt-get install
RUN apt-get update && apt-get install -y \
libpq-dev libgdal-dev libproj-dev libgeos-dev \
&& rm -rf /var/lib/apt/lists/*

RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

WORKDIR /app
COPY requirements.txt /app/
COPY web/scrapers/ParkAPI2_sources/requirements.txt /app/web/scrapers/ParkAPI2_sources/
COPY requirements.txt .
COPY web/scrapers/ParkAPI2_sources/requirements.txt ./ParkAPI2_sources_requirements.txt

RUN pip install -r requirements.txt -r ParkAPI2_sources_requirements.txt

# Operational stage
FROM ghcr.io/osgeo/gdal:alpine-small-3.9.2
LABEL maintainer="Holger Bruch <[email protected]>"

RUN apk add --no-cache bash git python3 py3-pip postgresql-client geos

RUN pip install -r requirements.txt -r web/scrapers/ParkAPI2_sources/requirements.txt
COPY --from=builder /opt/venv /opt/venv
ENV RUN_MIGRATION=0 \
CREATE_SUPERUSER=0 \
ASSIGN_LOCATIONS=0 \
PYTHONBUFFERED=1 \
PATH="/opt/venv/bin:$PATH"

COPY . /app
WORKDIR /app
COPY . /app/

EXPOSE 8000
ENTRYPOINT ["sh", "/app/entrypoint.sh"]
ENTRYPOINT ["/bin/bash", "/app/entrypoint.sh"]
CMD runserver 0.0.0.0:8000
14 changes: 11 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
#!/bin/bash
set -euo pipefail

cd web
if [ "$RUN_MIGRATION" -eq "1" ]; then
echo "RUN MIGRATION is TRUE"
fi

# Run migration only if explicitly set via ENV
if [ "$RUN_MIGRATION" != "false" ]; then
if [ "$RUN_MIGRATION" -eq "1" ]; then
./manage.py migrate
fi

if [ "$ASSING_LOCATIONS" != "false" ]; then
if [ "$ASSIGN_LOCATIONS" -eq "1" ]; then
./manage.py pa_find_locations
fi

# don't create an admin interface per default
#./manage.py createsuperuser
if [ "$CREATE_SUPERUSER" -eq "1" ]; then
./manage.py createsuperuser
fi

# start the server
./manage.py $@

0 comments on commit f908a0a

Please sign in to comment.