Skip to content

Commit

Permalink
Adding the three pipleine projects for Dev, test and Prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapil Arora authored and Kapil Arora committed Dec 27, 2015
1 parent 17880f7 commit 898bb0f
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 0 deletions.
Empty file added ruby-mysql-web-prod/README.md
Empty file.
3 changes: 3 additions & 0 deletions ruby-mysql-web-prod/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash
docker-compose stop
yes | docker-compose rm
4 changes: 4 additions & 0 deletions ruby-mysql-web-prod/database.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HOST=192.168.53.24
VOLUME=mysql_data_prod
MOUNT_AT=/mnt/mysql_data_prod
PASSWORD=netapp01
22 changes: 22 additions & 0 deletions ruby-mysql-web-prod/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /bin/bash

PORT=9494

echo "Staring application with docker compose"
docker-compose build
docker-compose up -d
echo "Sleeping for 20 seconds for web service and sc agent to start"
sleep 20s
echo "calling the webservice to see if it is active and returns http code 200"
#curl -s --head --request GET http://localhost:9292/locandtweet/netapp | grep "200 OK" > /dev/null
httpCode=`curl -sL -w "%{http_code}\\n" "http://10.65.57.126:$PORT/table/employees" -o /dev/null`
echo "Http code returned: $httpCode"
if [ $httpCode == 200 ]
then
echo "deployment success"
exit 0
else
echo "deployment failed"
exit 1
fi

14 changes: 14 additions & 0 deletions ruby-mysql-web-prod/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ruby_web_prod:
image: 10.65.57.126:5000/ruby-mysql-web:0.0.1-SNAPSHOT
ports:
- "9494:9494"
links:
- mysql_db_prod:mysql_host
mysql_db_prod:
build: mysql-image
volumes:
- /mnt/mysql_data_prod:/var/lib/mysql
- /software/snapcreator/scAgent4.1.2:/etc/netapp/snapcreator/scAgent4.1.2
environment:
MYSQL_ROOT_PASSWORD: netapp01
SCAGENT_HOME: /etc/netapp/snapcreator/scAgent4.1.2
10 changes: 10 additions & 0 deletions ruby-mysql-web-prod/loadInitialDB.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash
source database.config
MYSQL_HOST=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' rubymysqlwebprod_mysql_db_prod_1`
git clone https://github.com/datacharmer/test_db.git
cd test_db
mysql -h $MYSQL_HOST --user=root --password=$PASSWORD < employees.sql
cd ..
rm -rf test_db


16 changes: 16 additions & 0 deletions ruby-mysql-web-prod/mountProdData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
echo "Reading config...."
source database.config
echo "HOST: $HOST"
echo "VOLUME: $VOLUME"
echo "MOUNT_AT: $MOUNT_AT"
echo "creating $MOUNT_AT dir if not exist already"
mkdir -p $MOUNT_AT
echo "trying Umount volume"
umount $MOUNT_AT
echo "Mounting volume $HOST:/$VOLUME at location $MOUNT_AT"
mount -t nfs $HOST:/$VOLUME $MOUNT_AT
6 changes: 6 additions & 0 deletions ruby-mysql-web-prod/mysql-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mysql:latest
RUN apt-get update
RUN apt-get install -y openjdk-7-jre-headless
COPY new-entry-point.sh /new-entry-point.sh
ENTRYPOINT ["/new-entry-point.sh"]
CMD ["mysqld"]
5 changes: 5 additions & 0 deletions ruby-mysql-web-prod/mysql-image/new-entry-point.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/bash
echo "running sc agent "
/etc/netapp/snapcreator/scAgent4.1.2/bin/scAgent start
echo "running old entrypoint with args"
/entrypoint.sh "$@"
Empty file added ruby-mysql-web-test/README.md
Empty file.
3 changes: 3 additions & 0 deletions ruby-mysql-web-test/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash
docker-compose stop
yes | docker-compose rm
4 changes: 4 additions & 0 deletions ruby-mysql-web-test/database.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HOST=192.168.53.24
VOLUME=mysql_data_test
MOUNT_AT=/mnt/mysql_data_test
PASSWORD=netapp01
14 changes: 14 additions & 0 deletions ruby-mysql-web-test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ruby_web:
image: 10.65.57.126:5000/ruby-mysql-web:0.0.1-SNAPSHOT
environment:
PORT: 9393
ports:
- "9393:9393"
links:
- mysql_db:mysql_host
mysql_db:
image: mysql:latest
volumes:
- /mnt/mysql_data_test:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: netapp01
24 changes: 24 additions & 0 deletions ruby-mysql-web-test/executeAppAndTestWebService.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /bin/bash

DOCKER_REPO=10.65.57.126:5000/ruby-twitter-api
TAG=0.0.1-SNAPSHOT
CONTAINER_NAME=hello-world-app-test
TEST_PORT=9393

echo "Staring application with docker compose"
docker-compose up -d
echo "Sleeping for 10 seconds for web service to start"
sleep 10s
echo "calling the webservice to see if it is active and returns http code 200"
#curl -s --head --request GET http://localhost:9292/locandtweet/netapp | grep "200 OK" > /dev/null
httpCode=`curl -sL -w "%{http_code}\\n" "http://10.65.57.126:$TEST_PORT/table/employees" -o /dev/null`
echo "Http code returned: $httpCode"
if [ $httpCode == 200 ]
then
echo "test passed!"
exit 0
else
echo "test failed"
exit 1
fi

16 changes: 16 additions & 0 deletions ruby-mysql-web-test/mountTestData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
echo "Reading config...."
source database.config
echo "HOST: $HOST"
echo "VOLUME: $VOLUME"
echo "MOUNT_AT: $MOUNT_AT"
echo "creating $MOUNT_AT dir if not exist already"
mkdir -p $MOUNT_AT
echo "trying Umount volume"
umount $MOUNT_AT
echo "Mounting volume $HOST:/$VOLUME at location $MOUNT_AT"
mount -t nfs $HOST:/$VOLUME $MOUNT_AT
13 changes: 13 additions & 0 deletions ruby-mysql-web-test/umountTestData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi


echo "Reading config...."
source database.config
echo "VOLUME: $VOLUME"
echo "MOUNT_AT: $MOUNT_AT"
echo "Umount volume"
umount $MOUNT_AT
17 changes: 17 additions & 0 deletions ruby-mysql-web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y ruby
RUN apt-get install -y ruby-dev
RUN apt-get install -y rubygems-integration
RUN apt-get install -y libmysqlclient-dev
RUN gem install bundler
COPY src/* /etc/app/
RUN gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
RUN \curl -sSL https://get.rvm.io | bash -s stable
RUN /usr/local/rvm/bin/rvm requirements
RUN cd /etc/app && bundle install
ENV PORT 9494
WORKDIR /etc/app
#CMD ["bundle", "exec", "rackup", "-p", "$PORT", "-o", "0.0.0.0", "config.ru"]
CMD bundle exec rackup -p "$PORT" -o 0.0.0.0 config.ru
Empty file added ruby-mysql-web/README.md
Empty file.
7 changes: 7 additions & 0 deletions ruby-mysql-web/buildAndPushDockerImage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#! /bin/bash

DOCKER_REPO=10.65.57.126:5000/ruby-mysql-web
TAG=0.0.1-SNAPSHOT

docker build -t $DOCKER_REPO:$TAG .
docker push $DOCKER_REPO:$TAG
6 changes: 6 additions & 0 deletions ruby-mysql-web/src/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'
gem 'rack'
gem 'sinatra'
gem "sinatra-cross_origin"
gem 'json'
gem 'mysql2json'
30 changes: 30 additions & 0 deletions ruby-mysql-web/src/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
GEM
remote: https://rubygems.org/
specs:
json (1.7.7)
mysql2 (0.3.20)
mysql2json (0.0.4)
json (~> 1.7.7)
mysql2 (~> 0.3.11)
rack (1.6.4)
rack-protection (1.5.3)
rack
sinatra (1.4.6)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (>= 1.3, < 3)
sinatra-cross_origin (0.3.2)
tilt (2.0.1)

PLATFORMS
ruby

DEPENDENCIES
json
mysql2json
rack
sinatra
sinatra-cross_origin

BUNDLED WITH
1.11.2
33 changes: 33 additions & 0 deletions ruby-mysql-web/src/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'sinatra'
require 'sinatra/cross_origin'
require 'json'
require 'mysql2'
require 'mysql2json'

configure do
enable :cross_origin
end

OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE

helpers do
def getTable(table_name)
client = Mysql2::Client.new(:host => "mysql_host", :username => "root", :password => "netapp01", :database => 'employees')
begin
result = Mysql2json.query("SELECT * FROM #{table_name} limit 200", client)
rescue Exception=>e
puts "Error: #{e}"
return "Error: #{e}"
else
return result
end
end

end


get '/table/:name' do
content_type :json
getTable(params['name'])
end

8 changes: 8 additions & 0 deletions ruby-mysql-web/src/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rubygems'
require 'bundler'

Bundler.require

require './app.rb'

run Sinatra::Application

0 comments on commit 898bb0f

Please sign in to comment.