Merge pull request #202 from sclorg/support_testing_rhel9

Add support for testing nginx on RHEL9
This commit is contained in:
phracek 2022-06-14 08:52:46 +00:00
commit fa41e110a6
77 changed files with 5080 additions and 2 deletions

1
1.18 Symbolic link
View file

@ -0,0 +1 @@
.

85
Dockerfile Normal file
View file

@ -0,0 +1,85 @@
FROM registry.fedoraproject.org/f34/s2i-core:latest
# nginx 1.18 image.
#
# Volumes:
# * /var/log/nginx/ - Storage for logs
EXPOSE 8080
EXPOSE 8443
ENV NAME=nginx \
NGINX_VERSION=1.18 \
NGINX_SHORT_VER=118 \
VERSION=0 \
ARCH=x86_64
ENV SUMMARY="Platform for running nginx $NGINX_VERSION or building nginx-based application" \
DESCRIPTION="Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP \
protocols, with a strong focus on high concurrency, performance and low memory usage. The container \
image provides a containerized packaging of the nginx $NGINX_VERSION daemon. The image can be used \
as a base image for other applications based on nginx $NGINX_VERSION web server. \
Nginx server image can be extended using source-to-image tool."
LABEL summary="${SUMMARY}" \
description="${DESCRIPTION}" \
io.k8s.description="${DESCRIPTION}" \
io.k8s.display-name="Nginx ${NGINX_VERSION}" \
io.openshift.expose-services="8080:http" \
io.openshift.expose-services="8443:https" \
io.openshift.tags="builder,${NAME},${NAME}${NGINX_SHORT_VER}" \
com.redhat.component="${NAME}" \
name="${FGC}/${NAME}" \
version="${VERSION}" \
maintainer="SoftwareCollections.org <sclorg@redhat.com>" \
help="For more information visit https://github.com/sclorg/${NAME}-container" \
usage="s2i build <SOURCE-REPOSITORY> ${FGC}/nginx <APP-NAME>"
ENV NGINX_CONFIGURATION_PATH=${APP_ROOT}/etc/nginx.d \
NGINX_CONF_PATH=/etc/nginx/nginx.conf \
NGINX_DEFAULT_CONF_PATH=${APP_ROOT}/etc/nginx.default.d \
NGINX_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nginx \
NGINX_APP_ROOT=${APP_ROOT} \
NGINX_LOG_PATH=/var/log/nginx \
NGINX_PERL_MODULE_PATH=${APP_ROOT}/etc/perl
RUN dnf install -y gettext hostname && \
INSTALL_PKGS="nss_wrapper bind-utils nginx nginx-mod-stream nginx-mod-http-perl" && \
dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
dnf clean all
# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
# Copy extra files to the image.
COPY ./root/ /
# In order to drop the root user, we have to make some directories world
# writeable as OpenShift default security model is to run the container under
# random UID.
RUN sed -i -f ${NGINX_APP_ROOT}/nginxconf-fed.sed ${NGINX_CONF_PATH} && \
chmod a+rwx ${NGINX_CONF_PATH} && \
mkdir -p ${NGINX_APP_ROOT}/etc/nginx.d/ && \
mkdir -p ${NGINX_APP_ROOT}/etc/nginx.default.d/ && \
mkdir -p ${NGINX_APP_ROOT}/src/nginx-start/ && \
mkdir -p ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
mkdir -p ${NGINX_LOG_PATH} && \
mkdir -p ${NGINX_PERL_MODULE_PATH} && \
chmod -R a+rwx ${NGINX_APP_ROOT}/etc && \
chmod -R a+rwx /var /run && \
chmod -R a+rwx ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
chown -R 1001:0 ${NGINX_APP_ROOT} && \
chown -R 1001:0 /var && \
chown -R 1001:0 ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \
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 ["/usr/share/nginx/html"]
# VOLUME ["/var/log/nginx/"]
CMD $STI_SCRIPTS_PATH/usage

1
Dockerfile.fedora Symbolic link
View file

@ -0,0 +1 @@
Dockerfile

210
README.md
View file

@ -1,3 +1,209 @@
# nginx
Nginx 1.18 server and a reverse proxy server container image
============================================================
This container image includes Nginx 1.18 server and a reverse server for OpenShift and general usage.
Users can choose between RHEL, CentOS, CentOS Stream 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 in the [Quay.io](https://quay.io/organization/centos7),
the CentOS Stream images are available in the [Quay.io](https://quay.io/organization/sclorg),
and the Fedora images are available in the [Quay.io](https://quay.io/organization/fedora).
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
-----------
Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and IMAP
protocols, with a strong focus on high concurrency, performance and low memory usage. The container
image provides a containerized packaging of the nginx 1.18 daemon. The image can be used
as a base image for other applications based on nginx 1.18 web server.
Nginx server image can be extended using Openshift's `Source` build feature.
Usage in OpenShift
------------------
In this example, we assume that you are using the `ubi8/nginx-118` image, available through the `nginx:1.18` imagestream tag in Openshift.
To build a simple [test-app](https://github.com/sclorg/nginx-container/tree/master/examples/1.18/test-app) application in Openshift:
```
oc new-app nginx:1.18~https://github.com/sclorg/nginx-container.git --context-dir=1.18/test/test-app/
```
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/4.4/builds/build-strategies.html#images-create-s2i_build-strategies)
(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 Nginx container image, and produce
a new image that runs the assembled application as an output.
In case of Nginx container image, the application source code is typically
either static HTML pages or configuration files.
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 (HTML pages), Nginx configuration files, and places them into appropriate directories inside the image. The structure of nginx-app can look like this:
**`./nginx.conf`**--
The main nginx configuration file
**`./nginx-cfg/*.conf`**
Should contain all nginx configuration we want to include into image
**`./nginx-default-cfg/*.conf`**
Contains any nginx config snippets to include in the default server block
**`./nginx-start/*.sh`**
Contains shell scripts that are sourced right before nginx is launched
**`./nginx-perl/*.pm`**
Contains perl modules to be use by `perl_modules` and `perl_require` directives
**`./`**
Should contain nginx 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 Nginx 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 Nginx image in a Dockerfile, follow these steps:
#### 1. Pull a base builder image to build on
podman pull ubi8/nginx-118
#### 2. Pull an application code
An example application available at https://github.com/sclorg/nginx-container.git is used here. To adjust the example application, clone the repository.
```
git clone https://github.com/sclorg/nginx-container.git nginx-container
cd nginx-container/examples/1.18/
```
#### 3. Prepare an application inside a container
This step usually consists of at least these parts:
* putting the application source into the container
* moving configuration files 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 `nginx` command 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 nginx 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.access.redhat.com/ubi8/nginx-118
# Add application sources
ADD test-app/nginx.conf "${NGINX_CONF_PATH}"
ADD test-app/nginx-default-cfg/*.conf "${NGINX_DEFAULT_CONF_PATH}"
ADD test-app/nginx-cfg/*.conf "${NGINX_CONFIGURATION_PATH}"
ADD test-app/*.html .
# Run script uses standard ways to run the application
CMD nginx -g "daemon off;"
```
##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content:
```
FROM registry.access.redhat.com/ubi8/nginx-118
# Add application sources to a directory that the assemble script expects them
# and set permissions so that the container runs without root access
# With older docker that does not support --chown option for ADD statement,
# use these statements instead:
# USER 0
# ADD app-src /tmp/src
# RUN chown -R 1001:0 /tmp/src
# USER 1001
ADD --chown 1001:0 app-src /tmp/src
# 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
```
#### 4. Build a new image from a Dockerfile prepared in the previous step
```
podman build -t nginx-app .
```
#### 5. Run the resulting image with the final application
```
podman run -d nginx-app
```
Direct usage with a mounted directory
-------------------------------------
An example of the data on the host for the following example:
```
$ 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 nginx -p 8080:8080 -v /wwwdata:/opt/app-root/src:Z ubi8/nginx-118 nginx -g "daemon off;"
```
This creates a container named `nginx` running the Nginx server, serving data from
the `/wwwdata/` directory. Port 8080 is exposed and mapped to the host.
You can pull the data from the nginx container using this command:
```
$ curl -Lk 127.0.0.1:8080
```
You can replace `/wwwdata/` with location of your web root. Please note that this has to be an **absolute** path, due to podman requirements.
Environment variables and volumes
---------------------------------
The nginx container image supports the following configuration variable, which can be set by using the `-e` option with the podman run command:
**`NGINX_LOG_TO_VOLUME`**
When `NGINX_LOG_TO_VOLUME` is set, nginx logs into `/var/log/nginx/`. In case of RHEL-7 and CentOS-7 images, this is a symlink to `/var/opt/rh/rh-nginx118/log/nginx/`.
Troubleshooting
---------------
By default, nginx access logs are written to standard output and error logs are written to standard error, so both are available in the container log. The log can be examined by running:
podman logs <container>
**If `NGINX_LOG_TO_VOLUME` variable is set, nginx logs into `/var/log/nginx/`. In case of RHEL-7 and CentOS-7 images, this is a symlink to `/var/opt/rh/rh-nginx118/log/nginx/`, which can be mounted to host system using the container volumes.**
See also
--------
Dockerfile and other sources for this container image are available on
https://github.com/sclorg/nginx-container.
In that repository you also can find another versions of Python environment Dockerfiles.
Dockerfile for CentOS is called `Dockerfile`, Dockerfile for RHEL7 is called `Dockerfile.rhel7`,
for RHEL8 it's `Dockerfile.rhel8`, Dockerfile for CentOS Stream 8 is called `Dockerfile.c8s`,
Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s` and the Fedora Dockerfile is called `Dockerfile.fedora`.
The nginx package

1
help.md Symbolic link
View file

@ -0,0 +1 @@
README.md

View file

@ -0,0 +1,9 @@
# Set current user in nss_wrapper
PASSWD_DIR="/opt/app-root/etc"
export USER_ID=$(id -u)
export GROUP_ID=$(id -g)
envsubst < ${PASSWD_DIR}/passwd.template > ${PASSWD_DIR}/passwd
export LD_PRELOAD=libnss_wrapper.so
export NSS_WRAPPER_PASSWD=${PASSWD_DIR}/passwd
export NSS_WRAPPER_GROUP=/etc/group

View file

@ -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

View 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 rh-nginx$NGINX_SHORT_VER

View file

@ -0,0 +1,10 @@
/listen/s%80%8080 default_server%
s/^user *nginx;//
s%/etc/nginx/conf.d/%/opt/app-root/etc/nginx.d/%
s%/etc/nginx/default.d/%/opt/app-root/etc/nginx.default.d/%
s%/usr/share/nginx/html%/opt/app-root/src%
# See: https://github.com/sclorg/nginx-container/pull/69
/error_page/d
/40x.html/,+1d
/50x.html/,+1d

View file

@ -0,0 +1,10 @@
/listen/s%80%8080 default_server%
s/^user *nginx;//
s%/etc/opt/rh/rh-nginx118/nginx/conf.d/%/opt/app-root/etc/nginx.d/%
s%/etc/opt/rh/rh-nginx118/nginx/default.d/%/opt/app-root/etc/nginx.default.d/%
s%/opt/rh/rh-nginx118/root/usr/share/nginx/html%/opt/app-root/src%
# See: https://github.com/sclorg/nginx-container/pull/69
/error_page/d
/40x.html/,+1d
/50x.html/,+1d

View file

@ -0,0 +1,31 @@
#!/bin/sh
# 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
if [ $filename ]; then
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
fi
done <<<"$(get_matched_files "$custom_dir" "$default_dir" '*.sh' | sort -u)"
}

50
s2i/bin/assemble Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
set -e
echo "---> Installing application source"
cp -Rf /tmp/src/. ./
# Fix source directory permissions
fix-permissions ./
if [ -f ./nginx.conf ]; then
echo "---> Copying nginx.conf configuration file..."
cp -v ./nginx.conf "${NGINX_CONF_PATH}"
rm -f ./nginx.conf
fi
if [ -d ./nginx-cfg ]; then
echo "---> Copying nginx configuration files..."
if [ "$(ls -A ./nginx-cfg/*.conf)" ]; then
cp -av ./nginx-cfg/*.conf "${NGINX_CONFIGURATION_PATH}"
rm -rf ./nginx-cfg
fi
chmod -Rf g+rw ${NGINX_CONFIGURATION_PATH}
fi
if [ -d ./nginx-default-cfg ]; then
echo "---> Copying nginx default server configuration files..."
if [ "$(ls -A ./nginx-default-cfg/*.conf)" ]; then
cp -av ./nginx-default-cfg/*.conf "${NGINX_DEFAULT_CONF_PATH}"
rm -rf ./nginx-default-cfg
fi
chmod -Rf g+rw ${NGINX_DEFAULT_CONF_PATH}
fi
if [ -d ./nginx-start ]; then
echo "---> Copying nginx start-hook scripts..."
if [ "$(ls -A ./nginx-start/* 2>/dev/null)" ]; then
cp -av ./nginx-start/* "${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start/"
rm -rf ./nginx-start
fi
fi
if [ -d ./nginx-perl ]; then
echo "---> Copying nginx perl module files..."
if [ "$(ls -A ./nginx-perl/*.pm)" ]; then
cp -av ./nginx-perl/*.pm "${NGINX_PERL_MODULE_PATH}"
rm -rf ./nginx-perl
fi
chmod -Rf g+rw ${NGINX_PERL_MODULE_PATH}
fi

16
s2i/bin/run Executable file
View file

@ -0,0 +1,16 @@
#!/bin/bash
source /opt/app-root/etc/generate_container_user
set -e
source ${NGINX_CONTAINER_SCRIPTS_PATH}/common.sh
process_extending_files ${NGINX_APP_ROOT}/src/nginx-start ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start
if [ ! -v NGINX_LOG_TO_VOLUME -a -v NGINX_LOG_PATH ]; then
/bin/ln -sf /dev/stdout ${NGINX_LOG_PATH}/access.log
/bin/ln -sf /dev/stderr ${NGINX_LOG_PATH}/error.log
fi
exec nginx -g "daemon off;"

19
s2i/bin/usage Executable file
View file

@ -0,0 +1,19 @@
#!/bin/sh
DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'`
cat <<EOF
This is a S2I ${IMAGE_DESCRIPTION} ${DISTRO} base image.
To use it in OpenShift, run:
oc new-app nginx:${NGINX_VERSION}~https://github.com/sclorg/nginx-container.git --context-dir=${NGINX_VERSION}/test/test-app/
You can then run the resulting image via:
docker run -p 8080:8080 nginx-sample-app
Alternatively, to run the image directly using podman or docker, or how to use it as a parent image in a Dockerfile, see documentation at
https://github.com/sclorg/nginx-container/blob/master/${NGINX_VERSION}/README.md.
EOF

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

View file

@ -0,0 +1,93 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
# perl_modules /opt/app-root/etc/perl;
# perl_require Version.pm;
# perl_set $perl_version Version::installed;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/app-root/etc/nginx.d/*.conf;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /opt/app-root/src;
# Load configuration files for the default server block.
include /opt/app-root/etc/nginx.default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /opt/app-root/src;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /opt/app-root/etc/nginx.default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

View file

@ -0,0 +1,93 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
# perl_modules /opt/app-root/etc/perl;
# perl_require Version.pm;
# perl_set $perl_version Version::installed;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/app-root/etc/nginx.d/*.conf;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /opt/app-root/src;
# Load configuration files for the default server block.
include /opt/app-root/etc/nginx.default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /opt/app-root/src;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /opt/app-root/etc/nginx.default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

View file

@ -0,0 +1,93 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
# perl_modules /opt/app-root/etc/perl;
# perl_require Version.pm;
# perl_set $perl_version Version::installed;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/app-root/etc/nginx.d/*.conf;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /opt/app-root/src;
# Load configuration files for the default server block.
include /opt/app-root/etc/nginx.default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /opt/app-root/src;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /opt/app-root/etc/nginx.default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

View file

@ -0,0 +1,93 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
# perl_modules /opt/app-root/etc/perl;
# perl_require Version.pm;
# perl_set $perl_version Version::installed;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/app-root/etc/nginx.d/*.conf;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /opt/app-root/src;
# Load configuration files for the default server block.
include /opt/app-root/etc/nginx.default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /opt/app-root/src;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /opt/app-root/etc/nginx.default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

View file

@ -0,0 +1,93 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
# perl_modules /opt/app-root/etc/perl;
# perl_require Version.pm;
# perl_set $perl_version Version::installed;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/app-root/etc/nginx.d/*.conf;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /opt/app-root/src;
# Load configuration files for the default server block.
include /opt/app-root/etc/nginx.default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /opt/app-root/src;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /opt/app-root/etc/nginx.default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

View file

@ -0,0 +1,93 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
# perl_modules /opt/app-root/etc/perl;
# perl_require Version.pm;
# perl_set $perl_version Version::installed;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/app-root/etc/nginx.d/*.conf;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /opt/app-root/src;
# Load configuration files for the default server block.
include /opt/app-root/etc/nginx.default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /opt/app-root/src;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /opt/app-root/etc/nginx.default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080 default_server;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

12
test/examples/Dockerfile Normal file
View file

@ -0,0 +1,12 @@
FROM registry.access.redhat.com/ubi8/nginx-118
ENV NGINX_VERSION=1.18
# Add application sources
ADD nginx-container/examples/$NGINX_VERSION/test-app/nginx.conf "${NGINX_CONF_PATH}"
ADD nginx-container/examples/$NGINX_VERSION/test-app/nginx-default-cfg/*.conf "${NGINX_DEFAULT_CONF_PATH}"
ADD nginx-container/examples/$NGINX_VERSION/test-app/nginx-cfg/*.conf "${NGINX_CONFIGURATION_PATH}"
ADD nginx-container/examples/$NGINX_VERSION/test-app/*.html ./
# Run script uses standard ways to run the application
CMD nginx -g "daemon off;"

View file

@ -0,0 +1,30 @@
FROM registry.access.redhat.com/ubi8/nginx-118
ENV NGINX_VERSION=1.18
# 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
# With a newer docker that supports --chown option for ADD statement, or with
# podman, we can replace the following four statements with
# ADD --chown 1001:0 <app-src> /tmp/src
USER 0
ADD nginx-container/examples/$NGINX_VERSION/test-app /tmp/src/
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

19
test/examples/README.md Normal file
View file

@ -0,0 +1,19 @@
# Test application for Nginx
This is a simple example of static content and configuration files served using nginx.
## Building with s2i and Dockerfile
See [the main documentation](/1.18/README.md) for steps how to use this image
with a podman directly or in a Dockerfile, utilizing the source-to-image scripts.
## Building and deploying in OpenShift
### Version 1.16
```
oc new-app nginx:1.16~https://github.com/sclorg/nginx-container.git --context-dir=1.16/test/test-app/
```
### Version 1.18
```
oc new-app nginx:1.18~https://github.com/sclorg/nginx-container.git --context-dir=1.18/test/test-app/
```

View file

@ -0,0 +1,133 @@
{
"apiVersion": "image.openshift.io/v1",
"kind": "ImageStream",
"metadata": {
"annotations": {
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy (nginx)"
},
"name": "nginx"
},
"spec": {
"tags": [
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP Server and a reverse proxy (nginx) on CentOS. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version of Nginx available on OpenShift, including major version updates.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy (Latest)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx"
},
"from": {
"kind": "ImageStreamTag",
"name": "1.20-ubi8"
},
"referencePolicy": {
"type": "Local"
},
"name": "latest"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.20 (UBI 9)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.20"
},
"from": {
"kind": "DockerImage",
"name": "registry.access.redhat.com/ubi9/nginx-120:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.20-ubi9"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.20 (UBI 8)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.20"
},
"from": {
"kind": "DockerImage",
"name": "registry.access.redhat.com/ubi8/nginx-120:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.20-ubi8"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.20 (UBI 7)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.20"
},
"from": {
"kind": "DockerImage",
"name": "registry.access.redhat.com/ubi7/nginx-118:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.20-ubi7"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.18/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.18 (UBI 8)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.18"
},
"from": {
"kind": "DockerImage",
"name": "registry.access.redhat.com/ubi8/nginx-118:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.18-ubi8"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.18/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.18 (UBI 7)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.18"
},
"from": {
"kind": "DockerImage",
"name": "registry.access.redhat.com/ubi7/nginx-118:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.18-ubi7"
}
]
}
}

View file

@ -0,0 +1,93 @@
{
"apiVersion": "image.openshift.io/v1",
"kind": "ImageStream",
"metadata": {
"annotations": {
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy (nginx)"
},
"name": "nginx"
},
"spec": {
"tags": [
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version of Nginx available on OpenShift, including major version updates.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy (Latest)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx"
},
"from": {
"kind": "ImageStreamTag",
"name": "1.20-ubi8"
},
"referencePolicy": {
"type": "Local"
},
"name": "latest"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.20 (UBI 9)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.20"
},
"from": {
"kind": "DockerImage",
"name": "registry.redhat.io/ubi9/nginx-120:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.20-ubi9"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.20 (UBI 8)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.20"
},
"from": {
"kind": "DockerImage",
"name": "registry.redhat.io/ubi8/nginx-120:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.20-ubi8"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.18/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.18 (UBI 8)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.18"
},
"from": {
"kind": "DockerImage",
"name": "registry.redhat.io/ubi8/nginx-118:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.18-ubi8"
}
]
}
}

View file

@ -0,0 +1,133 @@
{
"apiVersion": "image.openshift.io/v1",
"kind": "ImageStream",
"metadata": {
"annotations": {
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy (nginx)"
},
"name": "nginx"
},
"spec": {
"tags": [
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.\n\nWARNING: By selecting this tag, your application will automatically update to use the latest version of Nginx available on OpenShift, including major version updates.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy (Latest)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx"
},
"from": {
"kind": "ImageStreamTag",
"name": "1.20-ubi8"
},
"referencePolicy": {
"type": "Local"
},
"name": "latest"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.20 (UBI 9)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.20"
},
"from": {
"kind": "DockerImage",
"name": "registry.redhat.io/ubi9/nginx-120:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.20-ubi9"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.20 (UBI 8)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.20"
},
"from": {
"kind": "DockerImage",
"name": "registry.redhat.io/ubi8/nginx-120:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.20-ubi8"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.20/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.20 (UBI 7)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.20"
},
"from": {
"kind": "DockerImage",
"name": "registry.redhat.io/ubi7/nginx-120:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.20-ubi7"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 8. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.18/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.18 (UBI 8)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.18"
},
"from": {
"kind": "DockerImage",
"name": "registry.redhat.io/ubi8/nginx-118:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.18-ubi8"
},
{
"annotations": {
"description": "Build and serve static content via Nginx HTTP server and a reverse proxy (nginx) on RHEL 7. For more information about using this builder image, including OpenShift considerations, see https://github.com/sclorg/nginx-container/blob/master/1.18/README.md.",
"iconClass": "icon-nginx",
"openshift.io/display-name": "Nginx HTTP server and a reverse proxy 1.18 (UBI 7)",
"openshift.io/provider-display-name": "Red Hat, Inc.",
"sampleRepo": "https://github.com/sclorg/nginx-ex.git",
"supports": "nginx",
"tags": "builder,nginx",
"version": "1.18"
},
"from": {
"kind": "DockerImage",
"name": "registry.redhat.io/ubi7/nginx-118:latest"
},
"referencePolicy": {
"type": "Local"
},
"name": "1.18-ubi7"
}
]
}
}

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,17 @@
package Version;
use nginx;
sub installed {
return "$^V";
}
sub handler {
my $r = shift;
$r->send_http_header("text/html");
$r->print("Perl location handler is working");
return OK;
}
1;
__END__

View file

@ -0,0 +1,99 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
perl_modules /opt/app-root/etc/perl;
perl_require Version.pm;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
perl_set $perl_version Version::installed;
add_header X-Perl-Version $perl_version;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/app-root/etc/nginx.d/*.conf;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /opt/app-root/src;
# Load configuration files for the default server block.
include /opt/app-root/etc/nginx.default.d/*.conf;
location / {
}
location /perl {
perl Version::handler;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /opt/app-root/src;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /opt/app-root/etc/nginx.default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

471
test/run Executable file
View file

@ -0,0 +1,471 @@
#!/bin/bash
#
# The 'run' performs a simple test that verifies that S2I image.
# The main focus here is to excersise the S2I scripts.
#
# IMAGE_NAME specifies a name of the candidate image used for testing.
# The image has to be available before this script is executed.
#
test -n "${IMAGE_NAME-}" || false 'make sure $IMAGE_NAME is defined'
test -n "${VERSION-}" || false 'make sure $VERSION is defined'
# TODO: Make command compatible for Mac users
test_dir="$(readlink -f $(dirname "${BASH_SOURCE[0]}"))"
image_dir=$(readlink -f ${test_dir}/..)
test_short_summary=''
TESTSUITE_RESULT=0
TEST_LIST_APP="\
test_s2i_usage
test_docker_run_usage
test_application
test_log_output
test_log_volume_output
test_application_user
"
TEST_LIST_HOOK_APP="test_pre_init_script"
TEST_LIST_PERL_APP="test_perl_directive"
. $test_dir/test-lib.sh
# TODO: This should be part of the image metadata
test_port=8080
info() {
echo -e "\n\e[1m[INFO] $@...\e[0m\n"
}
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() {
ct_s2i_build_as_df file://${test_dir}/${1} ${IMAGE_NAME} ${IMAGE_NAME}-${1} ${s2i_args}
}
prepare() {
if ! image_exists ${IMAGE_NAME}; then
echo "ERROR: The image ${IMAGE_NAME} must exist before this script is executed."
exit 1
fi
# TODO: S2I build require the application is a valid 'GIT' repository, we
# should remove this restriction in the future when a file:// is used.
info "Build the test application image"
pushd ${test_dir}/${1} >/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_test_application() {
run_args=${CONTAINER_ARGS:-}
info "Running docker run --user=10001 ${run_args} -d --cidfile=${cid_file} ${IMAGE_NAME}-${1}"
docker run --user=10001 ${run_args} -d --cidfile=${cid_file} ${IMAGE_NAME}-${1}
}
cleanup_test_app() {
info "Cleaning up the test application"
if [ -n "$cid_file" ] && [ -f "$cid_file" ]; then
if container_exists; then
docker stop $(cat $cid_file)
docker rm $(cat $cid_file)
fi
rm $cid_file
fi
}
cleanup() {
info "Cleaning up the test application image"
if image_exists ${IMAGE_NAME}-${1}; then
docker rmi -f ${IMAGE_NAME}-${1}
fi
rm -rf ${test_dir}/${1}/.git
}
check_result() {
local result="$1"
if [[ "$result" != "0" ]]; then
cleanup_test_app
TESTCASE_RESULT=1
fi
return $result
}
wait_for_cid() {
local max_attempts=10
local sleep_time=1
local attempt=1
local result=1
info "Waiting for application container to start"
while [ $attempt -le $max_attempts ]; do
[ -f $cid_file ] && [ -s $cid_file ] && break
attempt=$(( $attempt + 1 ))
sleep $sleep_time
done
}
test_s2i_usage() {
info "Testing 's2i usage'"
ct_s2i_usage ${IMAGE_NAME} ${s2i_args} &>/dev/null
}
test_docker_run_usage() {
info "Testing 'docker run' usage"
docker run ${IMAGE_NAME} &>/dev/null
}
test_scl_usage() {
local run_cmd="$1"
local expected="$2"
info "Testing the image SCL enable"
out=$(docker run --rm ${IMAGE_NAME} /bin/bash -c "${run_cmd} 2>&1")
if ! echo "${out}" | grep -q "${expected}"; then
echo "ERROR[/bin/bash -c "${run_cmd}"] Expected '${expected}', got '${out}'"
return 1
fi
test_command "$run_cmd" "$expected"
return $?
}
test_command() {
local run_cmd="$1"
local expected="$2"
local message="$3"
echo "Test command"
if [ $message ]; then
info ${3}
fi
out=$(docker exec "$(cat ${cid_file})" /bin/bash -c "${run_cmd}" 2>&1)
if ! echo "${out}" | grep -q "${expected}"; then
echo "ERROR[exec /bin/bash -c "${run_cmd}"] Expected '${expected}', got '${out}'"
return 1
fi
out=$(docker exec "$(cat ${cid_file})" /bin/sh -ic "${run_cmd}" 2>&1)
if ! echo "${out}" | grep -q "${expected}"; then
echo "ERROR[exec /bin/sh -ic "${run_cmd}"] Expected '${expected}', got '${out}'"
return 1
fi
return 0
}
test_logs() {
local expected="$1"
local message="$2"
local logfile="$3"
if [ "$message" ]; then
info ${message}
fi
if [ "x$logfile" = "xstdouterr" ]; then
out=$(docker logs $(cat ${cid_file}) 2>&1)
elif [ "x$logfile" = "xstdout" ]; then
out=$(docker logs $(cat ${cid_file}) 2>/dev/null)
elif [ "x$logfile" = "xstderr" ]; then
out=$(docker logs $(cat ${cid_file}) 2>&1 1>/dev/null)
elif [ -n "$logfile" ]; then
info "Extracting $logfile via docker exec <cont> cat ${logfile}..."
out=$(docker exec $(cat ${cid_file}) cat ${logfile})
else
out=$(docker logs $(cat ${cid_file}) 2>&1)
fi
if ! echo "${out}" | egrep -q "${expected}"; then
echo "ERROR[docker logs $logfile] Expected '${expected}', got '${out}'"
return 1
fi
return 0
}
test_for_output() {
local url="$1"
local expect="$2"
local host="${3-localhost}"
local max_attempts=5
local sleep_time=1
local attempt=1
local result=1
info "Testing URL $url with HTTP hostname ${host} produces output $expect"
while [ $attempt -le $max_attempts ]; do
response=$(curl -is -H "Host: ${host}" ${url})
status=$?
echo "${response}"
if [ $status -eq 0 ]; then
if echo "${response}" | grep -q "${expect}"; then
info "Success!"
result=0
break
else
echo "Response: ${response}"
fi
fi
attempt=$(( $attempt + 1 ))
sleep $sleep_time
done
return $result
}
test_connection() {
cat $cid_file
info "Testing the HTTP connection (http://$(container_ip):${test_port})"
if test_for_output "http://$(container_ip):${test_port}/" "NGINX is working" &&
test_for_output "http://$(container_ip):${test_port}/" "NGINX2 is working" localhost2 &&
test_for_output "http://$(container_ip):${test_port}/aliased/index2.html" "NGINX2 is working" &&
test_for_output "http://$(container_ip):${test_port}/nginx-cfg/default.conf" "404"; then
return 0
fi
return 1
}
test_connection_s2i() {
cat $cid_file
info "Testing the HTTP connection (http://$(container_ip):${test_port})"
if test_for_output "http://$(container_ip):${test_port}/" "NGINX is working" &&
test_for_output "http://$(container_ip):${test_port}/" "NGINX2 is working" localhost2 &&
test_for_output "http://$(container_ip):${test_port}/nginx-cfg/default.conf" "404"; then
return 0
fi
return 1
}
test_application() {
# Verify that the HTTP connection can be established to test application container
run_test_application "test-app" &
# Wait for the container to write it's CID file
wait_for_cid
test_scl_usage "nginx -v" "nginx version: nginx/$VERSION."
check_result $? || return 1
test_connection
check_result $? || return 1
cleanup_test_app
return 0
}
test_pre_init_script() {
# Verify that the HTTP connection can be established to test application container
run_test_application "start-hook-test-app" &
# Wait for the container to write it's CID file
wait_for_cid
test_command "cat /opt/app-root/etc/nginx.d/default.conf | grep 'resolver' | sed -e 's/resolver\(.*\);/\1/' | grep 'DNS_SERVER'" ""
check_result $? || return 1
test_connection_s2i
check_result $? || return 1
cleanup_test_app
return 0
}
test_log_output() {
info "Testing log output for $IMAGE_NAME"
# Verify that the HTTP connection can be established to test application container
run_test_application "test-app" &
# Wait for the container to write it's CID file
wait_for_cid
info "Testing that GET / was logged as 200"
test_for_output "http://$(container_ip):${test_port}/" "NGINX is working"
check_result $? || return 1
test_logs '"GET / HTTP/1.1" 200' 'Test that GET / is logged as 200' stdout
check_result $? || return 1
info "Testing that GET /nothing-at-all was logged as 404"
test_for_output "http://$(container_ip):${test_port}/nothing-at-all" "404"
check_result $? || return 1
test_logs '"GET /nothing-at-all HTTP/1.1" 404' 'Test that bad GET is logged as 404' stdout
check_result $? || return 1
test_logs 'open.*failed.*No such file or directory' 'Test that bad GET is logged to error.log' stdouterr
check_result $? || return 1
cleanup_test_app
return 0
}
test_log_volume_output() {
info "Testing log volume output for $IMAGE_NAME"
# Verify that the HTTP connection can be established to test application container
CONTAINER_ARGS="-e NGINX_LOG_TO_VOLUME=y" run_test_application "test-app" &
# Wait for the container to write it's CID file
wait_for_cid
info "Testing that GET / was logged as 200"
test_for_output "http://$(container_ip):${test_port}/" "NGINX is working"
check_result $? || return 1
test_logs '"GET / HTTP/1.1" 200' 'Test that GET / is logged as 200' /var/log/nginx/access.log
check_result $? || return 1
info "Testing that GET /nothing-at-all was logged as 404"
test_for_output "http://$(container_ip):${test_port}/nothing-at-all" "404"
check_result $? || return 1
test_logs '"GET /nothing-at-all HTTP/1.1" 404' 'Test that bad GET is logged as 404' /var/log/nginx/access.log
check_result $? || return 1
test_logs 'open.*failed.*No such file or directory' 'Test that bad GET is logged to error.log' /var/log/nginx/error.log
check_result $? || return 1
info "Log volume output tested successfully."
cleanup_test_app
return 0
}
test_perl_directive() {
run_test_application "perl-test-app" &
# Wait for the container to write it's CID file
wait_for_cid
local perl_version=$(docker exec $(cat ${cid_file}) /bin/bash -c "perl -e 'print \"$^V\"'" 2>&1)
info "Testing perl_set directive sets header with perl version"
test_for_output "http://$(container_ip):${test_port}/" "X-Perl-Version: ${perl_version}"
check_result $? || return 1
info "Testing perl directive runs perl location handler"
test_for_output "http://$(container_ip):${test_port}/perl" "Perl location handler is working"
check_result $? || return 1
cleanup_test_app
return 0
}
test_application_user() {
# Test application with random uid
CONTAINER_ARGS="--user=12345" test_application
}
function run_all_tests() {
local APP_NAME="${1:-}"
for test_case in $TEST_LIST; do
info "Running test $test_case ...."
TESTCASE_RESULT=0
$test_case
check_result $?
local test_msg
if [ $TESTCASE_RESULT -eq 0 ]; then
test_msg="[PASSED]"
else
test_msg="[FAILED]"
TESTSUITE_RESULT=1
fi
printf -v test_short_summary "%s %s %s\n" "${test_short_summary}" "${test_msg}" "$test_case"
[ -n "${FAIL_QUICKLY:-}" ] && cleanup "${APP_NAME}" && return 1
done;
[ -n "${APP_NAME}" ] && cleanup "${APP_NAME}"
}
function build_image() {
local test_name="$1"
cid_file="$CID_FILE_DIR/$test_name"
# Since we built the candidate image locally, we don't want S2I attempt to pull
# it from Docker hub
s2i_args="--pull-policy=never"
prepare "${test_name}"
run_s2i_build "${test_name}"
check_result $?
}
test_scl_enable() {
echo "Testing nginx availability in Dockerfile"
ct_binary_found_from_df nginx
check_result $? || return 1
echo "Testing variable presence during \`docker exec\`"
ct_check_exec_env_vars
check_result $? || return 1
echo "Checking if all scl variables are defined in Dockerfile"
ct_check_scl_enable_vars
check_result $? || return 1
}
function run_dockerfiles_test() {
local dockerfile_tmp=$(mktemp)
sed -e "s/^ENV NGINX_VERSION.*$/ENV NGINX_VERSION=$VERSION/" -e "s/\$NGINX_VERSION/$VERSION/g" "${test_dir}/examples/Dockerfile" >"$dockerfile_tmp"
ct_test_app_dockerfile "$dockerfile_tmp" 'https://github.com/sclorg/nginx-container.git' "NGINX is working" nginx-container
check_result $? || return 1
sed -e "s/^ENV NGINX_VERSION.*$/ENV NGINX_VERSION=$VERSION/" -e "s/\$NGINX_VERSION/$VERSION/g" "${test_dir}/examples/Dockerfile" >"$dockerfile_tmp"
ct_test_app_dockerfile "$dockerfile_tmp" 'https://github.com/sclorg/nginx-container.git' "NGINX is working" nginx-container
check_result $? || return 1
rm "$dockerfile_tmp"
}
CID_FILE_DIR=$(mktemp -d)
build_image "test-app"
# Run the chosen tests
TEST_LIST=${TEST_LIST_APP} run_all_tests "test-app"
build_image "start-hook-test-app"
# Run the chosen tests
TEST_LIST=${TEST_LIST_HOOK_APP} run_all_tests "start-hook-test-app"
build_image "perl-test-app"
# Run the chosen tests
TEST_LIST=${TEST_LIST_PERL_APP} run_all_tests "perl-test-app"
# Run the rest of the tests by defining TEST_LIST to include the rest of the relevant cases
TEST_LIST=run_dockerfiles_test
# These tests only make sense for rhscl
if [ "$OS" == "rhel7" ] || [ "$OS" == "centos7" ]; then
# autocleanup only enabled here as only the following tests so far use it
ct_enable_cleanup
TEST_LIST="$TEST_LIST test_scl_enable"
fi
# Execute the rest of the tests depending on what TEST_LIST includes now
run_all_tests
# All tests executed, see the results
echo "$test_short_summary"
if [ $TESTSUITE_RESULT -eq 0 ] ; then
echo "Tests for ${IMAGE_NAME} succeeded."
else
echo "Tests for ${IMAGE_NAME} failed."
fi
exit $TESTSUITE_RESULT

1
test/run-openshift Symbolic link
View file

@ -0,0 +1 @@
run-openshift-local-cluster

View file

@ -0,0 +1,37 @@
#!/bin/bash
#
# Test the nginx 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 nginx runtime in format of X.Y
# OS specifies RHEL version (e.g. OS=rhel7)
#
THISDIR=$(dirname ${BASH_SOURCE[0]})
source ${THISDIR}/test-lib-nginx.sh
source ${THISDIR}/test-lib-remote-openshift.sh
TEST_LIST="\
test_nginx_integration
test_nginx_imagestream
"
trap ct_os_cleanup EXIT SIGINT
ct_os_set_ocp4
ct_os_check_compulsory_vars
ct_os_check_login || exit 1
set -u
# For testing on OpenShift 4 we use internal registry
export CT_OCP4_TEST=true
TEST_SUMMARY=''
TEST_SET=${TESTS:-$TEST_LIST} ct_run_tests_from_testset "openshift-remote-cluster"
# vim: set tabstop=2:shiftwidth=2:expandtab:

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index ${INDEX_FILE};
resolver ${DNS_SERVER};
}

View file

@ -0,0 +1,19 @@
setup_dns_env_var() {
if [ -z "$DNS_SERVER" ]; then
export DNS_SERVER=`cat /etc/resolv.conf | grep "nameserver " | awk '{print $2}' | tr '\n' ' '`
echo "Using system dns server ${DNS_SERVER}"
else
echo "Using user defined dns server: ${DNS_SERVER}"
fi
}
inject_env_vars() {
## Replace only specified environment variables in specified file.
envsubst '${DNS_SERVER},${INDEX_FILE}' < ${NGINX_CONFIGURATION_PATH}/$1 > output.conf
cp output.conf ${NGINX_CONFIGURATION_PATH}/$1
echo "This is $1: " && cat ${NGINX_CONFIGURATION_PATH}/$1
}
export INDEX_FILE=index2.html
setup_dns_env_var
inject_env_vars "default.conf"

8
test/test-app/index.html Normal file
View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX is working</h1>
</body>
</html>

View file

@ -0,0 +1,8 @@
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>NGINX2 is working</h1>
</body>
</html>

View file

@ -0,0 +1,6 @@
server {
listen 8080;
server_name localhost2;
root /opt/app-root/src;
index index2.html;
}

View file

@ -0,0 +1,3 @@
location /aliased/ {
alias /opt/app-root/src/;
}

93
test/test-app/nginx.conf Normal file
View file

@ -0,0 +1,93 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
# perl_modules /opt/app-root/etc/perl;
# perl_require Version.pm;
# perl_set $perl_version Version::installed;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /opt/app-root/etc/nginx.d/*.conf;
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
root /opt/app-root/src;
# Load configuration files for the default server block.
include /opt/app-root/etc/nginx.default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /opt/app-root/src;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers PROFILE=SYSTEM;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /opt/app-root/etc/nginx.default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

33
test/test-lib-nginx.sh Normal file
View file

@ -0,0 +1,33 @@
#!/bin/bash
#
# Functions for tests for the nginx 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_nginx_integration() {
ct_os_test_s2i_app "${IMAGE_NAME}" \
"https://github.com/sclorg/nginx-container.git" \
"examples/${VERSION}/test-app" \
"Test NGINX passed"
}
# Check the imagestream
function test_nginx_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/nginx-${OS%[0-9]*}.json" "${IMAGE_NAME}" \
"https://github.com/sclorg/nginx-container.git" \
"examples/${VERSION}/test-app" \
"Test NGINX passed"
}
# vim: set tabstop=2:shiftwidth=2:expandtab:

1414
test/test-lib-openshift.sh Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
../common/test-lib-remote-openshift.sh

1201
test/test-lib.sh Normal file

File diff suppressed because it is too large Load diff