Student User
2019-05-22 55f6e7d35b3fe8bd4f813e1f4ec526e61468a5eb
ocb initial release
13 files added
436 ■■■■■ changed files
.s2i/bin/assemble 48 ●●●●● patch | view | raw | blame | history
.s2i/bin/assemble~ 48 ●●●●● patch | view | raw | blame | history
.s2i/bin/run 10 ●●●●● patch | view | raw | blame | history
.s2i/bin/run~ 10 ●●●●● patch | view | raw | blame | history
.s2i/bin/save-artifacts 10 ●●●●● patch | view | raw | blame | history
.s2i/bin/usage 12 ●●●●● patch | view | raw | blame | history
Dockerfile 42 ●●●●● patch | view | raw | blame | history
Dockerfile~ 42 ●●●●● patch | view | raw | blame | history
Makefile 10 ●●●●● patch | view | raw | blame | history
redhat.repo 10 ●●●●● patch | view | raw | blame | history
rhel_dvd.repo 5 ●●●●● patch | view | raw | blame | history
test/run 154 ●●●●● patch | view | raw | blame | history
training.repo 35 ●●●●● patch | view | raw | blame | history
.s2i/bin/assemble
New file
@@ -0,0 +1,48 @@
#!/bin/bash -e
#
# S2I assemble script for the 'ocb' image.
# The 'assemble' script builds your application source so that it is ready to run.
#
# For more information refer to the documentation:
#    https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#
if [[ "$1" == "-h" ]]; then
    # If the 'ocb' assemble script is executed with '-h' flag,
    # print the usage.
    exec /usr/libexec/s2i/usage
fi
# printf ">>> DEBUG:\n"
# env
# find /tmp -ls
# printf "<<< END\n"
# pwd
#id -a
# ls -la
mkdir -p /opt/app-root /opt/app-src
cd /opt/app-src
# Restore artifacts from the previous build (if they exist).
#
if [ "$(ls /tmp/artifacts/ 2>/dev/null)" ]; then
  echo "---> Restoring build artifacts..."
  mv /tmp/artifacts/. ./
fi
echo "---> Installing application source..."
cp -Rf /tmp/src/. ./
echo "---> Building application from source..."
# TODO: Add build steps for your application, eg npm install, bundle install
rt=0
if [ -f ./configure ]; then
    ./configure --prefix=/opt/app-root
    rt=$?
fi
if [ ${rt} -eq 0 ]; then
    make all && make install
else
    printf "E: configure failed, not going to run make!\n"
fi
.s2i/bin/assemble~
New file
@@ -0,0 +1,48 @@
#!/bin/bash -e
#
# S2I assemble script for the 'ocb' image.
# The 'assemble' script builds your application source so that it is ready to run.
#
# For more information refer to the documentation:
#    https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#
if [[ "$1" == "-h" ]]; then
    # If the 'ocb' assemble script is executed with '-h' flag,
    # print the usage.
    exec /usr/libexec/s2i/usage
fi
# printf ">>> DEBUG:\n"
# env
# find /tmp -ls
# printf "<<< END\n"
# pwd
id -a
# ls -la
mkdir -p /opt/app-root /opt/app-src
cd /opt/app-src
ls -la
# Restore artifacts from the previous build (if they exist).
#
if [ "$(ls /tmp/artifacts/ 2>/dev/null)" ]; then
  echo "---> Restoring build artifacts..."
  mv /tmp/artifacts/. ./
fi
echo "---> Installing application source..."
cp -Rf /tmp/src/. ./
echo "---> Building application from source..."
# TODO: Add build steps for your application, eg npm install, bundle install
rt=0
if [ -f ./configure ]; then
    ./configure --prefix=/opt/app-root
    rt=$?
fi
if [ ${rt} -eq 0 ]; then
    make all && make install
else
    printf "E: configure failed, not going to run make!\n"
fi
.s2i/bin/run
New file
@@ -0,0 +1,10 @@
#!/bin/bash -e
#
# S2I run script for the 'ocb' image.
# The run script executes the server that runs your application.
#
# For more information see the documentation:
#    https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#
exec /opt/app-root/bin/server $(uname -n) 8080
.s2i/bin/run~
New file
@@ -0,0 +1,10 @@
#!/bin/bash -e
#
# S2I run script for the 'ocb' image.
# The run script executes the server that runs your application.
#
# For more information see the documentation:
#    https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#
exec /opt/app-root/bin/server start
.s2i/bin/save-artifacts
New file
@@ -0,0 +1,10 @@
#!/bin/sh -e
#
# S2I save-artifacts script for the 'ocb' image.
# The save-artifacts script streams a tar archive to standard output.
# The archive contains the files and folders you want to re-use in the next build.
#
# For more information see the documentation:
#    https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#
# tar cf - <list of files and folders>
.s2i/bin/usage
New file
@@ -0,0 +1,12 @@
#!/bin/bash -e
cat <<EOF
This is the ocb S2I image:
To use it, install S2I: https://github.com/openshift/source-to-image
Sample invocation:
s2i build git://<source code> ocb <application image>
You can then run the resulting image via:
docker run <application image>
EOF
Dockerfile
New file
@@ -0,0 +1,42 @@
# ocb
FROM rhel7
# TODO: Put the maintainer name in the image metadata
MAINTAINER Olaf Bohlen <obohlen@redhat.com>
# TODO: Rename the builder environment variable to inform users about application you provide them
ENV BUILDER_VERSION 0.1
# TODO: Set labels used in OpenShift to describe the builder image
LABEL io.k8s.description="Platform for building C" \
      io.k8s.display-name="builder 0.1.0" \
      io.openshift.expose-services="8080:http" \
      io.openshift.tags="builder,C,make" \
      io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \
      io.openshift.s2i.destination="/tmp"
COPY training.repo redhat.repo rhel_dvd.repo /etc/yum.repos.d/
# TODO: Install required packages here:
RUN yum install -y gcc-4.8.5-11.el7 make-3.82-23.el7 autoconf automake libtool && \
yum clean all -y && \
mkdir /opt/app-root /opt/app-src && \
chown 1001:0 /opt/app-root /opt/app-src
# TODO (optional): Copy the builder files into /opt/app-root
# COPY ./<builder_folder>/ /opt/app-root/
# TODO: Copy the S2I scripts to /usr/libexec/s2i, since openshift/base-centos7 image sets io.openshift.s2i.scripts-url label that way, or update that label
COPY ./.s2i/bin/ /usr/libexec/s2i
# TODO: Drop the root user and make the content of /opt/app-root owned by user 1001
RUN chown -R 1001:1001 /opt/app-root
# This default user is created in the openshift/base-centos7 image
USER 1001
# TODO: Set the default port for applications built using this image
EXPOSE 8080
# TODO: Set the default CMD for the image
CMD ["usage"]
Dockerfile~
New file
@@ -0,0 +1,42 @@
# ocb
FROM rhel7
# TODO: Put the maintainer name in the image metadata
MAINTAINER Olaf Bohlen <obohlen@redhat.com>
# TODO: Rename the builder environment variable to inform users about application you provide them
ENV BUILDER_VERSION 0.1
# TODO: Set labels used in OpenShift to describe the builder image
LABEL io.k8s.description="Platform for building C" \
      io.k8s.display-name="builder 0.1.0" \
      io.openshift.expose-services="8080:http" \
      io.openshift.tags="builder,C,make" \
      io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \
      io.openshift.s2i.destination="/tmp"
COPY training.repo redhat.repo rhel_dvd.repo /etc/yum.repos.d/
# TODO: Install required packages here:
RUN yum install -y gcc-4.8.5-11.el7 autoconf automake libtool && \
yum clean all -y && \
mkdir /opt/app-root /opt/app-src && \
chown 1001:0 /opt/app-root /opt/app-src
# TODO (optional): Copy the builder files into /opt/app-root
# COPY ./<builder_folder>/ /opt/app-root/
# TODO: Copy the S2I scripts to /usr/libexec/s2i, since openshift/base-centos7 image sets io.openshift.s2i.scripts-url label that way, or update that label
COPY ./.s2i/bin/ /usr/libexec/s2i
# TODO: Drop the root user and make the content of /opt/app-root owned by user 1001
RUN chown -R 1001:1001 /opt/app-root
# This default user is created in the openshift/base-centos7 image
USER 1001
# TODO: Set the default port for applications built using this image
EXPOSE 8080
# TODO: Set the default CMD for the image
CMD ["usage"]
Makefile
New file
@@ -0,0 +1,10 @@
IMAGE_NAME = ocb
build:
    docker build -t $(IMAGE_NAME) .
.PHONY: test
test:
    docker build -t $(IMAGE_NAME)-candidate .
    IMAGE_NAME=$(IMAGE_NAME)-candidate test/run
redhat.repo
New file
@@ -0,0 +1,10 @@
#
# Certificate-Based Repositories
# Managed by (rhsm) subscription-manager
#
# *** This file is auto-generated.  Changes made here will be over-written. ***
# *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
#
# If this file is empty and this system is subscribed consider
# a "yum repolist" to refresh available repos
#
rhel_dvd.repo
New file
@@ -0,0 +1,5 @@
[rhel_dvd]
baseurl = http://content.example.com/rhel7.3/x86_64/dvd
enabled = true
gpgcheck = false
name = Remote classroom copy of dvd
test/run
New file
@@ -0,0 +1,154 @@
#!/bin/bash
#
# The 'run' performs a simple test that verifies the S2I image.
# The main focus here is to exercise the S2I scripts.
#
# For more information see the documentation:
# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
#
IMAGE_NAME=${IMAGE_NAME-ocb-candidate}
# Determining system utility executables (darwin compatibility check)
READLINK_EXEC="readlink"
MKTEMP_EXEC="mktemp"
if (echo "$OSTYPE" | egrep -qs 'darwin'); then
  ! type -a "greadlink" &>"/dev/null" || READLINK_EXEC="greadlink"
  ! type -a "gmktemp" &>"/dev/null" || MKTEMP_EXEC="gmktemp"
fi
test_dir="$($READLINK_EXEC -zf $(dirname "${BASH_SOURCE[0]}"))"
image_dir=$($READLINK_EXEC -zf ${test_dir}/..)
scripts_url="file://${image_dir}/.s2i/bin"
cid_file=$($MKTEMP_EXEC -u --suffix=.cid)
# Since we built the candidate image locally, we don't want S2I to attempt to pull
# it from Docker hub
s2i_args="--force-pull=false --loglevel=2"
# Port the image exposes service to be tested
test_port=8080
image_exists() {
  docker inspect $1 &>/dev/null
}
container_exists() {
  image_exists $(cat $cid_file)
}
container_ip() {
  docker inspect --format="{{ .NetworkSettings.IPAddress }}" $(cat $cid_file)
}
run_s2i_build() {
  s2i build --incremental=true ${s2i_args} file://${test_dir}/test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp
}
prepare() {
  if ! image_exists ${IMAGE_NAME}; then
    echo "ERROR: The image ${IMAGE_NAME} must exist before this script is executed."
    exit 1
  fi
  # s2i build requires the application is a valid 'Git' repository
  pushd ${test_dir}/test-app >/dev/null
  git init
  git config user.email "build@localhost" && git config user.name "builder"
  git add -A && git commit -m "Sample commit"
  popd >/dev/null
  run_s2i_build
}
run_test_application() {
  docker run --rm --cidfile=${cid_file} -p ${test_port} ${IMAGE_NAME}-testapp
}
cleanup() {
  if [ -f $cid_file ]; then
    if container_exists; then
      docker stop $(cat $cid_file)
    fi
  fi
  if image_exists ${IMAGE_NAME}-testapp; then
    docker rmi ${IMAGE_NAME}-testapp
  fi
}
check_result() {
  local result="$1"
  if [[ "$result" != "0" ]]; then
    echo "S2I image '${IMAGE_NAME}' test FAILED (exit code: ${result})"
    cleanup
    exit $result
  fi
}
wait_for_cid() {
  local max_attempts=10
  local sleep_time=1
  local attempt=1
  local result=1
  while [ $attempt -le $max_attempts ]; do
    [ -f $cid_file ] && break
    echo "Waiting for container to start..."
    attempt=$(( $attempt + 1 ))
    sleep $sleep_time
  done
}
test_usage() {
  echo "Testing 's2i usage'..."
  s2i usage ${s2i_args} ${IMAGE_NAME} &>/dev/null
}
test_connection() {
  echo "Testing HTTP connection..."
  local max_attempts=10
  local sleep_time=1
  local attempt=1
  local result=1
  while [ $attempt -le $max_attempts ]; do
    echo "Sending GET request to http://$(container_ip):${test_port}/"
    if (echo "$OSTYPE" | egrep -qs 'darwin'); then
      echo "Warning for OSX users: if you can't access the container's IP ${container_ip} directly (because you use boot2docker for example)"
      echo "you should run the curl command in a container, for example using:"
      echo "docker run --rm -it sequenceiq/alpine-curl curl -s -w %{http_code} -o /dev/null http://$(container_ip):${test_port}/"
    fi
    response_code=$(curl -s -w %{http_code} -o /dev/null http://$(container_ip):${test_port}/)
    status=$?
    if [ $status -eq 0 ]; then
      if [ $response_code -eq 200 ]; then
        result=0
      fi
      break
    fi
    attempt=$(( $attempt + 1 ))
    sleep $sleep_time
  done
  return $result
}
# Build the application image twice to ensure the 'save-artifacts' and
# 'restore-artifacts' scripts are working properly
prepare
run_s2i_build
check_result $?
# Verify the 'usage' script is working properly
test_usage
check_result $?
# Verify that the HTTP connection can be established to test application container
run_test_application &
# Wait for the container to write its CID file
wait_for_cid
test_connection
check_result $?
cleanup
training.repo
New file
@@ -0,0 +1,35 @@
[rhel-7-server-extras-rpms]
baseurl = http://content.example.com/ocp3.6/x86_64/extras
enabled = true
gpgcheck = false
name = Remote classroom copy of RHEL Extras RPMS
[rhel-7-server-updates-rpms]
baseurl = http://content.example.com/ocp3.6/x86_64/updates
enabled = true
gpgcheck = false
name = Remote classroom copy of RHEL Updates
[rhel-7-server-optional-rpms]
baseurl = http://content.example.com/ocp3.6/x86_64/rhelopt
enabled = true
gpgcheck = false
name = Remote classroom copy of RHEL Optional RPMS
[rhel-7-server-ose-3.6-rpms]
baseurl = http://content.example.com/ocp3.6/x86_64/ocp
enabled = true
gpgcheck = false
name = Remote classroom copy of OCP RPMS
[rhel-7-fast-datapath-rpms]
baseurl = http://content.example.com/ocp3.6/x86_64/fast
enabled = true
gpgcheck = false
name = Remote classroom copy of Fast Datapath RPMS
[rhel-server-rhscl-7-rpms]
baseurl = http://content.example.com/ocp3.6/x86_64/rhelrhscl
enabled = true
gpgcheck = false
name = Remote classroom copy of RHEL RHSCL RPMS