-
Notifications
You must be signed in to change notification settings - Fork 196
Minimization #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Minimization #376
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| FROM quay.io/centos/centos:stream10 | ||
|
|
||
| EXPOSE 8080 | ||
| EXPOSE 8443 | ||
|
|
||
| ENV NAME=nginx \ | ||
| NGINX_VERSION=1.26 \ | ||
| NGINX_SHORT_VER=126 \ | ||
| VERSION=0 | ||
|
|
||
| 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}-${NGINX_SHORT_VER}-container" \ | ||
| name="sclorg/${NAME}-${NGINX_SHORT_VER}-minimal-c11s" \ | ||
| version="1" \ | ||
| com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI" \ | ||
| maintainer="SoftwareCollections.org <sclorg@redhat.com>" \ | ||
| help="For more information visit https://github.com/sclorg/${NAME}-container" \ | ||
| usage="s2i build <SOURCE-REPOSITORY> quay.io/sclorg/${NAME}-${NGINX_SHORT_VER}-minimal-c11s:latest <APP-NAME>" | ||
|
|
||
| # Install nginx and required packages using microdnf | ||
| RUN INSTALL_PKGS="nginx nss_wrapper-libs gettext hostname findutils tar" && \ | ||
| microdnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ | ||
| nginx -v 2>&1 | grep -qe "$NGINX_VERSION\." && echo "Found VERSION $NGINX_VERSION" && \ | ||
| microdnf -y clean all --enablerepo='*' | ||
|
|
||
| # These variables are normally provided by s2i-core, but we're using minimal base | ||
| ENV HOME=/opt/app-root/src \ | ||
| STI_SCRIPTS_PATH=/usr/libexec/s2i \ | ||
| APP_ROOT=/opt/app-root | ||
|
|
||
| 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 | ||
|
|
||
| COPY root / | ||
| COPY ./s2i/bin/ $STI_SCRIPTS_PATH | ||
|
|
||
| # Changing ownership and user rights to support following use-cases: | ||
| # 1) running container on OpenShift, whose default security model | ||
| # is to run the container under random UID, but GID=0 | ||
| # 2) for working root-less container with UID=1001, which does not have | ||
| # to have GID=0 | ||
| # 3) for default use-case, that is running container directly on operating system, | ||
| # with default UID and GID (1001:0) | ||
| # Supported combinations of UID:GID are thus following: | ||
| # UID=1001 && GID=0 | ||
| # UID=<any>&& GID=0 | ||
| # UID=1001 && GID=<any> | ||
| RUN sed -i -f ${NGINX_APP_ROOT}/nginxconf.sed ${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} && \ | ||
| chown -R 1001:0 ${NGINX_CONF_PATH} && \ | ||
| chown -R 1001:0 ${NGINX_APP_ROOT}/etc && \ | ||
| chown -R 1001:0 ${NGINX_APP_ROOT}/src/nginx-start/ && \ | ||
| chown -R 1001:0 ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \ | ||
| chown -R 1001:0 /var/lib/nginx /var/log/nginx /run && \ | ||
| chmod ug+rw ${NGINX_CONF_PATH} && \ | ||
| chmod -R ug+rwX ${NGINX_APP_ROOT}/etc && \ | ||
| chmod -R ug+rwX ${NGINX_APP_ROOT}/src/nginx-start/ && \ | ||
| chmod -R ug+rwX ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \ | ||
| chmod -R ug+rwX /var/lib/nginx /var/log/nginx /run | ||
|
|
||
| USER 1001 | ||
|
|
||
| STOPSIGNAL SIGQUIT | ||
|
|
||
| # 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| FROM ubi10-minimal:latest | ||
|
|
||
| EXPOSE 8080 | ||
| EXPOSE 8443 | ||
|
|
||
| ENV NAME=nginx \ | ||
| NGINX_VERSION=1.26 \ | ||
| NGINX_SHORT_VER=126 \ | ||
| VERSION=0 | ||
|
|
||
| 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}-${NGINX_SHORT_VER}-container" \ | ||
| name="rhel11/${NAME}-${NGINX_SHORT_VER}-minimal" \ | ||
| version="1" \ | ||
| com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#rhel" \ | ||
| maintainer="SoftwareCollections.org <sclorg@redhat.com>" \ | ||
| help="For more information visit https://github.com/sclorg/${NAME}-container" \ | ||
| usage="podman run -d --name nginx -p 8080:8080 rhel11/${NAME}-${NGINX_SHORT_VER}-minimal" | ||
|
|
||
| # Install nginx and required packages using microdnf | ||
| RUN INSTALL_PKGS="nginx nss_wrapper-libs gettext hostname findutils tar" && \ | ||
| microdnf -y --setopt=tsflags=nodocs install $INSTALL_PKGS && \ | ||
| nginx -v 2>&1 | grep -qe "$NGINX_VERSION\." && echo "Found VERSION $NGINX_VERSION" && \ | ||
| microdnf -y clean all --enablerepo='*' | ||
|
|
||
| # These variables are normally provided by s2i-core, but we're using minimal base | ||
| ENV HOME=/opt/app-root/src \ | ||
| STI_SCRIPTS_PATH=/usr/libexec/s2i \ | ||
| APP_ROOT=/opt/app-root | ||
|
|
||
| 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 | ||
|
|
||
| COPY $NGINX_VERSION/root / | ||
| COPY $NGINX_VERSION/s2i/bin/ $STI_SCRIPTS_PATH | ||
|
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🔴 Critical 🧩 Analysis chain🏁 Script executed: #!/bin/bash
fd -t d 'root$' -p '1.26*'
fd -a 'Makefile' -d 2
rg -n 'NGINX_VERSION|VERSIONS|context|COPY .*root' Makefile 2>/dev/nullRepository: sclorg/nginx-container Length of output: 325 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== top-level files/dirs around 1.26 =="
fd -a -t d '^(1\.26|1\.26-minimal)$' .
echo
echo "== Dockerfile snippets =="
for f in 1.26-minimal/Dockerfile.rhel11 1.26/Dockerfile.rhel11; do
if [ -f "$f" ]; then
echo "-- $f --"
nl -ba "$f" | sed -n '1,140p'
fi
done
echo
echo "== make/build context references =="
rg -n '^(VERSIONS|.*context|.*docker build|.*buildx|.*dockerfile|.*1\.26|minimal)' /home/jailuser/git/Makefile 2>/dev/null || true
echo
echo "== files under version dirs matching root or s2i/bin =="
find 1.26 1.26-minimal -maxdepth 3 \( -path '*/root' -o -path '*/s2i/bin' -o -path '*/s2i/bin/*' \) -print 2>/dev/null | sortRepository: sclorg/nginx-container Length of output: 396 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== inspect repository tree relevant to 1.26 variants =="
find . -maxdepth 2 \( -type d -o -type f \) | sed 's#^\./##' | sort | rg '^(1\.26|1\.26-minimal)(/|$)|(^|/)Makefile$|(^|/)Dockerfile\.rhel11$'Repository: sclorg/nginx-container Length of output: 602 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== 1.26-minimal/Dockerfile.rhel11 =="
sed -n '1,120p' 1.26-minimal/Dockerfile.rhel11
echo
echo "== 1.26-minimal/Dockerfile.c11s =="
sed -n '1,120p' 1.26-minimal/Dockerfile.c11s
echo
echo "== Makefile build rules mentioning 1.26-minimal or Dockerfile.rhel11 =="
rg -n -C 2 '1\.26-minimal|Dockerfile\.rhel11|docker build|buildx|context|root /|s2i/bin' MakefileRepository: sclorg/nginx-container Length of output: 8429 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== minimal variant references across repo =="
rg -n -C 2 '1\.26-minimal|Dockerfile\.rhel11|COPY .*root|COPY .*s2i/bin|STI_SCRIPTS_PATH|NGINX_VERSION' 1.26-minimal 1.26 MakefileRepository: sclorg/nginx-container Length of output: 21686 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== 1.26-minimal/Dockerfile.rhel11 =="
sed -n '1,120p' 1.26-minimal/Dockerfile.rhel11
echo
echo "== 1.26-minimal/Dockerfile.c11s =="
sed -n '1,120p' 1.26-minimal/Dockerfile.c11s
echo
echo "== Makefile snippets for 1.26-minimal build context =="
rg -n -C 3 '1\.26-minimal|Dockerfile\.rhel11|docker build|buildx|context' MakefileRepository: sclorg/nginx-container Length of output: 8412 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== line-numbered excerpt from 1.26-minimal/Dockerfile.rhel11 =="
python3 - <<'PY'
from pathlib import Path
p = Path("1.26-minimal/Dockerfile.rhel11")
for i, line in enumerate(p.read_text().splitlines(), 1):
if 1 <= i <= 120:
print(f"{i:4d}: {line}")
PYRepository: sclorg/nginx-container Length of output: 4828 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Makefile around version/build rules =="
python3 - <<'PY'
from pathlib import Path
p = Path("Makefile")
for i, line in enumerate(p.read_text().splitlines(), 1):
if 1 <= i <= 220:
print(f"{i:4d}: {line}")
PYRepository: sclorg/nginx-container Length of output: 672 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== build tooling references to DOCKER_BUILD_CONTEXT =="
rg -n -C 3 'DOCKER_BUILD_CONTEXT|docker build|context-dir|Dockerfile\.rhel11|1\.26-minimal' common Makefile .github 2>/dev/null || true
echo
echo "== minimal README hints =="
sed -n '1,120p' 1.26-minimal/README.mdRepository: sclorg/nginx-container Length of output: 6157 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== common/build.sh excerpt =="
if [ -f common/build.sh ]; then
python3 - <<'PY'
from pathlib import Path
p = Path("common/build.sh")
for i, line in enumerate(p.read_text().splitlines(), 1):
if 1 <= i <= 240:
print(f"{i:4d}: {line}")
PY
fi
echo
echo "== common/common.mk excerpt =="
if [ -f common/common.mk ]; then
python3 - <<'PY'
from pathlib import Path
p = Path("common/common.mk")
for i, line in enumerate(p.read_text().splitlines(), 1):
if 1 <= i <= 260:
print(f"{i:4d}: {line}")
PY
fiRepository: sclorg/nginx-container Length of output: 222 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== tree comparison: 1.26 vs 1.26-minimal =="
for d in root s2i/bin; do
echo "-- $d --"
echo "1.26/$d:"
find "1.26/$d" -maxdepth 3 -type f | sort | sed 's#^# #'
echo "1.26-minimal/$d:"
find "1.26-minimal/$d" -maxdepth 3 -type f | sort | sed 's#^# #'
done
echo
echo "== build entrypoints mentioning Dockerfile.rhel11 or minimal =="
rg -n -C 2 'Dockerfile\.rhel11|1\.26-minimal|minimal' . --glob '!*README.md' --glob '!**/README.md' 2>/dev/null || trueRepository: sclorg/nginx-container Length of output: 5701 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== root Makefile around build targets =="
python3 - <<'PY'
from pathlib import Path
p = Path("Makefile")
lines = p.read_text().splitlines()
for i, line in enumerate(lines, 1):
if 1 <= i <= 220:
print(f"{i:4d}: {line}")
PY
echo
echo "== search for DOCKER_BUILD_CONTEXT usage =="
rg -n -C 3 'DOCKER_BUILD_CONTEXT|docker build|buildx|Dockerfile\.rhel11|1\.26-minimal' . 2>/dev/null | sed -n '1,220p'Repository: sclorg/nginx-container Length of output: 1715 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== versioned directories under repo root =="
find . -maxdepth 2 -type d \( -name '1.26' -o -name '1.26-minimal' -o -name 'common' \) | sort
echo
echo "== any Makefile in subdirs =="
find . -maxdepth 2 -name 'Makefile' -o -name 'makefile' | sortRepository: sclorg/nginx-container Length of output: 293 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Makefile (full, if small enough) =="
wc -l Makefile
sed -n '1,260p' Makefile
echo
echo "== files referencing DOCKER_BUILD_CONTEXT or versioned Dockerfiles =="
rg -n -C 2 'DOCKER_BUILD_CONTEXT|Dockerfile\.rhel11|1\.26-minimal|docker build|build:' . 2>/dev/nullRepository: sclorg/nginx-container Length of output: 1806 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== repository files at shallow depth =="
find . -maxdepth 2 \( -type f -o -type d \) | sed 's#^\./##' | sort | sed -n '1,240p'Repository: sclorg/nginx-container Length of output: 2345 Copy the minimal overlay locally in 🤖 Prompt for AI Agents |
||
|
|
||
| # Changing ownership and user rights to support following use-cases: | ||
| # 1) running container on OpenShift, whose default security model | ||
| # is to run the container under random UID, but GID=0 | ||
| # 2) for working root-less container with UID=1001, which does not have | ||
| # to have GID=0 | ||
| # 3) for default use-case, that is running container directly on operating system, | ||
| # with default UID and GID (1001:0) | ||
| # Supported combinations of UID:GID are thus following: | ||
| # UID=1001 && GID=0 | ||
| # UID=<any>&& GID=0 | ||
| # UID=1001 && GID=<any> | ||
| RUN sed -i -f ${NGINX_APP_ROOT}/nginxconf.sed ${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} && \ | ||
| chown -R 1001:0 ${NGINX_CONF_PATH} && \ | ||
| chown -R 1001:0 ${NGINX_APP_ROOT}/etc && \ | ||
| chown -R 1001:0 ${NGINX_APP_ROOT}/src/nginx-start/ && \ | ||
| chown -R 1001:0 ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \ | ||
| chown -R 1001:0 /var/lib/nginx /var/log/nginx /run && \ | ||
| chmod ug+rw ${NGINX_CONF_PATH} && \ | ||
| chmod -R ug+rwX ${NGINX_APP_ROOT}/etc && \ | ||
| chmod -R ug+rwX ${NGINX_APP_ROOT}/src/nginx-start/ && \ | ||
| chmod -R ug+rwX ${NGINX_CONTAINER_SCRIPTS_PATH}/nginx-start && \ | ||
| chmod -R ug+rwX /var/lib/nginx /var/log/nginx /run | ||
|
|
||
| USER 1001 | ||
|
|
||
| STOPSIGNAL SIGQUIT | ||
|
|
||
| # 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 | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,205 @@ | ||||||||||||||||||||||||||||||||||
| Nginx 1.26 server and a reverse proxy server container image | ||||||||||||||||||||||||||||||||||
| ============================================================ | ||||||||||||||||||||||||||||||||||
| This container image includes Nginx 1.26 server and a reverse server for OpenShift and general usage. | ||||||||||||||||||||||||||||||||||
| Users can choose between RHEL, CentOS Stream and Fedora based images. | ||||||||||||||||||||||||||||||||||
| The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), | ||||||||||||||||||||||||||||||||||
| 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.26 daemon. The image can be used | ||||||||||||||||||||||||||||||||||
| as a base image for other applications based on nginx 1.26 web server. | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win README does not reflect the minimal / UBI10 variant. This README lives under Also applies to: 25-25 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| 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 `ubi9/nginx-126` image, available through the `nginx:1.26` imagestream tag in Openshift. | ||||||||||||||||||||||||||||||||||
| To build a simple [test-app](https://github.com/sclorg/nginx-container/tree/master/examples/1.26/test-app) application in Openshift: | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||
| oc new-app nginx:1.26~https://github.com/sclorg/nginx-container.git --context-dir=1.26/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.14/openshift_images/create-images.html#images-create-s2i_create-images) | ||||||||||||||||||||||||||||||||||
| (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 ubi9/nginx-126 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #### 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.26/ | ||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #### 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); see more about these scripts in the section "Source-to-Image framework and scripts" above), that already know how to set-up and run some common Nginx applications. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ##### 3.1. To use your own setup, create a Dockerfile with this content: | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||
| FROM registry.access.redhat.com/ubi9/nginx-126 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # 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/ubi9/nginx-126 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Add application sources to a directory where 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 ubi9/nginx-126 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/`. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| 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> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| 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. | ||||||||||||||||||||||||||||||||||
| for RHEL8 it's `Dockerfile.rhel8`, Dockerfile for RHEL10 is called `Dockerfile.rhel10`, | ||||||||||||||||||||||||||||||||||
| Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s`, | ||||||||||||||||||||||||||||||||||
| Dockerfile for CentOS Stream 10 is called `Dockerfile.c10s`, and the Fedora Dockerfile is called `Dockerfile.fedora`. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
Comment on lines
+197
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Two problems here:
📝 Proposed fix-In that repository you also can find another versions of Python environment Dockerfiles.
-for RHEL8 it's `Dockerfile.rhel8`, Dockerfile for RHEL10 is called `Dockerfile.rhel10`,
-Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s`,
-Dockerfile for CentOS Stream 10 is called `Dockerfile.c10s`, and the Fedora Dockerfile is called `Dockerfile.fedora`.
+In that repository you also can find other versions of nginx Dockerfiles.
+For this minimal variant, the RHEL Dockerfile is called `Dockerfile.rhel11`
+and the CentOS Stream 10 Dockerfile is called `Dockerfile.c11s`.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Duplicate
io.openshift.expose-serviceslabel drops the HTTP mapping.LABELkeys must be unique; the second declaration overrides the first, so the final image only advertises8443:httpsand loses8080:http. Combine both ports into a single value.🐛 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents