<commit_before>#!/bin/bash -e
# $1 - Specifies distribution - RHEL7/CentOS7
# $2 - Specifies MongoDB version - 2.4
# TEST_MODE - If set, build a candidate image and test it

# Array of all versions of MongoDB
declare -a VERSIONS=(2.4)

OS=$1
VERSION=$2

# TODO: Remove once docker 1.5 is in usage (support for named Dockerfiles)
function docker_build {
	TAG=$1
	DOCKERFILE=$2

	if [ -n "$DOCKERFILE" -a "$DOCKERFILE" != "Dockerfile" ]; then
		# Swap Dockerfiles and setup a trap restoring them
		mv Dockerfile Dockerfile.centos7
		mv "${DOCKERFILE}" Dockerfile
		trap "mv Dockerfile ${DOCKERFILE} && mv Dockerfile.centos7 Dockerfile" ERR RETURN
	fi

	docker build -t ${TAG} . && trap - ERR
}

if [ -z ${VERSION} ]; then
	# Build all versions
	dirs=${VERSIONS}
else
	# Build only specified version on MongoDB
	dirs=${VERSION}
fi

for dir in ${dirs}; do
	IMAGE_NAME=openshift/mongodb-${dir//./}-${OS}
	if [ -v TEST_MODE ]; then
		IMAGE_NAME="${IMAGE_NAME}-candidate"
	fi
	echo ">>>> Building ${IMAGE_NAME}"

	pushd ${dir} > /dev/null

	if [ "$OS" == "rhel7" ]; then
		docker_build ${IMAGE_NAME} Dockerfile.rhel7
	else
		docker_build ${IMAGE_NAME}
	fi

	if [ -v TEST_MODE ]; then
		IMAGE_NAME=${IMAGE_NAME} test/run
	fi

	popd > /dev/null
done<commit_msg>update squash tool version<commit_after>#!/bin/bash -e
# $1 - Specifies distribution - RHEL7/CentOS7
# $2 - Specifies MongoDB version - 2.4
# TEST_MODE - If set, build a candidate image and test it

# Array of all versions of MongoDB
declare -a VERSIONS=(2.4)

OS=$1
VERSION=$2

function squash { 
  # install the docker layer squashing tool
  easy_install --user docker-scripts==0.3.3
  base=$(awk '/^FROM/{print $2}' Dockerfile)
  $HOME/.local/bin/docker-scripts squash -f $base ${IMAGE_NAME}
}

# TODO: Remove once docker 1.5 is in usage (support for named Dockerfiles)
function docker_build {
	TAG=$1
	DOCKERFILE=$2

	if [ -n "$DOCKERFILE" -a "$DOCKERFILE" != "Dockerfile" ]; then
		# Swap Dockerfiles and setup a trap restoring them
		mv Dockerfile Dockerfile.centos7
		mv "${DOCKERFILE}" Dockerfile
		trap "mv Dockerfile ${DOCKERFILE} && mv Dockerfile.centos7 Dockerfile" ERR RETURN
	fi

	docker build -t ${TAG} . && trap - ERR
	squash
}

if [ -z ${VERSION} ]; then
	# Build all versions
	dirs=${VERSIONS}
else
	# Build only specified version on MongoDB
	dirs=${VERSION}
fi

for dir in ${dirs}; do
	IMAGE_NAME=openshift/mongodb-${dir//./}-${OS}
	if [ -v TEST_MODE ]; then
		IMAGE_NAME="${IMAGE_NAME}-candidate"
	fi
	echo ">>>> Building ${IMAGE_NAME}"

	pushd ${dir} > /dev/null

	if [ "$OS" == "rhel7" ]; then
		docker_build ${IMAGE_NAME} Dockerfile.rhel7
	else
		docker_build ${IMAGE_NAME}
	fi
	if [ -v TEST_MODE ]; then
		IMAGE_NAME=${IMAGE_NAME} test/run
	fi

	popd > /dev/null
done
{'fraction_non_alphanumeric': 0.13598250091141087, 'fraction_numerical': 0.014582573824279986, 'mean_word_length': 3.8395061728395063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4173870', 'n_tokens_mistral': 1077, 'n_tokens_neox': 986, 'n_words': 305}