-
Notifications
You must be signed in to change notification settings - Fork 84
Fix ciscripts #13
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
Merged
Merged
Fix ciscripts #13
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| ## 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}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
これも、スクリプトの中に入れましょう。