Skip to content

Instantly share code, notes, and snippets.

@briancline
Last active January 1, 2016 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briancline/8119051 to your computer and use it in GitHub Desktop.
Save briancline/8119051 to your computer and use it in GitHub Desktop.
Updated set of steps to take within a Docker container to run a Swift All-in-One (SAIO) dev/test install (to be turned into an improved Dockerfile)
#!/usr/bin/env bash
## Known awesomeness:
## - Passes all unit tests
## - Passes all functional tests (skips the last 20 though)
## - Passes all probe tests
##
## Known issues:
## - Certain package upgrades cause issues, mostly around upstart not working in
## Ubuntu containers; as a result, initctl and ischroot are linked to /bin/true
##
## Known prep steps:
## - Use 'ubuntu' or 'stackbrew/ubuntu:precise' Docker images
## - Have a directory on an XFS mount in your host system mounted in your Docker
## container under /swift, via 'docker run -v=/host/path/to/data:/swift ...'
## - Pass host port 8080 to container, via 'docker run -p=8080:8080 ...'
## - Pass host port 10022 to container port 22, via 'docker run -p=10022:22 ...'
## - Want to use a local repo mirror? Set a APT_MIRROR env var thusly:
## 'docker run -e APT_MIRROR=10.0.0.8 ...'
## - Want a specific Swift tag/branch? Set a SWIFT_TAG env var thusly:
## 'docker run -e SWIFT_TAG=1.11.0 ...'
##
## Example Docker invocation:
## docker run -name=swift-saio-04 \
## -p=10022:22 \
## -p=8080:8080 \
## -h=swift-saio-04 \
## -v=/mnt/media/lxc/swift-saio-04:/swift \
## -e=APT_MIRROR=10.0.0.8 \
## -e=SWIFT_TAG=1.11.0 \
## -t -i \
## ubuntu /bin/bash
##
## Based on the excellent initial Swift Dockerfile updates at
## https://github.com/ualbertalib/docker-swift, thanks and/or "big ups" to:
## - Peter Binkley (University of Alberta Libraries)
## - Chuck Thier (Rackspace)
SWIFT_TAG=${SWIFT_TAG:-master}
GITHUB_REPO=${GITHUB_REPO:-briancline/docker-swift}
fetch_github () {
echo $2 >&2
curl -so ${2} https://raw.github.com/${GITHUB_REPO}/master/${1}
}
## Docker has issues with upstart: https://github.com/dotcloud/docker/issues/1024
## This is a problem during init-scripts package upgrades and a few others
dpkg-divert --local --rename --add /sbin/initctl
dpkg-divert --local --rename --add /usr/bin/ischroot
ln -fs /bin/true /sbin/initctl
ln -fs /bin/true /usr/bin/ischroot
## Necessary to pick up sysklogd... rsyslog needs upstart. *sigh*
echo 'deb http://archive.ubuntu.com/ubuntu precise universe' >> /etc/apt/sources.list
## Use local package repo for great good, requires 'docker run -e APT_MIRROR=10.0.0.8'
[ -n "$APT_MIRROR" ] && \
sed -i -e "s|archive.ubuntu.com|${APT_MIRROR}|g" /etc/apt/sources.list
export DEBIAN_FRONTEND=noninteractive
apt-get -q -y update
apt-get -q -y upgrade
apt-get -q -y install \
locales sudo xfsprogs attr openssh-server openssh-client \
man vim curl psmisc
apt-get -q -y install \
sysklogd rsync git-core memcached sqlite3 gcc libffi-dev \
python-{setuptools,simplejson,xattr,eventlet,greenlet,pastedeploy,netifaces,pip,dnspython} \
python-{coverage,dev,nose,mock}
## Set up and enable rsync daemon
fetch_github misc/rsyncd.conf /etc/rsyncd.conf
sed -i 's|\(RSYNC_ENABLE\)=false|\1=true|' /etc/default/rsync
## Set up syslog log files corresponding to Swift syslog facilities
cat >>/etc/syslog.conf <<EOF
#
# Swift logging
#
local1,local2,local3,local4,local5.* -/var/log/swift/all.log
local1.*;local1.!notice -/var/log/swift/proxy.log
local1.notice -/var/log/swift/proxy.error
local1.* ~
local2.*;local2.!notice -/var/log/swift/storage1.log
local2.notice -/var/log/swift/storage1.error
local2.* ~
local3.*;local3.!notice -/var/log/swift/storage2.log
local3.notice -/var/log/swift/storage2.error
local3.* ~
local4.*;local4.!notice -/var/log/swift/storage3.log
local4.notice -/var/log/swift/storage3.error
local4.* ~
local5.*;local5.!notice -/var/log/swift/storage4.log
local5.notice -/var/log/swift/storage4.error
local5.* ~
EOF
## Set up supervisor to keep SSHD running
easy_install supervisor
fetch_github misc/supervisord.conf /etc/supervisord.conf
mkdir /var/log/supervisor
mkdir /var/run/sshd
## Clone Swift and Swift client source
mkdir -p /swift/src
pushd /swift/src
git clone https://github.com/openstack/python-swiftclient.git
git clone https://github.com/openstack/swift.git
popd
pushd /swift/src/python-swiftclient
python setup.py install
popd
pushd /swift/src/swift
git checkout ${SWIFT_TAG}
python setup.py install
popd
## Main requirements should already be satisfied by packages (this is LTS after all),
## but we will need test requirements too
pip install -r /swift/src/swift/requirements.txt
pip install -r /swift/src/swift/test-requirements.txt
mkdir -p /var/log/swift
mkdir -p /var/run/swift
mkdir -p /var/cache/swift
mkdir -p /etc/swift
## Configure Swift
cp /swift/src/swift/test/sample.conf /etc/swift/test.conf
fetch_github swift/proxy-server.conf /etc/swift/proxy-server.conf
fetch_github swift/swift.conf /etc/swift/swift.conf
mkdir -p /etc/swift/{account,container,object}-server
for ii in $(seq 1 4); do
for svr in account container object; do
fetch_github swift/${svr}-server/${ii}.conf /etc/swift/${svr}-server/${ii}.conf
done
## Set up SAIO node storage and /srv links
mkdir -p /swift/nodes/${ii}/node/sdb${ii}
ln -fs /swift/nodes/${ii} /srv/${ii}
mkdir -p /var/run/swift${ii}
mkdir -p /var/cache/swift${ii}
done
## Set up Swift user
useradd -m -d /swift -U swift -s /bin/bash
usermod -a -G sudo swift
echo swift:swift | chpasswd
sed -i -e 's|^\(%sudo\s.*\) ALL$|\1 NOPASSWD: ALL|' /etc/sudoers
[ ! -f /swift/.bashrc ] && cp /etc/skel/.[^.]* /swift/
echo 'export SWIFT_TEST_CONFIG_FILE=/etc/swift/test.conf' >> /swift/.bashrc
echo 'export PATH=$PATH:~/bin' >> /swift/.bashrc
mkdir -p /swift/bin
fetch_github bin/launch.sh /swift/bin/launch.sh
fetch_github bin/remakerings /swift/bin/remakerings
fetch_github bin/resetswift /swift/bin/resetswift
fetch_github bin/startmain /swift/bin/startmain
fetch_github bin/startrest /swift/bin/startrest
chmod +x /swift/bin/*
## Override upstream resetswift file (sorry for the heredoc vomit)
cat >/swift/bin/resetswift <<EOF
#!/bin/bash
swift-init all stop
find /var/log/swift -type f -exec rm -f {} \;
for ii in \$(seq 1 4); do
rm -rf /swift/nodes/\${ii}
mkdir -p /swift/nodes/\${ii}/node/sdb\${ii}
ln -fs /swift/nodes/\${ii} /srv/\${ii}
done
sudo rm -f /var/log/debug /var/log/messages /var/log/rsyncd.log /var/log/syslog
sudo rm -f /var/log/swift/*
find /var/cache/swift* -type f -name '*.recon' -exec rm -f {} \;
sudo service sysklogd restart
sudo service rsync restart
sudo service memcached restart
EOF
## Give swift access to everything it needs
chown -R swift.swift /swift /etc/swift /srv /var/run/swift* /var/cache/swift*
## Jane, start this crazy thing!
/etc/init.d/sysklogd restart || /etc/init.d/sysklogd start
service rsync start
service memcached start
sudo -u swift /swift/bin/remakerings
sudo -u swift /swift/bin/startmain
sudo -u swift /swift/bin/startrest
## Starts up sshd; -n must remain present here for the container to
## stick around if you started with 'docker run -i -t'
/usr/local/bin/supervisord -n -c /etc/supervisord.conf
## Run the tests
#ln -fs /swift/bin/resetswift /usr/local/bin/resetswift
#sudo -u swift /swift/src/swift/.unittests
#sudo -u swift /swift/src/swift/.functests
#sudo -u swift /swift/src/swift/.probetests
###############################################################################
## Fun things to do from the comfort of your host
## SSH in from host (password, as set above, is swift)
# ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 10022 swift@localhost
## Try an auth test
# curl -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://localhost:8080/auth/v1.0 -v
# SWIFT_TOKEN=$(curl -si -H 'X-Storage-User: test:tester' -H 'X-Storage-Pass: testing' http://localhost:8080/auth/v1.0 | awk '/Auth-Token/ {print $2}')
# curl -H "X-Auth-Token: ${SWIFT_TOKEN}" http://localhost:8080/v1/AUTH_test -I
## Or use the Swift client
# swift -A http://localhost:8080/auth/v1.0 -U test:tester -K testing stat
#
# export ST_AUTH=http://localhost:8080/auth/v1.0
# export ST_USER=test:tester
# export ST_KEY=testing
#
# swift stat
# swift post mycontainer
# swift list -l --lh
#
# find /etc/swift -type f -exec swift upload mycontainer {} \;
# pushd /swift/src/; find swift/doc/ -type f -exec swift upload mycontainer {} \; ; popd
# swift list -l --lh
# swift delete mycontainer
# swift stat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment