diff --git a/18-minimal/.exclude-c8s b/18-minimal/.exclude-c8s deleted file mode 100644 index e69de29b..00000000 diff --git a/18-minimal/.exclude-c9s b/18-minimal/.exclude-c9s deleted file mode 100644 index e69de29b..00000000 diff --git a/18-minimal/Dockerfile.c8s b/18-minimal/Dockerfile.c8s deleted file mode 100644 index 07b65fb4..00000000 --- a/18-minimal/Dockerfile.c8s +++ /dev/null @@ -1,70 +0,0 @@ -FROM quay.io/sclorg/s2i-core-c8s - -EXPOSE 8080 - -# Add $HOME/node_modules/.bin to the $PATH, allowing user to make npm scripts -# available on the CLI without using npm's --global installation mode -# This image will be initialized with "npm run $NPM_RUN" -# See https://docs.npmjs.com/misc/scripts, and your repo's package.json -# file for possible values of NPM_RUN -# Description -# Environment: -# * $NPM_RUN - Select an alternate / custom runtime mode, defined in your package.json files' scripts section (default: npm run "start"). -# Expose ports: -# * 8080 - Unprivileged port used by nodejs application -ENV APP_ROOT=/opt/app-root \ - # The $HOME is not set by default, but some applications need this variable - HOME=/opt/app-root/src \ - NPM_RUN=start \ - PLATFORM="el8" \ - NODEJS_VERSION=18 \ - NPM_RUN=start \ - NAME=nodejs - -ENV SUMMARY="Minimal image for running Node.js $NODEJS_VERSION applications" \ - DESCRIPTION="Node.js $NODEJS_VERSION available as container is a base platform for \ -running various Node.js $NODEJS_VERSION applications and frameworks. \ -Node.js is a platform built on Chrome's JavaScript runtime for easily building \ -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model \ -that makes it lightweight and efficient, perfect for data-intensive real-time applications \ -that run across distributed devices." \ - NPM_CONFIG_PREFIX=$HOME/.npm-global \ - PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="Node.js $NODEJS_VERSION Minimal" \ - io.openshift.expose-services="8080:http" \ - io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ - io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.s2i.scripts-url="image:///usr/libexec/s2i" \ - com.redhat.dev-mode="DEV_MODE:false" \ - com.redhat.deployments-dir="${APP_ROOT}/src" \ - com.redhat.dev-mode.port="DEBUG_PORT:5858" \ - com.redhat.component="${NAME}-${NODEJS_VERSION}-minimal-container" \ - name="sclorg/$NAME-$NODEJS_VERSION-minimal-c8s" \ - version="1" \ - maintainer="SoftwareCollections.org " \ - help="For more information visit https://github.com/sclorg/s2i-nodejs-container" - -# nodejs-full-i18n is included for error strings -RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which" && \ - microdnf -y module disable nodejs && \ - microdnf -y module enable nodejs:$NODEJS_VERSION && \ - microdnf --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ - node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ - microdnf clean all && \ - rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* - -COPY ./s2i/bin/ /usr/libexec/s2i - -RUN chmod +x /usr/libexec/s2i/init-wrapper - -# Copy extra files to the image. -COPY ./root/ / - -# Drop the root user and make the content of /opt/app-root owned by user 1001 -RUN mkdir -p "$HOME" && chown -R 1001:0 "$APP_ROOT" && chmod -R ug+rwx "$APP_ROOT" -WORKDIR "$HOME" -USER 1001 diff --git a/18-minimal/Dockerfile.c9s b/18-minimal/Dockerfile.c9s deleted file mode 100644 index ecba5276..00000000 --- a/18-minimal/Dockerfile.c9s +++ /dev/null @@ -1,69 +0,0 @@ -FROM quay.io/sclorg/s2i-core-c9s - -EXPOSE 8080 - -# Add $HOME/node_modules/.bin to the $PATH, allowing user to make npm scripts -# available on the CLI without using npm's --global installation mode -# This image will be initialized with "npm run $NPM_RUN" -# See https://docs.npmjs.com/misc/scripts, and your repo's package.json -# file for possible values of NPM_RUN -# Description -# Environment: -# * $NPM_RUN - Select an alternate / custom runtime mode, defined in your package.json files' scripts section (default: npm run "start"). -# Expose ports: -# * 8080 - Unprivileged port used by nodejs application -ENV APP_ROOT=/opt/app-root \ - # The $HOME is not set by default, but some applications need this variable - HOME=/opt/app-root/src \ - NPM_RUN=start \ - PLATFORM="el9" \ - NODEJS_VERSION=18 \ - NPM_RUN=start \ - NAME=nodejs - -ENV SUMMARY="Minimal image for running Node.js $NODEJS_VERSION applications" \ - DESCRIPTION="Node.js $NODEJS_VERSION available as container is a base platform for \ -running various Node.js $NODEJS_VERSION applications and frameworks. \ -Node.js is a platform built on Chrome's JavaScript runtime for easily building \ -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model \ -that makes it lightweight and efficient, perfect for data-intensive real-time applications \ -that run across distributed devices." \ - NPM_CONFIG_PREFIX=$HOME/.npm-global \ - PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="Node.js $NODEJS_VERSION Micro" \ - io.openshift.expose-services="8080:http" \ - io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ - io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.s2i.scripts-url="image:///usr/libexec/s2i" \ - com.redhat.dev-mode="DEV_MODE:false" \ - com.redhat.deployments-dir="${APP_ROOT}/src" \ - com.redhat.dev-mode.port="DEBUG_PORT:5858" \ - com.redhat.component="${NAME}-${NODEJS_VERSION}-minimal-container" \ - name="sclorg/$NAME-$NODEJS_VERSION-minimal-c9s" \ - version="1" \ - maintainer="SoftwareCollections.org " \ - help="For more information visit https://github.com/sclorg/s2i-nodejs-container" - -# nodejs-full-i18n is included for error strings -RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which" && \ - microdnf -y module disable nodejs && \ - microdnf -y module enable nodejs:$NODEJS_VERSION && \ - microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ - node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ - microdnf clean all && \ - rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* - -COPY ./s2i/bin/ /usr/libexec/s2i -RUN chmod +x /usr/libexec/s2i/init-wrapper - -# Copy extra files to the image. -COPY ./root/ / - -# Drop the root user and make the content of /opt/app-root owned by user 1001 -RUN mkdir -p "$HOME" && chown -R 1001:0 "$APP_ROOT" && chmod -R ug+rwx "$APP_ROOT" -WORKDIR "$HOME" -USER 1001 diff --git a/18-minimal/Dockerfile.rhel8 b/18-minimal/Dockerfile.rhel8 deleted file mode 100644 index 61327509..00000000 --- a/18-minimal/Dockerfile.rhel8 +++ /dev/null @@ -1,71 +0,0 @@ -FROM ubi8/ubi-minimal:latest - -EXPOSE 8080 - -# Add $HOME/node_modules/.bin to the $PATH, allowing user to make npm scripts -# available on the CLI without using npm's --global installation mode -# This image will be initialized with "npm run $NPM_RUN" -# See https://docs.npmjs.com/misc/scripts, and your repo's package.json -# file for possible values of NPM_RUN -# Description -# Environment: -# * $NPM_RUN - Select an alternate / custom runtime mode, defined in your package.json files' scripts section (default: npm run "start"). -# Expose ports: -# * 8080 - Unprivileged port used by nodejs application -ENV APP_ROOT=/opt/app-root \ - # The $HOME is not set by default, but some applications need this variable - HOME=/opt/app-root/src \ - NPM_RUN=start \ - PLATFORM="el8" \ - NODEJS_VERSION=18 \ - NPM_RUN=start \ - NAME=nodejs - -ENV SUMMARY="Minimal image for running Node.js $NODEJS_VERSION applications" \ - DESCRIPTION="Node.js $NODEJS_VERSION available as container is a base platform for \ -running various Node.js $NODEJS_VERSION applications and frameworks. \ -Node.js is a platform built on Chrome's JavaScript runtime for easily building \ -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model \ -that makes it lightweight and efficient, perfect for data-intensive real-time applications \ -that run across distributed devices." \ - NPM_CONFIG_PREFIX=$HOME/.npm-global \ - PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="Node.js $NODEJS_VERSION Minimal" \ - io.openshift.expose-services="8080:http" \ - io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ - io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.s2i.scripts-url="image:///usr/libexec/s2i" \ - com.redhat.dev-mode="DEV_MODE:false" \ - com.redhat.deployments-dir="${APP_ROOT}/src" \ - com.redhat.dev-mode.port="DEBUG_PORT:5858" \ - com.redhat.component="${NAME}-${NODEJS_VERSION}-minimal-container" \ - name="ubi8/$NAME-$NODEJS_VERSION-minimal" \ - version="1" \ - com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI" \ - maintainer="SoftwareCollections.org " \ - help="For more information visit https://github.com/sclorg/s2i-nodejs-container" - -# nodejs-full-i18n is included for error strings -RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which" && \ - microdnf -y module disable nodejs && \ - microdnf -y module enable nodejs:$NODEJS_VERSION && \ - microdnf --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ - node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ - microdnf clean all && \ - rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* - -COPY ./s2i/bin/ /usr/libexec/s2i - -RUN chmod +x /usr/libexec/s2i/init-wrapper - -# Copy extra files to the image. -COPY ./root/ / - -# Drop the root user and make the content of /opt/app-root owned by user 1001 -RUN mkdir -p "$HOME" && chown -R 1001:0 "$APP_ROOT" && chmod -R ug+rwx "$APP_ROOT" -WORKDIR "$HOME" -USER 1001 diff --git a/18-minimal/Dockerfile.rhel9 b/18-minimal/Dockerfile.rhel9 deleted file mode 100644 index cdff8219..00000000 --- a/18-minimal/Dockerfile.rhel9 +++ /dev/null @@ -1,71 +0,0 @@ -FROM ubi9/ubi-minimal - -EXPOSE 8080 - -# Add $HOME/node_modules/.bin to the $PATH, allowing user to make npm scripts -# available on the CLI without using npm's --global installation mode -# This image will be initialized with "npm run $NPM_RUN" -# See https://docs.npmjs.com/misc/scripts, and your repo's package.json -# file for possible values of NPM_RUN -# Description -# Environment: -# * $NPM_RUN - Select an alternate / custom runtime mode, defined in your package.json files' scripts section (default: npm run "start"). -# Expose ports: -# * 8080 - Unprivileged port used by nodejs application -ENV APP_ROOT=/opt/app-root \ - # The $HOME is not set by default, but some applications need this variable - HOME=/opt/app-root/src \ - NPM_RUN=start \ - PLATFORM="el9" \ - NODEJS_VERSION=18 \ - NPM_RUN=start \ - NAME=nodejs - -ENV SUMMARY="Minimal image for running Node.js $NODEJS_VERSION applications" \ - DESCRIPTION="Node.js $NODEJS_VERSION available as container is a base platform for \ -running various Node.js $NODEJS_VERSION applications and frameworks. \ -Node.js is a platform built on Chrome's JavaScript runtime for easily building \ -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model \ -that makes it lightweight and efficient, perfect for data-intensive real-time applications \ -that run across distributed devices." \ - NPM_CONFIG_PREFIX=$HOME/.npm-global \ - PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH - -LABEL summary="$SUMMARY" \ - description="$DESCRIPTION" \ - io.k8s.description="$DESCRIPTION" \ - io.k8s.display-name="Node.js $NODEJS_VERSION Micro" \ - io.openshift.expose-services="8080:http" \ - io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ - io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.s2i.scripts-url="image:///usr/libexec/s2i" \ - com.redhat.dev-mode="DEV_MODE:false" \ - com.redhat.deployments-dir="${APP_ROOT}/src" \ - com.redhat.dev-mode.port="DEBUG_PORT:5858" \ - com.redhat.component="${NAME}-${NODEJS_VERSION}-minimal-container" \ - name="ubi9/$NAME-$NODEJS_VERSION-minimal" \ - version="1" \ - com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI" \ - maintainer="SoftwareCollections.org " \ - help="For more information visit https://github.com/sclorg/s2i-nodejs-container" - -# nodejs-full-i18n is included for error strings -RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which" && \ - microdnf -y module disable nodejs && \ - microdnf -y module enable nodejs:$NODEJS_VERSION && \ - microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ - node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ - microdnf clean all && \ - rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* - -COPY ./s2i/bin/ /usr/libexec/s2i - -RUN chmod +x /usr/libexec/s2i/init-wrapper - -# Copy extra files to the image. -COPY ./root/ / - -# Drop the root user and make the content of /opt/app-root owned by user 1001 -RUN mkdir -p "$HOME" && chown -R 1001:0 "$APP_ROOT" && chmod -R ug+rwx "$APP_ROOT" -WORKDIR "$HOME" -USER 1001 diff --git a/18-minimal/README.md b/18-minimal/README.md deleted file mode 100644 index 28f2ac21..00000000 --- a/18-minimal/README.md +++ /dev/null @@ -1,4 +0,0 @@ -NodeJS 18 minimal container image -========================= - -**The NodeJS 18 minimal image is deprecated.** \ No newline at end of file diff --git a/18-minimal/root/usr/bin/fix-permissions b/18-minimal/root/usr/bin/fix-permissions deleted file mode 100755 index ddd33ace..00000000 --- a/18-minimal/root/usr/bin/fix-permissions +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# Allow this script to fail without failing a build -set +e - -SYMLINK_OPT=${2:--L} - -# Fix permissions on the given directory or file to allow group read/write of -# regular files and execute of directories. - -[ $(id -u) -ne 0 ] && CHECK_OWNER=" -uid $(id -u)" - -# If argument does not exist, script will still exit with 0, -# but at least we'll see something went wrong in the log -if ! [ -e "$1" ] ; then - echo "ERROR: File or directory $1 does not exist." >&2 - # We still want to end successfully - exit 0 -fi - -find $SYMLINK_OPT "$1" ${CHECK_OWNER} \! -gid 0 -exec chgrp 0 {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} \! -perm -g+rw -exec chmod g+rw {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} -perm /u+x -a \! -perm /g+x -exec chmod g+x {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} -type d \! -perm /g+x -exec chmod g+x {} + - -# Always end successfully -exit 0 diff --git a/18-minimal/s2i/bin/assemble b/18-minimal/s2i/bin/assemble deleted file mode 100755 index a5767210..00000000 --- a/18-minimal/s2i/bin/assemble +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash - -# Prevent running assemble in builders different than official STI image. -# The official nodejs:8-onbuild already run npm install and use different -# application folder. -[ -d "/usr/src/app" ] && exit 0 - -set -e - -# FIXME: Linking of global modules is disabled for now as it causes npm failures -# under RHEL7 -# Global modules good to have -# npmgl=$(grep "^\s*[^#\s]" ../etc/npm_global_module_list | sort -u) -# Available global modules; only match top-level npm packages -#global_modules=$(npm ls -g 2> /dev/null | perl -ne 'print "$1\n" if /^\S+\s(\S+)\@[\d\.-]+/' | sort -u) -# List all modules in common -#module_list=$(/usr/bin/comm -12 <(echo "${global_modules}") | tr '\n' ' ') -# Link the modules -#npm link $module_list - -safeLogging () { - if [[ $1 =~ http[s]?://.*@.*$ ]]; then - echo $1 | sed 's/^.*@/redacted@/' - else - echo $1 - fi -} - -shopt -s dotglob -if [ -d /tmp/artifacts ] && [ "$(ls /tmp/artifacts/ 2>/dev/null)" ]; then - echo "---> Restoring previous build artifacts ..." - mv -T --verbose /tmp/artifacts/node_modules "${HOME}/node_modules" -fi - -echo "---> Installing application source ..." -mv /tmp/src/* ./ - -# Fix source directory permissions -fix-permissions ./ - -if [ ! -z $HTTP_PROXY ]; then - echo "---> Setting npm http proxy to" $(safeLogging $HTTP_PROXY) - npm config set proxy $HTTP_PROXY -fi - -if [ ! -z $http_proxy ]; then - echo "---> Setting npm http proxy to" $(safeLogging $http_proxy) - npm config set proxy $http_proxy -fi - -if [ ! -z $HTTPS_PROXY ]; then - echo "---> Setting npm https proxy to" $(safeLogging $HTTPS_PROXY) - npm config set https-proxy $HTTPS_PROXY -fi - -if [ ! -z $https_proxy ]; then - echo "---> Setting npm https proxy to" $(safeLogging $https_proxy) - npm config set https-proxy $https_proxy -fi - -# Change the npm registry mirror if provided -if [ -n "$NPM_MIRROR" ]; then - npm config set registry $NPM_MIRROR -fi - -# Set the DEV_MODE to false by default. -if [ -z "$DEV_MODE" ]; then - export DEV_MODE=false -fi - -# If NODE_ENV is not set by the user, then NODE_ENV is determined by whether -# the container is run in development mode. -if [ -z "$NODE_ENV" ]; then - if [ "$DEV_MODE" == true ]; then - export NODE_ENV=development - else - export NODE_ENV=production - fi -fi - -if [ "$NODE_ENV" != "production" ]; then - - echo "---> Building your Node application from source" - npm install - -else - - echo "---> Installing all dependencies" - NODE_ENV=development npm install - - #do not fail when there is no build script - echo "---> Building in production mode" - npm run ${NPM_BUILD:-build} --if-present - - echo "---> Pruning the development dependencies" - npm prune - - # Clear the npm's cache and tmp directories only if they are not a docker volumes - NPM_TMP=$(npm config get tmp) - if ! mountpoint $NPM_TMP; then - echo "---> Cleaning the $NPM_TMP/npm-*" - rm -rf $NPM_TMP/npm-* - fi - - NPM_CACHE=$(npm config get cache) - if ! mountpoint $NPM_CACHE; then - echo "---> Cleaning the npm cache $NPM_CACHE" - #As of npm@5 even the 'npm cache clean --force' does not fully remove the cache directory - # instead of $NPM_CACHE* use $NPM_CACHE/*. - # We do not want to delete .npmrc file. - rm -rf "${NPM_CACHE:?}/" - fi - -fi - -# Fix source directory permissions -fix-permissions ./ diff --git a/18-minimal/s2i/bin/run b/18-minimal/s2i/bin/run deleted file mode 100755 index 45d23d69..00000000 --- a/18-minimal/s2i/bin/run +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash - -# S2I run script for the 'nodejs' image. -# The run script executes the server that runs your application. -# -# For more information see the documentation: -# https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md -# - -set -e - -# Runs the nodejs application server. If the container is run in development mode, -# hot deploy and debugging are enabled. -run_node() { - echo -e "Environment: \n\tDEV_MODE=${DEV_MODE}\n\tNODE_ENV=${NODE_ENV}\n\tDEBUG_PORT=${DEBUG_PORT}" - if [ "$DEV_MODE" == true ]; then - echo "Launching via nodemon..." - exec nodemon --inspect="$DEBUG_PORT" - elif [ -n "$NODE_CMD" ] && [ "$INIT_WRAPPER" == true ]; then - echo "launching via init wrapper..." - exec ${STI_SCRIPTS_PATH}/init-wrapper $NODE_CMD - elif [ -n "$NODE_CMD" ] && [ "$INIT_WRAPPER" == false ]; then - echo "Launching via ${NODE_CMD}" - exec $NODE_CMD - elif [ ! -n "$NODE_CMD" ] && [ "$INIT_WRAPPER" == true ]; then - - package_json_start=$(sed -n 's/\s*"start"\s*:\s*"\(.*\)".*/\1/p' package.json) - package_json_main=$(sed -n 's/\s*"main"\s*:\s*"\(.*\)".*/\1/p' package.json) - - if [ -n "$package_json_start" ]; then - start_command=$package_json_start - elif [ -n $package_json_main ]; then - start_command="node ." - elif [ -f "server.js" ]; then - start_command="node server.js" - else - echo "Failed to find file for starting the Node.js application" - exit 1 - fi - echo "launching via init wrapper..." - exec ${STI_SCRIPTS_PATH}/init-wrapper $start_command - else - echo "Launching via npm..." - exec npm run -d $NPM_RUN - fi -} - -#Set the debug port to 5858 by default. -if [ -z "$DEBUG_PORT" ]; then - export DEBUG_PORT=5858 -fi - -# Set the environment to development by default. -if [ -z "$DEV_MODE" ]; then - export DEV_MODE=false -fi - -# If NODE_ENV is not set by the user, then NODE_ENV is determined by whether -# the container is run in development mode. -if [ -z "$NODE_ENV" ]; then - if [ "$DEV_MODE" == true ]; then - export NODE_ENV=development - else - export NODE_ENV=production - fi -fi - -# If the official dockerhub node image is used, skip the SCL setup below -# and just run the nodejs server -if [ -d "/usr/src/app" ]; then - run_node -fi - -# Allow users to inspect/debug the builder image itself, by using: -# $ docker run -i -t openshift/centos-nodejs-builder --debug -# -[ "$1" == "--debug" ] && exec /bin/bash - -run_node diff --git a/18-minimal/s2i/bin/usage b/18-minimal/s2i/bin/usage deleted file mode 100755 index e2d9e3be..00000000 --- a/18-minimal/s2i/bin/usage +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh - -DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` - -cat </dev/null)" ]; then - tar -C "${HOME}" -cf - node_modules -fi diff --git a/18/test b/18/test deleted file mode 120000 index ae78e219..00000000 --- a/18/test +++ /dev/null @@ -1 +0,0 @@ -../test/ \ No newline at end of file diff --git a/20-minimal/.exclude-c8s b/20-minimal/.exclude-c8s deleted file mode 100644 index e69de29b..00000000 diff --git a/20-minimal/.exclude-fedora b/20-minimal/.exclude-fedora deleted file mode 100644 index e69de29b..00000000 diff --git a/20-minimal/README.md b/20-minimal/README.md deleted file mode 100644 index dbf6c136..00000000 --- a/20-minimal/README.md +++ /dev/null @@ -1,375 +0,0 @@ -NodeJS 20 minimal container image -========================= - -This container image includes Node.JS 20 on top of a minimal base image for your Node.JS 20 applications. This image is designed to be used -with the full-sized s2i-enabled Node.JS 20 image to build the application. The image can be used as a standalone s2i-enabled image as well, -but compared to the full-sized Node.JS 20 image it will be missing many build-time dependencies. -Users can choose between RHEL, CentOS and Fedora based images. -The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), -the CentOS Stream images are available in the [Quay.io](https://quay.io/organization/sclorg), -and the Fedora images are available in [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 ------------ - -Node.js 20 available as a minimal container is a base platform for -running various Node.js 20 applications and frameworks. -Node.js is a platform built on Chrome's JavaScript runtime for easily building -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model -that makes it lightweight and efficient, perfect for data-intensive real-time applications -that run across distributed devices. - -Usage in OpenShift ------------------- -In this example, we will assume that you are using the `ubi8/nodejs-20` image, available via `nodejs:20-ubi8` imagestream tag in Openshift -to build the application, as well as the `ubi8/nodejs-20-minimal` image, available via `nodejs:20-ubi8-minimal` image stream -for running the resulting application. - -With these two images we can create a [chained build](https://docs.openshift.com/container-platform/4.7/cicd/builds/advanced-build-operations.html#builds-chaining-builds_advanced-build-operations) in Openshift using two BuildConfigs: - -The first BuildConfig defines and builds the builder image, using the source-to-image strategy, and pushes the result into -the `nodejs-builder-image` imagestream. - -``` -apiVersion: build.openshift.io/v1 -kind: BuildConfig -metadata: - name: nodejs-builder-image -spec: - output: - to: - kind: ImageStreamTag - name: nodejs-builder-image:latest - source: - git: - uri: https://github.com/sclorg/nodejs-ex.git - strategy: - sourceStrategy: - from: - kind: ImageStreamTag - name: nodejs:20-ubi8 - namespace: openshift -``` - -The second BuildConfig takes the resulting image from the `nodejs-builder-image` imagestream, copies the application source (including build artifacts) -from the image and creates a new runtime image on top of the nodejs minimal image, with the application copied in and prepared to run. -The resulting runtime image is then pushed into the `nodejs-runtime-image` imagestream. - -``` -apiVersion: build.openshift.io/v1 -kind: BuildConfig -metadata: - name: nodejs-runtime-image -spec: - output: - to: - kind: ImageStreamTag - name: nodejs-runtime-image:latest - source: - dockerfile: |- - FROM nodejs:20-ubi8-minimal - COPY src $HOME - CMD /usr/libexec/s2i/run - images: - - from: - kind: ImageStreamTag - name: nodejs-builder-image:latest - paths: - - sourcePath: /opt/app-root/src - destinationDir: "." - strategy: - dockerStrategy: - from: - kind: ImageStreamTag - name: nodejs:20-ubi8-minimal - triggers: - - imageChange: {} - type: ImageChange -``` - -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 Node.js container image, and produce -a new image that runs the assembled application as an output. - -To support the Source-to-Image framework, only the `run` script is included in this 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). It runs `npm run` for production, or `nodemon` if `DEV_MODE` is set to `true` (see the **Environment variables** section below). - -Building an application using a Dockerfile ------------------------------------------- -Compared to the Source-to-Image strategy, using a Dockerfile is a more -flexible way to build a Node.js 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 Node.js image in a Dockerfile, follow these steps: - -#### 1. Pull the base builder and minimal runtime images - -``` -podman pull ubi8/nodejs-20 -podman pull ubi8/nodejs-20-minimal -``` - -The UBI images `ubi8/nodejs-20` and `ubi8/nodejs-20-minimal` that are used in this example are both usable and freely redistributable under the terms of the UBI End User License Agreement (EULA). See more about UBI at [UBI FAQ](https://developers.redhat.com/articles/ubi-faq). - -#### 2. Pull an application code - -An example application available at https://github.com/sclorg/nodejs-ex.git is used here. Feel free to clone the repository for further experiments. - -``` -git clone https://github.com/sclorg/nodejs-ex.git app-src -``` - -#### 3. Prepare an application inside a container - -This step usually consists of at least these parts: - -* putting the application source into the container -* installing the dependencies -* setting the default command in the resulting image - -For all these three parts, users can either setup all manually and use commands `nodejs` and `npm` explicitly in the Dockerfile ([3.1.](#31-to-use-your-own-setup-create-a-dockerfile-with-this-content)), or users 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 Node.js applications. - -##### 3.1. To use your own setup, create a Dockerfile with this content: -``` -# First stage builds the application -FROM ubi8/nodejs-20 as builder - -# Add application sources -ADD app-src $HOME - -# Install the dependencies -RUN npm install - -# Second stage copies the application to the minimal image -FROM ubi8/nodejs-20-minimal - -# Copy the application source and build artifacts from the builder image to this one -COPY --from=builder $HOME $HOME - -# Run script uses standard ways to run the application -CMD npm run -d start -``` - -##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content: -``` -# First stage builds the application -FROM ubi8/nodejs-20 as builder - -# Add application sources to a directory that the assemble script expects them -# and set permissions so that the container runs without root access -USER 0 -ADD app-src /tmp/src -RUN chown -R 1001:0 /tmp/src -USER 1001 - -# Install the dependencies -RUN /usr/libexec/s2i/assemble - -# Second stage copies the application to the minimal image -FROM ubi8/nodejs-20-minimal - -# Copy the application source and build artifacts from the builder image to this one -COPY --from=builder $HOME $HOME - -# Set the default command for the resulting image -CMD /usr/libexec/s2i/run -``` - -#### 4. Build a new image from a Dockerfile prepared in the previous step - -``` -podman build -t node-app . -``` - -#### 5. Run the resulting image with the final application - -``` -podman run -d node-app -``` - -Environment variables for Source-to-Image ---------------------- - -Application developers can use the following environment variables to configure the runtime behavior of this image in OpenShift: - -#### Used in the minimal image - -**`NODE_ENV`** - NodeJS runtime mode (default: "production") - -**`DEV_MODE`** - When set to "true", `nodemon` will be used to automatically reload the server while you work (default: "false"). Setting `DEV_MODE` to "true" will change the `NODE_ENV` default to "development" (if not explicitly set). - -**`NPM_BUILD`** - Select an alternate / custom build command, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "build"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NPM_RUN`** - Select an alternate / custom runtime mode, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "start"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NODE_CMD`** - When specified (e.g.Specify `NODE_CMD="node server.js"`) the value of `NODE_CMD` is used to start the application instead of `npm start`. - -**`INIT_WRAPPER`** - When set to "true", the application is started via the `init-wrapper` script instead of using `npm start`, by looking for the presence of the files `server.js`, `index.js` or `main.js` in the order in which they are listed. In case of `NODE_CMD` environemnt variale is specified, then `init-wrapper` script will use the value of `NODE_CMD` to start your application. - -#### Additional variables used in the full-sized image - -**`HTTP_PROXY`** - Use an npm proxy during assembly - -**`HTTPS_PROXY`** - Use an npm proxy during assembly - -**`NPM_MIRROR`** - Use a custom NPM registry mirror to download packages during the build process - -**`NPM_TOKEN`** - Use authentication token for a custom NPM registry mirror - -One way to define a set of environment variables is to include them as key value pairs in your repo's `.s2i/environment` file. - -Example: DATABASE_USER=sampleUser - -#### NOTE: Define your own "`DEV_MODE`": - -The following `package.json` example includes a `scripts.dev` entry. You can define your own custom [`NPM_RUN`](https://docs.npmjs.com/cli/run-script) scripts in your application's `package.json` file. - -#### Note: Setting logging output verbosity -To alter the level of logs output during an `npm install` the npm_config_loglevel environment variable can be set. See [npm-config](https://docs.npmjs.com/misc/config). - -Development Mode ----------------- -This image supports development mode. This mode can be switched on and off with the environment variable `DEV_MODE`. `DEV_MODE` can either be set to `true` or `false`. -Development mode supports two features: -* Hot Deploy -* Debugging - -The debug port can be specified with the environment variable `DEBUG_PORT`. `DEBUG_PORT` is only valid if `DEV_MODE=true`. - -A simple example command for running the container in development mode is: -``` -podman run --env DEV_MODE=true my-image-id -``` - -To run the container in development mode with a debug port of 5454, run: -``` -$ podman run --env DEV_MODE=true DEBUG_PORT=5454 my-image-id -``` - -To run the container in production mode, run: -``` -$ podman run --env DEV_MODE=false my-image-id -``` - -By default, `DEV_MODE` is set to `false`, and `DEBUG_PORT` is set to `5858`, however the `DEBUG_PORT` is only relevant if `DEV_MODE=true`. - -Hot deploy ----------- - -As part of development mode, this image supports hot deploy. If development mode is enabled, any souce code that is changed in the running container will be immediately reflected in the running nodejs application. - -### Using Podman's exec - -To change your source code in a running container, use Podman's [exec](https://github.com/containers/libpod) command: -``` -$ podman exec -it /bin/bash -``` - -After you [Podman exec](https://github.com/containers/libpod) into the running container, your current directory is set to `/opt/app-root/src`, where the source code for your application is located. - -### Using OpenShift's rsync - -If you have deployed the container to OpenShift, you can use [oc rsync](https://docs.openshift.org/latest/dev_guide/copy_files_to_container.html) to copy local files to a remote container running in an OpenShift pod. - -#### Warning: - -The default behaviour of the s2i-nodejs container image is to run the Node.js application using the command `npm start`. This runs the _start_ script in the _package.json_ file. In developer mode, the application is run using the command `nodemon`. The default behaviour of nodemon is to look for the _main_ attribute in the _package.json_ file, and execute that script. If the _main_ attribute doesn't appear in the _package.json_ file, it executes the _start_ script. So, in order to achieve some sort of uniform functionality between production and development modes, the user should remove the _main_ attribute. - -Below is an example _package.json_ file with the _main_ attribute and _start_ script marked appropriately: - -```json -{ - "name": "node-echo", - "version": "0.0.1", - "description": "node-echo", - "main": "example.js", <--- main attribute - "dependencies": { - }, - "devDependencies": { - "nodemon": "*" - }, - "engine": { - "node": "*", - "npm": "*" - }, - "scripts": { - "dev": "nodemon --ignore node_modules/ server.js", - "start": "node server.js" <-- start script - }, - "keywords": [ - "Echo" - ], - "license": "", -} -``` - -#### Note: -`oc rsync` is only available in versions 3.1+ of OpenShift. - -## init-wrapper - -init-wrapper script is located on `/usr/libexec/s2i/init-wrapper` and is used to handle: - -- Proper signal handling and propagation, as Node.js was not designed to run as PID 1. -- Reaping zombie child processes -Avoiding use of npm, there is more information on why you want to avoid that in the [Node.js reference architecture](https://github.com/nodeshift/nodejs-reference-architecture/blob/e4c4dc1fd20c2cac392e862859aaad27f85d504f/docs/development/building-good-containers.md#avoiding-using-npm-to-start-application). When the INIT_WRAPPER is set to true the application is started via the init script instead of using npm start. - -A detailed explanation on how the init-wrapper script works is avalable in -[this url](http://veithen.io/2014/11/16/sigterm-propagation.html). - -Example of using init-wrapper: - -**During image build** -``` -s2i -e INIT_WRAPPER=true build . buildImage node-app -docker run node-app -``` -**During container start** -``` -s2i build . buildImage node-app -docker run -e INIT_WRAPPER=true node-app -``` - -`init-wrapper` script can be disabled by setting the `INIT_WRAPPER` env variable to `false`. - -``` -docker run -e INIT_WRAPPER=false node-app -``` -`NODE_CMD` can be used during the build process or container start, in order to have more control on the command that `init-wrapper` script will wrap. - -For example: - -**during container build** -``` -s2i -e INIT_WRAPPER=true -e NODE_CMD="node index.js" build . buildImage node-app -``` -**during container start** -``` -docker run -e INIT_WRAPPER=false -e NODE_CMD="node index.js" node-app -``` - -See also --------- -Dockerfile and other sources are available on https://github.com/sclorg/s2i-nodejs-container. -In that repository you also can find another versions of Node.js environment Dockerfiles. -Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s`, -for RHEL8 it's `Dockerfile.rhel8` and the Fedora Dockerfile is called Dockerfile.fedora. diff --git a/20-minimal/README.md b/20-minimal/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/20-minimal/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/18/root/opt/app-root/etc/generate_container_user b/20-minimal/root/opt/app-root/etc/generate_container_user similarity index 100% rename from 18/root/opt/app-root/etc/generate_container_user rename to 20-minimal/root/opt/app-root/etc/generate_container_user diff --git a/18/root/opt/app-root/etc/npm_global_module_list b/20-minimal/root/opt/app-root/etc/npm_global_module_list similarity index 100% rename from 18/root/opt/app-root/etc/npm_global_module_list rename to 20-minimal/root/opt/app-root/etc/npm_global_module_list diff --git a/18/root/opt/app-root/etc/scl_enable b/20-minimal/root/opt/app-root/etc/scl_enable similarity index 100% rename from 18/root/opt/app-root/etc/scl_enable rename to 20-minimal/root/opt/app-root/etc/scl_enable diff --git a/20-minimal/root/usr/bin/fix-permissions b/20-minimal/root/usr/bin/fix-permissions deleted file mode 100755 index ddd33ace..00000000 --- a/20-minimal/root/usr/bin/fix-permissions +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# Allow this script to fail without failing a build -set +e - -SYMLINK_OPT=${2:--L} - -# Fix permissions on the given directory or file to allow group read/write of -# regular files and execute of directories. - -[ $(id -u) -ne 0 ] && CHECK_OWNER=" -uid $(id -u)" - -# If argument does not exist, script will still exit with 0, -# but at least we'll see something went wrong in the log -if ! [ -e "$1" ] ; then - echo "ERROR: File or directory $1 does not exist." >&2 - # We still want to end successfully - exit 0 -fi - -find $SYMLINK_OPT "$1" ${CHECK_OWNER} \! -gid 0 -exec chgrp 0 {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} \! -perm -g+rw -exec chmod g+rw {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} -perm /u+x -a \! -perm /g+x -exec chmod g+x {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} -type d \! -perm /g+x -exec chmod g+x {} + - -# Always end successfully -exit 0 diff --git a/20-minimal/s2i/bin/assemble b/20-minimal/s2i/bin/assemble index 3230d038..f644a811 100755 --- a/20-minimal/s2i/bin/assemble +++ b/20-minimal/s2i/bin/assemble @@ -63,13 +63,6 @@ if [ -n "$NPM_MIRROR" ]; then npm config set registry $NPM_MIRROR fi -# Change the npm authentication token if provided -if [ -n "$NPM_TOKEN" ]; then - echo "---> Setting npm authentication token for $NPM_MIRROR" - INTERNAL_NPM_REGISTRY=$(echo "$NPM_MIRROR" | sed -n 's|https://||p') - npm config set "//${INTERNAL_NPM_REGISTRY:-registry.npmjs.org}:_auth" $NPM_TOKEN -fi - # Set the DEV_MODE to false by default. if [ -z "$DEV_MODE" ]; then export DEV_MODE=false diff --git a/20-minimal/s2i/bin/init-wrapper b/20-minimal/s2i/bin/init-wrapper old mode 100644 new mode 100755 diff --git a/20-minimal/s2i/bin/run b/20-minimal/s2i/bin/run index 10150f34..9fc5cf90 100755 --- a/20-minimal/s2i/bin/run +++ b/20-minimal/s2i/bin/run @@ -9,6 +9,10 @@ set -e +if [ -e "/opt/app-root/etc/generate_container_user" ]; then + source /opt/app-root/etc/generate_container_user +fi + # Runs the nodejs application server. If the container is run in development mode, # hot deploy and debugging are enabled. run_node() { @@ -43,7 +47,7 @@ run_node() { echo "Launching via npm..." exec npm run -d $NPM_RUN fi -} +} #Set the debug port to 5858 by default. if [ -z "$DEBUG_PORT" ]; then diff --git a/20-minimal/s2i/bin/usage b/20-minimal/s2i/bin/usage index b8c1dca8..d77326cf 100755 --- a/20-minimal/s2i/bin/usage +++ b/20-minimal/s2i/bin/usage @@ -3,12 +3,12 @@ DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` cat < nodejs-sample-app +s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=18/test/test-app/ ${NAMESPACE}/nodejs-18-${DISTRO}7 nodejs-sample-app You can then run the resulting image via: podman run -p 8080:8080 nodejs-sample-app diff --git a/20-minimal/test b/20-minimal/test new file mode 120000 index 00000000..419df4f9 --- /dev/null +++ b/20-minimal/test @@ -0,0 +1 @@ +../test \ No newline at end of file diff --git a/20-minimal/test/__init__.py b/20-minimal/test/__init__.py deleted file mode 120000 index d0f4746a..00000000 --- a/20-minimal/test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -../../test/__init__.py \ No newline at end of file diff --git a/20-minimal/test/check_imagestreams.py b/20-minimal/test/check_imagestreams.py deleted file mode 120000 index 56bb2be7..00000000 --- a/20-minimal/test/check_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../common/check_imagestreams.py \ No newline at end of file diff --git a/20-minimal/test/conftest.py b/20-minimal/test/conftest.py deleted file mode 120000 index 3f2d7840..00000000 --- a/20-minimal/test/conftest.py +++ /dev/null @@ -1 +0,0 @@ -../../test/conftest.py \ No newline at end of file diff --git a/20-minimal/test/examples b/20-minimal/test/examples deleted file mode 120000 index d15735c1..00000000 --- a/20-minimal/test/examples +++ /dev/null @@ -1 +0,0 @@ -../../examples \ No newline at end of file diff --git a/20-minimal/test/imagestreams b/20-minimal/test/imagestreams deleted file mode 120000 index 7a0aee9c..00000000 --- a/20-minimal/test/imagestreams +++ /dev/null @@ -1 +0,0 @@ -../../imagestreams \ No newline at end of file diff --git a/20-minimal/test/run b/20-minimal/test/run deleted file mode 120000 index f446a740..00000000 --- a/20-minimal/test/run +++ /dev/null @@ -1 +0,0 @@ -../../test/run-minimal \ No newline at end of file diff --git a/20-minimal/test/run-openshift-remote-cluster b/20-minimal/test/run-openshift-remote-cluster deleted file mode 120000 index 1bffcba8..00000000 --- a/20-minimal/test/run-openshift-remote-cluster +++ /dev/null @@ -1 +0,0 @@ -../../test/run-openshift-remote-cluster \ No newline at end of file diff --git a/20-minimal/test/run-pytest b/20-minimal/test/run-pytest deleted file mode 120000 index efe32b48..00000000 --- a/20-minimal/test/run-pytest +++ /dev/null @@ -1 +0,0 @@ -../../test/run-pytest \ No newline at end of file diff --git a/20-minimal/test/test-app b/20-minimal/test/test-app deleted file mode 120000 index 6ba4f290..00000000 --- a/20-minimal/test/test-app +++ /dev/null @@ -1 +0,0 @@ -../../test/test-app \ No newline at end of file diff --git a/20-minimal/test/test-binary b/20-minimal/test/test-binary deleted file mode 120000 index cd7b631f..00000000 --- a/20-minimal/test/test-binary +++ /dev/null @@ -1 +0,0 @@ -../../test/test-binary \ No newline at end of file diff --git a/20-minimal/test/test-express-webapp b/20-minimal/test/test-express-webapp deleted file mode 120000 index 6a5bbd41..00000000 --- a/20-minimal/test/test-express-webapp +++ /dev/null @@ -1 +0,0 @@ -../../test/test-express-webapp \ No newline at end of file diff --git a/20-minimal/test/test-fips b/20-minimal/test/test-fips deleted file mode 120000 index fbe9489f..00000000 --- a/20-minimal/test/test-fips +++ /dev/null @@ -1 +0,0 @@ -../../test/test-fips \ No newline at end of file diff --git a/20-minimal/test/test-hw b/20-minimal/test/test-hw deleted file mode 120000 index ad784558..00000000 --- a/20-minimal/test/test-hw +++ /dev/null @@ -1 +0,0 @@ -../../test/test-hw \ No newline at end of file diff --git a/20-minimal/test/test-incremental b/20-minimal/test/test-incremental deleted file mode 120000 index 0a357b1f..00000000 --- a/20-minimal/test/test-incremental +++ /dev/null @@ -1 +0,0 @@ -../../test/test-incremental \ No newline at end of file diff --git a/20-minimal/test/test-lib-nodejs.sh b/20-minimal/test/test-lib-nodejs.sh deleted file mode 120000 index 8915d844..00000000 --- a/20-minimal/test/test-lib-nodejs.sh +++ /dev/null @@ -1 +0,0 @@ -../../test/test-lib-nodejs.sh \ No newline at end of file diff --git a/20-minimal/test/test-lib-openshift.sh b/20-minimal/test/test-lib-openshift.sh deleted file mode 120000 index 4f9f2996..00000000 --- a/20-minimal/test/test-lib-openshift.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib-openshift.sh \ No newline at end of file diff --git a/20-minimal/test/test-lib-remote-openshift.sh b/20-minimal/test/test-lib-remote-openshift.sh deleted file mode 120000 index 92ad2f4d..00000000 --- a/20-minimal/test/test-lib-remote-openshift.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib-remote-openshift.sh \ No newline at end of file diff --git a/20-minimal/test/test-lib.sh b/20-minimal/test/test-lib.sh deleted file mode 120000 index 1ac99b93..00000000 --- a/20-minimal/test/test-lib.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib.sh \ No newline at end of file diff --git a/20-minimal/test/test-openshift.yaml b/20-minimal/test/test-openshift.yaml deleted file mode 120000 index 8613fbba..00000000 --- a/20-minimal/test/test-openshift.yaml +++ /dev/null @@ -1 +0,0 @@ -../../common/test-openshift.yaml \ No newline at end of file diff --git a/20-minimal/test/test_container_apps.py b/20-minimal/test/test_container_apps.py deleted file mode 120000 index 9870de8e..00000000 --- a/20-minimal/test/test_container_apps.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_container_apps.py \ No newline at end of file diff --git a/20-minimal/test/test_container_basics.py b/20-minimal/test/test_container_basics.py deleted file mode 120000 index b85dc139..00000000 --- a/20-minimal/test/test_container_basics.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_container_basics.py \ No newline at end of file diff --git a/20/.exclude-c8s b/20/.exclude-c8s deleted file mode 100644 index e69de29b..00000000 diff --git a/20/.exclude-fedora b/20/.exclude-fedora deleted file mode 100644 index e69de29b..00000000 diff --git a/20/README.md b/20/README.md deleted file mode 100644 index 3cebc465..00000000 --- a/20/README.md +++ /dev/null @@ -1,303 +0,0 @@ -NodeJS 20 container image -========================= - -This container image includes Node.JS 20 as a [S2I](https://github.com/openshift/source-to-image) base image for your Node.JS 20 applications. -Users can choose between RHEL, CentOS and Fedora based images. -The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), -and the Fedora images are available in [Quay.io](https://quay.io/organization/fedora). -the CentOS Stream images are available in the [Quay.io](https://quay.io/organization/sclorg), -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 ------------ - -Node.js 20 available as container is a base platform for -building and running various Node.js 20 applications and frameworks. -Node.js is a platform built on Chrome's JavaScript runtime for easily building -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model -that makes it lightweight and efficient, perfect for data-intensive real-time applications -that run across distributed devices. - -Usage in OpenShift ------------------- -In this example, we will assume that you are using the `ubi8/nodejs-20` image, available via `nodejs:20` imagestream tag in Openshift. - -To build a simple [nodejs-sample-app](https://github.com/sclorg/nodejs-ex.git) application in Openshift: - -``` -oc new-app nodejs:20~https://github.com/sclorg/nodejs-ex.git -``` - -To access the application: -``` -$ oc get pods -$ oc exec -- 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 Node.js container image, and produce -a new image that runs the assembled application as an output. - -To support the Source-to-Image framework, important scripts are included in the builder image: - -* The `/usr/libexec/s2i/assemble` script inside the image is run to produce a new image with the application artifacts. The script takes sources of a given application and places them into appropriate directories inside the image. It utilizes some common patterns in Node.js application development (see the **Environment variables** section below). -* The `/usr/libexec/s2i/run` script is set as the default command in the resulting container image (the new image with the application artifacts). It runs `npm run` for production, or `nodemon` if `DEV_MODE` is set to `true` (see the **Environment variables** section below). - -Building an application using a Dockerfile ------------------------------------------- -Compared to the Source-to-Image strategy, using a Dockerfile is a more -flexible way to build a Node.js 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 Node.js image in a Dockerfile, follow these steps: - -#### 1. Pull a base builder image to build on - -``` -podman pull ubi8/nodejs-20 -``` - -An UBI image `ubi8/nodejs-20` is used in this example. This image is usable and freely redistributable under the terms of the UBI End User License Agreement (EULA). See more about UBI at [UBI FAQ](https://developers.redhat.com/articles/ubi-faq). - -#### 2. Pull an application code - -An example application available at https://github.com/sclorg/nodejs-ex.git is used here. Feel free to clone the repository for further experiments. - -``` -git clone https://github.com/sclorg/nodejs-ex.git app-src -``` - -#### 3. Prepare an application inside a container - -This step usually consists of at least these parts: - -* putting the application source into the container -* installing the dependencies -* setting the default command in the resulting image - -For all these three parts, users can either setup all manually and use commands `nodejs` and `npm` explicitly in the Dockerfile ([3.1.](#31-to-use-your-own-setup-create-a-dockerfile-with-this-content)), or users 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 Node.js applications. - -##### 3.1. To use your own setup, create a Dockerfile with this content: -``` -FROM ubi8/nodejs-20 - -# Add application sources -ADD app-src . - -# Install the dependencies -RUN npm install - -# Run script uses standard ways to run the application -CMD npm run -d start -``` - -##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content: -``` -FROM ubi8/nodejs-20 - -# Add application sources to a directory that the assemble script expects them -# and set permissions so that the container runs without root access -USER 0 -ADD app-src /tmp/src -RUN chown -R 1001:0 /tmp/src -USER 1001 - -# Install the dependencies -RUN /usr/libexec/s2i/assemble - -# Set the default command for the resulting image -CMD /usr/libexec/s2i/run -``` - -#### 4. Build a new image from a Dockerfile prepared in the previous step - -``` -podman build -t node-app . -``` - -#### 5. Run the resulting image with the final application - -``` -podman run -d node-app -``` - -Environment variables for Source-to-Image ---------------------- - -Application developers can use the following environment variables to configure the runtime behavior of this image in OpenShift: - -**`NODE_ENV`** - NodeJS runtime mode (default: "production") - -**`DEV_MODE`** - When set to "true", `nodemon` will be used to automatically reload the server while you work (default: "false"). Setting `DEV_MODE` to "true" will change the `NODE_ENV` default to "development" (if not explicitly set). - -**`NPM_BUILD`** - Select an alternate / custom build command, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "build"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NPM_RUN`** - Select an alternate / custom runtime mode, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "start"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NODE_CMD`** - When specified (e.g.Specify `NODE_CMD="node server.js"`) the value of `NODE_CMD` is used to start the application instead of `npm start`. - -**`INIT_WRAPPER`** - When set to "true", the application is started via the `init-wrapper` script instead of using `npm start`, by looking for the presence of the files `server.js`, `index.js` or `main.js` in the order in which they are listed. In case of `NODE_CMD` environemnt variale is specified, then `init-wrapper` script will use the value of `NODE_CMD` to start your application. - -**`HTTP_PROXY`** - Use an npm proxy during assembly - -**`HTTPS_PROXY`** - Use an npm proxy during assembly - -**`NPM_MIRROR`** - Use a custom NPM registry mirror to download packages during the build process - -**`NPM_TOKEN`** - Use authentication token for a custom NPM registry mirror - -One way to define a set of environment variables is to include them as key value pairs in your repo's `.s2i/environment` file. - -Example: DATABASE_USER=sampleUser - -#### NOTE: Define your own "`DEV_MODE`": - -The following `package.json` example includes a `scripts.dev` entry. You can define your own custom [`NPM_RUN`](https://docs.npmjs.com/cli/run-script) scripts in your application's `package.json` file. - -#### Note: Setting logging output verbosity -To alter the level of logs output during an `npm install` the npm_config_loglevel environment variable can be set. See [npm-config](https://docs.npmjs.com/misc/config). - -Development Mode ----------------- -This image supports development mode. This mode can be switched on and off with the environment variable `DEV_MODE`. `DEV_MODE` can either be set to `true` or `false`. -Development mode supports two features: -* Hot Deploy -* Debugging - -The debug port can be specified with the environment variable `DEBUG_PORT`. `DEBUG_PORT` is only valid if `DEV_MODE=true`. - -A simple example command for running the container in development mode is: -``` -podman run --env DEV_MODE=true my-image-id -``` - -To run the container in development mode with a debug port of 5454, run: -``` -$ podman run --env DEV_MODE=true DEBUG_PORT=5454 my-image-id -``` - -To run the container in production mode, run: -``` -$ podman run --env DEV_MODE=false my-image-id -``` - -By default, `DEV_MODE` is set to `false`, and `DEBUG_PORT` is set to `5858`, however the `DEBUG_PORT` is only relevant if `DEV_MODE=true`. - -Hot deploy ----------- - -As part of development mode, this image supports hot deploy. If development mode is enabled, any souce code that is changed in the running container will be immediately reflected in the running nodejs application. - -### Using Podman's exec - -To change your source code in a running container, use Podman's [exec](https://github.com/containers/libpod) command: -``` -$ podman exec -it /bin/bash -``` - -After you [Podman exec](https://github.com/containers/libpod) into the running container, your current directory is set to `/opt/app-root/src`, where the source code for your application is located. - -### Using OpenShift's rsync - -If you have deployed the container to OpenShift, you can use [oc rsync](https://docs.openshift.org/latest/dev_guide/copy_files_to_container.html) to copy local files to a remote container running in an OpenShift pod. - -#### Warning: - -The default behaviour of the s2i-nodejs container image is to run the Node.js application using the command `npm start`. This runs the _start_ script in the _package.json_ file. In developer mode, the application is run using the command `nodemon`. The default behaviour of nodemon is to look for the _main_ attribute in the _package.json_ file, and execute that script. If the _main_ attribute doesn't appear in the _package.json_ file, it executes the _start_ script. So, in order to achieve some sort of uniform functionality between production and development modes, the user should remove the _main_ attribute. - -Below is an example _package.json_ file with the _main_ attribute and _start_ script marked appropriately: - -```json -{ - "name": "node-echo", - "version": "0.0.1", - "description": "node-echo", - "main": "example.js", <--- main attribute - "dependencies": { - }, - "devDependencies": { - "nodemon": "*" - }, - "engine": { - "node": "*", - "npm": "*" - }, - "scripts": { - "dev": "nodemon --ignore node_modules/ server.js", - "start": "node server.js" <-- start script - }, - "keywords": [ - "Echo" - ], - "license": "", -} -``` - -#### Note: -`oc rsync` is only available in versions 3.1+ of OpenShift. - -## init-wrapper - -init-wrapper script is located on `/usr/libexec/s2i/init-wrapper` and is used to handle: - -- Proper signal handling and propagation, as Node.js was not designed to run as PID 1. -- Reaping zombie child processes -Avoiding use of npm, there is more information on why you want to avoid that in the [Node.js reference architecture](https://github.com/nodeshift/nodejs-reference-architecture/blob/e4c4dc1fd20c2cac392e862859aaad27f85d504f/docs/development/building-good-containers.md#avoiding-using-npm-to-start-application). When the INIT_WRAPPER is set to true the application is started via the init script instead of using npm start. - -A detailed explanation on how the init-wrapper script works is avalable in -[this url](http://veithen.io/2014/11/16/sigterm-propagation.html). - -Example of using init-wrapper: - -**During image build** -``` -s2i -e INIT_WRAPPER=true build . buildImage node-app -docker run node-app -``` -**During container start** -``` -s2i build . buildImage node-app -docker run -e INIT_WRAPPER=true node-app -``` - -`init-wrapper` script can be disabled by setting the `INIT_WRAPPER` env variable to `false`. - -``` -docker run -e INIT_WRAPPER=false node-app -``` -`NODE_CMD` can be used during the build process or container start, in order to have more control on the command that `init-wrapper` script will wrap. - -For example: - -**during container build** -``` -s2i -e INIT_WRAPPER=true -e NODE_CMD="node index.js" build . buildImage node-app -``` -**during container start** -``` -docker run -e INIT_WRAPPER=false -e NODE_CMD="node index.js" node-app -``` - -See also --------- -Dockerfile and other sources are available on https://github.com/sclorg/s2i-nodejs-container. -In that repository you also can find another versions of Node.js environment Dockerfiles. -Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s`, -for RHEL8 it's `Dockerfile.rhel8`, for RHEL9 it's `Dockerfile.rhel9` and the Fedora Dockerfile is called Dockerfile.fedora. diff --git a/20/README.md b/20/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/20/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/20/s2i/bin/assemble b/20/s2i/bin/assemble index 3230d038..f644a811 100755 --- a/20/s2i/bin/assemble +++ b/20/s2i/bin/assemble @@ -63,13 +63,6 @@ if [ -n "$NPM_MIRROR" ]; then npm config set registry $NPM_MIRROR fi -# Change the npm authentication token if provided -if [ -n "$NPM_TOKEN" ]; then - echo "---> Setting npm authentication token for $NPM_MIRROR" - INTERNAL_NPM_REGISTRY=$(echo "$NPM_MIRROR" | sed -n 's|https://||p') - npm config set "//${INTERNAL_NPM_REGISTRY:-registry.npmjs.org}:_auth" $NPM_TOKEN -fi - # Set the DEV_MODE to false by default. if [ -z "$DEV_MODE" ]; then export DEV_MODE=false diff --git a/20/s2i/bin/init-wrapper b/20/s2i/bin/init-wrapper old mode 100644 new mode 100755 diff --git a/20/s2i/bin/run b/20/s2i/bin/run index 9a207bce..9fc5cf90 100755 --- a/20/s2i/bin/run +++ b/20/s2i/bin/run @@ -47,7 +47,7 @@ run_node() { echo "Launching via npm..." exec npm run -d $NPM_RUN fi -} +} #Set the debug port to 5858 by default. if [ -z "$DEBUG_PORT" ]; then diff --git a/20/s2i/bin/usage b/20/s2i/bin/usage index b8c1dca8..d77326cf 100755 --- a/20/s2i/bin/usage +++ b/20/s2i/bin/usage @@ -3,12 +3,12 @@ DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` cat < nodejs-sample-app +s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=18/test/test-app/ ${NAMESPACE}/nodejs-18-${DISTRO}7 nodejs-sample-app You can then run the resulting image via: podman run -p 8080:8080 nodejs-sample-app diff --git a/22-minimal/.exclude-c8s b/22-minimal/.exclude-c8s deleted file mode 100644 index e69de29b..00000000 diff --git a/22-minimal/.exclude-c9s b/22-minimal/.exclude-c9s deleted file mode 100644 index e69de29b..00000000 diff --git a/22-minimal/.exclude-fedora b/22-minimal/.exclude-fedora deleted file mode 100644 index e69de29b..00000000 diff --git a/22-minimal/Dockerfile.c8s b/22-minimal/Dockerfile.c8s index d7829589..810774ba 100644 --- a/22-minimal/Dockerfile.c8s +++ b/22-minimal/Dockerfile.c8s @@ -17,7 +17,7 @@ ENV APP_ROOT=/opt/app-root \ HOME=/opt/app-root/src \ NPM_RUN=start \ PLATFORM="el8" \ - NODEJS_VERSION=20 \ + NODEJS_VERSION=22 \ NPM_RUN=start \ NAME=nodejs diff --git a/22-minimal/README.md b/22-minimal/README.md deleted file mode 100644 index ae2b7dd6..00000000 --- a/22-minimal/README.md +++ /dev/null @@ -1,376 +0,0 @@ -NodeJS 22 minimal container image -========================= - -This container image includes Node.JS 22 on top of a minimal base image for your Node.JS 22 applications. This image is designed to be used -with the full-sized s2i-enabled Node.JS 22 image to build the application. The image can be used as a standalone s2i-enabled image as well, -but compared to the full-sized Node.JS 22 image it will be missing many build-time dependencies. -Users can choose between RHEL, CentOS and Fedora based images. -The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), -the CentOS Stream images are available in the [Quay.io](https://quay.io/organization/sclorg), -and the Fedora images are available in [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 ------------ - -Node.js 22 available as a minimal container is a base platform for -running various Node.js 22 applications and frameworks. -Node.js is a platform built on Chrome's JavaScript runtime for easily building -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model -that makes it lightweight and efficient, perfect for data-intensive real-time applications -that run across distributed devices. - -Usage in OpenShift ------------------- -In this example, we will assume that you are using the `ubi8/nodejs-22` image, available via `nodejs:22-ubi8` imagestream tag in Openshift -to build the application, as well as the `ubi8/nodejs-22-minimal` image, available via `nodejs:22-ubi8-minimal` image stream -for running the resulting application. - -With these two images we can create a [chained build](https://docs.openshift.com/container-platform/4.7/cicd/builds/advanced-build-operations.html#builds-chaining-builds_advanced-build-operations) in Openshift using two BuildConfigs: - -The first BuildConfig defines and builds the builder image, using the source-to-image strategy, and pushes the result into -the `nodejs-builder-image` imagestream. - -``` -apiVersion: build.openshift.io/v1 -kind: BuildConfig -metadata: - name: nodejs-builder-image -spec: - output: - to: - kind: ImageStreamTag - name: nodejs-builder-image:latest - source: - git: - uri: https://github.com/sclorg/nodejs-ex.git - strategy: - sourceStrategy: - from: - kind: ImageStreamTag - name: nodejs:22-ubi8 - namespace: openshift -``` - -The second BuildConfig takes the resulting image from the `nodejs-builder-image` imagestream, copies the application source (including build artifacts) -from the image and creates a new runtime image on top of the nodejs minimal image, with the application copied in and prepared to run. -The resulting runtime image is then pushed into the `nodejs-runtime-image` imagestream. - -``` -apiVersion: build.openshift.io/v1 -kind: BuildConfig -metadata: - name: nodejs-runtime-image -spec: - output: - to: - kind: ImageStreamTag - name: nodejs-runtime-image:latest - source: - dockerfile: |- - FROM nodejs:22-ubi8-minimal - COPY src $HOME - CMD /usr/libexec/s2i/run - images: - - from: - kind: ImageStreamTag - name: nodejs-builder-image:latest - paths: - - sourcePath: /opt/app-root/src - destinationDir: "." - strategy: - dockerStrategy: - from: - kind: ImageStreamTag - name: nodejs:22-ubi8-minimal - triggers: - - imageChange: {} - type: ImageChange -``` - -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 Node.js container image, and produce -a new image that runs the assembled application as an output. - -To support the Source-to-Image framework, only the `run` script is included in this 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). It runs `npm run` for production, or `nodemon` if `DEV_MODE` is set to `true` (see the **Environment variables** section below). - -Building an application using a Dockerfile ------------------------------------------- -Compared to the Source-to-Image strategy, using a Dockerfile is a more -flexible way to build a Node.js 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 Node.js image in a Dockerfile, follow these steps: - -#### 1. Pull the base builder and minimal runtime images - -``` -podman pull ubi8/nodejs-22 -podman pull ubi8/nodejs-22-minimal -``` - -The UBI images `ubi8/nodejs-22` and `ubi8/nodejs-22-minimal` that are used in this example are both usable and freely redistributable under the terms of the UBI End User License Agreement (EULA). See more about UBI at [UBI FAQ](https://developers.redhat.com/articles/ubi-faq). - -#### 2. Pull an application code - -An example application available at https://github.com/sclorg/nodejs-ex.git is used here. Feel free to clone the repository for further experiments. - -``` -git clone https://github.com/sclorg/nodejs-ex.git app-src -``` - -#### 3. Prepare an application inside a container - -This step usually consists of at least these parts: - -* putting the application source into the container -* installing the dependencies -* setting the default command in the resulting image - -For all these three parts, users can either setup all manually and use commands `nodejs` and `npm` explicitly in the Dockerfile ([3.1.](#31-to-use-your-own-setup-create-a-dockerfile-with-this-content)), or users 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 Node.js applications. - -##### 3.1. To use your own setup, create a Dockerfile with this content: -``` -# First stage builds the application -FROM ubi8/nodejs-22 as builder - -# Add application sources -ADD app-src $HOME - -# Install the dependencies -RUN npm install - -# Second stage copies the application to the minimal image -FROM ubi8/nodejs-22-minimal - -# Copy the application source and build artifacts from the builder image to this one -COPY --from=builder $HOME $HOME - -# Run script uses standard ways to run the application -CMD npm run -d start -``` - -##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content: -``` -# First stage builds the application -FROM ubi8/nodejs-22 as builder - -# Add application sources to a directory that the assemble script expects them -# and set permissions so that the container runs without root access -USER 0 -ADD app-src /tmp/src -RUN chown -R 1001:0 /tmp/src -USER 1001 - -# Install the dependencies -RUN /usr/libexec/s2i/assemble - -# Second stage copies the application to the minimal image -FROM ubi8/nodejs-22-minimal - -# Copy the application source and build artifacts from the builder image to this one -COPY --from=builder $HOME $HOME - -# Set the default command for the resulting image -CMD /usr/libexec/s2i/run -``` - -#### 4. Build a new image from a Dockerfile prepared in the previous step - -``` -podman build -t node-app . -``` - -#### 5. Run the resulting image with the final application - -``` -podman run -d node-app -``` - -Environment variables for Source-to-Image ---------------------- - -Application developers can use the following environment variables to configure the runtime behavior of this image in OpenShift: - -#### Used in the minimal image - -**`NODE_ENV`** - NodeJS runtime mode (default: "production") - -**`DEV_MODE`** - When set to "true", `nodemon` will be used to automatically reload the server while you work (default: "false"). Setting `DEV_MODE` to "true" will change the `NODE_ENV` default to "development" (if not explicitly set). - -**`NPM_BUILD`** - Select an alternate / custom build command, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "build"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NPM_RUN`** - Select an alternate / custom runtime mode, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "start"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NODE_CMD`** - When specified (e.g.Specify `NODE_CMD="node server.js"`) the value of `NODE_CMD` is used to start the application instead of `npm start`. - -**`INIT_WRAPPER`** - When set to "true", the application is started via the `init-wrapper` script instead of using `npm start`, by looking for the presence of the files `server.js`, `index.js` or `main.js` in the order in which they are listed. In case of `NODE_CMD` environemnt variale is specified, then `init-wrapper` script will use the value of `NODE_CMD` to start your application. - -#### Additional variables used in the full-sized image - -**`HTTP_PROXY`** - Use an npm proxy during assembly - -**`HTTPS_PROXY`** - Use an npm proxy during assembly - -**`NPM_MIRROR`** - Use a custom NPM registry mirror to download packages during the build process - -**`NPM_TOKEN`** - Use authentication token for a custom NPM registry mirror - -One way to define a set of environment variables is to include them as key value pairs in your repo's `.s2i/environment` file. - -Example: DATABASE_USER=sampleUser - -#### NOTE: Define your own "`DEV_MODE`": - -The following `package.json` example includes a `scripts.dev` entry. You can define your own custom [`NPM_RUN`](https://docs.npmjs.com/cli/run-script) scripts in your application's `package.json` file. - -#### Note: Setting logging output verbosity -To alter the level of logs output during an `npm install` the npm_config_loglevel environment variable can be set. See [npm-config](https://docs.npmjs.com/misc/config). - -Development Mode ----------------- -This image supports development mode. This mode can be switched on and off with the environment variable `DEV_MODE`. `DEV_MODE` can either be set to `true` or `false`. -Development mode supports two features: -* Hot Deploy -* Debugging - -The debug port can be specified with the environment variable `DEBUG_PORT`. `DEBUG_PORT` is only valid if `DEV_MODE=true`. - -A simple example command for running the container in development mode is: -``` -podman run --env DEV_MODE=true my-image-id -``` - -To run the container in development mode with a debug port of 5454, run: -``` -$ podman run --env DEV_MODE=true DEBUG_PORT=5454 my-image-id -``` - -To run the container in production mode, run: -``` -$ podman run --env DEV_MODE=false my-image-id -``` - -By default, `DEV_MODE` is set to `false`, and `DEBUG_PORT` is set to `5858`, however the `DEBUG_PORT` is only relevant if `DEV_MODE=true`. - -Hot deploy ----------- - -As part of development mode, this image supports hot deploy. If development mode is enabled, any souce code that is changed in the running container will be immediately reflected in the running nodejs application. - -### Using Podman's exec - -To change your source code in a running container, use Podman's [exec](https://github.com/containers/libpod) command: -``` -$ podman exec -it /bin/bash -``` - -After you [Podman exec](https://github.com/containers/libpod) into the running container, your current directory is set to `/opt/app-root/src`, where the source code for your application is located. - -### Using OpenShift's rsync - -If you have deployed the container to OpenShift, you can use [oc rsync](https://docs.openshift.org/latest/dev_guide/copy_files_to_container.html) to copy local files to a remote container running in an OpenShift pod. - -#### Warning: - -The default behaviour of the s2i-nodejs container image is to run the Node.js application using the command `npm start`. This runs the _start_ script in the _package.json_ file. In developer mode, the application is run using the command `nodemon`. The default behaviour of nodemon is to look for the _main_ attribute in the _package.json_ file, and execute that script. If the _main_ attribute doesn't appear in the _package.json_ file, it executes the _start_ script. So, in order to achieve some sort of uniform functionality between production and development modes, the user should remove the _main_ attribute. - -Below is an example _package.json_ file with the _main_ attribute and _start_ script marked appropriately: - -```json -{ - "name": "node-echo", - "version": "0.0.1", - "description": "node-echo", - "main": "example.js", <--- main attribute - "dependencies": { - }, - "devDependencies": { - "nodemon": "*" - }, - "engine": { - "node": "*", - "npm": "*" - }, - "scripts": { - "dev": "nodemon --ignore node_modules/ server.js", - "start": "node server.js" <-- start script - }, - "keywords": [ - "Echo" - ], - "license": "", -} -``` - -#### Note: -`oc rsync` is only available in versions 3.1+ of OpenShift. - -## init-wrapper - -init-wrapper script is located on `/usr/libexec/s2i/init-wrapper` and is used to handle: - -- Proper signal handling and propagation, as Node.js was not designed to run as PID 1. -- Reaping zombie child processes -Avoiding use of npm, there is more information on why you want to avoid that in the [Node.js reference architecture](https://github.com/nodeshift/nodejs-reference-architecture/blob/e4c4dc1fd20c2cac392e862859aaad27f85d504f/docs/development/building-good-containers.md#avoiding-using-npm-to-start-application). When the INIT_WRAPPER is set to true the application is started via the init script instead of using npm start. - -A detailed explanation on how the init-wrapper script works is avalable in -[this url](http://veithen.io/2014/11/16/sigterm-propagation.html). - -Example of using init-wrapper: - -**During image build** -``` -s2i -e INIT_WRAPPER=true build . buildImage node-app -docker run node-app -``` -**During container start** -``` -s2i build . buildImage node-app -docker run -e INIT_WRAPPER=true node-app -``` - -`init-wrapper` script can be disabled by setting the `INIT_WRAPPER` env variable to `false`. - -``` -docker run -e INIT_WRAPPER=false node-app -``` -`NODE_CMD` can be used during the build process or container start, in order to have more control on the command that `init-wrapper` script will wrap. - -For example: - -**during container build** -``` -s2i -e INIT_WRAPPER=true -e NODE_CMD="node index.js" build . buildImage node-app -``` -**during container start** -``` -docker run -e INIT_WRAPPER=false -e NODE_CMD="node index.js" node-app -``` -See also --------- -Dockerfile and other sources are available on https://github.com/sclorg/s2i-nodejs-container. -In that repository you also can find another versions of Node.js environment Dockerfiles. -Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s`, -Dockerfile for CentOS Stream 10 is called `Dockerfile.c10s`, -for RHEL8 it's `Dockerfile.rhel8`, for RHEL9 it's `Dockerfile.rhel9`, -for RHEL10 it's `Dockerfile.rhel10` and the Fedora Dockerfile is called Dockerfile.fedora. diff --git a/22-minimal/README.md b/22-minimal/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/22-minimal/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/22-minimal/root/opt/app-root/etc/generate_container_user b/22-minimal/root/opt/app-root/etc/generate_container_user new file mode 100644 index 00000000..b28a7a3d --- /dev/null +++ b/22-minimal/root/opt/app-root/etc/generate_container_user @@ -0,0 +1,17 @@ +# Set current user in nss_wrapper +USER_ID=$(id -u) +GROUP_ID=$(id -g) + +if [ x"$USER_ID" != x"0" -a x"$USER_ID" != x"1001" ]; then + + NSS_WRAPPER_PASSWD=/opt/app-root/etc/passwd + NSS_WRAPPER_GROUP=/etc/group + + cat /etc/passwd | sed -e 's/^default:/builder:/' > $NSS_WRAPPER_PASSWD + + echo "default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/sbin/nologin" >> $NSS_WRAPPER_PASSWD + + export NSS_WRAPPER_PASSWD + export NSS_WRAPPER_GROUP + export LD_PRELOAD=libnss_wrapper.so +fi diff --git a/22-minimal/root/opt/app-root/etc/npm_global_module_list b/22-minimal/root/opt/app-root/etc/npm_global_module_list new file mode 100644 index 00000000..005e1501 --- /dev/null +++ b/22-minimal/root/opt/app-root/etc/npm_global_module_list @@ -0,0 +1,5 @@ +async +mime +mkdirp +qs +minimatch diff --git a/22-minimal/root/opt/app-root/etc/scl_enable b/22-minimal/root/opt/app-root/etc/scl_enable new file mode 100644 index 00000000..4bfebea0 --- /dev/null +++ b/22-minimal/root/opt/app-root/etc/scl_enable @@ -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-nodejs${NODEJS_VERSION} diff --git a/22-minimal/root/usr/bin/fix-permissions b/22-minimal/root/usr/bin/fix-permissions deleted file mode 100755 index ddd33ace..00000000 --- a/22-minimal/root/usr/bin/fix-permissions +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# Allow this script to fail without failing a build -set +e - -SYMLINK_OPT=${2:--L} - -# Fix permissions on the given directory or file to allow group read/write of -# regular files and execute of directories. - -[ $(id -u) -ne 0 ] && CHECK_OWNER=" -uid $(id -u)" - -# If argument does not exist, script will still exit with 0, -# but at least we'll see something went wrong in the log -if ! [ -e "$1" ] ; then - echo "ERROR: File or directory $1 does not exist." >&2 - # We still want to end successfully - exit 0 -fi - -find $SYMLINK_OPT "$1" ${CHECK_OWNER} \! -gid 0 -exec chgrp 0 {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} \! -perm -g+rw -exec chmod g+rw {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} -perm /u+x -a \! -perm /g+x -exec chmod g+x {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} -type d \! -perm /g+x -exec chmod g+x {} + - -# Always end successfully -exit 0 diff --git a/22-minimal/s2i/bin/assemble b/22-minimal/s2i/bin/assemble index 3230d038..f644a811 100755 --- a/22-minimal/s2i/bin/assemble +++ b/22-minimal/s2i/bin/assemble @@ -63,13 +63,6 @@ if [ -n "$NPM_MIRROR" ]; then npm config set registry $NPM_MIRROR fi -# Change the npm authentication token if provided -if [ -n "$NPM_TOKEN" ]; then - echo "---> Setting npm authentication token for $NPM_MIRROR" - INTERNAL_NPM_REGISTRY=$(echo "$NPM_MIRROR" | sed -n 's|https://||p') - npm config set "//${INTERNAL_NPM_REGISTRY:-registry.npmjs.org}:_auth" $NPM_TOKEN -fi - # Set the DEV_MODE to false by default. if [ -z "$DEV_MODE" ]; then export DEV_MODE=false diff --git a/22-minimal/s2i/bin/init-wrapper b/22-minimal/s2i/bin/init-wrapper old mode 100644 new mode 100755 diff --git a/22-minimal/s2i/bin/run b/22-minimal/s2i/bin/run index 10150f34..9fc5cf90 100755 --- a/22-minimal/s2i/bin/run +++ b/22-minimal/s2i/bin/run @@ -9,6 +9,10 @@ set -e +if [ -e "/opt/app-root/etc/generate_container_user" ]; then + source /opt/app-root/etc/generate_container_user +fi + # Runs the nodejs application server. If the container is run in development mode, # hot deploy and debugging are enabled. run_node() { @@ -43,7 +47,7 @@ run_node() { echo "Launching via npm..." exec npm run -d $NPM_RUN fi -} +} #Set the debug port to 5858 by default. if [ -z "$DEBUG_PORT" ]; then diff --git a/22-minimal/s2i/bin/usage b/22-minimal/s2i/bin/usage index b8c1dca8..d77326cf 100755 --- a/22-minimal/s2i/bin/usage +++ b/22-minimal/s2i/bin/usage @@ -3,12 +3,12 @@ DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` cat < nodejs-sample-app +s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=18/test/test-app/ ${NAMESPACE}/nodejs-18-${DISTRO}7 nodejs-sample-app You can then run the resulting image via: podman run -p 8080:8080 nodejs-sample-app diff --git a/22-minimal/test b/22-minimal/test new file mode 120000 index 00000000..419df4f9 --- /dev/null +++ b/22-minimal/test @@ -0,0 +1 @@ +../test \ No newline at end of file diff --git a/22-minimal/test/__init__.py b/22-minimal/test/__init__.py deleted file mode 120000 index d0f4746a..00000000 --- a/22-minimal/test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -../../test/__init__.py \ No newline at end of file diff --git a/22-minimal/test/check_imagestreams.py b/22-minimal/test/check_imagestreams.py deleted file mode 120000 index 56bb2be7..00000000 --- a/22-minimal/test/check_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../common/check_imagestreams.py \ No newline at end of file diff --git a/22-minimal/test/conftest.py b/22-minimal/test/conftest.py deleted file mode 120000 index 3f2d7840..00000000 --- a/22-minimal/test/conftest.py +++ /dev/null @@ -1 +0,0 @@ -../../test/conftest.py \ No newline at end of file diff --git a/22-minimal/test/examples b/22-minimal/test/examples deleted file mode 120000 index da7b1965..00000000 --- a/22-minimal/test/examples +++ /dev/null @@ -1 +0,0 @@ -../../examples/ \ No newline at end of file diff --git a/22-minimal/test/imagestreams b/22-minimal/test/imagestreams deleted file mode 120000 index 0dcbe9e0..00000000 --- a/22-minimal/test/imagestreams +++ /dev/null @@ -1 +0,0 @@ -../../imagestreams/ \ No newline at end of file diff --git a/22-minimal/test/run b/22-minimal/test/run deleted file mode 120000 index f446a740..00000000 --- a/22-minimal/test/run +++ /dev/null @@ -1 +0,0 @@ -../../test/run-minimal \ No newline at end of file diff --git a/22-minimal/test/run-openshift-remote-cluster b/22-minimal/test/run-openshift-remote-cluster deleted file mode 120000 index 1bffcba8..00000000 --- a/22-minimal/test/run-openshift-remote-cluster +++ /dev/null @@ -1 +0,0 @@ -../../test/run-openshift-remote-cluster \ No newline at end of file diff --git a/22-minimal/test/run-pytest b/22-minimal/test/run-pytest deleted file mode 120000 index efe32b48..00000000 --- a/22-minimal/test/run-pytest +++ /dev/null @@ -1 +0,0 @@ -../../test/run-pytest \ No newline at end of file diff --git a/22-minimal/test/test-app b/22-minimal/test/test-app deleted file mode 120000 index 6ba4f290..00000000 --- a/22-minimal/test/test-app +++ /dev/null @@ -1 +0,0 @@ -../../test/test-app \ No newline at end of file diff --git a/22-minimal/test/test-binary b/22-minimal/test/test-binary deleted file mode 120000 index cd7b631f..00000000 --- a/22-minimal/test/test-binary +++ /dev/null @@ -1 +0,0 @@ -../../test/test-binary \ No newline at end of file diff --git a/22-minimal/test/test-express-webapp b/22-minimal/test/test-express-webapp deleted file mode 120000 index 6a5bbd41..00000000 --- a/22-minimal/test/test-express-webapp +++ /dev/null @@ -1 +0,0 @@ -../../test/test-express-webapp \ No newline at end of file diff --git a/22-minimal/test/test-fips b/22-minimal/test/test-fips deleted file mode 120000 index fbe9489f..00000000 --- a/22-minimal/test/test-fips +++ /dev/null @@ -1 +0,0 @@ -../../test/test-fips \ No newline at end of file diff --git a/22-minimal/test/test-hw b/22-minimal/test/test-hw deleted file mode 120000 index ad784558..00000000 --- a/22-minimal/test/test-hw +++ /dev/null @@ -1 +0,0 @@ -../../test/test-hw \ No newline at end of file diff --git a/22-minimal/test/test-incremental b/22-minimal/test/test-incremental deleted file mode 120000 index 0a357b1f..00000000 --- a/22-minimal/test/test-incremental +++ /dev/null @@ -1 +0,0 @@ -../../test/test-incremental \ No newline at end of file diff --git a/22-minimal/test/test-lib-nodejs.sh b/22-minimal/test/test-lib-nodejs.sh deleted file mode 120000 index 8915d844..00000000 --- a/22-minimal/test/test-lib-nodejs.sh +++ /dev/null @@ -1 +0,0 @@ -../../test/test-lib-nodejs.sh \ No newline at end of file diff --git a/22-minimal/test/test-lib-openshift.sh b/22-minimal/test/test-lib-openshift.sh deleted file mode 120000 index 4f9f2996..00000000 --- a/22-minimal/test/test-lib-openshift.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib-openshift.sh \ No newline at end of file diff --git a/22-minimal/test/test-lib-remote-openshift.sh b/22-minimal/test/test-lib-remote-openshift.sh deleted file mode 120000 index 92ad2f4d..00000000 --- a/22-minimal/test/test-lib-remote-openshift.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib-remote-openshift.sh \ No newline at end of file diff --git a/22-minimal/test/test-lib.sh b/22-minimal/test/test-lib.sh deleted file mode 120000 index 1ac99b93..00000000 --- a/22-minimal/test/test-lib.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib.sh \ No newline at end of file diff --git a/22-minimal/test/test-openshift.yaml b/22-minimal/test/test-openshift.yaml deleted file mode 120000 index 8613fbba..00000000 --- a/22-minimal/test/test-openshift.yaml +++ /dev/null @@ -1 +0,0 @@ -../../common/test-openshift.yaml \ No newline at end of file diff --git a/22-minimal/test/test_container_apps.py b/22-minimal/test/test_container_apps.py deleted file mode 120000 index 9870de8e..00000000 --- a/22-minimal/test/test_container_apps.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_container_apps.py \ No newline at end of file diff --git a/22-minimal/test/test_container_basics.py b/22-minimal/test/test_container_basics.py deleted file mode 120000 index b85dc139..00000000 --- a/22-minimal/test/test_container_basics.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_container_basics.py \ No newline at end of file diff --git a/22/.exclude-c8s b/22/.exclude-c8s deleted file mode 100644 index e69de29b..00000000 diff --git a/22/.exclude-c9s b/22/.exclude-c9s deleted file mode 100644 index e69de29b..00000000 diff --git a/22/.exclude-fedora b/22/.exclude-fedora deleted file mode 100644 index e69de29b..00000000 diff --git a/22/Dockerfile.c8s b/22/Dockerfile.c8s index 6a7e0501..1e63b3d8 100644 --- a/22/Dockerfile.c8s +++ b/22/Dockerfile.c8s @@ -16,12 +16,12 @@ EXPOSE 8080 # Expose ports: # * 8080 - Unprivileged port used by nodejs application -ENV NODEJS_VERSION=20 \ +ENV NODEJS_VERSION=22 \ NPM_RUN=start \ NAME=nodejs \ NPM_CONFIG_PREFIX=$HOME/.npm-global \ PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ - CNB_STACK_ID=com.redhat.stacks.c8s-nodejs-20 \ + CNB_STACK_ID=com.redhat.stacks.c8s-nodejs-22 \ CNB_USER_ID=1001 \ CNB_GROUP_ID=0 @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \ io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ io.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.buildpacks.stack.id="com.redhat.stacks.c8s-nodejs-20" \ + io.buildpacks.stack.id="com.redhat.stacks.c8s-nodejs-22" \ com.redhat.dev-mode="DEV_MODE:false" \ com.redhat.deployments-dir="${APP_ROOT}/src" \ com.redhat.dev-mode.port="DEBUG_PORT:5858" \ diff --git a/22/Dockerfile.rhel8 b/22/Dockerfile.rhel8 index cca2a4e4..99399e8f 100644 --- a/22/Dockerfile.rhel8 +++ b/22/Dockerfile.rhel8 @@ -21,7 +21,7 @@ ENV NODEJS_VERSION=22 \ NAME=nodejs \ NPM_CONFIG_PREFIX=$HOME/.npm-global \ PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ - CNB_STACK_ID=com.redhat.stacks.ubi8-nodejs-20 \ + CNB_STACK_ID=com.redhat.stacks.ubi8-nodejs-22 \ CNB_USER_ID=1001 \ CNB_GROUP_ID=0 @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \ io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ io.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.buildpacks.stack.id="com.redhat.stacks.ubi8-nodejs-20" \ + io.buildpacks.stack.id="com.redhat.stacks.ubi8-nodejs-22" \ com.redhat.dev-mode="DEV_MODE:false" \ com.redhat.deployments-dir="${APP_ROOT}/src" \ com.redhat.dev-mode.port="DEBUG_PORT:5858" \ diff --git a/22/Dockerfile.rhel9 b/22/Dockerfile.rhel9 index 5a7097e8..6a9e0c0b 100644 --- a/22/Dockerfile.rhel9 +++ b/22/Dockerfile.rhel9 @@ -21,7 +21,7 @@ ENV NODEJS_VERSION=22 \ NAME=nodejs \ NPM_CONFIG_PREFIX=$HOME/.npm-global \ PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ - CNB_STACK_ID=com.redhat.stacks.ubi9-nodejs-20 \ + CNB_STACK_ID=com.redhat.stacks.ubi9-nodejs-22 \ CNB_USER_ID=1001 \ CNB_GROUP_ID=0 @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \ io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ io.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.buildpacks.stack.id="com.redhat.stacks.ubi9-nodejs-20" \ + io.buildpacks.stack.id="com.redhat.stacks.ubi9-nodejs-22" \ com.redhat.dev-mode="DEV_MODE:false" \ com.redhat.deployments-dir="${APP_ROOT}/src" \ com.redhat.dev-mode.port="DEBUG_PORT:5858" \ diff --git a/22/README.md b/22/README.md deleted file mode 100644 index c05cbbd4..00000000 --- a/22/README.md +++ /dev/null @@ -1,305 +0,0 @@ -NodeJS 22 container image -========================= - -This container image includes Node.JS 22 as a [S2I](https://github.com/openshift/source-to-image) base image for your Node.JS 22 applications. -Users can choose between RHEL, CentOS and Fedora based images. -The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), -and the Fedora images are available in [Quay.io](https://quay.io/organization/fedora). -the CentOS Stream images are available in the [Quay.io](https://quay.io/organization/sclorg), -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 ------------ - -Node.js 22 available as container is a base platform for -building and running various Node.js 22 applications and frameworks. -Node.js is a platform built on Chrome's JavaScript runtime for easily building -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model -that makes it lightweight and efficient, perfect for data-intensive real-time applications -that run across distributed devices. - -Usage in OpenShift ------------------- -In this example, we will assume that you are using the `ubi8/nodejs-22` image, available via `nodejs:22` imagestream tag in Openshift. - -To build a simple [nodejs-sample-app](https://github.com/sclorg/nodejs-ex.git) application in Openshift: - -``` -oc new-app nodejs:22~https://github.com/sclorg/nodejs-ex.git -``` - -To access the application: -``` -$ oc get pods -$ oc exec -- 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 Node.js container image, and produce -a new image that runs the assembled application as an output. - -To support the Source-to-Image framework, important scripts are included in the builder image: - -* The `/usr/libexec/s2i/assemble` script inside the image is run to produce a new image with the application artifacts. The script takes sources of a given application and places them into appropriate directories inside the image. It utilizes some common patterns in Node.js application development (see the **Environment variables** section below). -* The `/usr/libexec/s2i/run` script is set as the default command in the resulting container image (the new image with the application artifacts). It runs `npm run` for production, or `nodemon` if `DEV_MODE` is set to `true` (see the **Environment variables** section below). - -Building an application using a Dockerfile ------------------------------------------- -Compared to the Source-to-Image strategy, using a Dockerfile is a more -flexible way to build a Node.js 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 Node.js image in a Dockerfile, follow these steps: - -#### 1. Pull a base builder image to build on - -``` -podman pull ubi8/nodejs-22 -``` - -An UBI image `ubi8/nodejs-22` is used in this example. This image is usable and freely redistributable under the terms of the UBI End User License Agreement (EULA). See more about UBI at [UBI FAQ](https://developers.redhat.com/articles/ubi-faq). - -#### 2. Pull an application code - -An example application available at https://github.com/sclorg/nodejs-ex.git is used here. Feel free to clone the repository for further experiments. - -``` -git clone https://github.com/sclorg/nodejs-ex.git app-src -``` - -#### 3. Prepare an application inside a container - -This step usually consists of at least these parts: - -* putting the application source into the container -* installing the dependencies -* setting the default command in the resulting image - -For all these three parts, users can either setup all manually and use commands `nodejs` and `npm` explicitly in the Dockerfile ([3.1.](#31-to-use-your-own-setup-create-a-dockerfile-with-this-content)), or users 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 Node.js applications. - -##### 3.1. To use your own setup, create a Dockerfile with this content: -``` -FROM ubi8/nodejs-22 - -# Add application sources -ADD app-src . - -# Install the dependencies -RUN npm install - -# Run script uses standard ways to run the application -CMD npm run -d start -``` - -##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content: -``` -FROM ubi8/nodejs-22 - -# Add application sources to a directory that the assemble script expects them -# and set permissions so that the container runs without root access -USER 0 -ADD app-src /tmp/src -RUN chown -R 1001:0 /tmp/src -USER 1001 - -# Install the dependencies -RUN /usr/libexec/s2i/assemble - -# Set the default command for the resulting image -CMD /usr/libexec/s2i/run -``` - -#### 4. Build a new image from a Dockerfile prepared in the previous step - -``` -podman build -t node-app . -``` - -#### 5. Run the resulting image with the final application - -``` -podman run -d node-app -``` - -Environment variables for Source-to-Image ---------------------- - -Application developers can use the following environment variables to configure the runtime behavior of this image in OpenShift: - -**`NODE_ENV`** - NodeJS runtime mode (default: "production") - -**`DEV_MODE`** - When set to "true", `nodemon` will be used to automatically reload the server while you work (default: "false"). Setting `DEV_MODE` to "true" will change the `NODE_ENV` default to "development" (if not explicitly set). - -**`NPM_BUILD`** - Select an alternate / custom build command, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "build"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NODE_CMD`** - When specified (e.g.Specify `NODE_CMD="node server.js"`) the value of `NODE_CMD` is used to start the application instead of `npm start`. - -**`INIT_WRAPPER`** - When set to "true", the application is started via the `init-wrapper` script instead of using `npm start`, by looking for the presence of the files `server.js`, `index.js` or `main.js` in the order in which they are listed. In case of `NODE_CMD` environemnt variale is specified, then `init-wrapper` script will use the value of `NODE_CMD` to start your application. - -**`NPM_RUN`** - Select an alternate / custom runtime mode, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "start"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`HTTP_PROXY`** - Use an npm proxy during assembly - -**`HTTPS_PROXY`** - Use an npm proxy during assembly - -**`NPM_MIRROR`** - Use a custom NPM registry mirror to download packages during the build process - -**`NPM_TOKEN`** - Use authentication token for a custom NPM registry mirror - -One way to define a set of environment variables is to include them as key value pairs in your repo's `.s2i/environment` file. - -Example: DATABASE_USER=sampleUser - -#### NOTE: Define your own "`DEV_MODE`": - -The following `package.json` example includes a `scripts.dev` entry. You can define your own custom [`NPM_RUN`](https://docs.npmjs.com/cli/run-script) scripts in your application's `package.json` file. - -#### Note: Setting logging output verbosity -To alter the level of logs output during an `npm install` the npm_config_loglevel environment variable can be set. See [npm-config](https://docs.npmjs.com/misc/config). - -Development Mode ----------------- -This image supports development mode. This mode can be switched on and off with the environment variable `DEV_MODE`. `DEV_MODE` can either be set to `true` or `false`. -Development mode supports two features: -* Hot Deploy -* Debugging - -The debug port can be specified with the environment variable `DEBUG_PORT`. `DEBUG_PORT` is only valid if `DEV_MODE=true`. - -A simple example command for running the container in development mode is: -``` -podman run --env DEV_MODE=true my-image-id -``` - -To run the container in development mode with a debug port of 5454, run: -``` -$ podman run --env DEV_MODE=true DEBUG_PORT=5454 my-image-id -``` - -To run the container in production mode, run: -``` -$ podman run --env DEV_MODE=false my-image-id -``` - -By default, `DEV_MODE` is set to `false`, and `DEBUG_PORT` is set to `5858`, however the `DEBUG_PORT` is only relevant if `DEV_MODE=true`. - -Hot deploy ----------- - -As part of development mode, this image supports hot deploy. If development mode is enabled, any souce code that is changed in the running container will be immediately reflected in the running nodejs application. - -### Using Podman's exec - -To change your source code in a running container, use Podman's [exec](https://github.com/containers/libpod) command: -``` -$ podman exec -it /bin/bash -``` - -After you [Podman exec](https://github.com/containers/libpod) into the running container, your current directory is set to `/opt/app-root/src`, where the source code for your application is located. - -### Using OpenShift's rsync - -If you have deployed the container to OpenShift, you can use [oc rsync](https://docs.openshift.org/latest/dev_guide/copy_files_to_container.html) to copy local files to a remote container running in an OpenShift pod. - -#### Warning: - -The default behaviour of the s2i-nodejs container image is to run the Node.js application using the command `npm start`. This runs the _start_ script in the _package.json_ file. In developer mode, the application is run using the command `nodemon`. The default behaviour of nodemon is to look for the _main_ attribute in the _package.json_ file, and execute that script. If the _main_ attribute doesn't appear in the _package.json_ file, it executes the _start_ script. So, in order to achieve some sort of uniform functionality between production and development modes, the user should remove the _main_ attribute. - -Below is an example _package.json_ file with the _main_ attribute and _start_ script marked appropriately: - -```json -{ - "name": "node-echo", - "version": "0.0.1", - "description": "node-echo", - "main": "example.js", <--- main attribute - "dependencies": { - }, - "devDependencies": { - "nodemon": "*" - }, - "engine": { - "node": "*", - "npm": "*" - }, - "scripts": { - "dev": "nodemon --ignore node_modules/ server.js", - "start": "node server.js" <-- start script - }, - "keywords": [ - "Echo" - ], - "license": "", -} -``` - -#### Note: -`oc rsync` is only available in versions 3.1+ of OpenShift. - -## init-wrapper - -init-wrapper script is located on `/usr/libexec/s2i/init-wrapper` and is used to handle: - -- Proper signal handling and propagation, as Node.js was not designed to run as PID 1. -- Reaping zombie child processes -Avoiding use of npm, there is more information on why you want to avoid that in the [Node.js reference architecture](https://github.com/nodeshift/nodejs-reference-architecture/blob/e4c4dc1fd20c2cac392e862859aaad27f85d504f/docs/development/building-good-containers.md#avoiding-using-npm-to-start-application). When the INIT_WRAPPER is set to true the application is started via the init script instead of using npm start. - -A detailed explanation on how the init-wrapper script works is avalable in -[this url](http://veithen.io/2014/11/16/sigterm-propagation.html). - -Example of using init-wrapper: - -**During image build** -``` -s2i -e INIT_WRAPPER=true build . buildImage node-app -docker run node-app -``` -**During container start** -``` -s2i build . buildImage node-app -docker run -e INIT_WRAPPER=true node-app -``` - -`init-wrapper` script can be disabled by setting the `INIT_WRAPPER` env variable to `false`. - -``` -docker run -e INIT_WRAPPER=false node-app -``` -`NODE_CMD` can be used during the build process or container start, in order to have more control on the command that `init-wrapper` script will wrap. - -For example: - -**during container build** -``` -s2i -e INIT_WRAPPER=true -e NODE_CMD="node index.js" build . buildImage node-app -``` -**during container start** -``` -docker run -e INIT_WRAPPER=false -e NODE_CMD="node index.js" node-app -``` - -See also --------- -Dockerfile and other sources are available on https://github.com/sclorg/s2i-nodejs-container. -In that repository you also can find another versions of Node.js environment Dockerfiles. -Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s`, -Dockerfile for CentOS Stream 10 is called `Dockerfile.c10s`, -for RHEL8 it's `Dockerfile.rhel8`, for RHEL9 it's `Dockerfile.rhel9`, -for RHEL10 it's `Dockerfile.rhel10` and the Fedora Dockerfile is called Dockerfile.fedora. diff --git a/22/README.md b/22/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/22/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/22/s2i/bin/assemble b/22/s2i/bin/assemble index 3230d038..f644a811 100755 --- a/22/s2i/bin/assemble +++ b/22/s2i/bin/assemble @@ -63,13 +63,6 @@ if [ -n "$NPM_MIRROR" ]; then npm config set registry $NPM_MIRROR fi -# Change the npm authentication token if provided -if [ -n "$NPM_TOKEN" ]; then - echo "---> Setting npm authentication token for $NPM_MIRROR" - INTERNAL_NPM_REGISTRY=$(echo "$NPM_MIRROR" | sed -n 's|https://||p') - npm config set "//${INTERNAL_NPM_REGISTRY:-registry.npmjs.org}:_auth" $NPM_TOKEN -fi - # Set the DEV_MODE to false by default. if [ -z "$DEV_MODE" ]; then export DEV_MODE=false diff --git a/22/s2i/bin/init-wrapper b/22/s2i/bin/init-wrapper old mode 100644 new mode 100755 diff --git a/22/s2i/bin/run b/22/s2i/bin/run index 9a207bce..9fc5cf90 100755 --- a/22/s2i/bin/run +++ b/22/s2i/bin/run @@ -47,7 +47,7 @@ run_node() { echo "Launching via npm..." exec npm run -d $NPM_RUN fi -} +} #Set the debug port to 5858 by default. if [ -z "$DEBUG_PORT" ]; then diff --git a/22/s2i/bin/usage b/22/s2i/bin/usage index b8c1dca8..d77326cf 100755 --- a/22/s2i/bin/usage +++ b/22/s2i/bin/usage @@ -3,12 +3,12 @@ DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` cat < nodejs-sample-app +s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=18/test/test-app/ ${NAMESPACE}/nodejs-18-${DISTRO}7 nodejs-sample-app You can then run the resulting image via: podman run -p 8080:8080 nodejs-sample-app diff --git a/22/test b/22/test index ae78e219..419df4f9 120000 --- a/22/test +++ b/22/test @@ -1 +1 @@ -../test/ \ No newline at end of file +../test \ No newline at end of file diff --git a/24-minimal/.exclude-c8s b/24-minimal/.exclude-c8s deleted file mode 100644 index e69de29b..00000000 diff --git a/24-minimal/.exclude-rhel8 b/24-minimal/.exclude-rhel8 deleted file mode 100644 index e69de29b..00000000 diff --git a/24-minimal/Dockerfile.c8s b/24-minimal/Dockerfile.c8s index d7829589..f0934512 100644 --- a/24-minimal/Dockerfile.c8s +++ b/24-minimal/Dockerfile.c8s @@ -17,7 +17,7 @@ ENV APP_ROOT=/opt/app-root \ HOME=/opt/app-root/src \ NPM_RUN=start \ PLATFORM="el8" \ - NODEJS_VERSION=20 \ + NODEJS_VERSION=24 \ NPM_RUN=start \ NAME=nodejs diff --git a/24-minimal/README.md b/24-minimal/README.md deleted file mode 100644 index 824d8635..00000000 --- a/24-minimal/README.md +++ /dev/null @@ -1,376 +0,0 @@ -NodeJS 24 minimal container image -========================= - -This container image includes Node.JS 24 on top of a minimal base image for your Node.JS 24 applications. This image is designed to be used -with the full-sized s2i-enabled Node.JS 24 image to build the application. The image can be used as a standalone s2i-enabled image as well, -but compared to the full-sized Node.JS 24 image it will be missing many build-time dependencies. -Users can choose between RHEL, CentOS and Fedora based images. -The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), -the CentOS Stream images are available in the [Quay.io](https://quay.io/organization/sclorg), -and the Fedora images are available in [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 ------------ - -Node.js 24 available as a minimal container is a base platform for -running various Node.js 24 applications and frameworks. -Node.js is a platform built on Chrome's JavaScript runtime for easily building -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model -that makes it lightweight and efficient, perfect for data-intensive real-time applications -that run across distributed devices. - -Usage in OpenShift ------------------- -In this example, we will assume that you are using the `ubi8/nodejs-24` image, available via `nodejs:24-ubi8` imagestream tag in Openshift -to build the application, as well as the `ubi8/nodejs-24-minimal` image, available via `nodejs:24-ubi8-minimal` image stream -for running the resulting application. - -With these two images we can create a [chained build](https://docs.openshift.com/container-platform/4.7/cicd/builds/advanced-build-operations.html#builds-chaining-builds_advanced-build-operations) in Openshift using two BuildConfigs: - -The first BuildConfig defines and builds the builder image, using the source-to-image strategy, and pushes the result into -the `nodejs-builder-image` imagestream. - -``` -apiVersion: build.openshift.io/v1 -kind: BuildConfig -metadata: - name: nodejs-builder-image -spec: - output: - to: - kind: ImageStreamTag - name: nodejs-builder-image:latest - source: - git: - uri: https://github.com/sclorg/nodejs-ex.git - strategy: - sourceStrategy: - from: - kind: ImageStreamTag - name: nodejs:24-ubi8 - namespace: openshift -``` - -The second BuildConfig takes the resulting image from the `nodejs-builder-image` imagestream, copies the application source (including build artifacts) -from the image and creates a new runtime image on top of the nodejs minimal image, with the application copied in and prepared to run. -The resulting runtime image is then pushed into the `nodejs-runtime-image` imagestream. - -``` -apiVersion: build.openshift.io/v1 -kind: BuildConfig -metadata: - name: nodejs-runtime-image -spec: - output: - to: - kind: ImageStreamTag - name: nodejs-runtime-image:latest - source: - dockerfile: |- - FROM nodejs:24-ubi8-minimal - COPY src $HOME - CMD /usr/libexec/s2i/run - images: - - from: - kind: ImageStreamTag - name: nodejs-builder-image:latest - paths: - - sourcePath: /opt/app-root/src - destinationDir: "." - strategy: - dockerStrategy: - from: - kind: ImageStreamTag - name: nodejs:24-ubi8-minimal - triggers: - - imageChange: {} - type: ImageChange -``` - -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 Node.js container image, and produce -a new image that runs the assembled application as an output. - -To support the Source-to-Image framework, only the `run` script is included in this 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). It runs `npm run` for production, or `nodemon` if `DEV_MODE` is set to `true` (see the **Environment variables** section below). - -Building an application using a Dockerfile ------------------------------------------- -Compared to the Source-to-Image strategy, using a Dockerfile is a more -flexible way to build a Node.js 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 Node.js image in a Dockerfile, follow these steps: - -#### 1. Pull the base builder and minimal runtime images - -``` -podman pull ubi8/nodejs-24 -podman pull ubi8/nodejs-24-minimal -``` - -The UBI images `ubi8/nodejs-24` and `ubi8/nodejs-24-minimal` that are used in this example are both usable and freely redistributable under the terms of the UBI End User License Agreement (EULA). See more about UBI at [UBI FAQ](https://developers.redhat.com/articles/ubi-faq). - -#### 2. Pull an application code - -An example application available at https://github.com/sclorg/nodejs-ex.git is used here. Feel free to clone the repository for further experiments. - -``` -git clone https://github.com/sclorg/nodejs-ex.git app-src -``` - -#### 3. Prepare an application inside a container - -This step usually consists of at least these parts: - -* putting the application source into the container -* installing the dependencies -* setting the default command in the resulting image - -For all these three parts, users can either setup all manually and use commands `nodejs` and `npm` explicitly in the Dockerfile ([3.1.](#31-to-use-your-own-setup-create-a-dockerfile-with-this-content)), or users 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 Node.js applications. - -##### 3.1. To use your own setup, create a Dockerfile with this content: -``` -# First stage builds the application -FROM ubi8/nodejs-24 as builder - -# Add application sources -ADD app-src $HOME - -# Install the dependencies -RUN npm install - -# Second stage copies the application to the minimal image -FROM ubi8/nodejs-24-minimal - -# Copy the application source and build artifacts from the builder image to this one -COPY --from=builder $HOME $HOME - -# Run script uses standard ways to run the application -CMD npm run -d start -``` - -##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content: -``` -# First stage builds the application -FROM ubi8/nodejs-24 as builder - -# Add application sources to a directory that the assemble script expects them -# and set permissions so that the container runs without root access -USER 0 -ADD app-src /tmp/src -RUN chown -R 1001:0 /tmp/src -USER 1001 - -# Install the dependencies -RUN /usr/libexec/s2i/assemble - -# Second stage copies the application to the minimal image -FROM ubi8/nodejs-24-minimal - -# Copy the application source and build artifacts from the builder image to this one -COPY --from=builder $HOME $HOME - -# Set the default command for the resulting image -CMD /usr/libexec/s2i/run -``` - -#### 4. Build a new image from a Dockerfile prepared in the previous step - -``` -podman build -t node-app . -``` - -#### 5. Run the resulting image with the final application - -``` -podman run -d node-app -``` - -Environment variables for Source-to-Image ---------------------- - -Application developers can use the following environment variables to configure the runtime behavior of this image in OpenShift: - -#### Used in the minimal image - -**`NODE_ENV`** - NodeJS runtime mode (default: "production") - -**`DEV_MODE`** - When set to "true", `nodemon` will be used to automatically reload the server while you work (default: "false"). Setting `DEV_MODE` to "true" will change the `NODE_ENV` default to "development" (if not explicitly set). - -**`NPM_BUILD`** - Select an alternate / custom build command, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "build"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NPM_RUN`** - Select an alternate / custom runtime mode, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "start"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NODE_CMD`** - When specified (e.g.Specify `NODE_CMD="node server.js"`) the value of `NODE_CMD` is used to start the application instead of `npm start`. - -**`INIT_WRAPPER`** - When set to "true", the application is started via the `init-wrapper` script instead of using `npm start`, by looking for the presence of the files `server.js`, `index.js` or `main.js` in the order in which they are listed. In case of `NODE_CMD` environemnt variale is specified, then `init-wrapper` script will use the value of `NODE_CMD` to start your application. - -#### Additional variables used in the full-sized image - -**`HTTP_PROXY`** - Use an npm proxy during assembly - -**`HTTPS_PROXY`** - Use an npm proxy during assembly - -**`NPM_MIRROR`** - Use a custom NPM registry mirror to download packages during the build process - -**`NPM_TOKEN`** - Use authentication token for a custom NPM registry mirror - -One way to define a set of environment variables is to include them as key value pairs in your repo's `.s2i/environment` file. - -Example: DATABASE_USER=sampleUser - -#### NOTE: Define your own "`DEV_MODE`": - -The following `package.json` example includes a `scripts.dev` entry. You can define your own custom [`NPM_RUN`](https://docs.npmjs.com/cli/run-script) scripts in your application's `package.json` file. - -#### Note: Setting logging output verbosity -To alter the level of logs output during an `npm install` the npm_config_loglevel environment variable can be set. See [npm-config](https://docs.npmjs.com/misc/config). - -Development Mode ----------------- -This image supports development mode. This mode can be switched on and off with the environment variable `DEV_MODE`. `DEV_MODE` can either be set to `true` or `false`. -Development mode supports two features: -* Hot Deploy -* Debugging - -The debug port can be specified with the environment variable `DEBUG_PORT`. `DEBUG_PORT` is only valid if `DEV_MODE=true`. - -A simple example command for running the container in development mode is: -``` -podman run --env DEV_MODE=true my-image-id -``` - -To run the container in development mode with a debug port of 5454, run: -``` -$ podman run --env DEV_MODE=true DEBUG_PORT=5454 my-image-id -``` - -To run the container in production mode, run: -``` -$ podman run --env DEV_MODE=false my-image-id -``` - -By default, `DEV_MODE` is set to `false`, and `DEBUG_PORT` is set to `5858`, however the `DEBUG_PORT` is only relevant if `DEV_MODE=true`. - -Hot deploy ----------- - -As part of development mode, this image supports hot deploy. If development mode is enabled, any souce code that is changed in the running container will be immediately reflected in the running nodejs application. - -### Using Podman's exec - -To change your source code in a running container, use Podman's [exec](https://github.com/containers/libpod) command: -``` -$ podman exec -it /bin/bash -``` - -After you [Podman exec](https://github.com/containers/libpod) into the running container, your current directory is set to `/opt/app-root/src`, where the source code for your application is located. - -### Using OpenShift's rsync - -If you have deployed the container to OpenShift, you can use [oc rsync](https://docs.openshift.org/latest/dev_guide/copy_files_to_container.html) to copy local files to a remote container running in an OpenShift pod. - -#### Warning: - -The default behaviour of the s2i-nodejs container image is to run the Node.js application using the command `npm start`. This runs the _start_ script in the _package.json_ file. In developer mode, the application is run using the command `nodemon`. The default behaviour of nodemon is to look for the _main_ attribute in the _package.json_ file, and execute that script. If the _main_ attribute doesn't appear in the _package.json_ file, it executes the _start_ script. So, in order to achieve some sort of uniform functionality between production and development modes, the user should remove the _main_ attribute. - -Below is an example _package.json_ file with the _main_ attribute and _start_ script marked appropriately: - -```json -{ - "name": "node-echo", - "version": "0.0.1", - "description": "node-echo", - "main": "example.js", <--- main attribute - "dependencies": { - }, - "devDependencies": { - "nodemon": "*" - }, - "engine": { - "node": "*", - "npm": "*" - }, - "scripts": { - "dev": "nodemon --ignore node_modules/ server.js", - "start": "node server.js" <-- start script - }, - "keywords": [ - "Echo" - ], - "license": "", -} -``` - -#### Note: -`oc rsync` is only available in versions 3.1+ of OpenShift. - -## init-wrapper - -init-wrapper script is located on `/usr/libexec/s2i/init-wrapper` and is used to handle: - -- Proper signal handling and propagation, as Node.js was not designed to run as PID 1. -- Reaping zombie child processes -Avoiding use of npm, there is more information on why you want to avoid that in the [Node.js reference architecture](https://github.com/nodeshift/nodejs-reference-architecture/blob/e4c4dc1fd20c2cac392e862859aaad27f85d504f/docs/development/building-good-containers.md#avoiding-using-npm-to-start-application). When the INIT_WRAPPER is set to true the application is started via the init script instead of using npm start. - -A detailed explanation on how the init-wrapper script works is avalable in -[this url](http://veithen.io/2014/11/16/sigterm-propagation.html). - -Example of using init-wrapper: - -**During image build** -``` -s2i -e INIT_WRAPPER=true build . buildImage node-app -docker run node-app -``` -**During container start** -``` -s2i build . buildImage node-app -docker run -e INIT_WRAPPER=true node-app -``` - -`init-wrapper` script can be disabled by setting the `INIT_WRAPPER` env variable to `false`. - -``` -docker run -e INIT_WRAPPER=false node-app -``` -`NODE_CMD` can be used during the build process or container start, in order to have more control on the command that `init-wrapper` script will wrap. - -For example: - -**during container build** -``` -s2i -e INIT_WRAPPER=true -e NODE_CMD="node index.js" build . buildImage node-app -``` -**during container start** -``` -docker run -e INIT_WRAPPER=false -e NODE_CMD="node index.js" node-app -``` -See also --------- -Dockerfile and other sources are available on https://github.com/sclorg/s2i-nodejs-container. -In that repository you also can find another versions of Node.js environment Dockerfiles. -Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s`, -Dockerfile for CentOS Stream 10 is called `Dockerfile.c10s`, -for RHEL8 it's `Dockerfile.rhel8`, for RHEL9 it's `Dockerfile.rhel9`, -for RHEL10 it's `Dockerfile.rhel10` and the Fedora Dockerfile is called Dockerfile.fedora. diff --git a/24-minimal/README.md b/24-minimal/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/24-minimal/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/24-minimal/root/opt/app-root/etc/generate_container_user b/24-minimal/root/opt/app-root/etc/generate_container_user new file mode 100644 index 00000000..b28a7a3d --- /dev/null +++ b/24-minimal/root/opt/app-root/etc/generate_container_user @@ -0,0 +1,17 @@ +# Set current user in nss_wrapper +USER_ID=$(id -u) +GROUP_ID=$(id -g) + +if [ x"$USER_ID" != x"0" -a x"$USER_ID" != x"1001" ]; then + + NSS_WRAPPER_PASSWD=/opt/app-root/etc/passwd + NSS_WRAPPER_GROUP=/etc/group + + cat /etc/passwd | sed -e 's/^default:/builder:/' > $NSS_WRAPPER_PASSWD + + echo "default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/sbin/nologin" >> $NSS_WRAPPER_PASSWD + + export NSS_WRAPPER_PASSWD + export NSS_WRAPPER_GROUP + export LD_PRELOAD=libnss_wrapper.so +fi diff --git a/24-minimal/root/opt/app-root/etc/npm_global_module_list b/24-minimal/root/opt/app-root/etc/npm_global_module_list new file mode 100644 index 00000000..005e1501 --- /dev/null +++ b/24-minimal/root/opt/app-root/etc/npm_global_module_list @@ -0,0 +1,5 @@ +async +mime +mkdirp +qs +minimatch diff --git a/24-minimal/root/opt/app-root/etc/scl_enable b/24-minimal/root/opt/app-root/etc/scl_enable new file mode 100644 index 00000000..4bfebea0 --- /dev/null +++ b/24-minimal/root/opt/app-root/etc/scl_enable @@ -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-nodejs${NODEJS_VERSION} diff --git a/24-minimal/root/usr/bin/fix-permissions b/24-minimal/root/usr/bin/fix-permissions deleted file mode 100755 index ddd33ace..00000000 --- a/24-minimal/root/usr/bin/fix-permissions +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh - -# Allow this script to fail without failing a build -set +e - -SYMLINK_OPT=${2:--L} - -# Fix permissions on the given directory or file to allow group read/write of -# regular files and execute of directories. - -[ $(id -u) -ne 0 ] && CHECK_OWNER=" -uid $(id -u)" - -# If argument does not exist, script will still exit with 0, -# but at least we'll see something went wrong in the log -if ! [ -e "$1" ] ; then - echo "ERROR: File or directory $1 does not exist." >&2 - # We still want to end successfully - exit 0 -fi - -find $SYMLINK_OPT "$1" ${CHECK_OWNER} \! -gid 0 -exec chgrp 0 {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} \! -perm -g+rw -exec chmod g+rw {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} -perm /u+x -a \! -perm /g+x -exec chmod g+x {} + -find $SYMLINK_OPT "$1" ${CHECK_OWNER} -type d \! -perm /g+x -exec chmod g+x {} + - -# Always end successfully -exit 0 diff --git a/24-minimal/s2i/bin/assemble b/24-minimal/s2i/bin/assemble index 3230d038..f644a811 100755 --- a/24-minimal/s2i/bin/assemble +++ b/24-minimal/s2i/bin/assemble @@ -63,13 +63,6 @@ if [ -n "$NPM_MIRROR" ]; then npm config set registry $NPM_MIRROR fi -# Change the npm authentication token if provided -if [ -n "$NPM_TOKEN" ]; then - echo "---> Setting npm authentication token for $NPM_MIRROR" - INTERNAL_NPM_REGISTRY=$(echo "$NPM_MIRROR" | sed -n 's|https://||p') - npm config set "//${INTERNAL_NPM_REGISTRY:-registry.npmjs.org}:_auth" $NPM_TOKEN -fi - # Set the DEV_MODE to false by default. if [ -z "$DEV_MODE" ]; then export DEV_MODE=false diff --git a/24-minimal/s2i/bin/init-wrapper b/24-minimal/s2i/bin/init-wrapper old mode 100644 new mode 100755 diff --git a/24-minimal/s2i/bin/run b/24-minimal/s2i/bin/run index 10150f34..9fc5cf90 100755 --- a/24-minimal/s2i/bin/run +++ b/24-minimal/s2i/bin/run @@ -9,6 +9,10 @@ set -e +if [ -e "/opt/app-root/etc/generate_container_user" ]; then + source /opt/app-root/etc/generate_container_user +fi + # Runs the nodejs application server. If the container is run in development mode, # hot deploy and debugging are enabled. run_node() { @@ -43,7 +47,7 @@ run_node() { echo "Launching via npm..." exec npm run -d $NPM_RUN fi -} +} #Set the debug port to 5858 by default. if [ -z "$DEBUG_PORT" ]; then diff --git a/24-minimal/s2i/bin/usage b/24-minimal/s2i/bin/usage index b8c1dca8..d77326cf 100755 --- a/24-minimal/s2i/bin/usage +++ b/24-minimal/s2i/bin/usage @@ -3,12 +3,12 @@ DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` cat < nodejs-sample-app +s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=18/test/test-app/ ${NAMESPACE}/nodejs-18-${DISTRO}7 nodejs-sample-app You can then run the resulting image via: podman run -p 8080:8080 nodejs-sample-app diff --git a/24-minimal/test b/24-minimal/test new file mode 120000 index 00000000..419df4f9 --- /dev/null +++ b/24-minimal/test @@ -0,0 +1 @@ +../test \ No newline at end of file diff --git a/24-minimal/test/__init__.py b/24-minimal/test/__init__.py deleted file mode 120000 index d0f4746a..00000000 --- a/24-minimal/test/__init__.py +++ /dev/null @@ -1 +0,0 @@ -../../test/__init__.py \ No newline at end of file diff --git a/24-minimal/test/check_imagestreams.py b/24-minimal/test/check_imagestreams.py deleted file mode 120000 index 56bb2be7..00000000 --- a/24-minimal/test/check_imagestreams.py +++ /dev/null @@ -1 +0,0 @@ -../../common/check_imagestreams.py \ No newline at end of file diff --git a/24-minimal/test/conftest.py b/24-minimal/test/conftest.py deleted file mode 120000 index 3f2d7840..00000000 --- a/24-minimal/test/conftest.py +++ /dev/null @@ -1 +0,0 @@ -../../test/conftest.py \ No newline at end of file diff --git a/24-minimal/test/examples b/24-minimal/test/examples deleted file mode 120000 index da7b1965..00000000 --- a/24-minimal/test/examples +++ /dev/null @@ -1 +0,0 @@ -../../examples/ \ No newline at end of file diff --git a/24-minimal/test/imagestreams b/24-minimal/test/imagestreams deleted file mode 120000 index 0dcbe9e0..00000000 --- a/24-minimal/test/imagestreams +++ /dev/null @@ -1 +0,0 @@ -../../imagestreams/ \ No newline at end of file diff --git a/24-minimal/test/run b/24-minimal/test/run deleted file mode 120000 index f446a740..00000000 --- a/24-minimal/test/run +++ /dev/null @@ -1 +0,0 @@ -../../test/run-minimal \ No newline at end of file diff --git a/24-minimal/test/run-openshift-remote-cluster b/24-minimal/test/run-openshift-remote-cluster deleted file mode 120000 index 1bffcba8..00000000 --- a/24-minimal/test/run-openshift-remote-cluster +++ /dev/null @@ -1 +0,0 @@ -../../test/run-openshift-remote-cluster \ No newline at end of file diff --git a/24-minimal/test/run-pytest b/24-minimal/test/run-pytest deleted file mode 120000 index efe32b48..00000000 --- a/24-minimal/test/run-pytest +++ /dev/null @@ -1 +0,0 @@ -../../test/run-pytest \ No newline at end of file diff --git a/24-minimal/test/test-app b/24-minimal/test/test-app deleted file mode 120000 index 6ba4f290..00000000 --- a/24-minimal/test/test-app +++ /dev/null @@ -1 +0,0 @@ -../../test/test-app \ No newline at end of file diff --git a/24-minimal/test/test-binary b/24-minimal/test/test-binary deleted file mode 120000 index cd7b631f..00000000 --- a/24-minimal/test/test-binary +++ /dev/null @@ -1 +0,0 @@ -../../test/test-binary \ No newline at end of file diff --git a/24-minimal/test/test-express-webapp b/24-minimal/test/test-express-webapp deleted file mode 120000 index 6a5bbd41..00000000 --- a/24-minimal/test/test-express-webapp +++ /dev/null @@ -1 +0,0 @@ -../../test/test-express-webapp \ No newline at end of file diff --git a/24-minimal/test/test-fips b/24-minimal/test/test-fips deleted file mode 120000 index fbe9489f..00000000 --- a/24-minimal/test/test-fips +++ /dev/null @@ -1 +0,0 @@ -../../test/test-fips \ No newline at end of file diff --git a/24-minimal/test/test-hw b/24-minimal/test/test-hw deleted file mode 120000 index ad784558..00000000 --- a/24-minimal/test/test-hw +++ /dev/null @@ -1 +0,0 @@ -../../test/test-hw \ No newline at end of file diff --git a/24-minimal/test/test-incremental b/24-minimal/test/test-incremental deleted file mode 120000 index 0a357b1f..00000000 --- a/24-minimal/test/test-incremental +++ /dev/null @@ -1 +0,0 @@ -../../test/test-incremental \ No newline at end of file diff --git a/24-minimal/test/test-lib-nodejs.sh b/24-minimal/test/test-lib-nodejs.sh deleted file mode 120000 index 8915d844..00000000 --- a/24-minimal/test/test-lib-nodejs.sh +++ /dev/null @@ -1 +0,0 @@ -../../test/test-lib-nodejs.sh \ No newline at end of file diff --git a/24-minimal/test/test-lib-openshift.sh b/24-minimal/test/test-lib-openshift.sh deleted file mode 120000 index 4f9f2996..00000000 --- a/24-minimal/test/test-lib-openshift.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib-openshift.sh \ No newline at end of file diff --git a/24-minimal/test/test-lib-remote-openshift.sh b/24-minimal/test/test-lib-remote-openshift.sh deleted file mode 120000 index 92ad2f4d..00000000 --- a/24-minimal/test/test-lib-remote-openshift.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib-remote-openshift.sh \ No newline at end of file diff --git a/24-minimal/test/test-lib.sh b/24-minimal/test/test-lib.sh deleted file mode 120000 index 1ac99b93..00000000 --- a/24-minimal/test/test-lib.sh +++ /dev/null @@ -1 +0,0 @@ -../../common/test-lib.sh \ No newline at end of file diff --git a/24-minimal/test/test-openshift.yaml b/24-minimal/test/test-openshift.yaml deleted file mode 120000 index 8613fbba..00000000 --- a/24-minimal/test/test-openshift.yaml +++ /dev/null @@ -1 +0,0 @@ -../../common/test-openshift.yaml \ No newline at end of file diff --git a/24-minimal/test/test_container_apps.py b/24-minimal/test/test_container_apps.py deleted file mode 120000 index 9870de8e..00000000 --- a/24-minimal/test/test_container_apps.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_container_apps.py \ No newline at end of file diff --git a/24-minimal/test/test_container_basics.py b/24-minimal/test/test_container_basics.py deleted file mode 120000 index b85dc139..00000000 --- a/24-minimal/test/test_container_basics.py +++ /dev/null @@ -1 +0,0 @@ -../../test/test_container_basics.py \ No newline at end of file diff --git a/24/.exclude-c8s b/24/.exclude-c8s deleted file mode 100644 index e69de29b..00000000 diff --git a/24/.exclude-rhel8 b/24/.exclude-rhel8 deleted file mode 100644 index e69de29b..00000000 diff --git a/24/Dockerfile.c8s b/24/Dockerfile.c8s index 6a7e0501..59e8ccb9 100644 --- a/24/Dockerfile.c8s +++ b/24/Dockerfile.c8s @@ -16,12 +16,12 @@ EXPOSE 8080 # Expose ports: # * 8080 - Unprivileged port used by nodejs application -ENV NODEJS_VERSION=20 \ +ENV NODEJS_VERSION=24 \ NPM_RUN=start \ NAME=nodejs \ NPM_CONFIG_PREFIX=$HOME/.npm-global \ PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ - CNB_STACK_ID=com.redhat.stacks.c8s-nodejs-20 \ + CNB_STACK_ID=com.redhat.stacks.c8s-nodejs-24 \ CNB_USER_ID=1001 \ CNB_GROUP_ID=0 @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \ io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ io.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.buildpacks.stack.id="com.redhat.stacks.c8s-nodejs-20" \ + io.buildpacks.stack.id="com.redhat.stacks.c8s-nodejs-24" \ com.redhat.dev-mode="DEV_MODE:false" \ com.redhat.deployments-dir="${APP_ROOT}/src" \ com.redhat.dev-mode.port="DEBUG_PORT:5858" \ diff --git a/24/Dockerfile.rhel8 b/24/Dockerfile.rhel8 index d5cc39de..4dff241e 100644 --- a/24/Dockerfile.rhel8 +++ b/24/Dockerfile.rhel8 @@ -21,7 +21,7 @@ ENV NODEJS_VERSION=24 \ NAME=nodejs \ NPM_CONFIG_PREFIX=$HOME/.npm-global \ PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ - CNB_STACK_ID=com.redhat.stacks.ubi8-nodejs-20 \ + CNB_STACK_ID=com.redhat.stacks.ubi8-nodejs-24 \ CNB_USER_ID=1001 \ CNB_GROUP_ID=0 @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \ io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ io.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.buildpacks.stack.id="com.redhat.stacks.ubi8-nodejs-20" \ + io.buildpacks.stack.id="com.redhat.stacks.ubi8-nodejs-24" \ com.redhat.dev-mode="DEV_MODE:false" \ com.redhat.deployments-dir="${APP_ROOT}/src" \ com.redhat.dev-mode.port="DEBUG_PORT:5858" \ diff --git a/24/Dockerfile.rhel9 b/24/Dockerfile.rhel9 index 74202d63..3982a7e5 100644 --- a/24/Dockerfile.rhel9 +++ b/24/Dockerfile.rhel9 @@ -21,7 +21,7 @@ ENV NODEJS_VERSION=24 \ NAME=nodejs \ NPM_CONFIG_PREFIX=$HOME/.npm-global \ PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH \ - CNB_STACK_ID=com.redhat.stacks.ubi9-nodejs-20 \ + CNB_STACK_ID=com.redhat.stacks.ubi9-nodejs-24 \ CNB_USER_ID=1001 \ CNB_GROUP_ID=0 @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \ io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ io.s2i.scripts-url="image:///usr/libexec/s2i" \ - io.buildpacks.stack.id="com.redhat.stacks.ubi9-nodejs-20" \ + io.buildpacks.stack.id="com.redhat.stacks.ubi9-nodejs-24" \ com.redhat.dev-mode="DEV_MODE:false" \ com.redhat.deployments-dir="${APP_ROOT}/src" \ com.redhat.dev-mode.port="DEBUG_PORT:5858" \ diff --git a/24/README.md b/24/README.md deleted file mode 100644 index 241d1173..00000000 --- a/24/README.md +++ /dev/null @@ -1,305 +0,0 @@ -NodeJS 24 container image -========================= - -This container image includes Node.JS 24 as a [S2I](https://github.com/openshift/source-to-image) base image for your Node.JS 24 applications. -Users can choose between RHEL, CentOS and Fedora based images. -The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/), -and the Fedora images are available in [Quay.io](https://quay.io/organization/fedora). -the CentOS Stream images are available in the [Quay.io](https://quay.io/organization/sclorg), -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 ------------ - -Node.js 24 available as container is a base platform for -building and running various Node.js 24 applications and frameworks. -Node.js is a platform built on Chrome's JavaScript runtime for easily building -fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model -that makes it lightweight and efficient, perfect for data-intensive real-time applications -that run across distributed devices. - -Usage in OpenShift ------------------- -In this example, we will assume that you are using the `ubi8/nodejs-24` image, available via `nodejs:24` imagestream tag in Openshift. - -To build a simple [nodejs-sample-app](https://github.com/sclorg/nodejs-ex.git) application in Openshift: - -``` -oc new-app nodejs:24~https://github.com/sclorg/nodejs-ex.git -``` - -To access the application: -``` -$ oc get pods -$ oc exec -- 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 Node.js container image, and produce -a new image that runs the assembled application as an output. - -To support the Source-to-Image framework, important scripts are included in the builder image: - -* The `/usr/libexec/s2i/assemble` script inside the image is run to produce a new image with the application artifacts. The script takes sources of a given application and places them into appropriate directories inside the image. It utilizes some common patterns in Node.js application development (see the **Environment variables** section below). -* The `/usr/libexec/s2i/run` script is set as the default command in the resulting container image (the new image with the application artifacts). It runs `npm run` for production, or `nodemon` if `DEV_MODE` is set to `true` (see the **Environment variables** section below). - -Building an application using a Dockerfile ------------------------------------------- -Compared to the Source-to-Image strategy, using a Dockerfile is a more -flexible way to build a Node.js 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 Node.js image in a Dockerfile, follow these steps: - -#### 1. Pull a base builder image to build on - -``` -podman pull ubi8/nodejs-24 -``` - -An UBI image `ubi8/nodejs-24` is used in this example. This image is usable and freely redistributable under the terms of the UBI End User License Agreement (EULA). See more about UBI at [UBI FAQ](https://developers.redhat.com/articles/ubi-faq). - -#### 2. Pull an application code - -An example application available at https://github.com/sclorg/nodejs-ex.git is used here. Feel free to clone the repository for further experiments. - -``` -git clone https://github.com/sclorg/nodejs-ex.git app-src -``` - -#### 3. Prepare an application inside a container - -This step usually consists of at least these parts: - -* putting the application source into the container -* installing the dependencies -* setting the default command in the resulting image - -For all these three parts, users can either setup all manually and use commands `nodejs` and `npm` explicitly in the Dockerfile ([3.1.](#31-to-use-your-own-setup-create-a-dockerfile-with-this-content)), or users 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 Node.js applications. - -##### 3.1. To use your own setup, create a Dockerfile with this content: -``` -FROM ubi8/nodejs-24 - -# Add application sources -ADD app-src . - -# Install the dependencies -RUN npm install - -# Run script uses standard ways to run the application -CMD npm run -d start -``` - -##### 3.2. To use the Source-to-Image scripts and build an image using a Dockerfile, create a Dockerfile with this content: -``` -FROM ubi8/nodejs-24 - -# Add application sources to a directory that the assemble script expects them -# and set permissions so that the container runs without root access -USER 0 -ADD app-src /tmp/src -RUN chown -R 1001:0 /tmp/src -USER 1001 - -# Install the dependencies -RUN /usr/libexec/s2i/assemble - -# Set the default command for the resulting image -CMD /usr/libexec/s2i/run -``` - -#### 4. Build a new image from a Dockerfile prepared in the previous step - -``` -podman build -t node-app . -``` - -#### 5. Run the resulting image with the final application - -``` -podman run -d node-app -``` - -Environment variables for Source-to-Image ---------------------- - -Application developers can use the following environment variables to configure the runtime behavior of this image in OpenShift: - -**`NODE_ENV`** - NodeJS runtime mode (default: "production") - -**`DEV_MODE`** - When set to "true", `nodemon` will be used to automatically reload the server while you work (default: "false"). Setting `DEV_MODE` to "true" will change the `NODE_ENV` default to "development" (if not explicitly set). - -**`NPM_BUILD`** - Select an alternate / custom build command, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "build"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`NODE_CMD`** - When specified (e.g.Specify `NODE_CMD="node server.js"`) the value of `NODE_CMD` is used to start the application instead of `npm start`. - -**`INIT_WRAPPER`** - When set to "true", the application is started via the `init-wrapper` script instead of using `npm start`, by looking for the presence of the files `server.js`, `index.js` or `main.js` in the order in which they are listed. In case of `NODE_CMD` environemnt variale is specified, then `init-wrapper` script will use the value of `NODE_CMD` to start your application. - -**`NPM_RUN`** - Select an alternate / custom runtime mode, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "start"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. - -**`HTTP_PROXY`** - Use an npm proxy during assembly - -**`HTTPS_PROXY`** - Use an npm proxy during assembly - -**`NPM_MIRROR`** - Use a custom NPM registry mirror to download packages during the build process - -**`NPM_TOKEN`** - Use authentication token for a custom NPM registry mirror - -One way to define a set of environment variables is to include them as key value pairs in your repo's `.s2i/environment` file. - -Example: DATABASE_USER=sampleUser - -#### NOTE: Define your own "`DEV_MODE`": - -The following `package.json` example includes a `scripts.dev` entry. You can define your own custom [`NPM_RUN`](https://docs.npmjs.com/cli/run-script) scripts in your application's `package.json` file. - -#### Note: Setting logging output verbosity -To alter the level of logs output during an `npm install` the npm_config_loglevel environment variable can be set. See [npm-config](https://docs.npmjs.com/misc/config). - -Development Mode ----------------- -This image supports development mode. This mode can be switched on and off with the environment variable `DEV_MODE`. `DEV_MODE` can either be set to `true` or `false`. -Development mode supports two features: -* Hot Deploy -* Debugging - -The debug port can be specified with the environment variable `DEBUG_PORT`. `DEBUG_PORT` is only valid if `DEV_MODE=true`. - -A simple example command for running the container in development mode is: -``` -podman run --env DEV_MODE=true my-image-id -``` - -To run the container in development mode with a debug port of 5454, run: -``` -$ podman run --env DEV_MODE=true DEBUG_PORT=5454 my-image-id -``` - -To run the container in production mode, run: -``` -$ podman run --env DEV_MODE=false my-image-id -``` - -By default, `DEV_MODE` is set to `false`, and `DEBUG_PORT` is set to `5858`, however the `DEBUG_PORT` is only relevant if `DEV_MODE=true`. - -Hot deploy ----------- - -As part of development mode, this image supports hot deploy. If development mode is enabled, any souce code that is changed in the running container will be immediately reflected in the running nodejs application. - -### Using Podman's exec - -To change your source code in a running container, use Podman's [exec](https://github.com/containers/libpod) command: -``` -$ podman exec -it /bin/bash -``` - -After you [Podman exec](https://github.com/containers/libpod) into the running container, your current directory is set to `/opt/app-root/src`, where the source code for your application is located. - -### Using OpenShift's rsync - -If you have deployed the container to OpenShift, you can use [oc rsync](https://docs.openshift.org/latest/dev_guide/copy_files_to_container.html) to copy local files to a remote container running in an OpenShift pod. - -#### Warning: - -The default behaviour of the s2i-nodejs container image is to run the Node.js application using the command `npm start`. This runs the _start_ script in the _package.json_ file. In developer mode, the application is run using the command `nodemon`. The default behaviour of nodemon is to look for the _main_ attribute in the _package.json_ file, and execute that script. If the _main_ attribute doesn't appear in the _package.json_ file, it executes the _start_ script. So, in order to achieve some sort of uniform functionality between production and development modes, the user should remove the _main_ attribute. - -Below is an example _package.json_ file with the _main_ attribute and _start_ script marked appropriately: - -```json -{ - "name": "node-echo", - "version": "0.0.1", - "description": "node-echo", - "main": "example.js", <--- main attribute - "dependencies": { - }, - "devDependencies": { - "nodemon": "*" - }, - "engine": { - "node": "*", - "npm": "*" - }, - "scripts": { - "dev": "nodemon --ignore node_modules/ server.js", - "start": "node server.js" <-- start script - }, - "keywords": [ - "Echo" - ], - "license": "", -} -``` - -#### Note: -`oc rsync` is only available in versions 3.1+ of OpenShift. - -## init-wrapper - -init-wrapper script is located on `/usr/libexec/s2i/init-wrapper` and is used to handle: - -- Proper signal handling and propagation, as Node.js was not designed to run as PID 1. -- Reaping zombie child processes -Avoiding use of npm, there is more information on why you want to avoid that in the [Node.js reference architecture](https://github.com/nodeshift/nodejs-reference-architecture/blob/e4c4dc1fd20c2cac392e862859aaad27f85d504f/docs/development/building-good-containers.md#avoiding-using-npm-to-start-application). When the INIT_WRAPPER is set to true the application is started via the init script instead of using npm start. - -A detailed explanation on how the init-wrapper script works is avalable in -[this url](http://veithen.io/2014/11/16/sigterm-propagation.html). - -Example of using init-wrapper: - -**During image build** -``` -s2i -e INIT_WRAPPER=true build . buildImage node-app -docker run node-app -``` -**During container start** -``` -s2i build . buildImage node-app -docker run -e INIT_WRAPPER=true node-app -``` - -`init-wrapper` script can be disabled by setting the `INIT_WRAPPER` env variable to `false`. - -``` -docker run -e INIT_WRAPPER=false node-app -``` -`NODE_CMD` can be used during the build process or container start, in order to have more control on the command that `init-wrapper` script will wrap. - -For example: - -**during container build** -``` -s2i -e INIT_WRAPPER=true -e NODE_CMD="node index.js" build . buildImage node-app -``` -**during container start** -``` -docker run -e INIT_WRAPPER=false -e NODE_CMD="node index.js" node-app -``` - -See also --------- -Dockerfile and other sources are available on https://github.com/sclorg/s2i-nodejs-container. -In that repository you also can find another versions of Node.js environment Dockerfiles. -Dockerfile for CentOS Stream 9 is called `Dockerfile.c9s`, -Dockerfile for CentOS Stream 10 is called `Dockerfile.c10s`, -for RHEL8 it's `Dockerfile.rhel8`, for RHEL9 it's `Dockerfile.rhel9`, -for RHEL10 it's `Dockerfile.rhel10` and the Fedora Dockerfile is called Dockerfile.fedora. diff --git a/24/README.md b/24/README.md new file mode 120000 index 00000000..32d46ee8 --- /dev/null +++ b/24/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/24/s2i/bin/assemble b/24/s2i/bin/assemble index 3230d038..f644a811 100755 --- a/24/s2i/bin/assemble +++ b/24/s2i/bin/assemble @@ -63,13 +63,6 @@ if [ -n "$NPM_MIRROR" ]; then npm config set registry $NPM_MIRROR fi -# Change the npm authentication token if provided -if [ -n "$NPM_TOKEN" ]; then - echo "---> Setting npm authentication token for $NPM_MIRROR" - INTERNAL_NPM_REGISTRY=$(echo "$NPM_MIRROR" | sed -n 's|https://||p') - npm config set "//${INTERNAL_NPM_REGISTRY:-registry.npmjs.org}:_auth" $NPM_TOKEN -fi - # Set the DEV_MODE to false by default. if [ -z "$DEV_MODE" ]; then export DEV_MODE=false diff --git a/24/s2i/bin/init-wrapper b/24/s2i/bin/init-wrapper old mode 100644 new mode 100755 diff --git a/24/s2i/bin/run b/24/s2i/bin/run index 9a207bce..9fc5cf90 100755 --- a/24/s2i/bin/run +++ b/24/s2i/bin/run @@ -47,7 +47,7 @@ run_node() { echo "Launching via npm..." exec npm run -d $NPM_RUN fi -} +} #Set the debug port to 5858 by default. if [ -z "$DEBUG_PORT" ]; then diff --git a/24/s2i/bin/usage b/24/s2i/bin/usage index b8c1dca8..d77326cf 100755 --- a/24/s2i/bin/usage +++ b/24/s2i/bin/usage @@ -3,12 +3,12 @@ DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` cat < nodejs-sample-app +s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=18/test/test-app/ ${NAMESPACE}/nodejs-18-${DISTRO}7 nodejs-sample-app You can then run the resulting image via: podman run -p 8080:8080 nodejs-sample-app diff --git a/24/test b/24/test index ae78e219..419df4f9 120000 --- a/24/test +++ b/24/test @@ -1 +1 @@ -../test/ \ No newline at end of file +../test \ No newline at end of file diff --git a/manifest-minimal.yml b/manifest-minimal.yml new file mode 100644 index 00000000..eeb8fbe8 --- /dev/null +++ b/manifest-minimal.yml @@ -0,0 +1,65 @@ +# Manifest for image directories creation (minimal variants) +# every dest path will be prefixed by $DESTDIR/$version + +# Files containing distgen directives, which are used for each +# (distro, version) combination not excluded in multispec +DISTGEN_MULTI_RULES: + - src: src/Dockerfile.minimal + dest: Dockerfile.rhel8 + + - src: src/Dockerfile.minimal + dest: Dockerfile.rhel9 + + - src: src/Dockerfile.minimal + dest: Dockerfile.rhel10 + + - src: src/Dockerfile.minimal + dest: Dockerfile.c8s + + - src: src/Dockerfile.minimal + dest: Dockerfile.c9s + + - src: src/Dockerfile.minimal + dest: Dockerfile.c10s + + - src: src/Dockerfile.minimal.fedora + dest: Dockerfile.fedora + +# Files to copy +COPY_RULES: + - src: src/s2i/bin/assemble + dest: s2i/bin/assemble + mode: "0755" + + - src: src/s2i/bin/run + dest: s2i/bin/run + mode: "0755" + + - src: src/s2i/bin/save-artifacts + dest: s2i/bin/save-artifacts + mode: "0755" + + - src: src/s2i/bin/usage + dest: s2i/bin/usage + mode: "0755" + + - src: src/s2i/bin/init-wrapper + dest: s2i/bin/init-wrapper + mode: "0755" + + - src: src/root/opt/app-root/etc/generate_container_user + dest: root/opt/app-root/etc/generate_container_user + + - src: src/root/opt/app-root/etc/npm_global_module_list + dest: root/opt/app-root/etc/npm_global_module_list + + - src: src/root/opt/app-root/etc/scl_enable + dest: root/opt/app-root/etc/scl_enable + +# Symbolic links +SYMLINK_RULES: + - src: ../test + dest: test + + - src: ../README.md + dest: README.md \ No newline at end of file diff --git a/manifest.yml b/manifest.yml new file mode 100644 index 00000000..17282ed7 --- /dev/null +++ b/manifest.yml @@ -0,0 +1,65 @@ +# Manifest for image directories creation +# every dest path will be prefixed by $DESTDIR/$version + +# Files containing distgen directives, which are used for each +# (distro, version) combination not excluded in multispec +DISTGEN_MULTI_RULES: + - src: src/Dockerfile + dest: Dockerfile.rhel8 + + - src: src/Dockerfile + dest: Dockerfile.rhel9 + + - src: src/Dockerfile + dest: Dockerfile.rhel10 + + - src: src/Dockerfile + dest: Dockerfile.c8s + + - src: src/Dockerfile + dest: Dockerfile.c9s + + - src: src/Dockerfile + dest: Dockerfile.c10s + + - src: src/Dockerfile.fedora + dest: Dockerfile.fedora + +# Files to copy +COPY_RULES: + - src: src/s2i/bin/assemble + dest: s2i/bin/assemble + mode: "0755" + + - src: src/s2i/bin/run + dest: s2i/bin/run + mode: "0755" + + - src: src/s2i/bin/save-artifacts + dest: s2i/bin/save-artifacts + mode: "0755" + + - src: src/s2i/bin/usage + dest: s2i/bin/usage + mode: "0755" + + - src: src/s2i/bin/init-wrapper + dest: s2i/bin/init-wrapper + mode: "0755" + + - src: src/root/opt/app-root/etc/generate_container_user + dest: root/opt/app-root/etc/generate_container_user + + - src: src/root/opt/app-root/etc/npm_global_module_list + dest: root/opt/app-root/etc/npm_global_module_list + + - src: src/root/opt/app-root/etc/scl_enable + dest: root/opt/app-root/etc/scl_enable + +# Symbolic links +SYMLINK_RULES: + - src: ../test + dest: test + + - src: ../README.md + dest: README.md diff --git a/specs/multispec.yml b/specs/multispec.yml new file mode 100644 index 00000000..56df17a2 --- /dev/null +++ b/specs/multispec.yml @@ -0,0 +1,202 @@ +version: 1 + +specs: + distroinfo: + fedora43: + distros: + - fedora-43-x86_64 + s2i_base: quay.io/fedora/s2i-core + org: "fedora" + prod: "fedora" + redhat_component: "${NAME}-${NODEJS_VERSION}-container" + img_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + latest_fedora: "43" + + rhel8: + distros: + - rhel-8-x86_64 + s2i_base: ubi8/s2i-core + org: "ubi8" + prod: "rhel8" + redhat_component: "${NAME}-${NODEJS_VERSION}-container" + img_name: "ubi8/$NAME-$NODEJS_VERSION" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + environment_setup: >- + dnf -y module enable nodejs:$NODEJS_VERSION && \ + post_install: >4- + (dnf -y reinstall tzdata || dnf -y update tzdata ) && \ + rhel9: + distros: + - rhel-9-x86_64 + s2i_base: ubi9/s2i-core + org: "ubi9" + prod: "rhel9" + redhat_component: "${NAME}-${NODEJS_VERSION}-container" + img_name: "ubi9/$NAME-$NODEJS_VERSION" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + environment_setup: >- + dnf -y module enable nodejs:$NODEJS_VERSION && \ + post_install: >4- + (dnf -y reinstall tzdata || dnf -y update tzdata ) && \ + rhel10: + distros: + - rhel-10-x86_64 + s2i_base: ubi10/s2i-core + org: "ubi10" + prod: "rhel10" + redhat_component: "${NAME}-${NODEJS_VERSION}-container" + img_name: "ubi10/$NAME-$NODEJS_VERSION" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + c9s: + distros: + - centos-stream-9-x86_64 + s2i_base: quay.io/sclorg/s2i-core-c9s:c9s + org: "c9s" + prod: "c9s" + redhat_component: "${NAME}-${NODEJS_VERSION}-container" + img_name: "sclorg/$NAME-$NODEJS_VERSION-c9s" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + environment_setup: >- + dnf -y module enable nodejs:$NODEJS_VERSION && \ + + c10s: + distros: + - centos-stream-10-x86_64 + s2i_base: quay.io/sclorg/s2i-core-c10s:c10s + org: "c10s" + prod: "c10s" + redhat_component: "${NAME}-${NODEJS_VERSION}-container" + img_name: "sclorg/$NAME-$NODEJS_VERSION-c10s" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + check_pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + + c8s: + distros: + - centos-stream-8-x86_64 + s2i_base: quay.io/sclorg/s2i-core-c8s + org: "c8s" + prod: "c8s" + redhat_component: "${NAME}-${NODEJS_VERSION}-container" + img_name: "sclorg/$NAME-$NODEJS_VERSION-c8s" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + environment_setup: >- + yum -y module enable nodejs:$NODEJS_VERSION && \ + + version: + "20": + version: "20" + short: "20" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + rhel_image_name: "rhel8/nodejs-{{ spec.short }}" + latest_fedora: "f45" + c8s_base: "quay.io/sclorg/s2i-core-c8s" + c9s_base: "quay.io/sclorg/s2i-core-c9s:c9s" + rhel8_base: "ubi8/s2i-core:latest" + rhel9_base: "ubi9/s2i-core:latest" + fedora_base: "quay.io/fedora/s2i-core:38" + + "22": + version: "22" + prev_version: "20" + short: "22" + prev_short: "20" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + fedora_base: "quay.io/fedora/s2i-core:40" + + "24": + version: "24" + prev_version: "22" + short: "24" + prev_short: "22" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + fedora_base: "quay.io/fedora/s2i-core:42" + + "20-minimal": + version: "20" + short: "20-minimal" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + rhel_image_name: "rhel8/nodejs-{{ spec.short }}" + latest_fedora: "f45" + fedora_minimal_base: "quay.io/fedora/fedora-minimal:38" + + "22-minimal": + version: "22" + prev_version: "20" + short: "22-minimal" + prev_short: "20-minimal" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + fedora_minimal_base: "quay.io/fedora/fedora-minimal:40" + + "24-minimal": + version: "24" + prev_version: "22" + short: "24-minimal" + prev_short: "22-minimal" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + fedora_minimal_base: "quay.io/fedora/fedora-minimal:42" + +matrix: + include: + - version: "20" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - fedora-43-x86_64 + - version: "22" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 + - version: "24" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 + - version: "20-minimal" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - fedora-43-x86_64 + - version: "22-minimal" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 + - version: "24-minimal" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 diff --git a/specs/multispec.yml.orig b/specs/multispec.yml.orig new file mode 100644 index 00000000..3518b24a --- /dev/null +++ b/specs/multispec.yml.orig @@ -0,0 +1,193 @@ +version: 1 + +specs: + distroinfo: + fedora43: + distros: + - fedora-43-x86_64 + s2i_base: quay.io/fedora/s2i-core + org: "fedora" + prod: "fedora" + redhat_component: "nodejs-{{ spec.short }}-container" + img_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + latest_fedora: "43" + + rhel8: + distros: + - rhel-8-x86_64 + s2i_base: ubi8/s2i-core + org: "rhel8" + prod: "rhel8" + redhat_component: "nodejs-{{ spec.short }}-container" + img_name: "{{ spec.org }}/nodejs-{{ spec.short }}" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + environment_setup: >4- + yum -y module enable nodejs:{{ spec.version }} && \ + post_install: >4- + (yum -y reinstall tzdata || yum -y update tzdata ) && \ + rhel9: + distros: + - rhel-9-x86_64 + s2i_base: ubi9/s2i-core + org: "rhel9" + prod: "rhel9" + redhat_component: "nodejs-{{ spec.short }}-container" + img_name: "{{ spec.org }}/nodejs-{{ spec.short }}" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + environment_setup: >4- + { yum -y module enable nodejs:{{ spec.version }} || :; } && \ + post_install: >4- + (yum -y reinstall tzdata || yum -y update tzdata ) && \ + rhel10: + distros: + - rhel-10-x86_64 + s2i_base: ubi10/s2i-core + org: "rhel10" + prod: "rhel10" + redhat_component: "nodejs-{{ spec.short }}-container" + img_name: "{{ spec.org }}/nodejs-{{ spec.short }}" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + c9s: + distros: + - centos-stream-9-x86_64 + s2i_base: quay.io/sclorg/s2i-core-c9s:c9s + org: "sclorg" + prod: "c9s" + redhat_component: "nodejs-{{ spec.short }}-container" + img_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + environment_setup: >4- + { yum -y module enable nodejs:{{ spec.version }} || :; } && \ + + c10s: + distros: + - centos-stream-10-x86_64 + - fedora-43-x86_64 + s2i_base: quay.io/sclorg/s2i-core-c10s:c10s + org: "sclorg" + prod: "c10s" + redhat_component: "nodejs-{{ spec.short }}-container" + img_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + check_pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + + c8s: + distros: + - centos-stream-8-x86_64 + s2i_base: quay.io/sclorg/s2i-core-c8s:c8s + org: "sclorg" + prod: "c8s" + redhat_component: "nodejs-{{ spec.short }}-container" + img_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + pkgs: "nodejs npm nodejs-nodemon nss_wrapper-libs which" + environment_setup: >4- + { yum -y module enable nodejs:{{ spec.version }} || :; } && + + version: + "20": + version: "20" + short: "20" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + rhel_image_name: "rhel8/nodejs-{{ spec.short }}" + latest_fedora: "f45" + + "22": + version: "22" + prev_version: "20" + short: "22" + prev_short: "20" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + + "24": + version: "24" + prev_version: "22" + short: "24" + prev_short: "22" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + + "20-minimal": + version: "20" + short: "20-minimal" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + rhel_image_name: "rhel8/nodejs-{{ spec.short }}" + latest_fedora: "f45" + + "22-minimal": + version: "22" + prev_version: "20" + short: "22-minimal" + prev_short: "20-minimal" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + + "24-minimal": + version: "24" + prev_version: "22" + short: "24-minimal" + prev_short: "22-minimal" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + +matrix: + include: + - version: "20" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - fedora-43-x86_64 + - version: "22" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 + - version: "24" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 + - version: "20-minimal" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - fedora-43-x86_64 + - version: "22-minimal" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 + - version: "24-minimal" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-8-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 00000000..c55c6ea0 --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,185 @@ +FROM {{ spec.s2i_base }}{% if not ":" in spec.s2i_base and spec.prod != "c8s" %}:latest{% endif %} + + +# This image provides a Node.JS environment you can use to run your Node.JS +# applications. + +EXPOSE 8080 + +# Add $HOME/node_modules/.bin to the $PATH, allowing user to make npm scripts +# available on the CLI without using npm's --global installation mode +# This image will be initialized with "npm run $NPM_RUN" +# See https://docs.npmjs.com/misc/scripts, and your repo's package.json +# file for possible values of NPM_RUN +# Description +# Environment: +# * $NPM_RUN - Select an alternate / custom runtime mode, defined in your package.json files' scripts section (default: npm run "start"). +# Expose ports: +# * 8080 - Unprivileged port used by nodejs application + +ENV NODEJS_VERSION={{ spec.version }} \ + NPM_RUN=start \ + NAME=nodejs \ + NPM_CONFIG_PREFIX=$HOME/.npm-global \ + PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH{% if spec.prod != "fedora" %} \ + CNB_STACK_ID=com.redhat.stacks.{{ spec.org }}-nodejs-{{ spec.version }} \ + CNB_USER_ID=1001 \ + CNB_GROUP_ID=0 +{% endif %} + +ENV SUMMARY="Platform for building and running Node.js $NODEJS_VERSION applications" \ + DESCRIPTION="Node.js $NODEJS_VERSION available as container is a base platform for \ +building and running various Node.js $NODEJS_VERSION applications and frameworks. \ +Node.js is a platform built on Chrome's JavaScript runtime for easily building \ +fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model \ +that makes it lightweight and efficient, perfect for data-intensive real-time applications \ +that run across distributed devices." + +LABEL summary="$SUMMARY" \ + description="$DESCRIPTION" \ + io.k8s.description="$DESCRIPTION" \ + io.k8s.display-name="Node.js $NODEJS_VERSION" \ + io.openshift.expose-services="8080:http" \ + io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ + io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ + io.s2i.scripts-url="image:///usr/libexec/s2i"{% if spec.prod != "fedora" %} \ + io.buildpacks.stack.id="com.redhat.stacks.{{ spec.org }}-nodejs-{{ spec.version }}"{% endif %} \ + com.redhat.dev-mode="DEV_MODE:false" \ + com.redhat.deployments-dir="${APP_ROOT}/src" \ + com.redhat.dev-mode.port="DEBUG_PORT:5858"{% if spec.prod != "fedora" %} \ + com.redhat.component="{{ spec.redhat_component }}" \ +{% endif %} name="{{ spec.img_name }}" \ +{% if spec.prod == "fedora" %} version="$NODEJS_VERSION" \ +{% elif spec.prod != "rhel10" %} version="1" \ +{% endif %}{% if spec.prod != "fedora" %} + com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI"{% endif %} \ + maintainer="SoftwareCollections.org " \ + help="For more information visit https://github.com/sclorg/s2i-nodejs-container" \ + usage="{% if spec.prod != "fedora" %}s2i build {% if spec.prod in ["c8s", "c9s", "c10s"] %}quay.io/{% endif %}{{ spec.img_name }}{% if spec.prod != "rhel10" %}:latest{% endif %} {% else %}oc new-app $FGC/$NAME~{% endif %}" + +{% if spec.prod in ["c9s", "rhel10", "c10s"] %} +# Package libatomic_ops was removed +{% endif %}{% if spec.prod in ["rhel10", "c10s"] and spec.version == "22" %} +RUN INSTALL_PKGS="make gcc gcc-c++ git openssl-devel nodejs nodejs-nodemon nodejs-npm nss_wrapper-libs which" && \ + dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + rm /usr/bin/node && ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + rm /usr/bin/npm && ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + rm /usr/bin/npx && ln -s /usr/bin/npx-$NODEJS_VERSION /usr/bin/npx && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + dnf -y clean all --enablerepo='*' +{% elif spec.prod in ["rhel10", "c10s"] and spec.version == "24" %} +RUN INSTALL_PKGS="make gcc gcc-c++ git openssl-devel nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm nss_wrapper-libs which" && \ + dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + ln -s /usr/bin/npx-$NODEJS_VERSION /usr/bin/npx && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + dnf -y clean all --enablerepo='*' +{% elif spec.environment_setup %} +{% if spec.prod == "rhel8" and spec.version == "20" -%} +RUN yum -y module enable nodejs:$NODEJS_VERSION && \ + MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS {{ spec.pkgs }}" && \ + ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ + ln -s /usr/libexec/platform-python /usr/bin/python3 && \ + yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + yum -y clean all --enablerepo='*' +{% elif spec.prod == "c8s" and spec.version == "20" -%} +RUN yum -y module enable nodejs:$NODEJS_VERSION && \ + MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS {{ spec.pkgs }}" && \ + ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ + ln -s /usr/libexec/platform-python /usr/bin/python3 && \ + yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + yum -y clean all --enablerepo='*' +{% elif spec.prod == "c9s" and spec.version == "20" -%} +RUN yum -y module enable nodejs:$NODEJS_VERSION && \ + MODULE_DEPS="make gcc gcc-c++ git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS {{ spec.pkgs }}" && \ + ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ + yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + yum -y clean all --enablerepo='*' +{% elif spec.prod == "rhel9" and spec.version == "20" -%} +RUN yum -y module enable nodejs:$NODEJS_VERSION && \ + MODULE_DEPS="make gcc gcc-c++ git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS {{ spec.pkgs }}" && \ + ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ + yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + yum -y clean all --enablerepo='*' +{% elif spec.prod == "rhel8" and spec.version != "20" -%} +RUN {{ spec.environment_setup }} + MODULE_DEPS="make gcc-toolset-13-gcc gcc-toolset-13-gcc-c++ gcc-toolset-13-runtime \ + libatomic_ops git openssl-devel python3.12" && \ + INSTALL_PKGS="$MODULE_DEPS {{ spec.pkgs }}" && \ + ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ + dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + dnf -y clean all --enablerepo='*' +{% elif spec.prod == "c8s" -%} +RUN {{ spec.environment_setup }} + MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS {{ spec.pkgs }}" && \ + ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ + ln -s /usr/libexec/platform-python /usr/bin/python3 && \ + yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + yum -y clean all --enablerepo='*' +{% else -%} +RUN {{ spec.environment_setup }} + MODULE_DEPS="make gcc gcc-c++{% if spec.prod not in ["c9s", "rhel9"] %} libatomic_ops{% endif %} git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS {{ spec.pkgs }}" && \ + ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ + dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + dnf -y clean all --enablerepo='*' +{% endif -%} +{% else %} +RUN MODULE_DEPS="make {% if spec.prod == "rhel8" and spec.version != "20" %}gcc-toolset-13-gcc gcc-toolset-13-gcc-c++ gcc-toolset-13-runtime \ + libatomic_ops git openssl-devel python3.12{% else %}gcc gcc-c++{% if spec.prod not in ["c9s", "rhel9"] %} libatomic_ops{% endif %} git openssl-devel{% endif %}" && \ + INSTALL_PKGS="$MODULE_DEPS {{ spec.pkgs }}" && \ + ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \ +{% if spec.prod in ["c8s"] or (spec.prod == "rhel8" and spec.version == "20") %} ln -s /usr/libexec/platform-python /usr/bin/python3 && \ +{% endif %} {% if spec.prod == "c8s" or (spec.prod == "rhel8" and spec.version == "20") or (spec.prod == "c9s" and spec.version == "20") %}yum{% else %}dnf{% endif %} install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ +{% if spec.prod == "c8s" or (spec.prod == "rhel8" and spec.version == "20") or (spec.prod == "c9s" and spec.version == "20") %} yum{% else %} dnf{% endif %} -y clean all --enablerepo='*' +{% endif %}{% if config.post_install %} + +RUN {{ spec.post_install }}{% endif %} + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH +RUN chmod +x {% if spec.version == "20" %}$STI_SCRIPTS_PATH/init-wrapper + +{% else %}/usr/libexec/s2i/init-wrapper + +{% endif %}# Copy extra files to the image. +COPY ./root/ / + +# Drop the root user and make the content of /opt/app-root owned by user 1001 +RUN chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 + +{% if spec.prod == "rhel8" and spec.version != "20" %} +# Enable the SCL for all bash scripts. +ENV BASH_ENV=/opt/rh/gcc-toolset-13/enable \ + ENV=/opt/rh/gcc-toolset-13/enable \ + PROMPT_COMMAND=". /opt/rh/gcc-toolset-13/enable" + +{% endif %}# Set the default CMD to print the usage of the language image +CMD $STI_SCRIPTS_PATH/usage diff --git a/18/Dockerfile.fedora b/src/Dockerfile.fedora similarity index 68% rename from 18/Dockerfile.fedora rename to src/Dockerfile.fedora index 8052e6b7..349e2487 100644 --- a/18/Dockerfile.fedora +++ b/src/Dockerfile.fedora @@ -1,4 +1,4 @@ -FROM quay.io/fedora/s2i-core:38 +FROM {{ spec.fedora_base }} # This image provides a Node.JS environment you can use to run your Node.JS # applications. @@ -16,7 +16,7 @@ EXPOSE 8080 # Expose ports: # * 8080 - Unprivileged port used by nodejs application -ENV NODEJS_VERSION=18 \ +ENV NODEJS_VERSION={{ spec.version }} \ NPM_RUN=start \ NAME=nodejs \ NPM_CONFIG_PREFIX=$HOME/.npm-global \ @@ -48,18 +48,33 @@ LABEL summary="$SUMMARY" \ help="For more information visit https://github.com/sclorg/s2i-nodejs-container" \ usage="oc new-app $FGC/$NAME~" -RUN MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \ - INSTALL_PKGS="$MODULE_DEPS nodejs nodejs-nodemon nodejs-npm nss_wrapper-libs which" && \ +{% if spec.version == "20" %}RUN MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm nss_wrapper-libs which" && \ yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ rpm -V $INSTALL_PKGS && \ + ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + ln -s /usr/bin/npx-$NODEJS_VERSION /usr/bin/npx && \ + ln -s /usr/lib/node_modules_18/nodemon /usr/lib/node_modules_$NODEJS_VERSION/nodemon && \ node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ yum -y clean all --enablerepo='*' +{% else %}RUN INSTALL_PKGS="make gcc gcc-c++ libatomic_ops git openssl-devel nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm nss_wrapper-libs which" && \ + dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + ln -s /usr/bin/npx-$NODEJS_VERSION /usr/bin/npx && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + dnf -y clean all --enablerepo='*' +{% endif %} # Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH COPY ./s2i/bin/ $STI_SCRIPTS_PATH -RUN chmod +x $STI_SCRIPTS_PATH/init-wrapper +{% if spec.version == "20" %}RUN chmod +x $STI_SCRIPTS_PATH/init-wrapper + +{% else %}RUN chmod +x /usr/libexec/s2i/init-wrapper -# Copy extra files to the image, including help file. +{% endif %}# Copy extra files to the image, including help file. COPY ./root/ / # Drop the root user and make the content of /opt/app-root owned by user 1001 diff --git a/src/Dockerfile.minimal b/src/Dockerfile.minimal new file mode 100644 index 00000000..1ebdde0e --- /dev/null +++ b/src/Dockerfile.minimal @@ -0,0 +1,134 @@ +{% if spec.prod == "rhel8" %}FROM ubi8/ubi-minimal:latest{% elif spec.prod == "rhel9" %}FROM ubi9/ubi-minimal{% elif spec.prod == "rhel10" %}FROM ubi10-minimal:latest{% elif spec.prod == "c8s" %}FROM quay.io/sclorg/s2i-core-c8s{% elif spec.prod == "c9s" %}FROM quay.io/centos/centos:stream9-minimal{% elif spec.prod == "c10s" %}FROM quay.io/centos/centos:stream10-minimal{% elif spec.prod == "fedora" %}FROM {{ spec.fedora_minimal_base }}{% endif %} + + +EXPOSE 8080 + +# Add $HOME/node_modules/.bin to the $PATH, allowing user to make npm scripts +# available on the CLI without using npm's --global installation mode +# This image will be initialized with "npm run $NPM_RUN" +# See https://docs.npmjs.com/misc/scripts, and your repo's package.json +# file for possible values of NPM_RUN +# Description +# Environment: +# * $NPM_RUN - Select an alternate / custom runtime mode, defined in your package.json files' scripts section (default: npm run "start"). +# Expose ports: +# * 8080 - Unprivileged port used by nodejs application +ENV APP_ROOT=/opt/app-root \ + # The $HOME is not set by default, but some applications need this variable + HOME=/opt/app-root/src \ + NPM_RUN=start \ +{% if spec.prod in ["rhel8", "c8s"] %} PLATFORM="el8" \ +{% elif spec.prod in ["rhel9", "c9s"] %} PLATFORM="el9" \ +{% elif spec.prod in ["rhel10", "c10s"] %} PLATFORM="el10" \ +{% elif spec.prod == "fedora" %} PLATFORM="fedora" \ +{% endif %} NODEJS_VERSION={{ spec.version }} \ + NPM_RUN=start \ + NAME=nodejs + +ENV SUMMARY="Minimal image for running Node.js $NODEJS_VERSION applications" \ + DESCRIPTION="Node.js $NODEJS_VERSION available as container is a base platform for \ +running various Node.js $NODEJS_VERSION applications and frameworks. \ +Node.js is a platform built on Chrome's JavaScript runtime for easily building \ +fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model \ +that makes it lightweight and efficient, perfect for data-intensive real-time applications \ +that run across distributed devices." \ + NPM_CONFIG_PREFIX=$HOME/.npm-global \ + PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH + +LABEL summary="$SUMMARY" \ + description="$DESCRIPTION" \ + io.k8s.description="$DESCRIPTION" \ + io.k8s.display-name="Node.js $NODEJS_VERSION {% if spec.prod in ["rhel9", "rhel10", "c9s", "c10s"] %}Micro{% else %}Minimal{% endif %}" \ + io.openshift.expose-services="8080:http" \ + io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \ + io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \ + io.s2i.scripts-url="image:///usr/libexec/s2i" \ + com.redhat.dev-mode="DEV_MODE:false" \ + com.redhat.deployments-dir="${APP_ROOT}/src" \ + com.redhat.dev-mode.port="DEBUG_PORT:5858"{% if spec.prod != "fedora" %} \ + com.redhat.component="${NAME}-${NODEJS_VERSION}-minimal-container" \ +{% endif %} name="{% if spec.prod in ["c8s", "c9s", "c10s"] %}sclorg/$NAME-$NODEJS_VERSION-minimal-{{ spec.prod }}{% else %}{{ spec.img_name }}-minimal{% endif %}"{% if spec.prod != "rhel10" %} \ + version="{% if spec.prod == "fedora" %}$NODEJS_VERSION{% else %}1{% endif %}"{% endif %}{% if spec.prod in ["rhel8", "rhel9", "rhel10"] %} \ + com.redhat.license_terms="https://www.redhat.com/en/about/red-hat-end-user-license-agreements#UBI"{% endif %} \ + maintainer="SoftwareCollections.org " \ + help="For more information visit https://github.com/sclorg/s2i-nodejs-container" + +{% if spec.prod == "fedora" %}# nodejs-full-i18n is included for error strings +RUN INSTALL_PKGS="nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm findutils tar which" && \ + dnf --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + ln -s /usr/bin/npx-$NODEJS_VERSION /usr/bin/npx && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + dnf clean all +{% elif spec.prod == "c8s" %}# nodejs-full-i18n is included for error strings +RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which" && \ + yum -y module disable nodejs && \ + yum -y module enable nodejs:$NODEJS_VERSION && \ + yum -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + yum clean all && \ + rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* +{% elif spec.prod == "c9s" and spec.version == "22" %}# nodejs-full-i18n is included for error strings +RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which" && \ + yum -y module disable nodejs && \ + yum -y module enable nodejs:$NODEJS_VERSION && \ + yum -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + yum clean all && \ + rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* +{% elif spec.prod == "rhel10" %}# nodejs-full-i18n is included for error strings +{% if spec.version == "22" %}RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which" && \ + microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + microdnf clean all && \ + rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* +{% else %}RUN INSTALL_PKGS="nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n nodejs$NODEJS_VERSION-npm findutils tar which" && \ + microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + microdnf clean all && \ + ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + ln -s /usr/bin/npx-$NODEJS_VERSION /usr/bin/npx && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* +{% endif %} +{% elif spec.prod == "c10s" %}# nodejs-full-i18n is included for error strings +{% if spec.version == "22" %}RUN INSTALL_PKGS="nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n npm findutils tar which" && \ + microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + node-22 -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + microdnf clean all && \ + rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* +{% else %}RUN INSTALL_PKGS="nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n nodejs$NODEJS_VERSION-npm findutils tar which" && \ + microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + microdnf clean all && \ + ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + ln -s /usr/bin/npx-$NODEJS_VERSION /usr/bin/npx && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* +{% endif %} +{% else %}# nodejs-full-i18n is included for error strings +RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which" && \ + microdnf -y module disable nodejs && \ + microdnf -y module enable nodejs:$NODEJS_VERSION && \ + microdnf {% if spec.prod != "rhel8" %}-y {% endif %}--nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + microdnf clean all && \ + rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* +{% endif %} + +COPY ./s2i/bin/ /usr/libexec/s2i +RUN chmod +x /usr/libexec/s2i/init-wrapper + +# Copy extra files to the image. +COPY ./root/ / + +# Drop the root user and make the content of /opt/app-root owned by user 1001 +{% if spec.prod in ["rhel8", "rhel9", "rhel10", "c8s", "c9s", "c10s"] %}RUN mkdir -p "$HOME" && chown -R 1001:0 "$APP_ROOT" && chmod -R ug+rwx "$APP_ROOT" +WORKDIR "$HOME" +USER 1001 +{% else %}RUN chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 +{% endif %} diff --git a/18-minimal/Dockerfile.fedora b/src/Dockerfile.minimal.fedora similarity index 80% rename from 18-minimal/Dockerfile.fedora rename to src/Dockerfile.minimal.fedora index 18ec1c36..65393e36 100644 --- a/18-minimal/Dockerfile.fedora +++ b/src/Dockerfile.minimal.fedora @@ -1,4 +1,4 @@ -FROM quay.io/fedora/fedora-minimal:38 +FROM {{ spec.fedora_minimal_base }} EXPOSE 8080 @@ -17,7 +17,7 @@ ENV APP_ROOT=/opt/app-root \ HOME=/opt/app-root/src \ NPM_RUN=start \ PLATFORM="fedora" \ - NODEJS_VERSION=18 \ + NODEJS_VERSION={{ spec.version }} \ NPM_RUN=start \ NAME=nodejs @@ -49,12 +49,17 @@ LABEL summary="$SUMMARY" \ help="For more information visit https://github.com/sclorg/s2i-nodejs-container" # nodejs-full-i18n is included for error strings -RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n nodejs-npm findutils tar which nss_wrapper-libs" && \ +RUN INSTALL_PKGS="nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n nodejs$NODEJS_VERSION-npm findutils tar which{% if spec.version != "24" %} nss_wrapper-libs{% endif %}" && \ microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ microdnf clean all && \ - node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + ln -s /usr/bin/npx-$NODEJS_VERSION /usr/bin/npx && \ +{% if spec.version == "20" %} ln -s /usr/lib/node_modules_18/nodemon /usr/lib/node_modules_$NODEJS_VERSION/nodemon && \ +{% endif %} node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ rm -rf /mnt/rootfs/var/cache/* /mnt/rootfs/var/log/dnf* /mnt/rootfs/var/log/yum.* +# COPY ./s2i/bin/ /usr/libexec/s2i RUN chmod +x /usr/libexec/s2i/init-wrapper diff --git a/src/root/opt/app-root/etc/generate_container_user b/src/root/opt/app-root/etc/generate_container_user new file mode 100644 index 00000000..b28a7a3d --- /dev/null +++ b/src/root/opt/app-root/etc/generate_container_user @@ -0,0 +1,17 @@ +# Set current user in nss_wrapper +USER_ID=$(id -u) +GROUP_ID=$(id -g) + +if [ x"$USER_ID" != x"0" -a x"$USER_ID" != x"1001" ]; then + + NSS_WRAPPER_PASSWD=/opt/app-root/etc/passwd + NSS_WRAPPER_GROUP=/etc/group + + cat /etc/passwd | sed -e 's/^default:/builder:/' > $NSS_WRAPPER_PASSWD + + echo "default:x:${USER_ID}:${GROUP_ID}:Default Application User:${HOME}:/sbin/nologin" >> $NSS_WRAPPER_PASSWD + + export NSS_WRAPPER_PASSWD + export NSS_WRAPPER_GROUP + export LD_PRELOAD=libnss_wrapper.so +fi diff --git a/src/root/opt/app-root/etc/npm_global_module_list b/src/root/opt/app-root/etc/npm_global_module_list new file mode 100644 index 00000000..005e1501 --- /dev/null +++ b/src/root/opt/app-root/etc/npm_global_module_list @@ -0,0 +1,5 @@ +async +mime +mkdirp +qs +minimatch diff --git a/src/root/opt/app-root/etc/scl_enable b/src/root/opt/app-root/etc/scl_enable new file mode 100644 index 00000000..4bfebea0 --- /dev/null +++ b/src/root/opt/app-root/etc/scl_enable @@ -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-nodejs${NODEJS_VERSION} diff --git a/18/s2i/bin/assemble b/src/s2i/bin/assemble similarity index 100% rename from 18/s2i/bin/assemble rename to src/s2i/bin/assemble diff --git a/18-minimal/s2i/bin/init-wrapper b/src/s2i/bin/init-wrapper similarity index 100% rename from 18-minimal/s2i/bin/init-wrapper rename to src/s2i/bin/init-wrapper diff --git a/18/s2i/bin/run b/src/s2i/bin/run similarity index 100% rename from 18/s2i/bin/run rename to src/s2i/bin/run diff --git a/18-minimal/s2i/bin/save-artifacts b/src/s2i/bin/save-artifacts similarity index 100% rename from 18-minimal/s2i/bin/save-artifacts rename to src/s2i/bin/save-artifacts diff --git a/18/s2i/bin/usage b/src/s2i/bin/usage similarity index 100% rename from 18/s2i/bin/usage rename to src/s2i/bin/usage