Skip to content

Instantly share code, notes, and snippets.

@8parth
Created February 13, 2019 03:38
Show Gist options
  • Save 8parth/417f0913fc186cd7a26cd6ef6fae4932 to your computer and use it in GitHub Desktop.
Save 8parth/417f0913fc186cd7a26cd6ef6fae4932 to your computer and use it in GitHub Desktop.
Codebuild Image for ruby 2.4.1 with ubuntu 16.04 based on https://jonbake.com/blog/2018/08/29/setting-up-codebuild-rails.html
#!/bin/sh
set -e
/usr/local/bin/dockerd \
--host=unix:///var/run/docker.sock \
--host=tcp://127.0.0.1:2375 \
--storage-driver=overlay &>/var/log/docker.log &
tries=0
d_timeout=60
until docker info >/dev/null 2>&1
do
if [ "$tries" -gt "$d_timeout" ]; then
cat /var/log/docker.log
echo 'Timed out trying to connect to internal docker host.' >&2
exit 1
fi
tries=$(( $tries + 1 ))
sleep 1
done
eval "$@"
# Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Amazon Software License (the "License"). You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://aws.amazon.com/asl/
#
# or in the "license" file accompanying this file.
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
# See the License for the specific language governing permissions and limitations under the License.
#
FROM ubuntu:16.04
ENV DOCKER_BUCKET="download.docker.com" \
DOCKER_VERSION="17.09.0-ce" \
DOCKER_CHANNEL="stable" \
DOCKER_SHA256="a9e90a73c3cdfbf238f148e1ec0eaff5eb181f92f35bdd938fd7dab18e1c4647" \
DIND_COMMIT="3b5fac462d21ca164b3778647420016315289034" \
DOCKER_COMPOSE_VERSION="1.21.2" \
GITVERSION_VERSION="3.6.5"
# Install git, SSH, and other utilities
RUN set -ex \
&& echo 'Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/99use-gzip-compression \
&& apt-get update \
&& apt install -y apt-transport-https \
&& apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF \
&& echo "deb https://download.mono-project.com/repo/ubuntu stable-trusty main" | tee /etc/apt/sources.list.d/mono-official-stable.list \
&& apt-get update \
&& apt-get install software-properties-common -y --no-install-recommends \
&& apt-add-repository ppa:git-core/ppa \
&& apt-get update \
&& apt-get install git=1:2.* -y --no-install-recommends \
&& git version \
&& apt-get install -y --no-install-recommends openssh-client \
&& mkdir ~/.ssh \
&& touch ~/.ssh/known_hosts \
&& ssh-keyscan -t rsa,dsa -H github.com >> ~/.ssh/known_hosts \
&& ssh-keyscan -t rsa,dsa -H bitbucket.org >> ~/.ssh/known_hosts \
&& chmod 600 ~/.ssh/known_hosts \
&& apt-get install -y --no-install-recommends \
wget python=2.7.* python2.7-dev=2.7.* fakeroot ca-certificates \
tar gzip zip autoconf automake \
bzip2 file g++ gcc imagemagick \
libbz2-dev libc6-dev libcurl4-openssl-dev libdb-dev \
libevent-dev libffi-dev libgeoip-dev libglib2.0-dev \
libjpeg-dev libkrb5-dev liblzma-dev \
libmagickcore-dev libmagickwand-dev libmysqlclient-dev \
libncurses5-dev libpng12-dev libpq-dev libreadline-dev \
libsqlite3-dev libssl-dev libtool libwebp-dev \
libxml2-dev libxslt1-dev libyaml-dev make \
patch xz-utils zlib1g-dev unzip curl \
e2fsprogs iptables xfsprogs xz-utils \
less groff liberror-perl \
asciidoc build-essential bzr cvs cvsps docbook-xml docbook-xsl dpkg-dev \
libdbd-sqlite3-perl libdbi-perl libdpkg-perl libhttp-date-perl \
libio-pty-perl libserf-1-1 libsvn-perl libsvn1 libtcl8.6 libtimedate-perl \
libunistring0 libxml2-utils libyaml-perl python-bzrlib python-configobj \
sgml-base sgml-data subversion tcl tcl8.6 xml-core xmlto xsltproc \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Download and set up GitVersion
RUN set -ex \
&& wget "https://github.com/GitTools/GitVersion/releases/download/v${GITVERSION_VERSION}/GitVersion_${GITVERSION_VERSION}.zip" -O /tmp/GitVersion_${GITVERSION_VERSION}.zip \
&& mkdir -p /usr/local/GitVersion_${GITVERSION_VERSION} \
&& unzip /tmp/GitVersion_${GITVERSION_VERSION}.zip -d /usr/local/GitVersion_${GITVERSION_VERSION} \
&& rm /tmp/GitVersion_${GITVERSION_VERSION}.zip \
&& echo "mono /usr/local/GitVersion_${GITVERSION_VERSION}/GitVersion.exe \$@" >> /usr/local/bin/gitversion \
&& chmod +x /usr/local/bin/gitversion
RUN set -ex \
&& sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& apt-get update -qq && apt-get install -y postgresql-9.6 \
&& sed -i -- 's/peer/trust/g' /etc/postgresql/9.6/main/pg_hba.conf
# Install Docker
RUN set -ex \
&& curl -fSL "https://${DOCKER_BUCKET}/linux/static/${DOCKER_CHANNEL}/x86_64/docker-${DOCKER_VERSION}.tgz" -o docker.tgz \
&& echo "${DOCKER_SHA256} *docker.tgz" | sha256sum -c - \
&& tar --extract --file docker.tgz --strip-components 1 --directory /usr/local/bin/ \
&& rm docker.tgz \
&& docker -v \
# set up subuid/subgid so that "--userns-remap=default" works out-of-the-box
&& addgroup dockremap \
&& useradd -g dockremap dockremap \
&& echo 'dockremap:165536:65536' >> /etc/subuid \
&& echo 'dockremap:165536:65536' >> /etc/subgid \
&& wget "https://raw.githubusercontent.com/docker/docker/${DIND_COMMIT}/hack/dind" -O /usr/local/bin/dind \
&& curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose \
&& chmod +x /usr/local/bin/dind /usr/local/bin/docker-compose \
# Ensure docker-compose works
&& docker-compose version
# Install dependencies by all python images equivalent to buildpack-deps:jessie
# on the public repos.
RUN set -ex \
&& wget "https://bootstrap.pypa.io/2.6/get-pip.py" -O /tmp/get-pip.py \
&& python /tmp/get-pip.py \
&& pip install awscli==1.* \
&& rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*
VOLUME /var/lib/docker
COPY dockerd-entrypoint.sh /usr/local/bin/
ENV RUBY_MAJOR="2.4" \
RUBY_VERSION="2.4.1" \
RUBY_DOWNLOAD_SHA256="a330e10d5cb5e53b3a0078326c5731888bb55e32c4abfeb27d9e7f8e5d000250" \
RUBYGEMS_VERSION="2.7.2" \
BUNDLER_VERSION="1.16.1" \
GEM_HOME="/usr/local/bundle"
ENV BUNDLE_PATH="$GEM_HOME" \
BUNDLE_BIN="$GEM_HOME/bin" \
BUNDLE_SILENCE_ROOT_WARNING=1 \
BUNDLE_APP_CONFIG="$GEM_HOME"
ENV PATH $BUNDLE_BIN:$PATH
RUN mkdir -p /usr/local/etc \
&& { \
echo 'install: --no-document'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc \
&& apt-get update && apt-get install -y --no-install-recommends \
bison libgdbm-dev ruby \
&& wget "https://cache.ruby-lang.org/pub/ruby/$RUBY_MAJOR/ruby-$RUBY_VERSION.tar.gz" -O /tmp/ruby.tar.gz \
&& echo "$RUBY_DOWNLOAD_SHA256 /tmp/ruby.tar.gz" | sha256sum -c - \
&& mkdir -p /usr/src/ruby \
&& tar -xzf /tmp/ruby.tar.gz -C /usr/src/ruby --strip-components=1 \
&& cd /usr/src/ruby \
&& { \
echo '#define ENABLE_PATH_CHECK 0'; \
echo; \
cat file.c; \
} > file.c.new \
&& mv file.c.new file.c \
&& autoconf \
&& ./configure --disable-install-doc \
&& make -j"$(nproc)" \
&& make install \
&& apt-get purge -y --auto-remove bison libgdbm-dev ruby \
&& cd / \
&& rm -r /usr/src/ruby \
&& gem update --system "$RUBYGEMS_VERSION" \
&& gem install bundler --version "$BUNDLER_VERSION" \
&& mkdir -p "$GEM_HOME" "$BUNDLE_BIN" \
&& chmod 777 "$GEM_HOME" "$BUNDLE_BIN" \
&& rm -fr /var/lib/apt/lists/* /tmp/* /var/tmp/*
CMD [ "irb" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment