Skip to content

Commit

Permalink
Added continuous deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
utsavgarg committed Jul 21, 2017
1 parent 24a4269 commit 18f056a
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 0 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ language: python
python:
- "2.7"

services:
- docker

cache:
directories:
- $HOME/.cache/pip
Expand All @@ -24,10 +27,12 @@ install:

before_script:
- export PYTHONPATH=$PYTHONPATH:$HOME/caffe/caffe/python

script:
- flake8 ./
- npm run ci
- KERAS_BACKEND=theano coverage run --source=caffe_app,keras_app,ide/utils manage.py test

after_success:
- coveralls
- sh docker/deploy.sh
17 changes: 17 additions & 0 deletions aws/prod/Dockerrun.aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"AWSEBDockerrunVersion": 2,
"containerDefinitions": [
{
"name": "fabrik-app",
"image": "<AWS_ACCOUNT_ID>.dkr.ecr.us-west-2.amazonaws.com/cloudcv/fabrik:latest",
"essential": true,
"memory": 512,
"portMappings": [
{
"hostPort": 8000,
"containerPort": 8000
}
]
}
]
}
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "2"
services:
app:
container_name: fabrik
host_name: fabrik
build:
context: .
dockerfile: docker/prod/Dockerfile
command: docker/prod/container-start.sh
ports:
- "8000:8000"
37 changes: 37 additions & 0 deletions docker/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
BRANCH="master"
SHA=`git rev-parse --verify HEAD`

if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$BRANCH" ]; then
echo "Skipping deploy to production server; The request or commit is not on master"
exit 0
fi

VERSION=$BRANCH-$SHA
ZIP=$VERSION.zip

aws configure set default.region us-west-2
# Authenticate against our Docker registry
eval $(aws ecr get-login)

# Build and push the image
docker build -t cloudcv/fabrik -f docker/prod/Dockerfile .
docker tag cloudcv/fabrik:latest $AWS_ACCOUNT_ID.dkr.ecr.us-west-2.amazonaws.com/cloudcv/fabrik:latest
docker push $AWS_ACCOUNT_ID.dkr.ecr.us-west-2.amazonaws.com/cloudcv/fabrik:latest

cd aws/prod

# Replace the <AWS_ACCOUNT_ID> with the real ID
sed -i='' "s/<AWS_ACCOUNT_ID>/$AWS_ACCOUNT_ID/" Dockerrun.aws.json

# Zip up the Dockerrun file and .ebextensions directory with it
zip -r $ZIP Dockerrun.aws.json

aws s3 cp $ZIP s3://$EB_BUCKET/$ZIP

# Create a new application version with the zipped up Dockerrun file
aws elasticbeanstalk create-application-version --application-name $APPLICATION \
--version-label $VERSION --source-bundle S3Bucket=$EB_BUCKET,S3Key=$ZIP

# Update the environment to use the new application version
aws elasticbeanstalk update-environment --environment-name $ENVIRONMENT \
--version-label $VERSION
75 changes: 75 additions & 0 deletions docker/prod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
FROM node:6

RUN mkdir -p /code
WORKDIR /code
ENV PYTHONUNBUFFERED 1

COPY package.json /code
RUN npm install
RUN npm install -g webpack

# Install Python.
RUN \
apt-get update && \
apt-get install -y python python-dev python-pip python-virtualenv && \
rm -rf /var/lib/apt/lists/*

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
unzip \
wget \
libatlas-base-dev \
libboost-all-dev \
libgflags-dev \
libgoogle-glog-dev \
libhdf5-serial-dev \
libleveldb-dev \
liblmdb-dev \
libopencv-dev \
libprotobuf-dev \
libsnappy-dev \
protobuf-compiler \
python-dev \
python-numpy \
python-pip \
python-setuptools \
python-scipy && \
rm -rf /var/lib/apt/lists/*

# Install Caffe
RUN cd /root &&\
wget https://github.com/BVLC/caffe/archive/25391bf9e0552740af8253c6d6fd484297889a49.zip &&\
unzip -o 25391bf9e0552740af8253c6d6fd484297889a49.zip &&\
rm 25391bf9e0552740af8253c6d6fd484297889a49.zip && \
mv caffe-25391bf9e0552740af8253c6d6fd484297889a49 caffe &&\
cd caffe &&\
pip install scikit-image &&\
mkdir build && cd build && \
cmake -DCPU_ONLY=1 -DWITH_PYTHON_LAYER=1 -DUSE_OPENCV=0 .. && \
make -j"$(nproc)"

# Set up Caffe environment variables
ENV CAFFE_ROOT=/root/caffe
ENV PYCAFFE_ROOT=$CAFFE_ROOT/python
ENV PYTHONPATH=$PYCAFFE_ROOT:$PYTHONPATH \
PATH=$CAFFE_ROOT/build/tools:$PYCAFFE_ROOT:$PATH

RUN echo "$CAFFE_ROOT/build/lib" >> /etc/ld.so.conf.d/caffe.conf && ldconfig

# Install Tensorflow
RUN pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl

# Install Keras
RUN pip install git+https://github.com/fchollet/keras.git

# Install Fabrik dependencies
COPY /requirements /code/requirements
RUN pip install -r requirements/common.txt

COPY . /code

EXPOSE 8000
CMD ["/bin/bash", "/code/docker/prod/container-start.sh"]
4 changes: 4 additions & 0 deletions docker/prod/container-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
cd /code && \
webpack
python manage.py runserver 0.0.0.0:8000

0 comments on commit 18f056a

Please sign in to comment.