Compare commits
8 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
09fc059ddf | ||
|
|
26c1699db4 | ||
|
|
66e413c1a6 | ||
|
|
af6d45b653 | ||
|
|
739625db96 | ||
|
|
72b927fcdb | ||
|
|
6928218b35 |
||
|
|
d32edfb53d |
13 changed files with 1 additions and 457 deletions
69
Dockerfile
69
Dockerfile
|
|
@ -1,69 +0,0 @@
|
|||
FROM registry.fedoraproject.org/f26/s2i-base:latest
|
||||
|
||||
# nginx 1.12 image.
|
||||
#
|
||||
# Volumes:
|
||||
# * /var/log/nginx/ - Storage for logs
|
||||
|
||||
EXPOSE 8080
|
||||
EXPOSE 8443
|
||||
|
||||
ENV NAME=nginx \
|
||||
NGINX_VERSION=1.12 \
|
||||
VERSION=0 \
|
||||
RELEASE=1 \
|
||||
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="$SUMMARY" \
|
||||
io.k8s.display-name="Nginx $NGINX_VERSION" \
|
||||
io.openshift.expose-services="8080:http" \
|
||||
io.openshift.expose-services="8443:https" \
|
||||
io.openshift.tags="builder,nginx,nginx112" \
|
||||
com.redhat.component="$NAME" \
|
||||
name="$FGC/$NAME" \
|
||||
version="$VERSION" \
|
||||
release="$RELEASE.$DISTTAG" \
|
||||
architecture="$ARCH" \
|
||||
usage="s2i build file:///your/app $FGC/nginx your-app"
|
||||
|
||||
ENV NGINX_CONFIGURATION_PATH=/opt/app-root/etc/nginx.d
|
||||
ENV NGINX_DEFAULT_CONF_PATH=/opt/app-root/etc/nginx.default.d
|
||||
|
||||
RUN dnf install -y gettext hostname && \
|
||||
INSTALL_PKGS="nss_wrapper bind-utils nginx" && \
|
||||
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 /opt/app-root/nginxconf-fed.sed /etc/nginx/nginx.conf && \
|
||||
mkdir -p /opt/app-root/etc/nginx.d/ && \
|
||||
mkdir -p /opt/app-root/etc/nginx.default.d/ && \
|
||||
chmod -R a+rwx /opt/app-root/etc && \
|
||||
chmod -R a+rwx /var /run && \
|
||||
chown -R 1001:0 /opt/app-root && \
|
||||
chown -R 1001:0 /var
|
||||
|
||||
USER 1001
|
||||
|
||||
VOLUME ["/usr/share/nginx/html"]
|
||||
VOLUME ["/var/log/nginx/"]
|
||||
|
||||
CMD $STI_SCRIPTS_PATH/usage
|
||||
80
README.md
80
README.md
|
|
@ -1,80 +0,0 @@
|
|||
Nginx 1.12 server and a reverse proxy server Docker image
|
||||
=========================================================
|
||||
|
||||
This container image includes Nginx 1.12 server and a reverse server for OpenShift and general usage.
|
||||
Users can choose RHEL based image.
|
||||
The RHEL image is available in the [Red Hat Container Catalog](https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/nginx-112-rhel7)
|
||||
as registry.access.redhat.com/rhscl/nginx-112-rhel7.
|
||||
|
||||
|
||||
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.12 daemon. The image can be used
|
||||
as a base image for other applications based on nginx 1.12 web server.
|
||||
Nginx server image can be extended using source-to-image tool.
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
To build a simple [sample-app](https://github.com/sclorg/nginx-container/tree/master/1.12/test/test-app) application
|
||||
using standalone [S2I](https://github.com/openshift/source-to-image) and then run the
|
||||
resulting image with [Docker](http://docker.io) execute:
|
||||
|
||||
* **For RHEL based image**
|
||||
```
|
||||
$ s2i build https://github.com/sclorg/nginx-container.git --context-dir=1.12/test/test-app/ rhscl/nginx-112-rhel7 nginx-sample-app
|
||||
$ docker run -p 8080:8080 nginx-sample-app
|
||||
```
|
||||
|
||||
* **For CentOS based image**
|
||||
```
|
||||
$ s2i build https://github.com/sclorg/nginx-container.git --context-dir=1.12/test/test-app/ centos/nginx-112-centos7 nginx-sample-app
|
||||
$ docker run -p 8080:8080 nginx-sample-app
|
||||
```
|
||||
|
||||
**Accessing the application:**
|
||||
```
|
||||
$ curl 127.0.0.1:8080
|
||||
```
|
||||
|
||||
|
||||
S2I build support
|
||||
-------------
|
||||
Nginx server image can be extended using S2I tool (see Usage section).
|
||||
S2I build folder structure:
|
||||
|
||||
| Folder name | Description |
|
||||
| :-------------------------- | ----------------------------------------- |
|
||||
| ./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 |
|
||||
| ./ | Should contain nginx application source code |
|
||||
|
||||
Environment variables and volumes
|
||||
-------------
|
||||
The nginx container image supports the following configuration variable, which can be set by using the `-e` option with the docker run command:
|
||||
|
||||
|
||||
| Variable name | Description |
|
||||
| :--------------------- | ----------------------------------------- |
|
||||
| `NGINX_LOG_TO_VOLUME` | When `NGINX_LOG_TO_VOLUME` is set, nginx logs into `/var/opt/rh/rh-nginx112/log/nginx/` |
|
||||
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
By default, nginx logs into standard output, so the log is available in the container log. The log can be examined by running:
|
||||
|
||||
docker logs <container>
|
||||
|
||||
**If `NGINX_LOG_TO_VOLUME` variable is set, nginx logs into `/var/opt/rh/rh-nginx112/log/nginx/`, which can be mounted to host system using the Docker volumes.**
|
||||
|
||||
|
||||
See also
|
||||
--------
|
||||
Dockerfile and other sources for this container image are available on
|
||||
https://github.com/sclorg/nginx-container.
|
||||
In that repository, Dockerfile for CentOS is called Dockerfile, Dockerfile
|
||||
for RHEL is called Dockerfile.rhel7.
|
||||
1
dead.package
Normal file
1
dead.package
Normal file
|
|
@ -0,0 +1 @@
|
|||
container sources not used for building fedora containers anymore
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# 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
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
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
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# This will make scl collection binaries work out of box.
|
||||
unset BASH_ENV PROMPT_COMMAND ENV
|
||||
source scl_source enable rh-nginx112
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
/listen/s%80%8080%
|
||||
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%
|
||||
s%/var/log/nginx/error.log%stderr%
|
||||
s%access_log /var/log/nginx/access.log main;%%
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
/listen/s%80%8080%
|
||||
s/^user *nginx;//
|
||||
s%/etc/opt/rh/rh-nginx112/nginx/conf.d/%/opt/app-root/etc/nginx.d/%
|
||||
s%/etc/opt/rh/rh-nginx112/nginx/default.d/%/opt/app-root/etc/nginx.default.d/%
|
||||
s%/opt/rh/rh-nginx112/root/usr/share/nginx/html%/opt/app-root/src%
|
||||
s%/var/opt/rh/rh-nginx112/log/nginx/error.log%stderr%
|
||||
s%access_log /var/opt/rh/rh-nginx112/log/nginx/access.log main;%%
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "---> Installing application source"
|
||||
cp -Rf /tmp/src/. ./
|
||||
|
||||
if [ -d ./nginx-cfg ]; then
|
||||
echo "---> Copying nginx configuration files..."
|
||||
if [ "$(ls -A ./nginx-cfg/*.conf)" ]; then
|
||||
cp -v ./nginx-cfg/*.conf "${NGINX_CONFIGURATION_PATH}"
|
||||
rm -rf ./nginx-cfg
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -d ./nginx-default-cfg ]; then
|
||||
echo "---> Copying nginx default server configuration files..."
|
||||
if [ "$(ls -A ./nginx-default-cfg/*.conf)" ]; then
|
||||
cp -v ./nginx-default-cfg/*.conf "${NGINX_DEFAULT_CONF_PATH}"
|
||||
rm -rf ./nginx-default-cfg
|
||||
fi
|
||||
fi
|
||||
|
||||
# Fix source directory permissions
|
||||
fix-permissions ./
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
source /opt/app-root/etc/generate_container_user
|
||||
|
||||
set -e
|
||||
|
||||
exec nginx -g "daemon off;"
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#!/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/nginx-container.git --context-dir=1.12/test/test-app/ ${NAMESPACE}/nginx-112-${DISTRO}7 nginx-sample-app
|
||||
|
||||
You can then run the resulting image via:
|
||||
docker run -p 8080:8080 nginx-sample-app
|
||||
EOF
|
||||
217
test/run
217
test/run
|
|
@ -1,217 +0,0 @@
|
|||
#!/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.
|
||||
#
|
||||
IMAGE_NAME=${IMAGE_NAME:-rhscl/nginx-112-rhel7}
|
||||
|
||||
# TODO: Make command compatible for Mac users
|
||||
test_dir="$(readlink -zf $(dirname "${BASH_SOURCE[0]}"))"
|
||||
image_dir=$(readlink -zf ${test_dir}/..)
|
||||
|
||||
# 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() {
|
||||
s2i build ${s2i_args} file://${test_dir}/test-app ${IMAGE_NAME} ${IMAGE_NAME}-testapp
|
||||
}
|
||||
|
||||
prepare() {
|
||||
if ! image_exists ${IMAGE_NAME}; then
|
||||
echo "ERROR: The image ${IMAGE_NAME} must exist before this script is executed."
|
||||
exit 1
|
||||
fi
|
||||
# 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}/test-app >/dev/null
|
||||
git init
|
||||
git config user.email "build@localhost" && git config user.name "builder"
|
||||
git add -A && git commit -m "Sample commit"
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
run_test_application() {
|
||||
run_args=${CONTAINER_ARGS:-}
|
||||
docker run --user=100001 ${run_args} --cidfile=${cid_file} ${IMAGE_NAME}-testapp
|
||||
}
|
||||
|
||||
cleanup_test_app() {
|
||||
info "Cleaning up the test application"
|
||||
if [ -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}-testapp; then
|
||||
docker rmi -f ${IMAGE_NAME}-testapp
|
||||
fi
|
||||
rm -rf ${test_dir}/test-app/.git
|
||||
}
|
||||
|
||||
check_result() {
|
||||
local result="$1"
|
||||
if [[ "$result" != "0" ]]; then
|
||||
info "TEST FAILED (${result})"
|
||||
cleanup
|
||||
exit $result
|
||||
fi
|
||||
}
|
||||
|
||||
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'"
|
||||
s2i usage ${s2i_args} ${IMAGE_NAME} &>/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
|
||||
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
|
||||
}
|
||||
|
||||
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 -s -H "Host: ${host}" ${url})
|
||||
echo "${response}"
|
||||
status=$?
|
||||
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_application() {
|
||||
# Verify that the HTTP connection can be established to test application container
|
||||
run_test_application &
|
||||
|
||||
# Wait for the container to write it's CID file
|
||||
wait_for_cid
|
||||
|
||||
test_scl_usage "nginx -v" "nginx version: nginx/1.12."
|
||||
check_result $?
|
||||
|
||||
test_connection
|
||||
check_result $?
|
||||
cleanup_test_app
|
||||
}
|
||||
|
||||
cid_file=$(mktemp -u --suffix=.cid)
|
||||
|
||||
# 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
|
||||
run_s2i_build
|
||||
check_result $?
|
||||
|
||||
# Verify the 'usage' script is working properly when running the base image with 's2i usage ...'
|
||||
test_s2i_usage
|
||||
check_result $?
|
||||
|
||||
# Verify the 'usage' script is working properly when running the base image with 'docker run ...'
|
||||
test_docker_run_usage
|
||||
check_result $?
|
||||
|
||||
# Test application with default uid
|
||||
test_application
|
||||
|
||||
# Test application with random uid
|
||||
CONTAINER_ARGS="-u 12345" test_application
|
||||
cleanup
|
||||
|
||||
info "All tests finished successfully."
|
||||
|
|
@ -1 +0,0 @@
|
|||
../../examples/1.12/test-app
|
||||
Loading…
Add table
Add a link
Reference in a new issue