Skip to content

Instantly share code, notes, and snippets.

@floudet
Created September 1, 2017 13:25
Show Gist options
  • Save floudet/6ca21ca2ca89b116c11e24626b3e8fb1 to your computer and use it in GitHub Desktop.
Save floudet/6ca21ca2ca89b116c11e24626b3e8fb1 to your computer and use it in GitHub Desktop.
Installs kitchen with the docker provider on Debian
#!/bin/bash
#
# This script installs kitchen with the docker provider
# Using the docker provider allows to run this in a VM or an EC2 instance, which is not possible with Vagrant.
#
# Only tested on Debian GNU/Linux 8.8 (jessie)
#
# Resources:
# https://github.com/test-kitchen/test-kitchen
# https://github.com/test-kitchen/kitchen-docker
#
# Dependencies: curl
# Modifiable Vars
OMNITRUCK_SCRIPT_URL="https://omnitruck.chef.io/install.sh"
CHEFDK_VERSION="1.5.0"
DEBIAN_VERSION_NAME=`dpkg --status tzdata|grep Provides|cut -f2 -d'-'`
DOCKER_KEY_SERVER_URL="p80.pool.sks-keyservers.net"
DOCKER_KEY="58118E89F3A912897C070ADBF76221572C52609D"
# Check whether a command exists
exists() {
if command -v $1 >/dev/null 2>&1
then
return 0
else
return 1
fi
}
# check if the script is run by root
if [[ $EUID -ne 0 ]]; then
echo "Error: This script must be run as root" 1>&2
exit 1
fi
# create tmp directory
if test "x$TMPDIR" = "x"; then
TMP="/tmp"
else
TMP=$TMPDIR
fi
TMP_DIR="$TMP/kitchen-docker-install.sh.$$"
(umask 077 && mkdir $TMP_DIR) || exit 1
# Check if curl is installed
if ! exists curl; then
echo "Error: curl is required. Please make sure it is installed and in your PATH before running this script"
exit 1
fi
# Is ChefDK already installed?
if [ -d /opt/chefdk ]; then
echo "Error: '/opt/chefdk' already exists, cowardly refusing to go further" 1>&2
exit 1
fi
# Download and run the Omnitruck Install Script to install ChefDK
curl --retry 5 -sL "$OMNITRUCK_SCRIPT_URL" | bash -s -- -P chefdk -v $CHEFDK_VERSION
if test $? -ne 0; then
echo "Error: Omnitruck Install failed"
exit 1
fi
# Install and start docker-engine
apt-get install apt-transport-https ca-certificates -y
echo "deb https://apt.dockerproject.org/repo debian-$DEBIAN_VERSION_NAME main" > /etc/apt/sources.list.d/docker.list
apt-key adv --keyserver hkp://$DOCKER_KEY_SERVER_URL:80 --recv-keys $DOCKER_KEY
apt-get update
apt-get install docker-engine -y
service docker start
# Test docker install
docker run hello-world
if test $? -ne 0; then
echo "Error: docker-engine install failed"
exit 1
fi
# Install the docker driver for the user who launched the present script
su - $(logname) -c 'eval "$(chef shell-init bash)" && gem install kitchen-docker'
echo "Installation completed!"
# remove tmp directory
if test "x$TMP_DIR" != "x"; then
rm -r "$TMP_DIR"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment