-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
3 changed files
with
36 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.dockerignore | ||
.gitignore | ||
.env | ||
docker-compose.yml | ||
Dockerfile | ||
env/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $@ |