Skip to content

Commit

Permalink
Crude beginnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfr committed Nov 14, 2017
1 parent 292686e commit 769f732
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 121 deletions.
146 changes: 42 additions & 104 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,104 +1,42 @@
#
# Image used for hosting scitran core with uwsgi.
#
# Example usage is in README.md
#

FROM ubuntu:14.04


# Install pre-requisites
RUN apt-get update \
&& apt-get install -y \
build-essential \
ca-certificates curl \
libatlas3-base \
numactl \
python-dev \
python-pip \
libffi-dev \
libssl-dev \
libpcre3 \
libpcre3-dev \
git \
&& rm -rf /var/lib/apt/lists/* \
&& pip install -U pip


# Grab gosu for easy step-down from root in a docker-friendly manner
# https://github.com/tianon/gosu
#
# Alternate key servers are due to reliability issues with ha.pool.sks-keyservers.net
RUN curl -o /usr/local/bin/gosu -SL "https://github.com/tianon/gosu/releases/download/1.6/gosu-$(dpkg --print-architecture)" \
&& curl -o /tmp/gosu.asc -SL "https://github.com/tianon/gosu/releases/download/1.6/gosu-$(dpkg --print-architecture).asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& for server in $(shuf -e ha.pool.sks-keyservers.net \
hkp://p80.pool.sks-keyservers.net:80 \
keyserver.ubuntu.com \
hkp://keyserver.ubuntu.com:80 \
pgp.mit.edu) ; do \
gpg --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && break || : ; \
done \
&& gpg --batch --verify /tmp/gosu.asc /usr/local/bin/gosu \
&& rm -r "$GNUPGHOME" /tmp/gosu.asc \
&& chmod +x /usr/local/bin/gosu


# Setup environment
WORKDIR /var/scitran

RUN mkdir -p \
/var/scitran/config \
/var/scitran/data \
/var/scitran/code/api \
/var/scitran/logs \
/var/scitran/keys

# Declaring a volume makes the intent to map externally explicit. This enables
# the contents to survive/persist across container versions, and easy access
# to the contents outside the container.
#
# Declaring the VOLUME in the Dockerfile guarantees the contents are empty
# for any new container that doesn't specify a volume map via 'docker run -v '
# or similar option.
#
VOLUME /var/scitran/keys
VOLUME /var/scitran/data
VOLUME /var/scitran/logs


# Install pip modules
#
# Split this out for better cache re-use.
#
COPY requirements.txt docker/requirements-docker.txt /var/scitran/code/api/

RUN pip install --upgrade pip wheel setuptools \
&& pip install -r /var/scitran/code/api/requirements-docker.txt \
&& pip install -r /var/scitran/code/api/requirements.txt

COPY tests /var/scitran/code/api/tests/
RUN bash -e -x /var/scitran/code/api/tests/bin/setup-integration-tests-ubuntu.sh


# Copy full repo
#
COPY . /var/scitran/code/api/

COPY docker/uwsgi-entrypoint.sh /var/scitran/
COPY docker/uwsgi-config.ini /var/scitran/config/
COPY docker/newrelic.ini /var/scitran/config/



# Inject build information into image so the source of the container can be
# determined from within it.
ARG BRANCH_LABEL=NULL
ARG COMMIT_HASH=0
COPY docker/inject_build_info.sh /
RUN /inject_build_info.sh ${BRANCH_LABEL} ${COMMIT_HASH} \
&& rm /inject_build_info.sh


ENTRYPOINT ["/var/scitran/uwsgi-entrypoint.sh"]
CMD ["uwsgi", "--ini", "/var/scitran/config/uwsgi-config.ini", "--http", "0.0.0.0:8080", "--http-keepalive", "--so-keepalive", "--add-header", "Connection: Keep-Alive" ]
FROM python:2.7-alpine3.6 as build

RUN apk add --no-cache build-base curl

WORKDIR /src/nginx-unit

RUN curl -L https://github.com/nginx/unit/archive/master.tar.gz | tar xz --strip-components 1
RUN ./configure --prefix=/usr/local --modules=lib --state=/var/local/unit --pid=/var/unit.pid --log=/var/log/unit.log \
&& ./configure python \
&& make install


FROM python:2.7-alpine3.6 as dist

RUN apk add --no-cache git

COPY --from=build /usr/local/sbin/unitd /usr/local/sbin/unitd
COPY --from=build /usr/local/lib/python.unit.so /usr/local/lib/python.unit.so

EXPOSE 80 8080 27017

VOLUME /data/db

WORKDIR /scr/core

COPY . .
COPY docker/unit.json /var/local/unit/conf.json

RUN pip install -e .

CMD ["unitd", "--control", "*:8080", "--no-daemon", "--log", "/dev/stdout"]


FROM dist as testing

RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community mongodb=3.4.4-r0

RUN pwd

CMD ["./docker/dev+mongo.sh"]

#docker run -it --rm -p 8080:80 -p 8081:8080 scitran/core:testing
3 changes: 3 additions & 0 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .web import start

application = start.app_factory()
6 changes: 6 additions & 0 deletions docker/dev+mongo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

mongod &
MONGOD_PID=$!

unitd --control "*:8888" --no-daemon --log /dev/stdout
18 changes: 18 additions & 0 deletions docker/unit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"listeners": {
"*:80": {
"application": "scitran-core"
}
},

"applications": {
"scitran-core": {
"type": "python",
"workers": 2,
"user": "root",
"group": "root",
"path": "/src/core",
"module": "api.app"
}
}
}
17 changes: 0 additions & 17 deletions requirements.txt

This file was deleted.

36 changes: 36 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from setuptools import setup, find_packages

install_requires = [
'django >= 1.11.5',
'elasticsearch==5.3.0',
'enum34==1.1.6',
'jsonschema==2.6.0',
'Markdown==2.6.5',
'pymongo==3.2',
'python-dateutil==2.4.2',
'pytz==2015.7',
'requests==2.9.1',
'rfc3987==1.3.4',
'strict-rfc3339==0.7',
'unicodecsv==0.9.0',
'webapp2==2.5.2',
'WebOb==1.5.1',
'gears',
]

dependency_links = [
'git+https://github.com/flywheel-io/[email protected]#egg=gears',
]

setup(
name = 'example',
version = '0.0.1',
description = '',
author = '',
author_email = '',
url = '',
license = '',
packages = find_packages(),
dependency_links = dependency_links,
install_requires = install_requires,
)

0 comments on commit 769f732

Please sign in to comment.