Skip to content

Instantly share code, notes, and snippets.

@jandubois
Created October 9, 2018 18:24
Show Gist options
  • Save jandubois/ec399b123cb1271c86953444cd2e26fe to your computer and use it in GitHub Desktop.
Save jandubois/ec399b123cb1271c86953444cd2e26fe to your computer and use it in GitHub Desktop.
splatform/bosh-cli
#!/bin/bash
# This script is run to create a bosh release
# A wrapper is required to handle UID creation
# Usage:
# $0 <uid> <gid> <bosh cache directory> <bosh create-release args>
set -o errexit -o nounset
if test "$(id -u)" != 0 ; then
printf "%bERROR%b: wrong user %s; this should be run as root (in the container)\n" \
"\033[0;1;31m" "\033[0m" "$(id -u)" >&2
exit 1
fi
uid="${1}"
gid="${2}"
bosh_cache="${3}"
shift 3
env | grep -i proxy | sort | sed -e 's/^/PROXY SETUP: /'
# Add a user in the given group, so we can run `bosh create release` as that user.
# All this stuff is to make sure that the correct user (the one that ran
# `make releases` for HCF) will own the files created, instead of root.
if ! getent group "${gid}" >/dev/null ; then
addgroup --gid "${gid}" docker-group
fi
group=$(getent group "${gid}" | cut -d: -f1)
if ! getent passwd "${uid}" >/dev/null ; then
useradd --gid "${gid}" --create-home --uid "${uid}" docker-user
fi
user=$(getent passwd "${uid}" | cut -d: -f1)
home=$(getent passwd "${uid}" | cut -d: -f6)
mkdir "${home}/.bosh"
chown "${user}:${group}" "${home}/.bosh"
ln -s "${bosh_cache}" "${home}/.bosh/cache"
exec sudo -E "--user=${user}" "--group=${group}" --set-home -- \
bash --login -c "bosh $*"
FROM ubuntu:16.04
# Don't run mesg unless we have a tty; otherwise we'll get a warning from `docker run ... bash -l -c ...`
RUN perl -i -pe 's/mesg n/tty -s && mesg n/' /root/.profile
# Install packages for building ruby
RUN apt-get update
RUN apt-get install -y --force-yes \
build-essential curl git sudo zlib1g-dev libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt-dev unzip vim
RUN echo 'gem: --no-rdoc --no-ri' >> /.gemrc
ENV RUBY_VERSION=2.2.3
# Install chruby, since we need to manage multiple versions of Ruby as CF transitions
RUN mkdir /tmp/chruby && \
curl --silent --show-error --location https://github.com/postmodern/chruby/archive/v0.3.9.tar.gz | \
tar -xz --strip-components=1 -C /tmp/chruby && \
make -C /tmp/chruby install && \
rm -rf /tmp/chruby && \
echo 'if test -n "${BASH_VERSION}" -o -n "${ZSH_VERSION}" ; then' >> /etc/profile.d/chruby.sh && \
echo ' source /usr/local/share/chruby/chruby.sh' >> /etc/profile.d/chruby.sh && \
echo ' source /usr/local/share/chruby/auto.sh' >> /etc/profile.d/chruby.sh && \
echo ' if chruby | grep --quiet ${RUBY_VERSION:-2.2.3} ; then' >> /etc/profile.d/chruby.sh && \
echo ' chruby ruby-${RUBY_VERSION:-2.2.3}' >> /etc/profile.d/chruby.sh && \
echo ' fi' >> /etc/profile.d/chruby.sh && \
echo 'fi' >> /etc/profile.d/chruby.sh && \
true
ADD ./versions.txt /root/versions.txt
ADD bosh.sh /usr/local/bin/
ADD https://s3.amazonaws.com/bosh-cli-artifacts/bosh-cli-2.0.48-linux-amd64 /usr/local/bin/bosh
RUN chmod a+x /usr/local/bin/bosh.sh /usr/local/bin/bosh
# Install the ruby-install to manage ruby installation
RUN set -o errexit ; \
mkdir /tmp/ruby-install ; \
curl --silent --show-error --location https://github.com/postmodern/ruby-install/archive/v0.6.1.tar.gz | \
tar -xz --strip-components=1 -C /tmp/ruby-install ; \
make -C /tmp/ruby-install install ; \
rm -rf /tmp/ruby-install
# Install the desired versions of ruby, and bundler for each
RUN bash --login -c '\
set -o errexit ; \
for version in $(cat /root/versions.txt) ; do \
ruby-install ruby ${version} -- --disable-install-doc ; \
source /etc/profile.d/chruby.sh ; \
chruby ruby-${version} ; \
gem install bundler ; \
gem install mustache -v 1.0.3 --no-ri --no-rdoc ; \
done \
'
2.1.7
2.2.3
2.3.1
2.4.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment