diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 906a46cf..af10aeeb 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -46,6 +46,22 @@ jobs: quayio_username: "QUAY_IMAGE_SCLORG_BUILDER_USERNAME" quayio_token: "QUAY_IMAGE_SCLORG_BUILDER_TOKEN" + - dockerfile: "24/Dockerfile.c10s" + docker_context: 24 + registry_namespace: "sclorg" + tag: "c10s" + image_name: "nodejs-24-c10s" + quayio_username: "QUAY_IMAGE_SCLORG_BUILDER_USERNAME" + quayio_token: "QUAY_IMAGE_SCLORG_BUILDER_TOKEN" + + - dockerfile: "24-minimal/Dockerfile.c10s" + docker_context: 24-minimal + registry_namespace: "sclorg" + tag: "c10s" + image_name: "nodejs-24-minimal-c10s" + quayio_username: "QUAY_IMAGE_SCLORG_BUILDER_USERNAME" + quayio_token: "QUAY_IMAGE_SCLORG_BUILDER_TOKEN" + - dockerfile: "18/Dockerfile.fedora" docker_context: 18 registry_namespace: "fedora" @@ -94,6 +110,22 @@ jobs: quayio_token: "QUAY_IMAGE_FEDORA_BUILDER_TOKEN" image_name: "nodejs-22-minimal" + - dockerfile: "24/Dockerfile.fedora" + docker_context: 24 + registry_namespace: "fedora" + tag: "fedora" + quayio_username: "QUAY_IMAGE_FEDORA_BUILDER_USERNAME" + quayio_token: "QUAY_IMAGE_FEDORA_BUILDER_TOKEN" + image_name: "nodejs-24" + + - dockerfile: "24-minimal/Dockerfile.fedora" + docker_context: 24-minimal + registry_namespace: "fedora" + tag: "fedora" + quayio_username: "QUAY_IMAGE_FEDORA_BUILDER_USERNAME" + quayio_token: "QUAY_IMAGE_FEDORA_BUILDER_TOKEN" + image_name: "nodejs-24-minimal" + steps: - name: Build and push to quay.io registry uses: sclorg/build-and-push-action@v4 diff --git a/24-minimal/.exclude-c10s b/24-minimal/.exclude-c10s new file mode 100644 index 00000000..e69de29b diff --git a/24-minimal/.exclude-c8s b/24-minimal/.exclude-c8s new file mode 100644 index 00000000..e69de29b diff --git a/24-minimal/.exclude-c9s b/24-minimal/.exclude-c9s new file mode 100644 index 00000000..e69de29b diff --git a/24-minimal/.exclude-rhel10 b/24-minimal/.exclude-rhel10 new file mode 100644 index 00000000..e69de29b diff --git a/24-minimal/.exclude-rhel8 b/24-minimal/.exclude-rhel8 new file mode 100644 index 00000000..e69de29b diff --git a/24-minimal/.exclude-rhel9 b/24-minimal/.exclude-rhel9 new file mode 100644 index 00000000..e69de29b diff --git a/24-minimal/Dockerfile.c10s b/24-minimal/Dockerfile.c10s new file mode 100644 index 00000000..ac0e602f --- /dev/null +++ b/24-minimal/Dockerfile.c10s @@ -0,0 +1,67 @@ +FROM quay.io/sclorg/s2i-core-c10s + +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="el10" \ + NODEJS_VERSION=24 \ + 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-c10s" \ + 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_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n npm findutils tar which" && \ + dnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + node-24 -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \ + dnf 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/24-minimal/Dockerfile.c8s b/24-minimal/Dockerfile.c8s new file mode 100644 index 00000000..d7829589 --- /dev/null +++ b/24-minimal/Dockerfile.c8s @@ -0,0 +1,69 @@ +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=20 \ + 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" && \ + 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.* + +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/24-minimal/Dockerfile.c9s b/24-minimal/Dockerfile.c9s new file mode 100644 index 00000000..37aa5e8e --- /dev/null +++ b/24-minimal/Dockerfile.c9s @@ -0,0 +1,69 @@ +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=24 \ + 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" && \ + 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.* + +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/24-minimal/Dockerfile.fedora b/24-minimal/Dockerfile.fedora new file mode 100644 index 00000000..0bafeebd --- /dev/null +++ b/24-minimal/Dockerfile.fedora @@ -0,0 +1,71 @@ +FROM quay.io/fedora/fedora-minimal:42 + +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="fedora" \ + NODEJS_VERSION=24 \ + 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="fedora/$NAME-$NODEJS_VERSION-minimal" \ + 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_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n nodejs$NODEJS_VERSION-npm findutils tar which nss_wrapper-libs" && \ + 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.* + +# +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/24-minimal/Dockerfile.rhel10 b/24-minimal/Dockerfile.rhel10 new file mode 100644 index 00000000..a23134fe --- /dev/null +++ b/24-minimal/Dockerfile.rhel10 @@ -0,0 +1,68 @@ +FROM ubi10-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="el10" \ + NODEJS_VERSION=24 \ + 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 --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/24-minimal/Dockerfile.rhel8 b/24-minimal/Dockerfile.rhel8 new file mode 100644 index 00000000..56635add --- /dev/null +++ b/24-minimal/Dockerfile.rhel8 @@ -0,0 +1,70 @@ +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=24 \ + 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/24-minimal/Dockerfile.rhel9 b/24-minimal/Dockerfile.rhel9 new file mode 100644 index 00000000..27247979 --- /dev/null +++ b/24-minimal/Dockerfile.rhel9 @@ -0,0 +1,70 @@ +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=24 \ + 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/24-minimal/README.md b/24-minimal/README.md new file mode 100644 index 00000000..3c2bb864 --- /dev/null +++ b/24-minimal/README.md @@ -0,0 +1,373 @@ +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 + +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/root/usr/bin/fix-permissions b/24-minimal/root/usr/bin/fix-permissions new file mode 100755 index 00000000..ddd33ace --- /dev/null +++ b/24-minimal/root/usr/bin/fix-permissions @@ -0,0 +1,27 @@ +#!/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 new file mode 100755 index 00000000..f644a811 --- /dev/null +++ b/24-minimal/s2i/bin/assemble @@ -0,0 +1,116 @@ +#!/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 + + NPM_TMP=$(npm config get tmp) + if ! mountpoint $NPM_TMP; then + echo "---> Cleaning the $NPM_TMP/npm-*" + rm -rf $NPM_TMP/npm-* + fi + + # Clear the npm's cache and tmp directories only if they are not a docker volumes + 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/24-minimal/s2i/bin/init-wrapper b/24-minimal/s2i/bin/init-wrapper new file mode 100644 index 00000000..24e0d078 --- /dev/null +++ b/24-minimal/s2i/bin/init-wrapper @@ -0,0 +1,18 @@ +#!/bin/bash + +# Overview of how this script works: http://veithen.io/2014/11/16/sigterm-propagation.html +# Set a trap to kill the main app process when this +# init script receives SIGTERM or SIGINT +trap 'kill -s TERM $PID' TERM INT +# Execute the main application in the background +"$@" & +PID=$! +# wait command always terminates when trap is caught, even if the process hasn't finished yet +wait $PID +# Remove the trap and wait till the app process finishes completely +trap - TERM INT +# We wait again, since the first wait terminates when trap is caught +wait $PID +# Exit with the exit code of the app process +STATUS=$? +exit $STATUS \ No newline at end of file diff --git a/24-minimal/s2i/bin/run b/24-minimal/s2i/bin/run new file mode 100755 index 00000000..10150f34 --- /dev/null +++ b/24-minimal/s2i/bin/run @@ -0,0 +1,79 @@ +#!/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/24-minimal/s2i/bin/save-artifacts b/24-minimal/s2i/bin/save-artifacts new file mode 100755 index 00000000..16be05e7 --- /dev/null +++ b/24-minimal/s2i/bin/save-artifacts @@ -0,0 +1,5 @@ +#!/bin/bash + +if [ -d "${HOME}/node_modules" ] && [ "$(ls "${HOME}/node_modules" 2>/dev/null)" ]; then + tar -C "${HOME}" -cf - node_modules +fi diff --git a/24-minimal/s2i/bin/usage b/24-minimal/s2i/bin/usage new file mode 100755 index 00000000..b8c1dca8 --- /dev/null +++ b/24-minimal/s2i/bin/usage @@ -0,0 +1,15 @@ +#!/bin/sh + +DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` + +cat < nodejs-sample-app + +You can then run the resulting image via: +podman run -p 8080:8080 nodejs-sample-app +EOF diff --git a/24-minimal/test/check_imagestreams.py b/24-minimal/test/check_imagestreams.py new file mode 120000 index 00000000..56bb2be7 --- /dev/null +++ b/24-minimal/test/check_imagestreams.py @@ -0,0 +1 @@ +../../common/check_imagestreams.py \ No newline at end of file diff --git a/24-minimal/test/examples b/24-minimal/test/examples new file mode 120000 index 00000000..da7b1965 --- /dev/null +++ b/24-minimal/test/examples @@ -0,0 +1 @@ +../../examples/ \ No newline at end of file diff --git a/24-minimal/test/imagestreams b/24-minimal/test/imagestreams new file mode 120000 index 00000000..0dcbe9e0 --- /dev/null +++ b/24-minimal/test/imagestreams @@ -0,0 +1 @@ +../../imagestreams/ \ No newline at end of file diff --git a/24-minimal/test/run b/24-minimal/test/run new file mode 120000 index 00000000..f446a740 --- /dev/null +++ b/24-minimal/test/run @@ -0,0 +1 @@ +../../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 new file mode 120000 index 00000000..1bffcba8 --- /dev/null +++ b/24-minimal/test/run-openshift-remote-cluster @@ -0,0 +1 @@ +../../test/run-openshift-remote-cluster \ No newline at end of file diff --git a/24-minimal/test/test-app b/24-minimal/test/test-app new file mode 120000 index 00000000..6ba4f290 --- /dev/null +++ b/24-minimal/test/test-app @@ -0,0 +1 @@ +../../test/test-app \ No newline at end of file diff --git a/24-minimal/test/test-binary b/24-minimal/test/test-binary new file mode 120000 index 00000000..cd7b631f --- /dev/null +++ b/24-minimal/test/test-binary @@ -0,0 +1 @@ +../../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 new file mode 120000 index 00000000..6a5bbd41 --- /dev/null +++ b/24-minimal/test/test-express-webapp @@ -0,0 +1 @@ +../../test/test-express-webapp \ No newline at end of file diff --git a/24-minimal/test/test-hw b/24-minimal/test/test-hw new file mode 120000 index 00000000..ad784558 --- /dev/null +++ b/24-minimal/test/test-hw @@ -0,0 +1 @@ +../../test/test-hw \ No newline at end of file diff --git a/24-minimal/test/test-incremental b/24-minimal/test/test-incremental new file mode 120000 index 00000000..0a357b1f --- /dev/null +++ b/24-minimal/test/test-incremental @@ -0,0 +1 @@ +../../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 new file mode 120000 index 00000000..8915d844 --- /dev/null +++ b/24-minimal/test/test-lib-nodejs.sh @@ -0,0 +1 @@ +../../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 new file mode 120000 index 00000000..4f9f2996 --- /dev/null +++ b/24-minimal/test/test-lib-openshift.sh @@ -0,0 +1 @@ +../../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 new file mode 120000 index 00000000..92ad2f4d --- /dev/null +++ b/24-minimal/test/test-lib-remote-openshift.sh @@ -0,0 +1 @@ +../../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 new file mode 120000 index 00000000..1ac99b93 --- /dev/null +++ b/24-minimal/test/test-lib.sh @@ -0,0 +1 @@ +../../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 new file mode 120000 index 00000000..8613fbba --- /dev/null +++ b/24-minimal/test/test-openshift.yaml @@ -0,0 +1 @@ +../../common/test-openshift.yaml \ No newline at end of file diff --git a/24/.exclude-c10s b/24/.exclude-c10s new file mode 100644 index 00000000..e69de29b diff --git a/24/.exclude-c8s b/24/.exclude-c8s new file mode 100644 index 00000000..e69de29b diff --git a/24/.exclude-c9s b/24/.exclude-c9s new file mode 100644 index 00000000..e69de29b diff --git a/24/.exclude-rhel10 b/24/.exclude-rhel10 new file mode 100644 index 00000000..e69de29b diff --git a/24/.exclude-rhel8 b/24/.exclude-rhel8 new file mode 100644 index 00000000..e69de29b diff --git a/24/.exclude-rhel9 b/24/.exclude-rhel9 new file mode 100644 index 00000000..e69de29b diff --git a/24/Dockerfile.c10s b/24/Dockerfile.c10s new file mode 100644 index 00000000..53cb44e1 --- /dev/null +++ b/24/Dockerfile.c10s @@ -0,0 +1,80 @@ +FROM quay.io/sclorg/s2i-core-c10s:c10s + +# 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=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.c10s-nodejs-24 \ + CNB_USER_ID=1001 \ + CNB_GROUP_ID=0 + +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" \ + io.buildpacks.stack.id="com.redhat.stacks.c10s-nodejs-24" \ + 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}-container" \ + name="sclorg/$NAME-$NODEJS_VERSION-c10s" \ + 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" \ + usage="s2i build quay.io/sclorg/$NAME-$NODEJS_VERSION-c10s:latest " + +# Package libatomic_ops was removed +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='*' + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH +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 chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 + +# Set the default CMD to print the usage of the language image +CMD $STI_SCRIPTS_PATH/usage diff --git a/24/Dockerfile.c8s b/24/Dockerfile.c8s new file mode 100644 index 00000000..6a7e0501 --- /dev/null +++ b/24/Dockerfile.c8s @@ -0,0 +1,80 @@ +FROM quay.io/sclorg/s2i-core-c8s + +# 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=20 \ + 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_USER_ID=1001 \ + CNB_GROUP_ID=0 + +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" \ + io.buildpacks.stack.id="com.redhat.stacks.c8s-nodejs-20" \ + 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}-container" \ + name="sclorg/$NAME-$NODEJS_VERSION-c8s" \ + 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" \ + usage="s2i build quay.io/sclorg/$NAME-$NODEJS_VERSION-c8s:latest " + +RUN yum -y module enable nodejs:$NODEJS_VERSION && \ + MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS nodejs npm nodejs-nodemon nss_wrapper-libs which" && \ + 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='*' + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH +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 chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 + +# Set the default CMD to print the usage of the language image +CMD $STI_SCRIPTS_PATH/usage diff --git a/24/Dockerfile.c9s b/24/Dockerfile.c9s new file mode 100644 index 00000000..f297ee4f --- /dev/null +++ b/24/Dockerfile.c9s @@ -0,0 +1,80 @@ +FROM quay.io/sclorg/s2i-core-c9s:c9s + +# 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=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.c9s-nodejs-24 \ + CNB_USER_ID=1001 \ + CNB_GROUP_ID=0 + +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" \ + io.buildpacks.stack.id="com.redhat.stacks.c9s-nodejs-24" \ + 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}-container" \ + name="sclorg/$NAME-$NODEJS_VERSION-c9s" \ + 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" \ + usage="s2i build quay.io/sclorg/$NAME-$NODEJS_VERSION-c9s:latest " + +# Package libatomic_ops was removed +RUN dnf -y module enable nodejs:$NODEJS_VERSION && \ + MODULE_DEPS="make gcc gcc-c++ git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS nodejs npm nodejs-nodemon nss_wrapper-libs which" && \ + 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='*' + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH +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 chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 + +# Set the default CMD to print the usage of the language image +CMD $STI_SCRIPTS_PATH/usage diff --git a/24/Dockerfile.fedora b/24/Dockerfile.fedora new file mode 100644 index 00000000..1880a2ed --- /dev/null +++ b/24/Dockerfile.fedora @@ -0,0 +1,74 @@ +FROM quay.io/fedora/s2i-core:42 + +# 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=24 \ + NPM_RUN=start \ + NAME=nodejs \ + NPM_CONFIG_PREFIX=$HOME/.npm-global \ + PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH + +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" \ + 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" \ + name="fedora/$NAME-$NODEJS_VERSION" \ + version="$NODEJS_VERSION" \ + maintainer="SoftwareCollections.org " \ + help="For more information visit https://github.com/sclorg/s2i-nodejs-container" \ + usage="oc new-app $FGC/$NAME~" + +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='*' + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH +RUN chmod +x /usr/libexec/s2i/init-wrapper + +# 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 +RUN chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 + +# Set the default CMD to print the usage of the language image +CMD $STI_SCRIPTS_PATH/usage diff --git a/24/Dockerfile.rhel10 b/24/Dockerfile.rhel10 new file mode 100644 index 00000000..77f775f4 --- /dev/null +++ b/24/Dockerfile.rhel10 @@ -0,0 +1,80 @@ +FROM ubi10/s2i-core:latest + +# 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=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.c10s-nodejs-24 \ + CNB_USER_ID=1001 \ + CNB_GROUP_ID=0 + +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" \ + io.buildpacks.stack.id="com.redhat.stacks.c10s-nodejs-24" \ + 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}-container" \ + name="ubi10/$NAME-$NODEJS_VERSION" \ + 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" \ + usage="s2i build ubi10/$NAME-$NODEJS_VERSION " + +# Package libatomic_ops was removed +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='*' + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH +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 chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 + +# Set the default CMD to print the usage of the language image +CMD $STI_SCRIPTS_PATH/usage diff --git a/24/Dockerfile.rhel8 b/24/Dockerfile.rhel8 new file mode 100644 index 00000000..aa3026c5 --- /dev/null +++ b/24/Dockerfile.rhel8 @@ -0,0 +1,85 @@ +FROM ubi8/s2i-core:1 + +# 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=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.ubi8-nodejs-20 \ + CNB_USER_ID=1001 \ + CNB_GROUP_ID=0 + +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" \ + io.buildpacks.stack.id="com.redhat.stacks.ubi8-nodejs-20" \ + 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}-container" \ + name="ubi8/$NAME-$NODEJS_VERSION" \ + 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" \ + usage="s2i build ubi8/$NAME-$NODEJS_VERSION:latest " + +RUN dnf -y module enable nodejs:$NODEJS_VERSION && \ + 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 nodejs npm nodejs-nodemon nss_wrapper-libs which" && \ + 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='*' + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH +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 chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 + +# 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" + +# Set the default CMD to print the usage of the language image +CMD $STI_SCRIPTS_PATH/usage diff --git a/24/Dockerfile.rhel9 b/24/Dockerfile.rhel9 new file mode 100644 index 00000000..bbdb9f51 --- /dev/null +++ b/24/Dockerfile.rhel9 @@ -0,0 +1,79 @@ +FROM ubi9/s2i-core:1 + +# 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=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.ubi9-nodejs-20 \ + CNB_USER_ID=1001 \ + CNB_GROUP_ID=0 + +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" \ + io.buildpacks.stack.id="com.redhat.stacks.ubi9-nodejs-20" \ + 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}-container" \ + name="ubi9/$NAME-$NODEJS_VERSION" \ + 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" \ + usage="s2i build ubi9/$NAME-$NODEJS_VERSION:latest " + +RUN dnf -y module enable nodejs:$NODEJS_VERSION && \ + MODULE_DEPS="make gcc gcc-c++ git openssl-devel" && \ + INSTALL_PKGS="$MODULE_DEPS nodejs npm nodejs-nodemon nss_wrapper-libs which" && \ + 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='*' + +# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH +COPY ./s2i/bin/ $STI_SCRIPTS_PATH +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 chown -R 1001:0 ${APP_ROOT} && chmod -R ug+rwx ${APP_ROOT} && \ + rpm-file-permissions + +USER 1001 + +# Set the default CMD to print the usage of the language image +CMD $STI_SCRIPTS_PATH/usage diff --git a/24/README.md b/24/README.md new file mode 100644 index 00000000..7d28862f --- /dev/null +++ b/24/README.md @@ -0,0 +1,302 @@ +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 + +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/root/opt/app-root/etc/generate_container_user b/24/root/opt/app-root/etc/generate_container_user new file mode 100644 index 00000000..b28a7a3d --- /dev/null +++ b/24/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/root/opt/app-root/etc/npm_global_module_list b/24/root/opt/app-root/etc/npm_global_module_list new file mode 100644 index 00000000..005e1501 --- /dev/null +++ b/24/root/opt/app-root/etc/npm_global_module_list @@ -0,0 +1,5 @@ +async +mime +mkdirp +qs +minimatch diff --git a/24/root/opt/app-root/etc/scl_enable b/24/root/opt/app-root/etc/scl_enable new file mode 100644 index 00000000..4bfebea0 --- /dev/null +++ b/24/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/s2i/bin/assemble b/24/s2i/bin/assemble new file mode 100755 index 00000000..f644a811 --- /dev/null +++ b/24/s2i/bin/assemble @@ -0,0 +1,116 @@ +#!/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 + + NPM_TMP=$(npm config get tmp) + if ! mountpoint $NPM_TMP; then + echo "---> Cleaning the $NPM_TMP/npm-*" + rm -rf $NPM_TMP/npm-* + fi + + # Clear the npm's cache and tmp directories only if they are not a docker volumes + 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/24/s2i/bin/init-wrapper b/24/s2i/bin/init-wrapper new file mode 100644 index 00000000..24e0d078 --- /dev/null +++ b/24/s2i/bin/init-wrapper @@ -0,0 +1,18 @@ +#!/bin/bash + +# Overview of how this script works: http://veithen.io/2014/11/16/sigterm-propagation.html +# Set a trap to kill the main app process when this +# init script receives SIGTERM or SIGINT +trap 'kill -s TERM $PID' TERM INT +# Execute the main application in the background +"$@" & +PID=$! +# wait command always terminates when trap is caught, even if the process hasn't finished yet +wait $PID +# Remove the trap and wait till the app process finishes completely +trap - TERM INT +# We wait again, since the first wait terminates when trap is caught +wait $PID +# Exit with the exit code of the app process +STATUS=$? +exit $STATUS \ No newline at end of file diff --git a/24/s2i/bin/run b/24/s2i/bin/run new file mode 100755 index 00000000..9a207bce --- /dev/null +++ b/24/s2i/bin/run @@ -0,0 +1,83 @@ +#!/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 + +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() { + 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/24/s2i/bin/save-artifacts b/24/s2i/bin/save-artifacts new file mode 100755 index 00000000..16be05e7 --- /dev/null +++ b/24/s2i/bin/save-artifacts @@ -0,0 +1,5 @@ +#!/bin/bash + +if [ -d "${HOME}/node_modules" ] && [ "$(ls "${HOME}/node_modules" 2>/dev/null)" ]; then + tar -C "${HOME}" -cf - node_modules +fi diff --git a/24/s2i/bin/usage b/24/s2i/bin/usage new file mode 100755 index 00000000..b8c1dca8 --- /dev/null +++ b/24/s2i/bin/usage @@ -0,0 +1,15 @@ +#!/bin/sh + +DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'` + +cat < nodejs-sample-app + +You can then run the resulting image via: +podman run -p 8080:8080 nodejs-sample-app +EOF diff --git a/24/test b/24/test new file mode 120000 index 00000000..ae78e219 --- /dev/null +++ b/24/test @@ -0,0 +1 @@ +../test/ \ No newline at end of file