Skip to content

Instantly share code, notes, and snippets.

@dayne
Last active July 27, 2020 13:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dayne/330c331ef2b5a69b318f5fb01c49b40a to your computer and use it in GitHub Desktop.
Save dayne/330c331ef2b5a69b318f5fb01c49b40a to your computer and use it in GitHub Desktop.
chef_omnibus_build

chef omnibus build script https://git.io/fpiRe

Chef omnibus build script to automate a build of chef for ARM. Primary goal to support rasbian_bootstrap.

curl -L https://git.io/fpiRv | sudo bash

The core details derived from Mattray's Chef14 ARM on the Beaglebone Black post.

This is a fully scripted build and install of chef for Raspbian (or any other deb).

  • installs build deps
  • sync time
  • create omnibus user
  • build omnibus-toolchain and install
  • build chef using omnibus-toolchain and install

After a run the .deb package can be found in:

  • /home/omnibus/omnibus_build/build/omnibus-toolchain/pkg
  • pwd/home/omnibus/omnibus_build/build/chef-14.8.10/omnibus/pkg

full build and install from scratch

curl -L https://git.io/fpiRv | sudo bash

or

git clone https://gist.githubusercontent.com/dayne/330c331ef2b5a69b318f5fb01c49b40a/ omnibus_build
cd omnibus_build
sudo ./build_and_install.sh

example of setting specific version of ruby or chef to build:

curl -L https://git.io/fpiRv | sudo RUBY_VER=2.5.3 CHEF_VER=14.8.10 bash

crazy?

Want to do this raspbian chef arm build on x86 inside a docker container?

I've tested the following and it works on my Ubuntu 18.06 box:

  • install docker
  • install install qemu-user: apt-get install qemu-user
  • launch a raspbian docker image:
    docker run -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static --rm -ti resin/rpi-raspbian
    curl -L https://git.io/fpiRv | sudo bash
    
#!/bin/bash
#
# A build script for creating chef via their omnibus build methods
#
#Optional - set version of ruby or chef
# RUBY_VER=2.5.3
# CHEF_VER=14.7.17
if [ "${RUBY_VER}" == "" ]; then
RUBY_VER=2.5.3
fi
if [ "${CHEF_VER}" == "" ]; then
CHEF_VER=14.8.10
fi
if [ "${USER}" != "root" ]; then
echo "fatal error: run this script as root"
exit 1
fi
#
# build dependancies and time sync
#
DEPS="curl wget git autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev fakeroot ntpdate"
dpkg -l $DEPS > /dev/null
if [ $? != 0 ]; then
apt-get update
apt-get install -y $DEPS
fi
ntpdate -u pool.ntp.org
#
# create omnibus user, clone the builder repo
#
if [ ! -d /home/omnibus/ ]; then
echo adding omnibus user
adduser --disabled-password --gecos "" omnibus
fi
if [ ! -d /var/cache/omnibus ]; then
mkdir /var/cache/omnibus && chown omnibus.omnibus /var/cache/omnibus
fi
if [ ! -d /opt/omnibus-toolchain ]; then
mkdir /opt/omnibus-toolchain && chown omnibus.omnibus /opt/omnibus-toolchain
fi
if [ ! -d /opt/chef ]; then
mkdir /opt/chef && chown omnibus.omnibus /opt/chef
fi
#
# get the omnibus_builder repo
#
if [ ! -d /home/omnibus/omnibus_build ]; then
cd /home/omnibus
sudo -u omnibus git clone https://gist.github.com/dayne/330c331ef2b5a69b318f5fb01c49b40a omnibus_build
if [ $? != 0 ]; then
echo "clone of omnibus_builder repo failed"
fi
else
cd /home/omnibus/omnibus_build
sudo -u omnibus git pull
fi
cd /home/omnibus/omnibus_build
#
# build omnibus-toolchain package if it isn't installed et
#
dpkg -s omnibus-toolchain > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "omnibus-toolchain already installed .. skipping build & install"
else
sudo -u omnibus bash omnibus_build.sh
omni_deb=$(ls build/omnibus-toolchain/pkg/omnibus-toolchain*.deb 2> /dev/null | tail -n 1)
if [ -f "${omni_deb}" ]; then
dpkg -i $omni_deb
else
echo "failed to get an omni_deb from omnibus-toolchain install: $omni_deb"
exit 1
fi
fi
#
# build chef
#
chef_deb=$(ls build/chef-${CHEF_VER}/omnibus/pkg/chef*.deb 2> /dev/null | tail -n 1)
if [ ! -f "${chef_deb}" ]; then
sudo -u omnibus bash chef_build.sh
chef_deb=$(ls build/chef-${CHEF_VER}/omnibus/pkg/chef*.deb 2> /dev/null | tail -n 1)
else
echo "using found prebuilt chef_deb: $chef_deb"
fi
echo "chef_deb built: $chef_deb"
#
# install chef if it isn't already
#
if [ -f $chef_deb ]; then
dpkg -s chef > /dev/null 2>&1
if [ $? != 0 ]; then
echo "installing chef_deb: $chef_deb"
dpkg -i $chef_deb
else
echo "chef already installed, skipping install"
fi
else
echo "Fatal sadness - no chef deb found or built"
exit 1
fi
#!/bin/bash
#
# builds chef using omnibus-toolchain
#
# https://github.com/chef/chef/releases/
if [ "${CHEF_VER}" == "" ]; then
CHEF_VER=14.8.10
fi
cd $(dirname "${0}")
# get valid ruby environment
. ruby_build.sh
# Ensure we've got omnibus-toolchain in path
export PATH="/opt/omnibus-toolchain/bin:$PATH"
# Ensure we've got a build dir
test -d build || mkdir build
cd build
# download and extract CHEF_VER if it isn't already here
if [ ! -d chef-${CHEF_VER} ]; then
test -d v{$CHEF_VER}.tar.gz || \
wget https://github.com/chef/chef/archive/v${CHEF_VER}.tar.gz \
&& tar xvfz v${CHEF_VER}.tar.gz
if [ $? -eq 1 ]; then
echo "download and extract failed of v${CHEF_VER}.tar.gz"
exit 1
fi
fi
# bug in omnibus-toolchain tar: https://github.com/chef/omnibus-toolchain/issues/73
test -f /opt/omnibus-toolchain/bin/tar && rm /opt/omnibus-toolchain/bin/tar
cd chef-${CHEF_VER}/omnibus \
&& bundle install --without development \
&& bundle exec omnibus build chef -l debug
ls -l pkg/*.deb
rbenv rehash
#!/bin/basheval "$(rbenv init -)"
#
#
#
# omnibus-toolchain build
#
cd "$(dirname "$0")"
. ruby_build.sh
test -d build || mkdir build
cd build
if [ ! -d omnibus-toolchain ]; then
git clone https://github.com/chef/omnibus-toolchain.git
if [ ! $? -eq 0 ]; then
echo "fatal: clone of omnibus-toolchain failed"
exit 1
fi
fi
cd omnibus-toolchain
omni_deb=$(ls pkg/omnibus-toolchain*.deb 2> /dev/null | tail -n 1)
if [ -f "${omni_deb}" ]; then
echo "omnibus-toolchain already built. force a new build by:"
echo " $ rm `pwd`/pkg/* "
else
bundle install --without development
bundle exec omnibus build omnibus-toolchain
rbenv rehash
omni_deb=$(ls pkg/omnibus-toolchain*.deb 2> /dev/null | tail -n 1)
fi
echo "package available: `pwd`/${omni_deb}"
#!/bin/bash
#
# installs rbenv if not already available
# installs ruby
# ensures environment setup for that ruby
# source ruby_build.sh
#
if [ "${RUBY_VER}" == "" ]; then
RUBY_VER=2.5.3
fi
#
# rbenv install and setup
#
export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
if [ ! -d $HOME/.rbenv/bin ]; then
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
fi
if [ $? != 0 ]; then
echo "something went wrong with install of rbenv"
exit 1
fi
hash -r
eval "$(rbenv init -)"
ruby --version 2> /dev/null | grep ${RUBY_VER} > /dev/null 2>&1
if [ $? != 0 ]; then
rbenv install $RUBY_VER
rbenv global $RUBY_VER
fi
gem list -i bundler
if [ $? != 0 ]; then
gem install bundler
fi
rbenv rehash
echo "### RUBY READY: $(ruby --version)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment