fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

319 lines
8.2 KiB

#!/bin/bash
set -eux
## 0k git remote path
GIT_0K_BASE=${GIT_0K_BASE:-"0k-ro:/var/git"}
## 0k git remote options
GIT_0K_CLONE_OPTIONS=${GIT_0K_CLONE_OPTIONS:-""}
##
## Install 0k-manage
##
mkdir -p /opt/apps
(
if [ -d "/opt/apps/0k-manage" ]; then
cd /opt/apps/0k-manage &&
git pull -r
else
cd /opt/apps &&
git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-manage.git" &&
cd /opt/apps/0k-manage &&
git checkout 0k/prod/master
fi
pip install sact.epoch || exit 1
if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "ImportError: No module named interface" ]; then
echo "Error: conflicting installation of zope.interface detected. Trying workaround."
(
cd /usr/local/lib/python2.7/dist-packages
mv zope zope-bad
) &&
pip install zope.interface --upgrade &&
pip install zope.component --upgrade
if [ "$(python -c 'import sact.epoch' 2>&1 | tail -n 1)" == "" ]; then
echo "Workaround worked."
else
echo "Failed work around."
exit 1
fi
fi
# ln -sf /opt/apps/0k-manage/src/bin/* /usr/local/bin/
)
##
## Install 0k-charm
##
(
if [ -d "/opt/apps/0k-charm" ]; then
cd /opt/apps/0k-charm &&
git checkout master &&
git pull -r
else
cd /opt/apps &&
git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charm.git"
fi
ln -sfn /opt/apps/0k-charm/bin/charm /usr/local/sbin/
)
apt-get install -y kal-shlib-charm </dev/null
##
## Install 0k-charms
##
(
if [ -d "/opt/apps/0k-charms" ]; then
cd /opt/apps/0k-charms &&
git checkout master &&
git pull -r
else
cd /opt/apps &&
git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-charms.git"
fi
if ! [ -d "/srv/charm-store" ]; then
mkdir -p /srv/charm-store
fi
ln -sfn /opt/apps/0k-charms /srv/charm-store/0k-charms
)
##
## Install lxc-scripts
##
(
if ! [ -d "/opt/apps/lxc-scripts" ]; then
cd /opt/apps &&
git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/lxc-scripts.git"
fi
cd /opt/apps/lxc-scripts &&
git checkout master &&
git pull -r &&
ln -sfn /opt/apps/lxc-scripts/bin/lxc-* /usr/local/sbin/ &&
if [ -f /etc/default/lxc ]; then
if [ -f /etc/default/lxc.pre-install ]; then
cp /etc/default/lxc.pre-install /etc/default/lxc
else
cp /etc/default/lxc /etc/default/lxc.pre-install
fi
[ -d /usr/lib/lxc/templates ] && {
ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/lib/lxc/templates/
echo TEMPLATE_PATH=/usr/lib/lxc/templates >> /etc/default/lxc
}
[ -d /usr/share/lxc/templates ] && {
ln -sfn /opt/apps/lxc-scripts/usr/lib/lxc/templates/lxc-0k-ubuntu-cloud /usr/share/lxc/templates
echo TEMPLATE_PATH=/usr/share/lxc/templates >> /etc/default/lxc
}
fi
)
##
## Install 0k-docker
##
(
if [ -d "/opt/apps/0k-docker" ]; then
cd /opt/apps/0k-docker &&
git checkout master &&
git pull -r
else
cd /opt/apps &&
git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-docker"
fi
ln -sfn /opt/apps/0k-docker/bin/* /usr/local/sbin/
## in update, will remove broken links to binaries that were removed
find -L /usr/local/sbin -maxdepth 1 -type l -delete
)
##
## Install 0k.io certificate authority
##
## Note that docker should be installed after (or be restarted).
apt-get install -y curl </dev/null
## This does not seem to work anymore (docker v1.12, ubutnu 14.04 on gani)
echo "Fetching 0k.io CA certificate..."
curl http://docker.0k.io/get/ca.0k.io.pem > /etc/ssl/ca.0k.io.pem
cat /etc/ssl/ca.0k.io.pem >> /etc/ssl/certs/ca-certificates.crt
## This is the new way: https://docs.docker.com/engine/security/certificates/
mkdir -p /etc/docker/certs.d/docker.0k.io
ln -sfn /etc/ssl/ca.0k.io.pem /etc/docker/certs.d/docker.0k.io/ca.crt
service docker restart
echo "Login into our server."
docker login -u vm -p iamavm https://docker.0k.io
sed -ri 's/^#(net\.ipv4\.ip_forward=1)$/\1/g' /etc/sysctl.conf
sysctl -w net.ipv4.ip_forward=1
##
## docker-compose
##
if type -p docker-compose >/dev/null; then
#echo "Found docker-compose..." >&2
if ! CURRENT_VERSION_TEXT="$(docker-compose --version 2>/dev/null)"; then
echo "'docker-compose' failed ! Please check your docker-compose binary."
echo "Failed install."
docker-compose --version
exit 1
fi
VALID_VERSION_TEXT="docker-compose version 1.21.2, build "
if ! [[ "$CURRENT_VERSION_TEXT" == "$VALID_VERSION_TEXT"* ]]; then
echo "Invalid version of docker-compose: we need exactly:"
echo "version text: $VALID_VERSION_TEXT"
echo "current version: $CURRENT_VERSION_TEXT"
echo "Failed install."
exit 1
fi
else
if ! [ -d /opt/apps/docker-compose ]; then
(
mkdir -p /opt/apps
cd /opt/apps
git clone https://github.com/docker/compose.git docker-compose &&
cd docker-compose &&
git checkout 0898c783ad2e0d01bd55b47fcb9eb7183edc1015 ## version pinning
)
fi
mkdir -p /opt/venv
if ! type -p virtualenv >/dev/null; then
pip install virtualenv==13.1.2
fi
if ! [ -d /opt/venv/docker-compose ]; then
virtualenv /opt/venv/docker-compose/
fi
set +eux
. /opt/venv/docker-compose/bin/activate
set -eux
## XXXvlab: docker version 3.5.0 is bugged on its requirement list:
## error: Setup script exited with error in docker setup command: 'tests_require' must be a string or list of strings containing valid project/version requirement specifiers; Expected ',' or end-of-list in pytest==2.9.1; python_version == '3.3' at ; python_version == '3.3'
pip install $(cat <<EOF
backports.ssl-match-hostname==3.5.0.1
cached-property==1.4.3
certifi==2018.4.16
chardet==3.0.4
docker==3.4.1
docker-compose==1.21.2
docker-pycreds==0.3.0
dockerpty==0.4.1
docopt==0.6.2
enum34==1.1.6
functools32==3.2.3.post2
idna==2.5
ipaddress==1.0.22
jsonschema==2.6.0
python-dateutil==2.7.3
pytz==2018.5
PyYAML==3.13
requests==2.17.3
sact.epoch==1.3.0
shyaml==0.5.2
six==1.11.0
texttable==0.9.1
urllib3==1.21.1
websocket-client==0.48.0
wheel==0.24.0
zope.component==4.4.1
zope.event==4.3.0
zope.interface==4.5.0
EOF
)
( cd /opt/apps/docker-compose &&
python setup.py install )
if ! pip freeze | grep "^requests==2.17.3\$" >/dev/null 2>&1; then
pip install requests==2.17.3 --upgrade
fi
deactivate
mkdir -p /etc/compose
if ! grep "^. /opt/venv/docker-compose/bin/activate$" /etc/compose/local.conf >/dev/null 2>&1; then
cat <<EOF >> /etc/compose/local.conf
. /opt/venv/docker-compose/bin/activate
EOF
fi
fi
if [ -d "/opt/apps/0k-compose" ]; then
cd "/opt/apps/0k-compose" &&
git pull -r
else
mkdir -p /opt/apps && cd /opt/apps
git clone "$GIT_0K_BASE"/0k/0k-compose.git
fi
[ -e /usr/local/bin/compose ] || ln -sfv /opt/apps/0k-compose/bin/compose /usr/local/bin/
rm -rf /var/cache/compose
cat <<EOF > /etc/default/datastore
DATASTORE=/srv/datastore
SNAPSHOT_BACKUP=/var/backups/snapshot
EOF
cat <<EOF > /etc/default/compose
## if not provided, this will be the default service launched.
export DEFAULT_SERVICES=""
export DEFAULT_PROJECT_NAME=$(hostname | cut -f 2 -d . )
export DOCKER_DATASTORE=\$([ -e /etc/default/datastore ] && . /etc/default/datastore && echo \$DATASTORE)
export DATASTORE=\$DOCKER_DATASTORE/data
export CONFIGSTORE=\$DOCKER_DATASTORE/config
EOF
if ! egrep "^DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml$" /etc/compose/local.conf >/dev/null 2>&1; then
echo "DEFAULT_COMPOSE_FILE=/etc/compose/compose.yml" >> /etc/compose/local.conf
fi
##
## Install pgm
##
(
if [ -d "/opt/apps/0k-pgm" ]; then
cd /opt/apps/0k-pgm &&
git pull -r
else
cd /opt/apps &&
git clone $GIT_0K_CLONE_OPTIONS "$GIT_0K_BASE/0k/0k-pgm.git" &&
cd /opt/apps/0k-pgm &&
git checkout master
fi
ln -sf /opt/apps/0k-pgm/bin/* /usr/local/bin/
apt-get install -y --force-yes pv buffer < /dev/null
apt-get install -y postgresql-client </dev/null
)