#8 [betka-master-sync]
Opened 2 years ago by phracek. Modified 2 years ago
container/ phracek/httpd f33  into  f33

2.4
file added
+1
@@ -0,0 +1,1 @@ 

+ . 

\ No newline at end of file

file added
+69
@@ -0,0 +1,69 @@ 

+ FROM registry.fedoraproject.org/f33/s2i-core:latest

+ 

+ # Apache HTTP Server image.

+ #

+ # Volumes:

+ #  * /var/www - Datastore for httpd

+ #  * /var/log/httpd - Storage for logs when $HTTPD_LOG_TO_VOLUME is set

+ # Environment:

+ #  * $HTTPD_LOG_TO_VOLUME (optional) - When set, httpd will log into /var/log/httpd

+ 

+ ENV HTTPD_VERSION=2.4 \

+     NAME=httpd \

+     ARCH=x86_64

+ 

+ ENV SUMMARY="Platform for running Apache httpd $HTTPD_VERSION or building httpd-based application" \

+     DESCRIPTION="Apache httpd $HTTPD_VERSION available as container, is a powerful, efficient, \

+ and extensible web server. Apache supports a variety of features, many implemented as compiled modules \

+ which extend the core functionality. \

+ These can range from server-side programming language support to authentication schemes. \

+ Virtual hosting allows one Apache installation to serve many different Web sites."

+ 

+ LABEL summary="$SUMMARY" \

+       description="$DESCRIPTION" \

+       io.k8s.description="$SUMMARY" \

+       io.k8s.display-name="Apache httpd $HTTPD_VERSION" \

+       io.openshift.expose-services="8080:http,8443:https" \

+       io.openshift.tags="builder,httpd,httpd24" \

+       com.redhat.component="$NAME" \

+       name="$FGC/$NAME" \

+       version="$HTTPD_VERSION" \

+       usage="s2i build https://github.com/sclorg/httpd-container.git --context-dir=examples/sample-test-app/ $FGC/$NAME sample-server" \

+       maintainer="SoftwareCollections.org <sclorg@redhat.com>"

+ 

+ EXPOSE 8080

+ EXPOSE 8443

+ 

+ RUN dnf install -y yum-utils gettext hostname && \

+     INSTALL_PKGS="nss_wrapper bind-utils httpd mod_ssl mod_ldap mod_session mod_security sscg" && \

+     dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \

+     rpm -V $INSTALL_PKGS && \

+     dnf clean all

+ 

+ ENV HTTPD_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/httpd/ \

+     HTTPD_APP_ROOT=${APP_ROOT} \

+     HTTPD_CONFIGURATION_PATH=${APP_ROOT}/etc/httpd.d \

+     HTTPD_MAIN_CONF_PATH=/etc/httpd/conf \

+     HTTPD_MAIN_CONF_MODULES_D_PATH=/etc/httpd/conf.modules.d \

+     HTTPD_MAIN_CONF_D_PATH=/etc/httpd/conf.d \

+     HTTPD_TLS_CERT_PATH=/etc/httpd/tls \

+     HTTPD_VAR_RUN=/var/run/httpd \

+     HTTPD_DATA_PATH=/var/www \

+     HTTPD_DATA_ORIG_PATH=/var/www \

+     HTTPD_LOG_PATH=/var/log/httpd

+ 

+ COPY ./s2i/bin/ $STI_SCRIPTS_PATH

+ COPY ./root /

+ 

+ # Generate SSL certs and reset permissions of filesystem to default values

+ # Reset permissions of filesystem to default values

+ RUN /usr/libexec/httpd-prepare && rpm-file-permissions

+ 

+ USER 1001

+ 

+ # Not using VOLUME statement since it's not working in OpenShift Online:

+ # https://github.com/sclorg/httpd-container/issues/30

+ # VOLUME ["${HTTPD_DATA_PATH}"]

+ # VOLUME ["${HTTPD_LOG_PATH}"]

+ 

+ CMD ["/usr/bin/run-httpd"]

file added
+1
@@ -0,0 +1,1 @@ 

+ Dockerfile 

\ No newline at end of file

file added
+1
@@ -0,0 +1,1 @@ 

+ root/usr/share/container-scripts/httpd/README.md 

\ No newline at end of file

file added
+1
@@ -0,0 +1,1 @@ 

+ README.md 

\ No newline at end of file

@@ -0,0 +1,3 @@ 

+ # This will make scl collection binaries work out of box.

+ unset BASH_ENV PROMPT_COMMAND ENV

+ source scl_source enable httpd24

@@ -0,0 +1,18 @@ 

+ #!/bin/bash

+ 

+ set -eu

+ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ # Check whether we run as s2i

+ if ! [ -v HTTPD_RUN_BY_S2I ] && runs_privileged ; then

+   config_privileged

+ else

+   # We run as non-root or as s2i

+   config_non_privileged

+   generate_container_user

+ fi

+ 

+ process_extending_files ${HTTPD_APP_ROOT}/src/httpd-pre-init/ ${HTTPD_CONTAINER_SCRIPTS_PATH}/pre-init/

+ 

+ exec httpd -D FOREGROUND $@

@@ -0,0 +1,44 @@ 

+ #!/bin/bash

+ 

+ set -e

+ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ # compatibility symlinks so we hide SCL paths

+ if [ -v HTTPD_SCL ] ; then

+   # /opt/rh/httpd24/root/etc/httpd will be symlink to /etc/httpd

+   mv /opt/rh/httpd24/root/etc/httpd /etc/httpd

+   ln -s /etc/httpd /opt/rh/httpd24/root/etc/httpd

+ 

+   # /opt/rh/httpd24/root/var/run/httpd will be symlink to /var/run/httpd

+   mv /opt/rh/httpd24/root/var/run/httpd /var/run/httpd

+   ln -s /var/run/httpd /opt/rh/httpd24/root/var/run/httpd

+ 

+   # /opt/rh/httpd24/root/var/www will be symlink to /var/www

+   rm -rf /var/www

+   mv /opt/rh/httpd24/root/var/www /var/www

+   ln -s /var/www /opt/rh/httpd24/root/var/www

+ fi

+ 

+ mkdir -p ${HTTPD_CONFIGURATION_PATH}

+ chmod -R a+rwx ${HTTPD_MAIN_CONF_PATH}

+ chmod -R a+rwx ${HTTPD_MAIN_CONF_D_PATH}

+ chmod -R a+rwx ${HTTPD_MAIN_CONF_MODULES_D_PATH}

+ mkdir -p ${HTTPD_APP_ROOT}/etc

+ chmod -R a+rwx ${HTTPD_APP_ROOT}/etc

+ chmod -R a+rwx ${HTTPD_VAR_RUN}

+ chown -R 1001:0 ${HTTPD_APP_ROOT}

+ chown -R 1001:0 ${HTTPD_DATA_PATH}

+ chmod -R g+rwx ${HTTPD_LOG_PATH}

+ chown -R 1001:0 ${HTTPD_LOG_PATH}

+ 

+ # remove bundled key pair and create new dir, where we store it

+ rm -f /etc/pki/tls/certs/localhost.crt 

+ rm -f /etc/pki/tls/private/localhost.key

+ mkdir -p $HTTPD_TLS_CERT_PATH

+ chmod -R a+rwx $HTTPD_TLS_CERT_PATH

+ 

+ mkdir -p ${HTTPD_CONTAINER_SCRIPTS_PATH}/pre-init

+ 

+ config_general

+ 

@@ -0,0 +1,248 @@ 

+ Apache HTTP Server 2.4 Container Image

+ ======================================

+ 

+ This container image includes Apache HTTP Server 2.4 for OpenShift and general usage.

+ Users can choose between RHEL, CentOS and Fedora based images.

+ The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/),

+ the CentOS images are available on [Quay.io](https://quay.io/organization/centos7),

+ and the Fedora images are available in [Fedora Registry](https://registry.fedoraproject.org/).

+ The resulting image can be run using [podman](https://github.com/containers/libpod).

+ 

+ Note: while the examples in this README are calling `podman`, you can replace any such calls by `docker` with the same arguments

+ 

+ Description

+ -----------

+ 

+ Apache HTTP Server 2.4 available as container, is a powerful, efficient,

+ and extensible web server. Apache supports a variety of features, many implemented as compiled modules

+ which extend the core functionality.

+ These can range from server-side programming language support to authentication schemes.

+ Virtual hosting allows one Apache installation to serve many different Web sites."

+ 

+ 

+ Usage in OpenShift

+ ------------------

+ In this example, we assume that you are using the `rhel8/httpd-24` image, available through the `httpd:24` imagestream tag in Openshift.

+ To build a simple [httpd-sample-app](https://github.com/sclorg/httpd-ex.git) application in Openshift:

+ 

+ ```

+ oc new-app httpd:24~https://github.com/sclorg/httpd-ex.git

+ ```

+ 

+ To access the application:

+ ```

+ $ oc get pods

+ $ oc exec <pod> -- curl 127.0.0.1:8080

+ ```

+ 

+ Source-to-Image framework and scripts

+ -------------------------------------

+ This image supports the [Source-to-Image](https://docs.openshift.com/container-platform/3.11/creating_images/s2i.html)

+ (S2I) strategy in OpenShift. The Source-to-Image is an OpenShift framework

+ which makes it easy to write images that take application source code as

+ an input, use a builder image like this httpd container image, and produce

+ a new image that runs the assembled application as an output.

+ 

+ To support the Source-to-Image framework, important scripts are included in the builder image:

+ 

+ * The `/usr/libexec/s2i/run` script is set as the default command in the resulting container image (the new image with the application artifacts).

+ 

+ * The `/usr/libexec/s2i/assemble` script inside the image is run to produce a new image with the application artifacts. The script takes sources of a given application and places them into appropriate directories inside the image. The structure of httpd-app can look like this:

+ 

+ **`./httpd-cfg`**  

+        Can contain additional Apache configuration files (`*.conf`)

+ 

+ **`./httpd-pre-init`**  

+        Can contain shell scripts (`*.sh`) that are sourced before `httpd` is started

+ 

+ **`./httpd-ssl`**  

+        Can contain user's own SSL certificate (in the `certs/` subdirectory) and a key (in the `private/` subdirectory)

+ 

+ **`./`**  

+        Application source code

+ 

+ 

+ Build an application using a Dockerfile

+ ---------------------------------------

+ Compared to the Source-to-Image strategy, using a Dockerfile is a more

+ flexible way to build an httpd container image with an application.

+ Use a Dockerfile when Source-to-Image is not sufficiently flexible for you or

+ when you build the image outside of the OpenShift environment.

+ 

+ To use the httpd image in a Dockerfile, follow these steps:

+ 

+ #### 1. Pull a base builder image to build on

+ 

+ ```

+ podman pull rhel8/httpd-24

+ ```

+ 

+ #### 2. Pull an application code

+ 

+ An example application available at https://github.com/sclorg/httpd-ex.git is used here. To adjust the example application, clone the repository.

+ 

+ ```

+ git clone https://github.com/sclorg/httpd-ex.git app-src

+ ```

+ 

+ #### 3. Prepare an application inside a container

+ 

+ This step usually consists of at least these parts:

+ 

+ * putting the application source into the container

+ * moving certificates to the correct place (if available in the application source code)

+ * setting the default command in the resulting image

+ 

+ For all these three parts, you can either set up all manually and use the `httpd` or `run-httpd` commands explicitly in the Dockerfile ([3.1.](#31-to-use-own-setup-create-a-dockerfile-with-this-content)), or you can use the Source-to-Image scripts inside the image ([3.2.](#32-to-use-the-source-to-image-scripts-and-build-an-image-using-a-dockerfile-create-a-dockerfile-with-this-content). For more information about these scripts, which enable you to set-up and run the httpd daemon, see the "Source-to-Image framework and scripts" section above.

+ 

+ ##### 3.1. To use your own setup, create a Dockerfile with this content:

+ ```

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD app-src/index.html /var/www/html/index.html

+ 

+ # The run script uses standard ways to run the application

+ CMD run-httpd

+ ```

+ 

+ ##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content:

+ ```

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources to a directory where the assemble script expects them

+ # and set permissions so that the container runs without the root access

+ USER 0

+ ADD app-src/index.html /tmp/src/index.html

+ RUN chown -R 1001:0 /tmp/src

+ USER 1001

+ 

+ # Let the assemble script install the dependencies

+ RUN /usr/libexec/s2i/assemble

+ 

+ # The run script uses standard ways to run the application

+ CMD /usr/libexec/s2i/run

+ ```

+ 

+ #### 4. Build a new image from a Dockerfile prepared in the previous step

+ 

+ ```

+ podman build -t httpd-app .

+ ```

+ 

+ #### 5. Run the resulting image with the final application

+ 

+ ```

+ podman run -d httpd-app

+ ```

+ 

+ 

+ Direct usage with a mounted directory

+ -------------------------------------

+ 

+ An example of the data on the host for both the examples above, which is served by

+ The Apache HTTP web server:

+ 

+ ```

+ $ ls -lZ /wwwdata/html

+ -rw-r--r--. 1 1001 1001 54321 Jan 01 12:34 index.html

+ -rw-r--r--. 1 1001 1001  5678 Jan 01 12:34 page.html

+ ```

+ 

+ If you want to run the image directly and mount the static pages available in the `/wwwdata/` directory on the host

+ as a container volume, execute the following command:

+ 

+ ```

+ $ podman run -d --name httpd -p 8080:8080 -v /wwwdata:/var/www:Z rhel8/httpd-24

+ ```

+ 

+ This creates a container named `httpd` running the Apache HTTP Server, serving data from

+ ` the /wwwdata/` directory. Port 8080 is exposed and mapped to the host.

+ 

+ 

+ 

+ Environment variables and volumes

+ ---------------------------------

+ 

+ The Apache HTTP Server container image supports the following configuration variable, which can be set by using the `-e` option with the podman run command:

+ 

+ **`HTTPD_LOG_TO_VOLUME`**  

+        By default, httpd logs into standard output, so the logs are accessible by using the podman logs command. When `HTTPD_LOG_TO_VOLUME` is set, httpd logs into `/var/log/httpd24`, which can be mounted to host system using the container volumes. This option is only allowed when container is run as UID 0.

+ 

+ **`HTTPD_MPM`**

+        The variable `HTTPD_MPM` can be set to change the default Multi-Processing Module (MPM) from the package default MPM.

+ 

+ 

+ If you want to run the image and mount the log files into `/wwwlogs` on the host

+ as a container volume, execute the following command:

+ 

+ ```

+ $ podman run -d -u 0 -e HTTPD_LOG_TO_VOLUME=1 --name httpd -v /wwwlogs:/var/log/httpd24:Z rhel8/httpd-24

+ ```

+ 

+ To run an image using the `event` MPM (rather than the default `prefork`), execute the following command:

+ 

+ ```

+ $ podman run -d -e HTTPD_MPM=event --name httpd rhel8/httpd-24

+ ```

+ 

+ You can also set the following mount points by passing the `-v /host:/container` flag to podman.

+ 

+ **`/var/www`**  

+        Apache HTTP Server data directory

+ 

+ **`/var/log/httpd24`**  

+        Apache HTTP Server log directory (available only when running as root, path `/var/log/httpd` is used in case of Fedora based image)

+ 

+ 

+ **Notice: When mouting a directory from the host into the container, ensure that the mounted

+ directory has the appropriate permissions and that the owner and group of the directory

+ matches the user UID or name which is running inside the container.**

+ 

+ Default SSL certificates

+ ------------------------

+ 

+ Default SSL certificates are generated when Apache HTTP server container is started for the first time or own SSL certificates were not provided (see bolow how to provide them). SSL certificates are not stored in the base image but generated, so each container will have unique default SSL key pair. SSL certificate/key are stored in /etc/httpd/tls directory:

+ 

+     /etc/httpd/tls/localhost.key

+     /etc/httpd/tls/localhost.crt

+ 

+ 

+ Using own SSL certificates

+ --------------------------

+ In order to provide own SSL certificates for securing the connection with SSL, use the extending feature described above. In particular, put the SSL certificates into a separate directory inside your application:

+ 

+     ./httpd-ssl/certs/server-cert-selfsigned.pem

+     ./httpd-ssl/private/server-key.pem

+ 

+ The default behaviour is to look for the certificate and the private key in subdirectories certs/ and private/; those files will be used for the ssl settings in the httpd.

+ 

+ 

+ Default user

+ ------------

+ 

+ By default, Apache HTTP Server container runs as UID 1001. That means the volume mounted directories for the files (if mounted using `-v` option) need to be prepared properly, so the UID 1001 can read them.

+ 

+ To run the container as a different UID, use `-u` option. For example if you want to run the container as UID 1234, execute the following command:

+ 

+ ```

+ podman run -d -u 1234 rhel8/httpd-24

+ ```

+ 

+ To log into a volume mounted directory, the container needs to be run as UID 0 (see above).

+ 

+ 

+ Troubleshooting

+ ---------------

+ The httpd deamon in the container logs to the standard output by default, so the log is available in the container log. The log can be examined by running:

+ 

+     podman logs <container>

+ 

+ 

+ See also

+ --------

+ Dockerfile and other sources for this container image are available on

+ https://github.com/sclorg/httpd-container.

+ In that repository, the Dockerfile for CentOS7 is called Dockerfile, the Dockerfile

+ for RHEL7 is called Dockerfile.rhel7, the Dockerfile for RHEL8 is called Dockerfile.rhel8,

+ and the Dockerfile for Fedora is called Dockerfile.fedora.

@@ -0,0 +1,207 @@ 

+ # Set of functions used in other scripts

+ 

+ if head "/etc/redhat-release" | grep -q "^Red Hat Enterprise Linux release 8"; then

+   HTTPCONF_LINENO=154

+ else

+   HTTPCONF_LINENO=151

+ fi

+ 

+ gen_ssl_certs() {

+   local sslcert=$HTTPD_TLS_CERT_PATH/localhost.crt

+   local sslkey=$HTTPD_TLS_CERT_PATH/localhost.key

+   local fqdn=`hostname`

+ 

+   # A >59 char FQDN means "root@FQDN" exceeds 64-char max length for emailAddress

+   if [ "x${fqdn}" = "x" -o ${#fqdn} -gt 59 ]; then

+     fqdn=localhost.localdomain

+   fi

+ 

+   if [ -f ${sslcert} -o -f ${sslkey} ]; then

+     return 0

+   fi

+ 

+   echo "---> Generating SSL key pair for httpd..."

+   if [ -x "/usr/bin/sscg" ]; then

+     sscg -q                                                           \

+        --cert-file           $sslcert                                 \

+        --cert-key-file       $sslkey                                  \

+        --ca-file             $sslcert                                 \

+        --lifetime            365                                      \

+        --hostname            $fqdn                                    \

+        --email               root@$fqdn

+   else

+     openssl genrsa -rand /proc/apm:/proc/cpuinfo:/proc/dma:/proc/filesystems:/proc/interrupts:/proc/ioports:/proc/pci:/proc/rtc:/proc/uptime 2048 > ${sslkey} 2> /dev/null

+ 

+     cat << EOF | openssl req -new -key ${sslkey} \

+               -x509 -sha256 -days 365 -set_serial $RANDOM -extensions v3_req \

+               -out ${sslcert} 2>/dev/null

+ --

+ SomeState

+ SomeCity

+ SomeOrganization

+ SomeOrganizationalUnit

+ ${fqdn}

+ root@${fqdn}

+ EOF

+    fi

+ 

+    chmod 644 ${sslcert}

+    chmod 644 ${sslkey}

+ }

+ 

+ config_general() {

+   sed -i -e 's/^Listen 80/Listen 0.0.0.0:8080/' ${HTTPD_MAIN_CONF_PATH}/httpd.conf && \

+   sed -i -e ${HTTPCONF_LINENO}'s%AllowOverride None%AllowOverride All%' ${HTTPD_MAIN_CONF_PATH}/httpd.conf && \

+   sed -i -e 's/^Listen 443/Listen 0.0.0.0:8443/' ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf

+   sed -i -e 's/_default_:443/_default_:8443/' ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf

+ 

+   # do sed for SSLCertificateFile and SSLCertificateKeyFile

+   sed -i -e "s|^SSLCertificateFile .*$|SSLCertificateFile ${HTTPD_TLS_CERT_PATH}/localhost.crt|" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf

+   sed -i -e "s|^SSLCertificateKeyFile .*$|SSLCertificateKeyFile ${HTTPD_TLS_CERT_PATH}/localhost.key|" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf

+ }

+ 

+ config_log_to_stdout() {

+   sed -ri " s!^(\s*CustomLog)\s+\S+!\1 |/usr/bin/cat!g; s!^(\s*ErrorLog)\s+\S+!\1 |/usr/bin/cat!g;" ${HTTPD_MAIN_CONF_PATH}/httpd.conf

+   sed -ri " s!^(\s*CustomLog)\s+\S+!\1 |/usr/bin/cat!g; s!^(\s*TransferLog)\s+\S+!\1 |/usr/bin/cat!g; s!^(\s*ErrorLog)\s+\S+!\1 |/usr/bin/cat!g;" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf

+ }

+ 

+ runs_privileged() {

+   test "$(id -u)" == "0"

+   return $?

+ }

+ 

+ config_privileged() {

+   # Change the s2i permissions back to the normal ones

+   chmod 644 ${HTTPD_MAIN_CONF_PATH}/* && \

+   chmod 755 ${HTTPD_MAIN_CONF_PATH} && \

+   chmod 644 ${HTTPD_MAIN_CONF_D_PATH}/* && \

+   chmod 755 ${HTTPD_MAIN_CONF_D_PATH} && \

+   chmod 644 ${HTTPD_MAIN_CONF_MODULES_D_PATH}/* && \

+   chmod 755 ${HTTPD_MAIN_CONF_MODULES_D_PATH} && \

+   chmod 600 ${HTTPD_TLS_CERT_PATH}/localhost.crt && \

+   chmod 600 ${HTTPD_TLS_CERT_PATH}/localhost.key && \

+   chmod 710 ${HTTPD_VAR_RUN}

+ 

+   if ! [ -v HTTPD_LOG_TO_VOLUME ] ; then

+     config_log_to_stdout

+   fi

+ }

+ 

+ config_s2i() {

+   sed -i -e "s%^DocumentRoot \"${HTTPD_DATA_ORIG_PATH}/html\"%DocumentRoot \"${HTTPD_APP_ROOT}/src\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf

+   sed -i -e "s%^<Directory \"${HTTPD_DATA_ORIG_PATH}/html\"%<Directory \"${HTTPD_APP_ROOT}/src\"%" ${HTTPD_MAIN_CONF_PATH}/httpd.conf

+   echo "IncludeOptional ${HTTPD_CONFIGURATION_PATH}/*.conf" >> ${HTTPD_MAIN_CONF_PATH}/httpd.conf && \

+   head -n${HTTPCONF_LINENO} ${HTTPD_MAIN_CONF_PATH}/httpd.conf | tail -n1 | grep "AllowOverride All" || exit

+ }

+ 

+ config_non_privileged() {

+   sed -i -e "s/^User apache/User default/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf

+   sed -i -e "s/^Group apache/Group root/" ${HTTPD_MAIN_CONF_PATH}/httpd.conf

+   config_log_to_stdout

+   if [ -v HTTPD_LOG_TO_VOLUME ] ; then

+     echo "Error: Option HTTPD_LOG_TO_VOLUME is only valid for privileged runs (as UID 0)."

+     return 1

+   fi

+ }

+ 

+ config_mpm() {

+   if [ -v HTTPD_MPM -a -f ${HTTPD_MAIN_CONF_MODULES_D_PATH}/00-mpm.conf ]; then

+     local mpmconf=${HTTPD_MAIN_CONF_MODULES_D_PATH}/00-mpm.conf

+     sed -i -e 's,^LoadModule,#LoadModule,' ${mpmconf}

+     sed -i -e "/LoadModule mpm_${HTTPD_MPM}/s,^#LoadModule,LoadModule," ${mpmconf}

+     echo "---> Set MPM to ${HTTPD_MPM} in ${mpmconf}"

+   fi

+ }

+ 

+ # get_matched_files finds file for image extending

+ function get_matched_files() {

+   local custom_dir default_dir

+   custom_dir="$1"

+   default_dir="$2"

+   files_matched="$3"

+   find "$default_dir" -maxdepth 1 -type f -name "$files_matched" -printf "%f\n"

+   [ -d "$custom_dir" ] && find "$custom_dir" -maxdepth 1 -type f -name "$files_matched" -printf "%f\n"

+ }

+ 

+ # process_extending_files process extending files in $1 and $2 directories

+ # - source all *.sh files

+ #   (if there are files with same name source only file from $1)

+ function process_extending_files() {

+   local custom_dir default_dir

+   custom_dir=$1

+   default_dir=$2

+   while read filename ; do

+     echo "=> sourcing $filename ..."

+     # Custom file is prefered

+     if [ -f $custom_dir/$filename ]; then

+       source $custom_dir/$filename

+     elif [ -f $default_dir/$filename ]; then 

+       source $default_dir/$filename

+     fi

+   done <<<"$(get_matched_files "$custom_dir" "$default_dir" '*.sh' | sort -u)"

+ }

+ 

+ # Set current user in nss_wrapper

+ generate_container_user() {

+   local passwd_output_dir="${HTTPD_APP_ROOT}/etc"

+ 

+   export USER_ID=$(id -u)

+   export GROUP_ID=$(id -g)

+   envsubst < ${HTTPD_CONTAINER_SCRIPTS_PATH}/passwd.template > ${passwd_output_dir}/passwd

+   export LD_PRELOAD=libnss_wrapper.so

+   export NSS_WRAPPER_PASSWD=${passwd_output_dir}/passwd

+   export NSS_WRAPPER_GROUP=/etc/group

+ }

+ 

+ # Copy config files from application to the location where httd expects them

+ # Param sets the directory where to look for files

+ process_config_files() {

+   local dir=${1:-.}

+   if [ -d ${dir}/httpd-cfg ]; then

+     echo "---> Copying httpd configuration files..."

+     if [ "$(ls -A ${dir}/httpd-cfg/*.conf)" ]; then

+       cp -v ${dir}/httpd-cfg/*.conf "${HTTPD_CONFIGURATION_PATH}"

+       rm -rf ${dir}/httpd-cfg

+     fi

+   else

+     if [ -d ${dir}/cfg ]; then

+       echo "---> Copying httpd configuration files from deprecated './cfg' directory, use './httpd-cfg' instead..."

+       if [ "$(ls -A ${dir}/cfg/*.conf)" ]; then

+         cp -v ${dir}/cfg/*.conf "${HTTPD_CONFIGURATION_PATH}"

+         rm -rf ${dir}/cfg

+       fi

+     fi

+   fi

+ }

+ 

+ # Copy SSL files provided in application source

+ process_ssl_certs() {

+   local dir=${1:-.}

+   if [ -d ${dir}/httpd-ssl/private ] && [ -d ${dir}/httpd-ssl/certs ]; then

+     echo "---> Moving the httpd-ssl directory included in the source to a directory that isn't exposed by httpd..."

+     mv ${dir}/httpd-ssl ${HTTPD_APP_ROOT}

+   fi

+   if [ -d ${HTTPD_APP_ROOT}/httpd-ssl/private ] && [ -d ${HTTPD_APP_ROOT}/httpd-ssl/certs ]; then

+     echo "---> Looking for SSL certs for httpd..."

+     local ssl_cert="$(ls -A ${HTTPD_APP_ROOT}/httpd-ssl/certs/*.pem | head -n 1)"

+     local ssl_private="$(ls -A ${HTTPD_APP_ROOT}/httpd-ssl/private/*.pem | head -n 1)"

+     if [ -f "${ssl_cert}" ] ; then

+       # do sed for SSLCertificateFile and SSLCertificateKeyFile

+       echo "---> Setting SSL cert file for httpd..."

+       sed -i -e "s|^SSLCertificateFile .*$|SSLCertificateFile ${ssl_cert}|" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf

+       if [ -f "${ssl_private}" ]; then

+         echo "---> Setting SSL key file for httpd..."

+         sed -i -e "s|^SSLCertificateKeyFile .*$|SSLCertificateKeyFile ${ssl_private}|" ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf

+       else

+         echo "---> Removing SSL key file settings for httpd..."

+         sed -i '/^SSLCertificateKeyFile .*/d'  ${HTTPD_MAIN_CONF_D_PATH}/ssl.conf

+       fi

+     else

+       # Generate TLS key pair if no SSL cert was found

+       gen_ssl_certs

+     fi

+   else

+     gen_ssl_certs

+   fi

+ }

+ 

@@ -0,0 +1,15 @@ 

+ root:x:0:0:root:/root:/bin/bash

+ bin:x:1:1:bin:/bin:/sbin/nologin

+ daemon:x:2:2:daemon:/sbin:/sbin/nologin

+ adm:x:3:4:adm:/var/adm:/sbin/nologin

+ lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

+ sync:x:5:0:sync:/sbin:/bin/sync

+ shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown

+ halt:x:7:0:halt:/sbin:/sbin/halt

+ mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

+ operator:x:11:0:operator:/root:/sbin/nologin

+ games:x:12:100:games:/usr/games:/sbin/nologin

+ ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

+ nobody:x:99:99:Nobody:/:/sbin/nologin

+ default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/sbin/nologin

+ apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin

@@ -0,0 +1,4 @@ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ # Copy config files from application to the location where httpd expects them

+ process_config_files

@@ -0,0 +1,4 @@ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ # Copy SSL files provided in application source

+ process_ssl_certs

@@ -0,0 +1,3 @@ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ config_mpm

@@ -0,0 +1,4 @@ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ # Copy config files from application to the location where httd expects them

+ process_config_files ${HTTPD_APP_ROOT}/src

@@ -0,0 +1,4 @@ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ # Copy SSL files provided in application source

+ process_ssl_certs ${HTTPD_APP_ROOT}/src

file added
+20
@@ -0,0 +1,20 @@ 

+ #!/bin/bash

+ 

+ set -e

+ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ echo "---> Enabling s2i support in httpd24 image"

+ 

+ config_s2i

+ 

+ echo "---> Installing application source"

+ cp -af /tmp/src/. ./

+ 

+ # Fix source directory permissions

+ fix-permissions ./

+ 

+ process_extending_files ${HTTPD_APP_ROOT}/src/httpd-post-assemble/ ${HTTPD_CONTAINER_SCRIPTS_PATH}/post-assemble/

+ 

+ # Fix source directory permissions

+ fix-permissions ./

file added
+7
@@ -0,0 +1,7 @@ 

+ #!/bin/bash

+ 

+ source ${HTTPD_CONTAINER_SCRIPTS_PATH}/common.sh

+ 

+ export HTTPD_RUN_BY_S2I=1

+ 

+ exec run-httpd $@

file added
+17
@@ -0,0 +1,17 @@ 

+ #!/bin/sh

+ 

+ DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'`

+ NAMESPACE=centos

+ [[ $DISTRO =~ rhel* ]] && NAMESPACE=rhscl

+ 

+ cat <<EOF

+ This is a S2I ${IMAGE_DESCRIPTION} ${DISTRO} base image:

+ To use it, install S2I: https://github.com/openshift/source-to-image

+ 

+ Sample invocation:

+ 

+ s2i build https://github.com/sclorg/httpd-container.git --context-dir=examples/sample-test-app/ ${NAMESPACE}/httpd-24-${DISTRO}7 httpd-sample-app

+ 

+ You can then run the resulting image via:

+ podman run -p 8080:8080 httpd-sample-app

+ EOF

@@ -0,0 +1,101 @@ 

+ #!/bin/env python3

+ 

+ # MIT License

+ #

+ # Copyright (c) 2018-2019 Red Hat, Inc.

+ 

+ # Permission is hereby granted, free of charge, to any person obtaining a copy

+ # of this software and associated documentation files (the "Software"), to deal

+ # in the Software without restriction, including without limitation the rights

+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

+ # copies of the Software, and to permit persons to whom the Software is

+ # furnished to do so, subject to the following conditions:

+ #

+ # The above copyright notice and this permission notice shall be included in all

+ # copies or substantial portions of the Software.

+ #

+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

+ # SOFTWARE.

+ 

+ import sys

+ import json

+ import logging

+ import os

+ 

+ from pathlib import Path

+ from typing import Dict, List, Any

+ 

+ IMAGESTREAMS_DIR: str = "imagestreams"

+ 

+ 

+ class ImageStreamChecker(object):

+     version: str = ""

+ 

+     def __init__(self, version: str):

+         self.version = version

+         self.results: Dict[Any, Any] = {}

+ 

+     def load_json_file(self, filename: Path) -> Any:

+         with open(str(filename)) as f:

+             data = json.load(f)

+             isinstance(data, Dict)

+             return data

+ 

+     def check_version(self, json_dict: Dict[Any, Any]) -> List[str]:

+         res = []

+         for tags in json_dict["spec"]["tags"]:

+             # The name can be"<stream>" or "<stream>-elX" or "<stream>-ubiX"

+             if tags["name"] == self.version or tags["name"].startswith(

+                 self.version + "-"

+             ):

+                 res.append(tags)

+         return res

+ 

+     def check_latest_tag(self, json_dict: Dict[Any, Any]) -> bool:

+         latest_tag_correct: bool = False

+         for tags in json_dict["spec"]["tags"]:

+             if tags["name"] != "latest":

+                 continue

+             # The latest can link to either "<stream>" or "<stream>-elX" or "<stream>-ubiX"

+             if tags["from"]["name"] == self.version or tags["from"]["name"].startswith(

+                 self.version + "-"

+             ):

+                 latest_tag_correct = True

+         return latest_tag_correct

+ 

+     def check_imagestreams(self) -> int:

+         p = Path(".")

+         json_files = p.glob(f"{IMAGESTREAMS_DIR}/*.json")

+         if not json_files:

+             print(f"No json files present in {IMAGESTREAMS_DIR}.")

+             return 0

+         for f in json_files:

+             if os.environ.get("TARGET") in ("rhel7", "centos7") and "aarch64" in str(f):

+                 print("Imagestream aarch64 is not supported on rhel7")

+                 continue

+             print(f"Checking file {str(f)}.")

+             json_dict = self.load_json_file(f)

+             if not (self.check_version(json_dict) and self.check_latest_tag(json_dict)):

+                 print(

+                     f"The latest version is not present in {str(f)} or in latest tag."

+                 )

+                 self.results[f] = False

+         if self.results:

+             return 1

+         print("Imagestreams contains the latest version.")

+         return 0

+ 

+ 

+ if __name__ == "__main__":

+     if len(sys.argv) != 2:

+         logging.fatal("%s: %s", sys.argv[0], "VERSION as an argument was not provided")

+         sys.exit(1)

+ 

+     print(f"Version to check is {sys.argv[1]}.")

+     isc = ImageStreamChecker(version=sys.argv[1])

+     sys.exit(isc.check_imagestreams())

@@ -0,0 +1,7 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD app-src/index.html /var/www/html/index.html

+ 

+ # Run script uses standard ways to run the application

+ CMD run-httpd

@@ -0,0 +1,25 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # This image supports the Source-to-Image

+ # (see more at https://docs.openshift.com/container-platform/3.11/creating_images/s2i.html).

+ # In order to support the Source-to-Image framework, there are some interesting

+ # scripts inside the builder image, that can be run in a Dockerfile directly as well:

+ # * The `/usr/libexec/s2i/assemble` script inside the image is run in order

+ #   to produce a new image with the application artifacts.

+ #   The script takes sources of a given application and places them into

+ #   appropriate directories inside the image.

+ # * The `/usr/libexec/s2i/run` script executes the application and is set as

+ #   a default command in the resulting container image.

+ 

+ # Add application sources to a directory that the assemble script expects them

+ # and set permissions so that the container runs without root access

+ USER 0

+ ADD app-src/index.html /tmp/src/index.html

+ RUN chown -R 1001:0 /tmp/src

+ USER 1001

+ 

+ # Let the assemble script to install the dependencies

+ RUN /usr/libexec/s2i/assemble

+ 

+ # Run script uses standard ways to run the application

+ CMD /usr/libexec/s2i/run

@@ -0,0 +1,50 @@ 

+ # Examples of HTTPD container image usage

+ =========================================

+ This directory includes several examples of how to use the httpd container to serve static HTML content.

+ 

+ Building and deploying in OpenShift

+ -------------------

+ ```

+ oc new-app rhel8/httpd-24~https://github.com/sclorg/httpd-ex.git

+ ```

+ 

+ Building with s2i

+ -------------------

+ ```

+ s2i build https://github.com/sclorg/httpd-container.git --context-dir=examples/sample-test-app/ centos/httpd-24-centos7 httpd-sample-app

+ ```

+ The `s2i` binary can be obtained from https://github.com/openshift/source-to-image.

+ 

+ 

+ Dockerfile examples

+ -------------------

+ 

+ This directory also contains example Dockerfiles that demonstrate how to use the image with a Dockerfile and `docker build`, with an example application code available at https://github.com/sclorg/httpd-ex.git.

+ 

+ 1. Pull the source to the local machine first:

+ ```

+ git clone https://github.com/sclorg/httpd-ex.git app-src

+ ```

+ 

+ 2.a. Build a new image from a Dockerfile in this directory:

+ ```

+ docker build -f Dockerfile -t httpd-app .

+ ```

+ 

+ 2.b. Alternatively, build a new image from a Dockerfile.s2i in this directory; this Dockerfile uses the Source-to-Image scripts that are available in the image:

+ ```

+ docker build -f Dockerfile.s2i -t httpd-app .

+ ```

+ 

+ 3. Run the resulting image with the final application:

+ ```

+ docker run -ti --rm -p 8080:8080 -p 8443:8443 httpd-app

+ ```

+ 

+ 4. Get the example static content using curl:

+ ```

+ curl http://127.0.0.1:8080

+ curl --insecure https://127.0.0.1:8443

+ ```

+ 

+ Note: The use of the `--insecure` option is caused by using self-signed certificates for HTTPS by default.

@@ -0,0 +1,8 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD index.html /var/www/html/index.html

+ 

+ # Run script uses standard ways to run the application and also generates

+ # self-signed certificates in order to allow SSL-protected connection

+ CMD run-httpd

@@ -0,0 +1,11 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD . /tmp/src

+ 

+ # Assemble script installs the dependencies

+ # TODO: describe what assemble does, and link to https://docs.openshift.com/container-platform/3.11/creating_images/s2i.html

+ RUN /usr/libexec/s2i/assemble

+ 

+ # Run script uses standard ways to run the application

+ CMD /usr/libexec/s2i/run

@@ -0,0 +1,1 @@ 

+ This is a sample s2i application with static content.

@@ -0,0 +1,13 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD index.html /var/www/html/index.html

+ 

+ # Add self-signed certificate files

+ # TODO: Test that we do not use a newly generated certs by:

+ # podman exec ... curl -kvvI https://127.0.0.1:8443 must match "start date: Dec  3 23:33:57 2017 GMT" or whatever the testing certs have

+ ADD httpd-ssl "${APP_ROOT}/httpd-ssl"

+ 

+ # Run script uses standard ways to run the application and also puts

+ # the certificate files into a correct directory

+ CMD run-httpd

@@ -0,0 +1,19 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD index.html /tmp/src/index.html

+ 

+ # Add self-signed certificate files

+ ADD httpd-ssl "/tmp/src/httpd-ssl"

+ 

+ # Assemble script installs the dependencies

+ # TODO: describe what assemble does, and link to https://docs.openshift.com/container-platform/3.11/creating_images/s2i.html

+ RUN /usr/libexec/s2i/assemble

+ 

+ USER 0

+ RUN sed -i -e '1 a\

+ set -x' /usr/bin/run-httpd

+ USER 1001

+ 

+ # Run script uses standard ways to run the application

+ CMD /usr/libexec/s2i/run

@@ -0,0 +1,20 @@ 

+ -----BEGIN CERTIFICATE-----

+ MIIDWjCCAkKgAwIBAgIJAI4x7HuBG49oMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNV

+ BAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQg

+ Q29tcGFueSBMdGQwHhcNMTcxMjAzMjMzMzU3WhcNMTgwMTAyMjMzMzU3WjBCMQsw

+ CQYDVQQGEwJYWDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZh

+ dWx0IENvbXBhbnkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA

+ vH4Vdq0a3UWUQd8Z6s2csxhxjAOyUx0rszGL0m3uTjQido6JRBdjN2dXiZc3LFo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Sbcp7eI1+koYp65eyN37q0ZuTnlWbC0MdDQY9APgKQKBgQCb

+ HqaKNXLUe2XDkGSf2ygOumXSanZS7vt9dsLg59bQ9DyjljBfogglNcBAXTqFOtxK

+ uXbyAYnn3+U399BKjYSjQXJRioj6tRn4xs2DiooAjlwtx9qQouS+fHLLns54iqVQ

+ oltTbo00eUV3gcGt4iWKNLrxdxUBIaOqaY0HEMDdDQKBgQCRvcHDF7JSPuBiO3Tw

+ PSOUD4q6dD/dhI+X2ZKg83w94SZXXms6eMSbedUkLoJ8TDunmdRUUWb6rgP/pJwr

+ zKRTskItF15i9IWCwC6jBrSfx5n2JcSoBALyc0aR9heF0GQjWwqURd+PC/msomrW

+ z9SCl8mpQVFtBlui7PcnDLTFAg==

+ -----END PRIVATE KEY-----

@@ -0,0 +1,1 @@ 

+ SSL test works

@@ -0,0 +1,93 @@ 

+ {

+   "apiVersion": "v1",

+   "kind": "ImageStream",

+   "metadata": {

+     "annotations": {

+       "openshift.io/display-name": "Apache HTTP Server (httpd)"

+     },

+     "name": "httpd"

+   },

+   "spec": {

+     "tags": [

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) on CentOS 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version of Httpd available on OpenShift, including major version updates.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server (Latest)",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd"

+         },

+         "from": {

+           "kind": "ImageStreamTag",

+           "name": "2.4-el8"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "latest"

+       },

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) 2.4 on CentOS 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server 2.4 (CentOS 8)",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd",

+           "version": "2.4"

+         },

+         "from": {

+           "kind": "DockerImage",

+           "name": "docker.io/centos/httpd-24-centos8:latest"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "2.4-el8"

+       },

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) 2.4 on CentOS 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server 2.4 (CentOS 7)",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd",

+           "version": "2.4"

+         },

+         "from": {

+           "kind": "DockerImage",

+           "name": "quay.io/centos7/httpd-24-centos7:latest"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "2.4-el7"

+       },

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) 2.4 on CentOS 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server 2.4",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd,hidden",

+           "version": "2.4"

+         },

+         "from": {

+           "kind": "DockerImage",

+           "name": "quay.io/centos7/httpd-24-centos7:latest"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "2.4"

+       }

+     ]

+   }

+ }

@@ -0,0 +1,53 @@ 

+ {

+   "apiVersion": "v1",

+   "kind": "ImageStream",

+   "metadata": {

+     "annotations": {

+       "openshift.io/display-name": "Apache HTTP Server (httpd)"

+     },

+     "name": "httpd"

+   },

+   "spec": {

+     "tags": [

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) on RHEL. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version of Httpd available on OpenShift, including major version updates.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server (Latest)",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd"

+         },

+         "from": {

+           "kind": "ImageStreamTag",

+           "name": "2.4-el8"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "latest"

+       },

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) 2.4 on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server 2.4 (RHEL 8)",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd",

+           "version": "2.4"

+         },

+         "from": {

+           "kind": "DockerImage",

+           "name": "registry.redhat.io/rhel8/httpd-24"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "2.4-el8"

+       }

+     ]

+   }

+ }

@@ -0,0 +1,93 @@ 

+ {

+   "apiVersion": "v1",

+   "kind": "ImageStream",

+   "metadata": {

+     "annotations": {

+       "openshift.io/display-name": "Apache HTTP Server (httpd)"

+     },

+     "name": "httpd"

+   },

+   "spec": {

+     "tags": [

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) on RHEL. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version of Httpd available on OpenShift, including major version updates.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server (Latest)",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd"

+         },

+         "from": {

+           "kind": "ImageStreamTag",

+           "name": "2.4-el8"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "latest"

+       },

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) 2.4 on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server 2.4 (RHEL 8)",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd",

+           "version": "2.4"

+         },

+         "from": {

+           "kind": "DockerImage",

+           "name": "registry.redhat.io/rhel8/httpd-24"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "2.4-el8"

+       },

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) 2.4 on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server 2.4 (RHEL 7)",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd",

+           "version": "2.4"

+         },

+         "from": {

+           "kind": "DockerImage",

+           "name": "registry.redhat.io/rhscl/httpd-24-rhel7"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "2.4-el7"

+       },

+       {

+         "annotations": {

+           "description": "Build and serve static content via Apache HTTP Server (httpd) 2.4 on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/httpd-container/blob/master/2.4/README.md.",

+           "iconClass": "icon-apache",

+           "openshift.io/display-name": "Apache HTTP Server 2.4",

+           "openshift.io/provider-display-name": "Red Hat, Inc.",

+           "sampleRepo": "https://github.com/sclorg/httpd-ex.git",

+           "supports": "httpd",

+           "tags": "builder,httpd,hidden",

+           "version": "2.4"

+         },

+         "from": {

+           "kind": "DockerImage",

+           "name": "registry.redhat.io/rhscl/httpd-24-rhel7"

+         },

+         "referencePolicy": {

+           "type": "Local"

+         },

+         "name": "2.4"

+       }

+     ]

+   }

+ }

@@ -0,0 +1,1 @@ 

+ echo 'This content was replaced by pre-init script.' > ${HTTPD_APP_ROOT}/src/index.html

@@ -0,0 +1,1 @@ 

+ This is a sample s2i application with static content.

file added
+211
@@ -0,0 +1,211 @@ 

+ #!/usr/bin/env bash

+ 

+ set -e

+ IMAGE_NAME="${IMAGE_NAME:-rhscl/httpd-24-rhel7}"

+ 

+ THISDIR=$(dirname ${BASH_SOURCE[0]})

+ . ${THISDIR}/utils.sh

+ test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"

+ 

+ . "$test_dir/test-lib.sh"

+ 

+ function _container_is_scl() {

+   docker inspect --format='{{.Config.Env}}' "${1-$IMAGE_NAME}" | grep -q HTTPD_SCL

+   return $?

+ }

+ 

+ function update_overall() {

+     res="$1"

+     if [ "$res" != 0 ]; then

+         overall="$res"

+     fi

+ }

+ 

+ function run() {

+     cmd="$1"

+     expected_res="${2:-0}"

+     msg="${3:-Running command '$cmd'}"

+     set +e

+     run_command "$cmd" "$expected_res" "$msg"

+     res=$?

+     set -e

+     test "$res" -eq "$expected_res" && res=0 || res=1

+     update_overall $res

+     return $res

+ }

+ 

+ function run_default_page_test() {

+   # Check default page

+   run "ct_create_container test_default_page"

+   cip=$(ct_get_cip 'test_default_page')

+   run "ct_test_response '${cip}':8080 403 'Test Page for the (Apache )?HTTP Server on' 50"

+ }

+ 

+ function run_as_root_test() {

+   # Try running as root

+   CONTAINER_ARGS="--user 0" run "ct_create_container test_run_as_root"

+   cip=$(ct_get_cip 'test_run_as_root')

+   run "ct_test_response '${cip}':8080 403 'Test Page for the (Apache )?HTTP Server on'"

+ }

+ 

+ 

+ function run_log_to_volume_test() {

+   _run_invalid_log_volume_test

+   if _container_is_scl ; then

+     _run_log_to_volume_test old /var/log/httpd24

+   else

+     _run_log_to_volume_test new /var/log/httpd

+   fi

+ }

+ 

+ function _run_log_to_volume_test() {

+   # Check the HTTP_LOG_TO_VOLUME env variable

+   local variant=${1}

+   local volume_dir=${2}

+   local logs_dir=$(mktemp -d /tmp/httpd-test-volume-XXXXXX)

+   run "ls -d ${logs_dir} || mkdir ${logs_dir}" 0 'Create log directory'

+   run "chown -R 1001:1001 ${logs_dir}"

+   run "chcon -Rvt svirt_sandbox_file_t ${logs_dir}" 0 'Change SELinux context on the log dir'

+   CONTAINER_ARGS="-e HTTPD_LOG_TO_VOLUME=1 --user 0 -v ${logs_dir}:${volume_dir}" run "ct_create_container test_log_dir_${variant}"

+   cip=$(ct_get_cip "test_log_dir_${variant}")

+   run "ct_test_response '${cip}':8080 403 '.*' > /dev/null"

+   ls ${logs_dir} > output

+   run "grep -e '^access_log$' output" 0 "Checking that file access_log exists"

+   run "grep -e '^error_log$' output" 0 "Checking that file error_log exists"

+   run "grep -e '^ssl_access_log$' output" 0 "Checking that file ssl_access_log exists"

+   run "grep -e '^ssl_error_log$' output" 0 "Checking that file ssl_error_log exists"

+   run "grep -e '^ssl_request_log$' output" 0 "Checking that file ssl_request_log exists"

+ }

+ 

+ function _run_invalid_log_volume_test() {

+   # Check wrong usage of the HTTP_LOG_TO_VOLUME env variable

+   CONTAINER_ARGS="-e HTTPD_LOG_TO_VOLUME=1 --user 1001" run "ct_create_container test_log_dir_fail"

+   sleep 3

+   cid=$(ct_get_cid "test_log_dir_fail")

+   exit_status=$(docker inspect -f '{{.State.ExitCode}}' ${cid})

+   run "test $exit_status == 1" 0 "Checking that setting HTTPD_LOG_TO_VOLUME is not allowed if UID is not 0"

+ }

+ 

+ 

+ function run_data_volume_test() {

+   if _container_is_scl ; then

+      _run_data_volume_test old /opt/rh/httpd24/root/var/www

+   fi

+    _run_data_volume_test new /var/www

+ }

+ 

+ function _run_data_volume_test() {

+   local variant=${1}

+   local volume_dir=${2}

+   # Test that docker volume for DocumentRoot works

+   datadir=$(mktemp -d /tmp/httpd-test-data-XXXXXX)

+   run "mkdir -p ${datadir}/html" 0 'Create document root'

+   run "echo hello > ${datadir}/html/index.html"

+   run "chown -R 1001:1001 ${datadir}"

+   run "chcon -Rvt svirt_sandbox_file_t ${datadir}/" 0 'Change SELinux context on the document root'

+   CONTAINER_ARGS="-v ${datadir}:${volume_dir}" run "ct_create_container test_doc_root_${variant}"

+   cip=$(ct_get_cip "test_doc_root_${variant}")

+   run "ct_test_response '${cip}:8080' 200 '^hello$'"

+ }

+ 

+ function _run_mpm_config_test() {

+   local mpm=$1

+   # Check worker MPM can be configured

+   CONTAINER_ARGS="-e HTTPD_MPM=$mpm --user 1001" run "ct_create_container test_mpm_${mpm}"

+   cid=$(ct_get_cid "test_mpm_$mpm")

+   cip=$(ct_get_cip "test_mpm_$mpm")

+   run "ct_test_response '${cip}:8080' 403 '.*'"

+   run "docker logs $cid | grep -s mpm_${mpm}':notice.*resuming normal operations'"

+ }

+ 

+ function run_mpm_config_test() {

+   for m in worker event prefork; do

+     _run_mpm_config_test $m

+   done

+ }

+ 

+ function run_s2i_test() {

+   # Test s2i use case

+   # Since we built the candidate image locally, we don't want S2I attempt to pull

+   # it from Docker hub

+   run "ct_s2i_usage ${IMAGE_NAME} ${s2i_args}" 0 "Testing 's2i usage'"

+   run "ct_s2i_build_as_df file://${test_dir}/sample-test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp ${s2i_args}" 0 "Testing 's2i build'"

+   CONTAINER_ARGS='--user 1000' IMAGE_NAME=${IMAGE_NAME}-testapp ct_create_container testing-app-s2i

+   cip=$(ct_get_cip 'testing-app-s2i')

+   run "ct_test_response '${cip}:8080' 200 'This is a sample s2i application with static content.'"

+ }

+ 

+ function run_pre_init_test() {

+   # Test s2i use case #2 - testing pre-init script

+   # Since we built the candidate image locally, we don't want S2I attempt to pull

+   # it from Docker hub

+   run "ct_s2i_build_as_df file://${test_dir}/pre-init-test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp2 ${s2i_args}" 0 "Testing 's2i build' with pre-init script"

+   CONTAINER_ARGS='--user 1000' IMAGE_NAME=${IMAGE_NAME}-testapp2 ct_create_container testing-app-pre-init

+   cip=$(ct_get_cip 'testing-app-pre-init')

+   run "ct_test_response '${cip}:8080' 200 'This content was replaced by pre-init script.'"

+ }

+ 

+ function run_self_cert_test() {

+   # Test s2i use case #3 - using own ssl certs

+   # Since we built the candidate image locally, we don't want S2I attempt to pull

+   # it from Docker hub

+   run "ct_s2i_build_as_df file://${test_dir}/self-signed-ssl ${IMAGE_NAME} ${IMAGE_NAME}-self-signed ${s2i_args}" 0 "Testing 's2i build' with self-signed cert"

+   CONTAINER_ARGS='--user 1000' IMAGE_NAME=${IMAGE_NAME}-self-signed ct_create_container testing-self-signed

+   cip=$(ct_get_cip 'testing-self-signed')

+   run "ct_test_response '${cip}:8080' 200 '.*'"

+   run "curl -k https://${cip}:8443 > output_ssl_cert"

+   run "fgrep -e 'SSL test works' output_ssl_cert"

+   echo | openssl s_client -showcerts -servername ${cip} -connect ${cip}:8443 2>/dev/null | openssl x509 -inform pem -noout -text >./servercert

+   openssl x509 -in ${test_dir}/self-signed-ssl/httpd-ssl/certs/server-cert-selfsigned.pem -inform pem -noout -text >./configcert

+   run "diff ./configcert ./servercert"

+   run "diff ./configcert ./servercert >cert.diff"

+ }

+ 

+ function run_all_tests() {

+   for test_case in $TEST_LIST; do

+     : "Running test $test_case"

+     $test_case

+   done;

+ }

+ 

+ function run_dockerfiles_test() {

+   run "ct_test_app_dockerfile examples/Dockerfile 'https://github.com/sclorg/httpd-ex.git' 'Welcome to your static httpd application on OpenShift' app-src" 0

+   run "ct_test_app_dockerfile examples/Dockerfile.s2i 'https://github.com/sclorg/httpd-ex.git' 'Welcome to your static httpd application on OpenShift' app-src" 0

+ }

+ 

+ ct_enable_cleanup

+ 

+ working_dir=`mktemp -d`

+ # copy example files that we need for run_dockerfiles_test

+ mkdir "$working_dir/examples"

+ cp -r "${THISDIR}"/examples/* "$working_dir"/examples

+ pushd "$working_dir" > /dev/null || exit 1

+ 

+ CID_FILE_DIR=$(mktemp --suffix=httpd_test_cidfiles -d)

+ 

+ s2i_args="--pull-policy=never"

+ 

+ overall=0

+ 

+ run "docker inspect $IMAGE_NAME >/dev/null || docker pull $IMAGE_NAME" 0

+ 

+ 

+ TEST_LIST="\

+ run_self_cert_test

+ run_default_page_test

+ run_as_root_test

+ run_log_to_volume_test

+ run_data_volume_test

+ run_s2i_test

+ run_pre_init_test

+ run_mpm_config_test

+ run_dockerfiles_test

+ "

+ 

+ test $# -eq 1 -a "${1-}" == --list && echo "$TEST_LIST" && exit 0

+ 

+ TEST_LIST=${@:-$TEST_LIST} run_all_tests

+ 

+ popd > /dev/null

+ 

+ exit "$overall"

file added
+1
@@ -0,0 +1,1 @@ 

+ run-openshift-local-cluster 

\ No newline at end of file

@@ -0,0 +1,37 @@ 

+ #!/bin/bash

+ #

+ # Test the httpd S2I image in OpenShift (remote cluster)

+ #

+ # IMAGE_NAME specifies a name of the candidate image used for testing.

+ # The image has to be available before this script is executed.

+ # VERSION specifies the major version of the httpd runtime in format of X.Y

+ # OS specifies RHEL version (e.g. OS=rhel7)

+ #

+ 

+ THISDIR=$(dirname ${BASH_SOURCE[0]})

+ 

+ source ${THISDIR}/test-lib-httpd.sh

+ source ${THISDIR}/test-lib-remote-openshift.sh

+ 

+ set -eo nounset

+ 

+ ct_os_set_ocp4

+ 

+ trap ct_os_cleanup EXIT SIGINT

+ 

+ ct_os_check_compulsory_vars

+ 

+ oc status || false "It looks like oc is not properly logged in."

+ 

+ # For testing on OpenShift 4 we use external registry

+ export CT_EXTERNAL_REGISTRY=true

+ 

+ test_httpd_integration "${IMAGE_NAME}"

+ 

+ # Check the imagestream

+ test_httpd_imagestream

+ 

+ OS_TESTSUITE_RESULT=0

+ 

+ # vim: set tabstop=2:shiftwidth=2:expandtab:

+ 

@@ -0,0 +1,8 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD index.html /var/www/html/index.html

+ 

+ # Run script uses standard ways to run the application and also generates

+ # self-signed certificates in order to allow SSL-protected connection

+ CMD run-httpd

@@ -0,0 +1,11 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD . /tmp/src

+ 

+ # Assemble script installs the dependencies

+ # TODO: describe what assemble does, and link to https://docs.openshift.com/container-platform/3.11/creating_images/s2i.html

+ RUN /usr/libexec/s2i/assemble

+ 

+ # Run script uses standard ways to run the application

+ CMD /usr/libexec/s2i/run

@@ -0,0 +1,1 @@ 

+ This is a sample s2i application with static content.

@@ -0,0 +1,13 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD index.html /var/www/html/index.html

+ 

+ # Add self-signed certificate files

+ # TODO: Test that we do not use a newly generated certs by:

+ # podman exec ... curl -kvvI https://127.0.0.1:8443 must match "start date: Dec  3 23:33:57 2017 GMT" or whatever the testing certs have

+ ADD httpd-ssl "${APP_ROOT}/httpd-ssl"

+ 

+ # Run script uses standard ways to run the application and also puts

+ # the certificate files into a correct directory

+ CMD run-httpd

@@ -0,0 +1,19 @@ 

+ FROM registry.redhat.io/rhel8/httpd-24

+ 

+ # Add application sources

+ ADD index.html /tmp/src/index.html

+ 

+ # Add self-signed certificate files

+ ADD httpd-ssl "/tmp/src/httpd-ssl"

+ 

+ # Assemble script installs the dependencies

+ # TODO: describe what assemble does, and link to https://docs.openshift.com/container-platform/3.11/creating_images/s2i.html

+ RUN /usr/libexec/s2i/assemble

+ 

+ USER 0

+ RUN sed -i -e '1 a\

+ set -x' /usr/bin/run-httpd

+ USER 1001

+ 

+ # Run script uses standard ways to run the application

+ CMD /usr/libexec/s2i/run

@@ -0,0 +1,20 @@ 

+ -----BEGIN CERTIFICATE-----

+ MIIDWjCCAkKgAwIBAgIJAI4x7HuBG49oMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNV

+ BAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQg

+ Q29tcGFueSBMdGQwHhcNMTcxMjAzMjMzMzU3WhcNMTgwMTAyMjMzMzU3WjBCMQsw

+ CQYDVQQGEwJYWDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZh

+ dWx0IENvbXBhbnkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA

+ vH4Vdq0a3UWUQd8Z6s2csxhxjAOyUx0rszGL0m3uTjQido6JRBdjN2dXiZc3LFoq

+ YeOKR3CeHsn7UdrlzaboHFDfjAaextse0740mB1g14H1bAS0POuTPeKa+3wGfzCb

+ sTSXnfSrICl3n2D/3KSO93WwmS90kBD6HmKt5nfkLpJnROM/4bHmuoV0Ry8CDjzj

+ mka7pQU4yzyMKLU3sHpncZU6g7o4Vezic9ksVzIAbdPCSbF7ktVz/hisyCuzyKN6

+ s2327jq593vBgGOsNU5PDPDjKW74Q0Bv/FxPK4nx+o4IkcRW1QEb+yAx8XOM7CDZ

+ ViKvI/A0b+Y4Y3rIQ465+wIDAQABo1MwUTAdBgNVHQ4EFgQUAY1i6ZNbqO1+46aw

+ pldCyPaWoYswHwYDVR0jBBgwFoAUAY1i6ZNbqO1+46awpldCyPaWoYswDwYDVR0T

+ AQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEADhGjnYGq9JvQcygMYEQiIdyS

+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 #!/bin/bash

+ #

+ # Functions for tests for the httpd image in OpenShift.

+ #

+ # IMAGE_NAME specifies a name of the candidate image used for testing.

+ # The image has to be available before this script is executed.

+ #

+ 

+ THISDIR=$(dirname ${BASH_SOURCE[0]})

+ 

+ source ${THISDIR}/test-lib.sh

+ source ${THISDIR}/test-lib-openshift.sh

+ 

+ function test_httpd_integration() {

+   local image_name=$1

+   ct_os_test_s2i_app "${image_name}" \

+                      "https://github.com/sclorg/httpd-container.git" \

+                      "examples/sample-test-app" \

+                      "This is a sample s2i application with static content"

+ }

+ 

+ # Check the imagestream

+ function test_httpd_imagestream() {

+   case ${OS} in

+     rhel7|centos7) ;;

+     *) echo "Imagestream testing not supported for $OS environment." ; return 0 ;;

+   esac

+ 

+   ct_os_test_image_stream_s2i "${THISDIR}/imagestreams/httpd-${OS%[0-9]*}.json" "${IMAGE_NAME}" \

+                               "https://github.com/sclorg/httpd-container.git" \

+                               "examples/sample-test-app" \

+                               "This is a sample s2i application with static content"

+ }

+ 

+ # vim: set tabstop=2:shiftwidth=2:expandtab:

The added file is too large to be shown here, see it at: test/test-lib-openshift.sh
@@ -0,0 +1,116 @@ 

+ # shellcheck shell=bash

+ # some functions are used from test-lib.sh, that is usually in the same dir

+ # shellcheck source=/dev/null

+ source "$(dirname "${BASH_SOURCE[0]}")"/test-lib.sh

+ 

+ # Set of functions for testing docker images in OpenShift using 'oc' command

+ 

+ # A variable containing the overall test result; must be changed to 0 in the end

+ # of the testing script:

+ #   OS_TESTSUITE_RESULT=0

+ # And the following trap must be set, in the beginning of the test script:

+ #   trap ct_os_cleanup EXIT SIGINT

+ 

+ # ct_os_set_path_oc_4 OC_VERSION

+ # --------------------

+ # This is a trick that helps using correct version 4 of the `oc`:

+ # The input is version of the openshift in format 4.4 etc.

+ # If the currently available version of oc is not of this version,

+ # it first takes a look into /usr/local/oc-<ver>/bin directory,

+ 

+ # Arguments: oc_version - X.Y part of the version of OSE (e.g. 3.9)

+ function ct_os_set_path_oc_4() {

+     echo "Setting OCP4 client"

+     local oc_version=$1

+     local installed_oc_path="/usr/local/oc-v${oc_version}/bin"

+     echo "PATH ${installed_oc_path}"

+     if [ -x "${installed_oc_path}/oc" ] ; then

+         oc_path="${installed_oc_path}"

+         echo "Binary oc found in ${installed_oc_path}" >&2

+     else

+        echo "OCP4 not found"

+        return 1

+     fi

+     export PATH="${oc_path}:${PATH}"

+     oc version

+     if ! oc version | grep -q "Client Version: ${oc_version}." ; then

+         echo "ERROR: something went wrong, oc located at ${oc_path}, but oc of version ${oc_version} not found in PATH ($PATH)" >&1

+         return 1

+     else

+         echo "PATH set correctly, binary oc found in version ${oc_version}: $(command -v oc)"

+     fi

+ }

+ 

+ # ct_os_prepare_ocp4

+ # ------------------

+ # Prepares environment for testing images in OpenShift 4 environment

+ #

+ #

+ function ct_os_set_ocp4() {

+   if [ "${CVP:-0}" -eq "1" ]; then

+     echo "Testing in CVP environment. No need to login to OpenShift cluster. This is already done by CVP pipeline."

+     return

+   fi

+   local login

+   OS_OC_CLIENT_VERSION=${OS_OC_CLIENT_VERSION:-4.4}

+   ct_os_set_path_oc_4 "${OS_OC_CLIENT_VERSION}"

+ 

+   oc version

+ 

+   login=$(cat "$KUBEPASSWORD")

+   oc login -u kubeadmin -p "$login"

+   echo "Login to OpenShift ${OS_OC_CLIENT_VERSION} is DONE"

+   # let openshift cluster to sync to avoid some race condition errors

+   sleep 3

+ }

+ 

+ function ct_os_upload_image_external_registry() {

+   local input_name="${1}" ; shift

+   local image_name=${input_name##*/}

+   local imagestream=${1:-$image_name:latest}

+   local output_name

+ 

+   ct_os_login_external_registry

+ 

+   output_name="${INTERNAL_DOCKER_REGISTRY}/rhscl-ci-testing/$imagestream"

+ 

+   docker images

+   docker tag "${input_name}" "${output_name}"

+   docker push "${output_name}"

+ }

+ 

+ 

+ function ct_os_login_external_registry() {

+   local docker_token

+   # docker login fails with "404 page not found" error sometimes, just try it more times

+   # shellcheck disable=SC2034

+   echo "loging"

+   [ -z "${INTERNAL_DOCKER_REGISTRY:-}" ] && "INTERNAL_DOCKER_REGISTRY has to be set for working with Internal registry" && return 1

+   # shellcheck disable=SC2034

+   for i in $(seq 12) ; do

+     # shellcheck disable=SC2015

+     docker_token=$(cat "$DOCKER_UPSHIFT_TOKEN")

+     # shellcheck disable=SC2015

+     docker login -u rhscl-ci-testing -p "$docker_token" "${INTERNAL_DOCKER_REGISTRY}" && return 0 || :

+     sleep 5

+   done

+   return 1

+ }

+ 

+ function ct_os_import_image_ocp4() {

+   local image_name="${1}"; shift

+   local imagestream=${1:-$image_name:latest}

+   local namespace

+ 

+   namespace=${CT_NAMESPACE:-"$(oc project -q)"}

+   deploy_image_name="${INTERNAL_DOCKER_REGISTRY}/rhscl-ci-testing/${imagestream}"

+   echo "Uploading image ${image_name} as ${deploy_image_name} , ${imagestream} into external registry."

+   ct_os_upload_image_external_registry "${image_name}" "${imagestream}"

+   if [ "${CT_TAG_IMAGE:-false}" == 'true' ]; then

+     echo "Tag ${deploy_image_name} to ${namespace}/${imagestream}"

+     oc tag --source=docker "${deploy_image_name}" "${namespace}/${imagestream}" --insecure=true --reference-policy=local

+   else

+     echo "Import image into OpenShift 4 environment ${namespace}/${imagestream} from ${deploy_image_name}"

+     oc import-image "${namespace}/${imagestream}" --from="${deploy_image_name}" --confirm --reference-policy=local

+   fi

+ }

file added
+1072
The added file is too large to be shown here, see it at: test/test-lib.sh
file added
+46
@@ -0,0 +1,46 @@ 

+ #!/usr/bin/env bash

+ 

+ function print_result {

+     local RESET='\e[0m'

+     local RED='\e[0;31m'

+     local GREEN='\e[0;32m'

+     local YELLOW='\e[1;33m'

+     local PASS="${RESET}${GREEN}[PASS]"

+     local FAIL="${RESET}${RED}[FAIL]"

+     local WORKING="${RESET}${YELLOW}[....]"

+     local STATUS="$1"

+     shift

+ 

+     if [ "${STATUS}" = pass ]; then

+         echo -en "${PASS}"

+     elif [ "${STATUS}" = fail ]; then

+         echo -en "${FAIL}"

+     elif [ "${STATUS}" = working ]; then

+         echo -en "${WORKING}"

+     else

+         return

+     fi

+ 

+     echo -en " ${@}${RESET}"

+     echo

+ }

+ 

+ function get_status {

+     if [ "$1" = "$2" ]; then

+         echo pass

+     else

+         echo fail

+     fi

+ }

+ 

+ function run_command {

+     local cmd="$1"

+     local expected="${2:-0}"

+     local msg="${3:-Running command '$cmd'}"

+     print_result working "$msg"

+     eval $cmd

+     local res="$?"

+     status=`get_status "$res" "$expected"`

+     print_result "$status" "$msg"

+     return "$res"

+ }

Metadata
Changes Summary 52
+1
file added
2.4
+69
file added
Dockerfile
+1
file added
Dockerfile.fedora
+1
file added
README.md
+1
file added
help.md
+3
file added
root/opt/app-root/scl_enable
+18
file added
root/usr/bin/run-httpd
+44
file added
root/usr/libexec/httpd-prepare
+248
file added
root/usr/share/container-scripts/httpd/README.md
+207
file added
root/usr/share/container-scripts/httpd/common.sh
+15
file added
root/usr/share/container-scripts/httpd/passwd.template
+4
file added
root/usr/share/container-scripts/httpd/post-assemble/20-copy-config.sh
+4
file added
root/usr/share/container-scripts/httpd/post-assemble/40-ssl-certs.sh
+3
file added
root/usr/share/container-scripts/httpd/pre-init/10-set-mpm.sh
+4
file added
root/usr/share/container-scripts/httpd/pre-init/20-copy-config.sh
+4
file added
root/usr/share/container-scripts/httpd/pre-init/40-ssl-certs.sh
+20
file added
s2i/bin/assemble
+7
file added
s2i/bin/run
+17
file added
s2i/bin/usage
+101
file added
test/check_imagestreams.py
+7
file added
test/examples/Dockerfile
+25
file added
test/examples/Dockerfile.s2i
+50
file added
test/examples/README.md
+8
file added
test/examples/sample-test-app/Dockerfile
+11
file added
test/examples/sample-test-app/Dockerfile.s2i
+1
file added
test/examples/sample-test-app/index.html
+13
file added
test/examples/self-signed-ssl/Dockerfile
+19
file added
test/examples/self-signed-ssl/Dockerfile.s2i
+20
file added
test/examples/self-signed-ssl/httpd-ssl/certs/server-cert-selfsigned.pem
+28
file added
test/examples/self-signed-ssl/httpd-ssl/private/server-key.pem
+1
file added
test/examples/self-signed-ssl/index.html
+93
file added
test/imagestreams/httpd-centos.json
+53
file added
test/imagestreams/httpd-rhel-aarch64.json
+93
file added
test/imagestreams/httpd-rhel.json
+1
file added
test/pre-init-test-app/httpd-pre-init/modify_index.sh
+1
file added
test/pre-init-test-app/index.html
+211
file added
test/run
+1
file added
test/run-openshift
+37
file added
test/run-openshift-remote-cluster
+8
file added
test/sample-test-app/Dockerfile
+11
file added
test/sample-test-app/Dockerfile.s2i
+1
file added
test/sample-test-app/index.html
+13
file added
test/self-signed-ssl/Dockerfile
+19
file added
test/self-signed-ssl/Dockerfile.s2i
+20
file added
test/self-signed-ssl/httpd-ssl/certs/server-cert-selfsigned.pem
+28
file added
test/self-signed-ssl/httpd-ssl/private/server-key.pem
+1
file added
test/self-signed-ssl/index.html
+35
file added
test/test-lib-httpd.sh
+1364
file added
test/test-lib-openshift.sh
+116
file added
test/test-lib-remote-openshift.sh
+1072
file added
test/test-lib.sh
+46
file added
test/utils.sh