-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rub21
committed
Dec 7, 2023
1 parent
bdee3bd
commit 0090e97
Showing
8 changed files
with
148 additions
and
96 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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM ghcr.io/willemarcel/osmcha-django:b1f4e6afc90e08707cadc4d74580632ca3b93dd2 | ||
RUN pip install django-debug-toolbar |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
set -e | ||
cmd="$@" | ||
|
||
# This entrypoint is used to play nicely with the current cookiecutter configuration. | ||
# Since docker-compose relies heavily on environment variables itself for configuration, we'd have to define multiple | ||
# environment variables just to support cookiecutter out of the box. That makes no sense, so this little entrypoint | ||
# does all this for us. | ||
export REDIS_URL=redis://redis:6379 | ||
# the official postgres image uses 'postgres' as default user if not set explictly. | ||
if [ -z "$POSTGRES_USER" ]; then | ||
export POSTGRES_USER=postgres | ||
fi | ||
|
||
if [ -z "$POSTGRES_HOST" ]; then | ||
export POSTGRES_HOST=postgres | ||
fi | ||
|
||
export PGHOST=$POSTGRES_HOST | ||
export POSTGRES_USER=$POSTGRES_USER | ||
export POSTGRES_PASSWORD=$POSTGRES_PASSWORD | ||
# export DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/$POSTGRES_USER | ||
|
||
export CELERY_BROKER_URL=$REDIS_URL/0 | ||
|
||
|
||
function postgres_ready(){ | ||
python << END | ||
import sys | ||
import psycopg2 | ||
try: | ||
conn = psycopg2.connect(dbname="$POSTGRES_USER", user="$POSTGRES_USER", password="$POSTGRES_PASSWORD", host="$POSTGRES_HOST") | ||
except psycopg2.OperationalError: | ||
sys.exit(-1) | ||
sys.exit(0) | ||
END | ||
} | ||
|
||
until postgres_ready; do | ||
>&2 echo "Postgres is unavailable - sleeping" | ||
sleep 1 | ||
done | ||
|
||
>&2 echo "Postgres is up - continuing..." | ||
|
||
# Collect static files | ||
python manage.py collectstatic --noinput | ||
|
||
# Create directory for static files | ||
mkdir -p /staticfiles/static | ||
|
||
# Copy static files | ||
cp -r /app/staticfiles/* /staticfiles/static/ | ||
|
||
# Execute the passed command | ||
exec $cmd | ||
|
||
# Start Gunicorn | ||
gunicorn --workers 4 --bind 0.0.0.0:5000 --log-file "-" --access-logfile "-" config.wsgi |
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,66 +1,21 @@ | ||
FROM ubuntu:20.04 | ||
ARG DEBIAN_FRONTEND=noninteractive | ||
FROM node:16-slim as builder | ||
|
||
RUN apt-get update -y -qq | ||
RUN apt-get install -y curl python3 python3-dev \ | ||
python3-pip git libgeos-dev libyaml-dev \ | ||
libcurl4-gnutls-dev librtmp-dev python3-gdal \ | ||
locales nginx supervisor yarnpkg nodejs npm | ||
RUN locale-gen en_US.UTF-8 | ||
RUN apt-get clean | ||
RUN rm -rf /var/lib/apt/lists/* | ||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
# Install yarn. | ||
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - | ||
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list | ||
RUN apt-get update -y | ||
RUN apt-get remove -y yarnpkg cmdtest && apt-get install -y yarn && apt-get clean && rm -rf /var/lib/apt/lists/* | ||
ARG BUILD_ENV=prod | ||
|
||
# Setup nginx | ||
RUN rm /etc/nginx/sites-enabled/default | ||
COPY django.conf /etc/nginx/sites-available/ | ||
RUN ln -s /etc/nginx/sites-available/django.conf /etc/nginx/sites-enabled/django.conf | ||
RUN echo "daemon off;" >> /etc/nginx/nginx.conf | ||
|
||
|
||
# Setting locale is required by unicode-slugify (osmcha-django python requirement) | ||
RUN locale-gen en_US.UTF-8 | ||
ENV LANG en_US.UTF-8 | ||
ENV LANGUAGE en_US:en | ||
RUN apt-get update && apt-get install -y git | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
ENV BACKEND_VERSION v4.19.0 | ||
RUN git clone https://github.com/willemarcel/osmcha-django . | ||
RUN git checkout $BACKEND_VERSION | ||
RUN git pull origin $BACKEND_VERSION | ||
RUN pip3 install -r requirements/production.txt | ||
RUN pip3 install -r requirements/local.txt | ||
|
||
ADD . /app | ||
ENV DJANGO_ROOT /app | ||
ENV DJANGO_SETTINGS_MODULE config.settings.aws_production | ||
|
||
# Replace social-auth-core by a modified version that provides OHM authentication | ||
RUN pip3 install git+https://github.com/OpenHistoricalMap/social-core.git@master | ||
|
||
# Upgrading requests to the latest version. | ||
RUN pip3 install -U requests | ||
RUN pip3 install certifi | ||
RUN pip3 install django-extensions | ||
|
||
# Clone and build the frontend | ||
RUN git clone https://github.com/mapbox/osmcha-frontend.git /osmcha-frontend | ||
RUN cd /osmcha-frontend && yarn install | ||
|
||
RUN echo "alias python=python3" >> ~/.bashrc | ||
RUN echo "alias pip=pip3" >> ~/.bashrc | ||
|
||
EXPOSE 80 | ||
RUN git clone https://github.com/sunu/osmcha-frontend.git /app | ||
RUN yarn install | ||
|
||
# Supervisor config | ||
RUN mkdir -p /var/log/supervisor | ||
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf | ||
COPY gunicorn.conf /etc/supervisor/conf.d/gunicorn.conf | ||
ENV REACT_APP_PRODUCTION_API_URL /api/v1 | ||
RUN yarn build:${BUILD_ENV} | ||
|
||
COPY ./start.sh . | ||
CMD ./start.sh | ||
FROM nginx:alpine | ||
# COPY config/nginx.conf /etc/nginx/ | ||
# COPY config/mime.types /etc/nginx/ | ||
# RUN nginx -t | ||
COPY --from=builder /app/build /assets |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
types { | ||
text/html html htm shtml; | ||
text/css css; | ||
text/xml xml; | ||
image/gif gif; | ||
image/jpeg jpeg jpg; | ||
application/javascript js; | ||
image/png png; | ||
image/svg+xml svg svgz; | ||
image/tiff tif tiff; | ||
image/x-icon ico; | ||
image/x-jng jng; | ||
application/font-woff woff; | ||
application/json json; | ||
application/zip zip; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
worker_processes 4; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
sendfile on; | ||
#tcp_nopush on; | ||
|
||
keepalive_timeout 65; | ||
|
||
#gzip on; | ||
|
||
upstream app { | ||
server host.docker.internal:500; | ||
} | ||
|
||
server { | ||
listen 80; | ||
charset utf-8; | ||
|
||
location ~ ^/static.* { | ||
root /staticfiles; | ||
try_files $uri @proxy_to_frontend; | ||
} | ||
|
||
location @proxy_to_frontend { | ||
root /assets; | ||
try_files $uri @django; | ||
} | ||
|
||
location / { | ||
root /assets; | ||
# checks for static file, if not found proxy to app | ||
try_files $uri $uri/ @django; | ||
} | ||
|
||
location @django { | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
# proxy_set_header Host $http_host; | ||
proxy_redirect off; | ||
proxy_pass http://app; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.