Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions ciscripts/image-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#!/bin/bash
#
#
set -e
set -o pipefail
set -u

# required shell params

: "${IMAGE_ID:?"should not be empty"}"
: "${YUM_HOST:?"should not be empty"}"

cd ${BASH_SOURCE[0]%/*}/wakame-vdc

# wait for the instance to be running
. ${BASH_SOURCE[0]%/*}/retry.sh

# vifs
network_id="nw-demo1"
security_group_id="sg-cicddemo"
vifs="vifs.json"

# instance-specific parameter
cpu_cores="1"
hypervisor="kvm"
memory_size="512"
image_id="${IMAGE_ID}"
ssh_key_id="ssh-cicddemo"

# create an musselrc
cat <<EOS > ~/.musselrc
DCMGR_HOST=10.0.2.2
account_id=a-shpoolxx
EOS

# create an vifs
cat <<EOS > "${vifs}"
{
"eth0":{"network":"${network_id}","security_groups":"${security_group_id}"}
}
EOS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これも、スクリプトの中に入れましょう。

## create database image

# db display name
display_name="db"

# create an instance
instance_id="$(
mussel instance create \
--cpu-cores "${cpu_cores}" \
--hypervisor "${hypervisor}" \
--image-id "${image_id}" \
--memory-size "${memory_size}" \
--ssh-key-id "${ssh_key_id}" \
--vifs "${vifs}" \
--display-name "${display_name}" \
| egrep ^:id: | awk '{print $2}'
)"
: "${instance_id:?"should not be empty"}"
echo "${instance_id} is initializing..."

trap 'mussel instance destroy "${instance_id}"' ERR

# wait for the instance to be running
retry_until [[ '"$(mussel instance show "${instance_id}" | egrep -w "^:state: running")"' ]]
echo "${instance_id} is running"

# get instance ipaddr
ipaddr="$(
mussel instance show "${instance_id}" \
| egrep :address: \
| awk '{print $2}' \
| tr '\n' ','
)"
: "${ipaddr:?"should not be empty"}"
ipaddr="${ipaddr%%,}"
echo "${instance_id} ipaddr: ${ipaddr}"

# wait for ssh to be ready
${BASH_SOURCE[0]%/*}/instance-wait4ssh.sh "${instance_id}"

# install package
${BASH_SOURCE[0]%/*}/instance-exec.sh "${instance_id}" < ${BASH_SOURCE[0]%/*}/provision-imgdb.sh

# instance state: running -> halted
mussel instance poweroff --force false ${instance_id}
echo "${instance_id} is halting"

# wait for the instance to be halted
retry_until [[ '"$(mussel instance show "${instance_id}" | egrep -w "^:state: halted")"' ]]
echo "${instance_id} is halted"

# instance backup
DB_IMAGE_ID="$(mussel instance backup ${instance_id} --display-name db | egrep ^:image_id: | awk '{print $2}')"
echo "database image id: ${DB_IMAGE_ID}"

# wait for the image to be available
retry_until [[ '"$(mussel image show "${DB_IMAGE_ID}" | egrep -w "^:state: available")"' ]]
echo "${DB_IMAGE_ID} is available"

# instance destroy
mussel instance destroy "${instance_id}"
echo "${instance_id} is deleted"

## create app image

# app display name
display_name="app"

# create an instance
instance_id="$(
mussel instance create \
--cpu-cores "${cpu_cores}" \
--hypervisor "${hypervisor}" \
--image-id "${image_id}" \
--memory-size "${memory_size}" \
--ssh-key-id "${ssh_key_id}" \
--vifs "${vifs}" \
--display-name "${display_name}" \
| egrep ^:id: | awk '{print $2}'
)"
: "${instance_id:?"should not be empty"}"
echo "${instance_id} is initializing..."

trap 'mussel instance destroy "${instance_id}"' ERR

# wait for the instance to be running
retry_until [[ '"$(mussel instance show "${instance_id}" | egrep -w "^:state: running")"' ]]
echo "${instance_id} is running"

# get instance ipaddr
ipaddr="$(
mussel instance show "${instance_id}" \
| egrep :address: \
| awk '{print $2}' \
| tr '\n' ','
)"
: "${ipaddr:?"should not be empty"}"
ipaddr="${ipaddr%%,}"
echo "${instance_id} ipaddr: ${ipaddr}"

# wait for ssh to be ready
${BASH_SOURCE[0]%/*}/instance-wait4ssh.sh "${instance_id}"

# install package
${BASH_SOURCE[0]%/*}/instance-exec.sh "${instance_id}" \
YUM_HOST="${YUM_HOST}" \
bash -l < ${BASH_SOURCE[0]%/*}/provision-imgapp.sh

# instance state: running -> halted
mussel instance poweroff --force false ${instance_id}
echo "${instance_id} is halting"

# wait for the instance to be halted
retry_until [[ '"$(mussel instance show "${instance_id}" | egrep -w "^:state: halted")"' ]]
echo "${instance_id} is halted"

# instance backup
APP_IMAGE_ID="$(mussel instance backup ${instance_id} --display-name app | egrep ^:image_id: | awk '{print $2}')"
echo "app image id: ${APP_IMAGE_ID}"

# wait for the image to be available
RETRY_WAIT_SEC=180 retry_until [[ '"$(mussel image show "${APP_IMAGE_ID}" | egrep -w "^:state: available")"' ]]
echo "${DB_IMAGE_ID} is available"

# instance destroy
mussel instance destroy "${instance_id}"
echo "${instance_id} is deleted"

echo DB_IMAGE_ID="${DB_IMAGE_ID}"
echo APP_IMAGE_ID="${APP_IMAGE_ID}"
48 changes: 0 additions & 48 deletions ciscripts/wakame-vdc/provision-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,8 @@ set -x

# required shell params

: "${YUM_HOST:?"should not be empty"}"
: "${DB_HOST:?"should not be empty"}"

# install tiny-web-example.repo
cat <<-EOS > /etc/yum.repos.d/tiny-web-example.repo
[tin-web-example]
name=tiny-web-example
baseurl=http://${YUM_HOST}/pub/
enabled=1
gpgcheck=0
EOS

# show available repo list
yum repolist

# install tiny-web-example.rpm
yum install -y tiny-web-example

## /etc/default/tiny-web-example-webapi
cat <<-'EOS' > /etc/default/tiny-web-example-webapi
# tiny-web-example
EXAMPLE_ROOT=/opt/axsh/tiny-web-example
PATH=/root/.rbenv/shims:$PATH

# Commnet out to run the vdc init script.
#RUN=yes

## rack params
RACK_ENV=development
BIND_ADDR=0.0.0.0
PORT=8080
UNICORN_CONF=/etc/tiny-web-example/unicorn-common.conf
EOS

## /etc/default/tiny-web-example-webapp
cat <<-'EOS' > /etc/default/tiny-web-example-webapp
# tiny-web-example
EXAMPLE_ROOT=/opt/axsh/tiny-web-example
PATH=/root/.rbenv/shims:$PATH

# Commnet out to run the vdc init script.
#RUN=yes

## rack params
RACK_ENV=development
BIND_ADDR=0.0.0.0
PORT=80
UNICORN_CONF=/etc/tiny-web-example/unicorn-common.conf
EOS

# configure db host
for config in /etc/tiny-web-example/webapi.conf /etc/tiny-web-example/webapp.yml; do
sed -i "s,localhost,${DB_HOST}," "${config}"
Expand Down
99 changes: 99 additions & 0 deletions ciscripts/wakame-vdc/provision-imgapp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash
#
# requires:
# bash
#
set -e
set -o pipefail
set -u
set -x

# required shell params
: "${YUM_HOST:?"should not be empty"}"

# git
yum install -y git

# epel
rpm -qa epel-release* | egrep -q epel-release || {
rpm -Uvh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/epel-release-6-8.noarch.rpm
sed -i \
-e 's,^#baseurl,baseurl,' \
-e 's,^mirrorlist=,#mirrorlist=,' \
-e 's,http://download.fedoraproject.org/pub/epel/,http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/,' \
/etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo
yum install -y ca-certificates
}
yum repolist

# install rbenv
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
# setup rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
exec $SHELL -l

# install build require for ruby-build
yum install -y gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel

# install ruby-build
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

# install ruby
ruby_version="2.0.0-p598"

rbenv install -v "${ruby_version}"
rbenv rehash
rbenv versions
rbenv global "${ruby_version}"
ruby -v

# install bundler
gem install bundler --no-ri --no-rdoc

# install tiny-web-example.repo
cat <<-EOS > /etc/yum.repos.d/tiny-web-example.repo
[tin-web-example]
name=tiny-web-example
baseurl=http://${YUM_HOST}/pub/
enabled=1
gpgcheck=0
EOS

# show available repo list
yum repolist

# install tiny-web-example.rpm
yum install -y tiny-web-example

## /etc/default/tiny-web-example-webapi
cat <<-'EOS' > /etc/default/tiny-web-example-webapi
# tiny-web-example
EXAMPLE_ROOT=/opt/axsh/tiny-web-example
PATH=/root/.rbenv/shims:$PATH

# Commnet out to run the vdc init script.
#RUN=yes

## rack params
RACK_ENV=development
BIND_ADDR=0.0.0.0
PORT=8080
UNICORN_CONF=/etc/tiny-web-example/unicorn-common.conf
EOS

## /etc/default/tiny-web-example-webapp
cat <<-'EOS' > /etc/default/tiny-web-example-webapp
# tiny-web-example
EXAMPLE_ROOT=/opt/axsh/tiny-web-example
PATH=/root/.rbenv/shims:$PATH

# Commnet out to run the vdc init script.
#RUN=yes

## rack params
RACK_ENV=development
BIND_ADDR=0.0.0.0
PORT=80
UNICORN_CONF=/etc/tiny-web-example/unicorn-common.conf
EOS