<commit_before>#!/bin/bash
#
# Build Docker images and run tests.
#
# PRE: Docker daemon running, s2i binary available.
#
# Supported environment variables:
#
# -----------------------------------------------------
# TEST_OPENSHIFT  If 'true' run tests to make sure
#                 released images work against the
#                 test application used in OpenShift
#
# VERSIONS        The list of versions to build/test.
#                 Defaults to all versions. i.e "2.1 3.1 5.0".
#
# IMAGE_OS        The base os image to use when building
#                 the containers.
#                 Options are CENTOS, RHEL7, RHEL8, and
#                 FEDORA.
#                 Defaults to match the OS.
#
# TEST_PORT       specifies the port on the docker host
#                 to bind to when creating containers
#                 during the asp.net tests. Affects
#                 tests only.
#
# FORCE           rebuild the containers even if they
#                 already exist.
# -----------------------------------------------------
#
# Usage:
#       $ sudo ./build.sh
#       $ sudo VERSIONS=2.1 ./build.sh
#

if [ "${DEBUG}" == "true" ]; then
  set -x
fi

FORCE=${FORCE:-false}

# Use podman instead of docker when available.
if command -v podman >/dev/null; then
  docker() {
    podman "$@"
  }
fi

base_image_name() {
  local version=$1
  local v_no_dot=$(echo ${version} | sed 's/\.//g')
  echo "dotnet-${v_no_dot}";
}

image_exists() {
  docker inspect $1 &>/dev/null
}

check_result_msg() {
  local retval=$1
  local msg=$2
  if [ ${retval} -ne 0 ]; then
    echo 1>&2 "${msg}"
    exit 1
  fi
}

build_image() {
  local path=$1
  local docker_filename=$2
  local name=$3
  if $FORCE || ! image_exists ${name}; then
    echo "Building Docker image ${name} ..."
    if [ ! -d "${path}" ]; then
      echo "No directory found at given location '${path}'. Skipping this image."
      return
    fi
    pushd ${path} &>/dev/null
      docker build --no-cache -f ${docker_filename} -t ${name} .
      check_result_msg $? "Building Docker image ${name} FAILED!"
    popd &>/dev/null
  fi
}

test_images() {
  local path=$1
  local test_image=$2
  local runtime_image=$3
  echo "Running tests..."
  IMAGE_NAME=${test_image} RUNTIME_IMAGE_NAME=${runtime_image} ${path}/run
  check_result_msg $? "Tests FAILED!"
}

if [ -z "${IMAGE_OS}" ]; then
  # Default to CentOS when not on RHEL.
  if [[ `grep "Red Hat Enterprise Linux Server release 7" /etc/redhat-release` ]]; then
    export IMAGE_OS="RHEL7"
  elif [[ `grep "Red Hat Enterprise Linux release 8" /etc/redhat-release` ]]; then
    export IMAGE_OS="RHEL8"
  elif [[ `grep "CentOS" /etc/redhat-release` ]]; then
    export IMAGE_OS="CENTOS"
  elif [[ `grep "Fedora" /etc/redhat-release` ]]; then
    export IMAGE_OS="FEDORA"
  else
    echo 1>&2 "Set IMAGE_OS to specify the base image."
    exit 1
  fi
fi

if [ "$IMAGE_OS" = "CENTOS" ]; then
  VERSIONS="${VERSIONS:-2.1 3.1 5.0}"
  image_postfix="-centos7"
  image_prefix="dotnet"
  docker_filename="Dockerfile"
elif [ "$IMAGE_OS" = "RHEL8" ]; then
  VERSIONS="${VERSIONS:-2.1 3.1 5.0}"
  image_prefix="ubi8"
  docker_filename="Dockerfile.rhel8"
elif [ "$IMAGE_OS" = "FEDORA" ]; then
  VERSIONS="${VERSIONS:-3.1 5.0}"
  image_prefix="fedora"
  docker_filename="Dockerfile.fedora"<commit_msg>build.sh: don't build 5.0 for CentOS because there are no packages for it yet. (#348)<commit_after>#!/bin/bash
#
# Build Docker images and run tests.
#
# PRE: Docker daemon running, s2i binary available.
#
# Supported environment variables:
#
# -----------------------------------------------------
# TEST_OPENSHIFT  If 'true' run tests to make sure
#                 released images work against the
#                 test application used in OpenShift
#
# VERSIONS        The list of versions to build/test.
#                 Defaults to all versions. i.e "2.1 3.1 5.0".
#
# IMAGE_OS        The base os image to use when building
#                 the containers.
#                 Options are CENTOS, RHEL7, RHEL8, and
#                 FEDORA.
#                 Defaults to match the OS.
#
# TEST_PORT       specifies the port on the docker host
#                 to bind to when creating containers
#                 during the asp.net tests. Affects
#                 tests only.
#
# FORCE           rebuild the containers even if they
#                 already exist.
# -----------------------------------------------------
#
# Usage:
#       $ sudo ./build.sh
#       $ sudo VERSIONS=2.1 ./build.sh
#

if [ "${DEBUG}" == "true" ]; then
  set -x
fi

FORCE=${FORCE:-false}

# Use podman instead of docker when available.
if command -v podman >/dev/null; then
  docker() {
    podman "$@"
  }
fi

base_image_name() {
  local version=$1
  local v_no_dot=$(echo ${version} | sed 's/\.//g')
  echo "dotnet-${v_no_dot}";
}

image_exists() {
  docker inspect $1 &>/dev/null
}

check_result_msg() {
  local retval=$1
  local msg=$2
  if [ ${retval} -ne 0 ]; then
    echo 1>&2 "${msg}"
    exit 1
  fi
}

build_image() {
  local path=$1
  local docker_filename=$2
  local name=$3
  if $FORCE || ! image_exists ${name}; then
    echo "Building Docker image ${name} ..."
    if [ ! -d "${path}" ]; then
      echo "No directory found at given location '${path}'. Skipping this image."
      return
    fi
    pushd ${path} &>/dev/null
      docker build --no-cache -f ${docker_filename} -t ${name} .
      check_result_msg $? "Building Docker image ${name} FAILED!"
    popd &>/dev/null
  fi
}

test_images() {
  local path=$1
  local test_image=$2
  local runtime_image=$3
  echo "Running tests..."
  IMAGE_NAME=${test_image} RUNTIME_IMAGE_NAME=${runtime_image} ${path}/run
  check_result_msg $? "Tests FAILED!"
}

if [ -z "${IMAGE_OS}" ]; then
  # Default to CentOS when not on RHEL.
  if [[ `grep "Red Hat Enterprise Linux Server release 7" /etc/redhat-release` ]]; then
    export IMAGE_OS="RHEL7"
  elif [[ `grep "Red Hat Enterprise Linux release 8" /etc/redhat-release` ]]; then
    export IMAGE_OS="RHEL8"
  elif [[ `grep "CentOS" /etc/redhat-release` ]]; then
    export IMAGE_OS="CENTOS"
  elif [[ `grep "Fedora" /etc/redhat-release` ]]; then
    export IMAGE_OS="FEDORA"
  else
    echo 1>&2 "Set IMAGE_OS to specify the base image."
    exit 1
  fi
fi

if [ "$IMAGE_OS" = "CENTOS" ]; then
  VERSIONS="${VERSIONS:-2.1 3.1}"
  image_postfix="-centos7"
  image_prefix="dotnet"
  docker_filename="Dockerfile"
elif [ "$IMAGE_OS" = "RHEL8" ]; then
  VERSIONS="${VERSIONS:-2.1 3.1 5.0}"
  image_prefix="ubi8"
  docker_filename="Dockerfile.rhel8"
elif [ "$IMAGE_OS" = "FEDORA" ]; then
  VERSIONS="${VERSIONS:-3.1 5.0}"
  image_prefix="fedora"
  docker_filename="Dockerfile.fedora"
{'fraction_non_alphanumeric': 0.16392707710699342, 'fraction_numerical': 0.015989240884638375, 'mean_word_length': 2.343156843156843, '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': '3759300', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2212, 'n_words': 660}