Skip to content

Commit

Permalink
docker images for osmcha
Browse files Browse the repository at this point in the history
  • Loading branch information
Rub21 committed Dec 7, 2023
1 parent bdee3bd commit 0090e97
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 96 deletions.
2 changes: 2 additions & 0 deletions chartpress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ charts:
valuesPath: osmchaWeb.image
osmcha-db:
valuesPath: osmchaDb.image
osmcha-api:
valuesPath: osmchaApi.image
2 changes: 2 additions & 0 deletions images/osmcha-api/Dockerfile
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
59 changes: 59 additions & 0 deletions images/osmcha-api/entrypoint.sh
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
73 changes: 14 additions & 59 deletions images/osmcha-web/Dockerfile
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
16 changes: 16 additions & 0 deletions images/osmcha-web/config/mime.types
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;
}
55 changes: 55 additions & 0 deletions images/osmcha-web/config/nginx.conf
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;
}
}
}
31 changes: 0 additions & 31 deletions images/osmcha-web/django.conf

This file was deleted.

6 changes: 0 additions & 6 deletions images/osmcha-web/gunicorn.conf

This file was deleted.

0 comments on commit 0090e97

Please sign in to comment.