-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Dockerfile, test scripts and CI (WIP) #1101
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
.git | ||
* | ||
|
||
# --- Below Should mirror .gitignore, without leading '/' --- # | ||
.DS_Store | ||
.*sw[op] | ||
*.py[co] | ||
*.egg-info | ||
persistent | ||
runtime | ||
bootstrap.json | ||
.cache | ||
.coverage* | ||
coverage.xml | ||
htmlcov | ||
node_modules | ||
!api | ||
!bin | ||
!docker/uwsgi-config.ini | ||
!docker/uwsgi-entrypoint.sh | ||
!requirements.txt | ||
!setup.py | ||
!swagger/examples | ||
!swagger/schemas | ||
!tests/requirements.txt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
.DS_Store | ||
.*sw[op] | ||
*.py[co] | ||
*.egg-info | ||
*.py[co] | ||
.*sw[op] | ||
.cache | ||
.DS_Store | ||
/.coverage* | ||
/bin/accesslog.csv | ||
/htmlcov | ||
/persistent | ||
/runtime | ||
bootstrap.json | ||
.cache | ||
/.coverage* | ||
coverage.xml | ||
endpoints.json | ||
/htmlcov | ||
node_modules/ | ||
/bin/accesslog.csv | ||
node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,59 @@ | ||
sudo: required | ||
dist: trusty | ||
sudo: required | ||
|
||
services: | ||
- mongodb | ||
- docker | ||
|
||
env: | ||
global: | ||
secure: HELJx6WPr+W2S0FV47KkRdlS9NCqlMcdRMK8xWgRqqrEPv24KEvNnHxCy0tRbzITqadYtyvI1MtqtmpG04uty8Gpkc7w6L6LMJ/OuLG0gVX7AnaUovYTlY04m1/L9oyzOrTDXk5J/BKbcyiz7uJtkTc/A8MMZAFfZh7hmhLID78= # BUILD_TRIGGER_URL | ||
|
||
install: | ||
- bin/install-ubuntu.sh | ||
- tests/bin/setup-integration-tests-ubuntu.sh | ||
- DOCKER_DIR="$HOME/.cache/docker" | ||
- secure: HhT1TdJcpqys8juVMw/DIZeK7oD4595TEKH5KlowH7MvwwFAUyQFb5W63F8dgk7elvRG+3fmga/m1JfXO+Iu7PVD912eiNDagW9aB3CEl3Z8zg+JUL8IjpMCkyKQDyJMnfOkrzdxdaqfOK+WmF+13f2qBu9Kc7wdXuzgHQrg4+0= # CI_REGISTRY_USER | ||
- secure: hh7VDZnkxgl/vqHtS4IpXfIAckKpVQvoCzNW7fstr5Mcu8KNiCWIPgObBRm+m13aqpcFTMWQ6lT2kzORz2wWRbDeVhI1eGWOJswGNHPHZLO0Jaei6yfY2nY2mpxZbl+vdg00jkN64mi1ab3e++QgeLFruW0gyNefXX7E5L/mHTs= # CI_REGISTRY_PASS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we replace these encrypted variables with Travis env variables, as used in the |
||
|
||
script: | ||
- SCITRAN_PERSISTENT_DB_PORT=27017 tests/bin/run-tests-ubuntu.sh | ||
cache: | ||
directories: | ||
- $DOCKER_DIR | ||
|
||
after_success: | ||
- if [ "$TRAVIS_EVENT_TYPE" == "push" -o "$TRAVIS_TAG" ]; then | ||
SSH_KEY_FILE=$(mktemp -p $HOME/.ssh/); | ||
before_install: | ||
- sudo apt-get update | ||
- sudo apt-get -y install docker-ce realpath | ||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASS | ||
|
||
openssl aes-256-cbc -K $encrypted_55750ae1fbc7_key -iv $encrypted_55750ae1fbc7_iv -in .github_deploy_key.enc -out "$SSH_KEY_FILE" -d; | ||
install: true | ||
|
||
chmod 600 "$SSH_KEY_FILE" && printf "%s\n" \ | ||
"Host github.com" \ | ||
" IdentityFile $SSH_KEY_FILE" \ | ||
" LogLevel ERROR" >> ~/.ssh/config; | ||
script: | ||
- test -f "$DOCKER_DIR/image.tar" && docker load -i "$DOCKER_DIR/image.tar" || true | ||
- docker build -t core:base --target base . | ||
- docker build -t core:dist --target dist --build-arg VCS_BRANCH="$TRAVIS_BRANCH" --build-arg VCS_COMMIT="$TRAVIS_COMMIT" . | ||
- docker build -t core:testing --target testing . | ||
- docker save -o "$DOCKER_DIR/image.tar" $(docker history -q core:base | grep -v '<missing>') $(docker history -q core:dist | grep -v '<missing>') | ||
- ./tests/bin/docker-tests.sh --image core:testing | ||
|
||
git config --global user.email "[email protected]"; | ||
git config --global user.name "Travis CI"; | ||
git config --global push.default simple; | ||
fi | ||
- if [ "$TRAVIS_BRANCH" == "master" -o "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then | ||
bash <(curl -s https://codecov.io/bash) -cF python; | ||
fi | ||
- if [ "$TRAVIS_TAG" ]; then | ||
./docker/build-trigger.sh Tag "$TRAVIS_TAG" "$BUILD_TRIGGER_URL"; | ||
./bin/push-docs.sh "$GIT_REMOTE" tags "$TRAVIS_TAG" "Travis Core Docs Build - ${TRAVIS_BUILD_NUMBER}"; | ||
fi | ||
- if [ "$TRAVIS_EVENT_TYPE" == "push" -a "$TRAVIS_BRANCH" == "master" ]; then | ||
./docker/build-trigger.sh Branch "$TRAVIS_BRANCH" "$BUILD_TRIGGER_URL"; | ||
fi | ||
- if [ "$TRAVIS_EVENT_TYPE" == "push" -a -z "$TRAVIS_TAG" ]; then | ||
./bin/push-docs.sh "$GIT_REMOTE" branches "$TRAVIS_BRANCH" "Travis Core Docs Build - ${TRAVIS_BUILD_NUMBER}"; | ||
fi | ||
|
||
after_success: | ||
- | | ||
if [ "$TRAVIS_EVENT_TYPE" == "push" -o "$TRAVIS_TAG" ]; then | ||
SSH_KEY_FILE=$(mktemp -p $HOME/.ssh/); | ||
openssl aes-256-cbc -K $encrypted_55750ae1fbc7_key -iv $encrypted_55750ae1fbc7_iv -in .github_deploy_key.enc -out $SSH_KEY_FILE -d; | ||
chmod 600 $SSH_KEY_FILE; | ||
printf "%s\n" \ | ||
"Host github.com" \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I would be a fan of moving these long multi-line bash scripts to a separate file, and invoking them. Keeps the yaml more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind having the details in here. I like the transparency of a single file. |
||
" IdentityFile $SSH_KEY_FILE" \ | ||
" LogLevel ERROR" >> ~/.ssh/config; | ||
git config --global user.email "[email protected]"; | ||
git config --global user.name "Travis CI"; | ||
git config --global push.default simple; | ||
fi | ||
- if [ "$TRAVIS_BRANCH" == "master" -o "$TRAVIS_EVENT_TYPE" == "pull_request" ]; then | ||
bash <(curl -s https://codecov.io/bash) -cF python; | ||
fi | ||
- if [ "$TRAVIS_TAG" ]; then | ||
docker tag core:dist scitran/core:$TRAVIS_TAG; | ||
docker push scitran/core:$TRAVIS_TAG; | ||
./bin/push-docs.sh "$GIT_REMOTE" tags "$TRAVIS_TAG" "Travis Core Docs Build - $TRAVIS_BUILD_NUMBER"; | ||
elif [ "$TRAVIS_EVENT_TYPE" == "push" ]; then | ||
./bin/push-docs.sh "$GIT_REMOTE" branches "$TRAVIS_BRANCH" "Travis Core Docs Build - $TRAVIS_BUILD_NUMBER"; | ||
fi | ||
- if [ "$TRAVIS_EVENT_TYPE" == "push" -a "$TRAVIS_BRANCH" == "master" ]; then | ||
docker tag core:dist scitran/core:latest; | ||
docker push scitran/core:latest; | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good way to further clean up the conditionals in the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,90 @@ | ||
# | ||
# 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/ | ||
FROM ubuntu:14.04 as base | ||
ENV TERM=xterm | ||
RUN set -eux \ | ||
&& apt-get -yqq update \ | ||
&& apt-get -yqq install \ | ||
build-essential \ | ||
ca-certificates \ | ||
curl \ | ||
git \ | ||
libatlas3-base \ | ||
libffi-dev \ | ||
libpcre3 \ | ||
libpcre3-dev \ | ||
libssl-dev \ | ||
numactl \ | ||
python-dev \ | ||
python-pip \ | ||
&& rm -rf /var/lib/apt/lists/* \ | ||
&& pip install -qq --upgrade pip setuptools wheel \ | ||
&& export GNUPGHOME="$(mktemp -d)" \ | ||
&& KEYSERVERS="\ | ||
ha.pool.sks-keyservers.net \ | ||
hkp://keyserver.ubuntu.com:80 \ | ||
hkp://p80.pool.sks-keyservers.net:80 \ | ||
keyserver.ubuntu.com \ | ||
pgp.mit.edu" \ | ||
&& for server in $(shuf -e $KEYSERVERS); do \ | ||
gpg --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && break || true; \ | ||
done \ | ||
&& curl -LSso /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/1.6/gosu-$(dpkg --print-architecture)" \ | ||
&& curl -LSso /tmp/gosu.asc "https://github.com/tianon/gosu/releases/download/1.6/gosu-$(dpkg --print-architecture).asc" \ | ||
&& gpg --batch --verify /tmp/gosu.asc /usr/local/bin/gosu \ | ||
&& chmod +x /usr/local/bin/gosu \ | ||
&& rm -rf "$GNUPGHOME" /tmp/gosu.asc \ | ||
&& mkdir -p \ | ||
/var/scitran/code/api \ | ||
/var/scitran/config \ | ||
/var/scitran/data \ | ||
/var/scitran/keys \ | ||
/var/scitran/logs | ||
|
||
VOLUME ["/var/scitran/keys", "/var/scitran/data", "/var/scitran/logs"] | ||
WORKDIR /var/scitran/code/api | ||
|
||
COPY docker/uwsgi-entrypoint.sh /var/scitran/ | ||
COPY docker/uwsgi-config.ini /var/scitran/config/ | ||
|
||
|
||
COPY docker/uwsgi-config.ini /var/scitran/config/ | ||
ENTRYPOINT ["/var/scitran/uwsgi-entrypoint.sh"] | ||
CMD ["uwsgi", "--ini=/var/scitran/config/uwsgi-config.ini", "--http=[::]:9000", \ | ||
"--http-keepalive", "--so-keepalive", "--add-header", "Connection: Keep-Alive"] | ||
|
||
# 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 | ||
|
||
FROM base as dist | ||
COPY requirements.txt /var/scitran/code/api/requirements.txt | ||
RUN set -eux \ | ||
&& pip install -qq --requirement /var/scitran/code/api/requirements.txt | ||
|
||
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" ] | ||
COPY . /var/scitran/code/api/ | ||
RUN set -eux \ | ||
&& pip install -qq --no-deps --editable /var/scitran/code/api | ||
|
||
ARG VCS_BRANCH=NULL | ||
ARG VCS_COMMIT=NULL | ||
RUN set -eux \ | ||
&& /var/scitran/code/api/bin/build_info.sh $VCS_BRANCH $VCS_COMMIT > /var/scitran/version.json \ | ||
&& cat /var/scitran/version.json | ||
|
||
|
||
FROM base as testing | ||
ENV MONGO_MAJOR=3.2 \ | ||
MONGO_VERSION=3.2.9 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
RUN set -eux \ | ||
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 \ | ||
&& echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/$MONGO_MAJOR multiverse" > /etc/apt/sources.list.d/mongodb-org-$MONGO_MAJOR.list \ | ||
&& apt-get -yqq update \ | ||
&& apt-get -yqq install \ | ||
mongodb-org=$MONGO_VERSION \ | ||
mongodb-org-server=$MONGO_VERSION \ | ||
mongodb-org-shell=$MONGO_VERSION \ | ||
mongodb-org-mongos=$MONGO_VERSION \ | ||
mongodb-org-tools=$MONGO_VERSION \ | ||
&& rm -rf /var/lib/apt/lists/* /var/lib/mongodb \ | ||
&& mkdir -p /data/db | ||
|
||
COPY --from=dist /usr/local /usr/local | ||
|
||
COPY tests/requirements.txt /var/scitran/code/api/tests/requirements.txt | ||
RUN set -eux \ | ||
&& pip install -qq --requirement /var/scitran/code/api/tests/requirements.txt | ||
|
||
COPY --from=dist /var/scitran /var/scitran |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
|
||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .web import start | ||
|
||
application = start.app_factory() |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆