Skip to content

Commit

Permalink
Merge pull request #21 from internetofwater/gt-access
Browse files Browse the repository at this point in the history
gitops workflow
  • Loading branch information
gzt5142 authored Aug 26, 2024
2 parents 1d90e16 + b7e73b6 commit aa1abf2
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 44 deletions.
66 changes: 26 additions & 40 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,57 +27,43 @@
#
# =================================================================

FROM ubuntu:jammy
FROM python:3.11-alpine as build

LABEL maintainer="Benjamin Webb <[email protected]>"

ARG ADD_DEB_PACKAGES="\
python3-gdal \
python3-psycopg2 \
python3-rasterio"

LABEL description="Docker image for the NLDI API"
# ENV settings
ENV TZ=${TZ} \
LANG=${LANG} \
DEBIAN_FRONTEND="noninteractive" \
DEB_BUILD_DEPS="\
curl \
gcc \
unzip" \
DEB_PACKAGES="\
locales \
tzdata \
gunicorn \
python3-dateutil \
python3-flask \
python3-flask-cors \
python3-gevent \
python3-greenlet \
python3-pip \
python3-tz \
python3-unicodecsv \
python3-yaml \
${ADD_DEB_PACKAGES}"
PIP_NO_CACHE_DIR=1

# Install operating system dependencies
RUN \
apk update && apk add curl build-base libpq-dev proj-util proj-dev gdal-dev geos-dev

COPY ./requirements-docker.txt ./requirements.txt ./req/


RUN pip install --no-cache-dir -r ./req/requirements.txt
RUN pip install --no-cache-dir -r ./req/requirements-docker.txt



FROM python:3.11-alpine as nldi
RUN apk update && apk add --no-cache gcompat libstdc++ curl proj-util libpq-dev
ADD . /nldi
WORKDIR /nldi
COPY --from=build /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
COPY --from=build /usr/lib/libgdal.so.35 /usr/lib/libgeos.so.3.12.2 /usr/lib/libproj.so.25 /usr/lib/libgeos_c.so.1.18.2 /usr/lib/
COPY --from=build /usr/local/bin/pygeoapi /usr/local/bin/gunicorn /usr/local/bin/

# Install operating system dependencies
RUN \
apt-get update -y \
&& apt-get upgrade -y \
&& apt-get --no-install-recommends install -y ${DEB_PACKAGES} ${DEB_BUILD_DEPS} \
# Install nldi
&& pip3 install --no-deps https://github.com/geopython/pygeoapi/archive/refs/heads/master.zip \
&& pip3 install -r requirements-docker.txt \
&& pip3 install -e . \
# Cleanup
&& apt-get remove --purge -y ${DEB_BUILD_DEPS} \
&& apt-get clean \
&& apt autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
# Set default config and entrypoint for Docker Image
ln -s /usr/lib/libgdal.so.35 /usr/lib/libgdal.so \
&& ln -s /usr/lib/libgeos.so.3.12.2 /usr/lib/libgeos.so \
# && ln -s /usr/lib/libproj.so.25 /usr/lib/libproj.so \
&& ln -s /usr/lib/libgeos_c.so.1.18.2 /usr/lib/libgeos_c.so.1 \
&& ln -s /usr/lib/libgeos_c.so.1 /usr/lib/libgeos_c.so

RUN pip install -e . \
&& cp /nldi/docker/default.source.yml /nldi/local.source.yml \
&& cp /nldi/docker/pygeoapi.config.yml /nldi/pygeoapi.config.yml \
&& cp /nldi/docker/entrypoint.sh /entrypoint.sh
Expand Down
6 changes: 3 additions & 3 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# =================================================================
#
# Author: Benjamin Webb <[email protected]>
Expand Down Expand Up @@ -40,7 +40,7 @@ export PYGEOAPI_CONFIG="${NLDI_HOME}/pygeoapi.config.yml"
export PYGEOAPI_OPENAPI="${NLDI_HOME}/pygeoapi.openapi.yml"

# gunicorn env settings with defaults
export SCRIPT_NAME=${NLDI_PATH:=/}
#export SCRIPT_NAME=${NLDI_PATH:=/}
CONTAINER_NAME=${CONTAINER_NAME:=nldi}
CONTAINER_HOST=${CONTAINER_HOST:=0.0.0.0}
CONTAINER_PORT=${CONTAINER_PORT:=80}
Expand Down Expand Up @@ -78,7 +78,7 @@ run)

# SCRIPT_NAME should not have value '/'
[[ "${SCRIPT_NAME}" = '/' ]] && export SCRIPT_NAME="" && echo "make SCRIPT_NAME empty from /"

unset SCRIPT_NAME
echo "Start gunicorn name=${CONTAINER_NAME} on ${CONTAINER_HOST}:${CONTAINER_PORT} with ${WSGI_WORKERS} workers and SCRIPT_NAME=${SCRIPT_NAME}"
exec gunicorn --workers ${WSGI_WORKERS} \
--worker-class=${WSGI_WORKER_CLASS} \
Expand Down
4 changes: 3 additions & 1 deletion nldi/flask_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from flask import (Blueprint, Flask, request,
stream_with_context, Response, send_from_directory)
from flask_cors import CORS
from jinja2.environment import TemplateStream
import logging
import os
Expand All @@ -52,6 +53,7 @@

APP = Flask(__name__, static_folder=STATIC_FOLDER, static_url_path='/static')
APP.url_map.strict_slashes = False
CORS(APP)
BLUEPRINT = Blueprint('nldi', __name__, static_folder=STATIC_FOLDER)

API_ = API(CONFIG)
Expand Down Expand Up @@ -231,4 +233,4 @@ def get_navigation(source_name=None, identifier=None, nav_mode=None, data_source
except KeyError:
LOGGER.info('Not including pygeoapi templates')

APP.register_blueprint(BLUEPRINT)
APP.register_blueprint(BLUEPRINT, url_prefix='/api/nldi')
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
click>7,<=8
Flask
flask-cors
gunicorn
geoalchemy
psycopg2
pygeoapi
Expand All @@ -9,3 +11,5 @@ PyYAML
requests
SQLAlchemy
unicodecsv
gevent
psycopg2

0 comments on commit aa1abf2

Please sign in to comment.