Skip to content

Commit

Permalink
[3/3] Add Node.js 20 (patch s/18/20)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhorak committed Aug 30, 2023
1 parent e64410b commit 333745c
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 61 deletions.
6 changes: 3 additions & 3 deletions 20-minimal/Dockerfile.c8s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV APP_ROOT=/opt/app-root \
HOME=/opt/app-root/src \
NPM_RUN=start \
PLATFORM="el8" \
NODEJS_VERSION=18 \
NODEJS_VERSION=20 \
NPM_RUN=start \
NAME=nodejs

Expand Down Expand Up @@ -49,8 +49,8 @@ LABEL summary="$SUMMARY" \
maintainer="SoftwareCollections.org <[email protected]>" \
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" && \
# nodejs-full-i20n is included for error strings
RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i20n npm findutils tar" && \
microdnf -y module disable nodejs && \
microdnf -y module enable nodejs:$NODEJS_VERSION && \
microdnf --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \
Expand Down
6 changes: 3 additions & 3 deletions 20-minimal/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV APP_ROOT=/opt/app-root \
HOME=/opt/app-root/src \
NPM_RUN=start \
PLATFORM="el9" \
NODEJS_VERSION=18 \
NODEJS_VERSION=20 \
NPM_RUN=start \
NAME=nodejs

Expand Down Expand Up @@ -49,8 +49,8 @@ LABEL summary="$SUMMARY" \
maintainer="SoftwareCollections.org <[email protected]>" \
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" && \
# nodejs-full-i20n is included for error strings
RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i20n npm findutils tar" && \
microdnf -y module disable nodejs && \
microdnf -y module enable nodejs:$NODEJS_VERSION && \
microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \
Expand Down
6 changes: 3 additions & 3 deletions 20-minimal/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV APP_ROOT=/opt/app-root \
HOME=/opt/app-root/src \
NPM_RUN=start \
PLATFORM="el8" \
NODEJS_VERSION=18 \
NODEJS_VERSION=20 \
NPM_RUN=start \
NAME=nodejs

Expand Down Expand Up @@ -49,8 +49,8 @@ LABEL summary="$SUMMARY" \
maintainer="SoftwareCollections.org <[email protected]>" \
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" && \
# nodejs-full-i20n is included for error strings
RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i20n npm findutils tar" && \
microdnf -y module disable nodejs && \
microdnf -y module enable nodejs:$NODEJS_VERSION && \
microdnf --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \
Expand Down
6 changes: 3 additions & 3 deletions 20-minimal/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV APP_ROOT=/opt/app-root \
HOME=/opt/app-root/src \
NPM_RUN=start \
PLATFORM="el9" \
NODEJS_VERSION=18 \
NODEJS_VERSION=20 \
NPM_RUN=start \
NAME=nodejs

Expand Down Expand Up @@ -49,8 +49,8 @@ LABEL summary="$SUMMARY" \
maintainer="SoftwareCollections.org <[email protected]>" \
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" && \
# nodejs-full-i20n is included for error strings
RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i20n npm findutils tar" && \
microdnf -y module disable nodejs && \
microdnf -y module enable nodejs:$NODEJS_VERSION && \
microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \
Expand Down
36 changes: 18 additions & 18 deletions 20-minimal/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
NodeJS 18 minimal container image
NodeJS 20 minimal container image
=========================

This container image includes Node.JS 18 on top of a minimal base image for your Node.JS 18 applications. This image is designed to be used
with the full-sized s2i-enabled Node.JS 18 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 18 image it will be missing many build-time dependencies.
This container image includes Node.JS 20 on top of a minimal base image for your Node.JS 20 applications. This image is designed to be used
with the full-sized s2i-enabled Node.JS 20 image to build the application. The image can be used as a standalone s2i-enabled image as well,
but compared to the full-sized Node.JS 20 image it will be missing many build-time dependencies.
Users can choose between RHEL, CentOS and Fedora based images.
The RHEL images are available in the [Red Hat Container Catalog](https://access.redhat.com/containers/),
the CentOS images are available on [Quay.io](https://quay.io/organization/centos7),
Expand All @@ -15,17 +15,17 @@ Note: while the examples in this README are calling `podman`, you can replace an
Description
-----------

Node.js 18 available as a minimal container is a base platform for
running various Node.js 18 applications and frameworks.
Node.js 20 available as a minimal container is a base platform for
running various Node.js 20 applications and frameworks.
Node.js is a platform built on Chrome's JavaScript runtime for easily building
fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model
that makes it lightweight and efficient, perfect for data-intensive real-time applications
that run across distributed devices.

Usage in OpenShift
------------------
In this example, we will assume that you are using the `ubi8/nodejs-18` image, available via `nodejs:18-ubi8` imagestream tag in Openshift
to build the application, as well as the `ubi8/nodejs-18-minimal` image, available via `nodejs:18-ubi8-minimal` image stream
In this example, we will assume that you are using the `ubi8/nodejs-20` image, available via `nodejs:20-ubi8` imagestream tag in Openshift
to build the application, as well as the `ubi8/nodejs-20-minimal` image, available via `nodejs:20-ubi8-minimal` image stream
for running the resulting application.

With these two images we can create a [chained build](https://docs.openshift.com/container-platform/4.7/cicd/builds/advanced-build-operations.html#builds-chaining-builds_advanced-build-operations) in Openshift using two BuildConfigs:
Expand All @@ -50,7 +50,7 @@ spec:
sourceStrategy:
from:
kind: ImageStreamTag
name: nodejs:18-ubi8
name: nodejs:20-ubi8
namespace: openshift
```

Expand All @@ -70,7 +70,7 @@ spec:
name: nodejs-runtime-image:latest
source:
dockerfile: |-
FROM nodejs:18-ubi8-minimal
FROM nodejs:20-ubi8-minimal
COPY src $HOME
CMD /usr/libexec/s2i/run
images:
Expand All @@ -84,7 +84,7 @@ spec:
dockerStrategy:
from:
kind: ImageStreamTag
name: nodejs:18-ubi8-minimal
name: nodejs:20-ubi8-minimal
triggers:
- imageChange: {}
type: ImageChange
Expand Down Expand Up @@ -114,11 +114,11 @@ 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-18
podman pull ubi8/nodejs-18-minimal
podman pull ubi8/nodejs-20
podman pull ubi8/nodejs-20-minimal
```

The UBI images `ubi8/nodejs-18` and `ubi8/nodejs-18-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).
The UBI images `ubi8/nodejs-20` and `ubi8/nodejs-20-minimal` that are used in this example are both usable and freely redistributable under the terms of the UBI End User License Agreement (EULA). See more about UBI at [UBI FAQ](https://developers.redhat.com/articles/ubi-faq).

#### 2. Pull an application code

Expand All @@ -141,7 +141,7 @@ For all these three parts, users can either setup all manually and use commands
##### 3.1. To use your own setup, create a Dockerfile with this content:
```
# First stage builds the application
FROM ubi8/nodejs-18 as builder
FROM ubi8/nodejs-20 as builder
# Add application sources
ADD app-src $HOME
Expand All @@ -150,7 +150,7 @@ ADD app-src $HOME
RUN npm install
# Second stage copies the application to the minimal image
FROM ubi8/nodejs-18-minimal
FROM ubi8/nodejs-20-minimal
# Copy the application source and build artifacts from the builder image to this one
COPY --from=builder $HOME $HOME
Expand All @@ -162,7 +162,7 @@ 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-18 as builder
FROM ubi8/nodejs-20 as builder
# Add application sources to a directory that the assemble script expects them
# and set permissions so that the container runs without root access
Expand All @@ -175,7 +175,7 @@ USER 1001
RUN /usr/libexec/s2i/assemble
# Second stage copies the application to the minimal image
FROM ubi8/nodejs-18-minimal
FROM ubi8/nodejs-20-minimal
# Copy the application source and build artifacts from the builder image to this one
COPY --from=builder $HOME $HOME
Expand Down
4 changes: 2 additions & 2 deletions 20-minimal/s2i/bin/usage
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
DISTRO=`cat /etc/*-release | grep ^ID= | grep -Po '".*?"' | tr -d '"'`

cat <<EOF
This is a S2I nodejs-18-minimal ${DISTRO} base image:
This is a S2I nodejs-${NODEJS_VERSION} ${DISTRO} base image:
To use it, install S2I: https://github.com/openshift/source-to-image
Sample invocation:
s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=18/test/test-app/ ${NAMESPACE}/nodejs-18-${DISTRO}7 nodejs-sample-app
s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=${NODEJS_VERSION}/test/test-app/ <IMAGE_NAME> nodejs-sample-app
You can then run the resulting image via:
podman run -p 8080:8080 nodejs-sample-app
Expand Down
6 changes: 3 additions & 3 deletions 20/Dockerfile.c8s
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ EXPOSE 8080
# Expose ports:
# * 8080 - Unprivileged port used by nodejs application

ENV NODEJS_VERSION=18 \
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.ubi8-nodejs-18 \
CNB_STACK_ID=com.redhat.stacks.ubi8-nodejs-20 \
CNB_USER_ID=1001 \
CNB_GROUP_ID=0

Expand All @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \
io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \
io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \
io.s2i.scripts-url="image:///usr/libexec/s2i" \
io.buildpacks.stack.id="com.redhat.stacks.ubi8-nodejs-18" \
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" \
Expand Down
6 changes: 3 additions & 3 deletions 20/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ EXPOSE 8080
# Expose ports:
# * 8080 - Unprivileged port used by nodejs application

ENV NODEJS_VERSION=18 \
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.c9s-nodejs-18 \
CNB_STACK_ID=com.redhat.stacks.c9s-nodejs-20 \
CNB_USER_ID=1001 \
CNB_GROUP_ID=0

Expand All @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \
io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \
io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \
io.s2i.scripts-url="image:///usr/libexec/s2i" \
io.buildpacks.stack.id="com.redhat.stacks.c9s-nodejs-18" \
io.buildpacks.stack.id="com.redhat.stacks.c9s-nodejs-20" \
com.redhat.dev-mode="DEV_MODE:false" \
com.redhat.deployments-dir="${APP_ROOT}/src" \
com.redhat.dev-mode.port="DEBUG_PORT:5858" \
Expand Down
15 changes: 10 additions & 5 deletions 20/Dockerfile.fedora
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM quay.io/fedora/s2i-core:36
FROM quay.io/fedora/s2i-core:38

# This image provides a Node.JS environment you can use to run your Node.JS
# applications.
Expand All @@ -16,7 +16,7 @@ EXPOSE 8080
# Expose ports:
# * 8080 - Unprivileged port used by nodejs application

ENV NODEJS_VERSION=18 \
ENV NODEJS_VERSION=20 \
NPM_RUN=start \
NAME=nodejs \
NPM_CONFIG_PREFIX=$HOME/.npm-global \
Expand Down Expand Up @@ -48,11 +48,16 @@ LABEL summary="$SUMMARY" \
help="For more information visit https://github.com/sclorg/s2i-nodejs-container" \
usage="oc new-app $FGC/$NAME~<SOURCE-REPOSITORY>"

RUN yum -y module enable nodejs:$NODEJS_VERSION && \
MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \
INSTALL_PKGS="$MODULE_DEPS nodejs nodejs-nodemon npm nss_wrapper-libs which" && \
ADD https://copr.fedorainfracloud.org/coprs/hhorak/nodemon-for-all/repo/fedora-38/hhorak-nodemon-for-all-fedora-38.repo /etc/yum.repos.d/hhorak-nodemon-for-all-fedora-38.repo

RUN MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \
INSTALL_PKGS="$MODULE_DEPS nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm nss_wrapper-libs which" && \
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
ln -s /usr/bin/node-20 /usr/bin/node && \
ln -s /usr/bin/npm-20 /usr/bin/npm && \
ln -s /usr/bin/npx-20 /usr/bin/npx && \
ln -s /usr/lib/node_modules_18/nodemon /usr/lib/node_modules_20/nodemon && \
node -v | grep -qe "^v$NODEJS_VERSION\." && echo "Found VERSION $NODEJS_VERSION" && \
yum -y clean all --enablerepo='*'

Expand Down
6 changes: 3 additions & 3 deletions 20/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ EXPOSE 8080
# Expose ports:
# * 8080 - Unprivileged port used by nodejs application

ENV NODEJS_VERSION=18 \
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.ubi8-nodejs-18 \
CNB_STACK_ID=com.redhat.stacks.ubi8-nodejs-20 \
CNB_USER_ID=1001 \
CNB_GROUP_ID=0

Expand All @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \
io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \
io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \
io.s2i.scripts-url="image:///usr/libexec/s2i" \
io.buildpacks.stack.id="com.redhat.stacks.ubi8-nodejs-18" \
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" \
Expand Down
6 changes: 3 additions & 3 deletions 20/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ EXPOSE 8080
# Expose ports:
# * 8080 - Unprivileged port used by nodejs application

ENV NODEJS_VERSION=18 \
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.ubi9-nodejs-18 \
CNB_STACK_ID=com.redhat.stacks.ubi9-nodejs-20 \
CNB_USER_ID=1001 \
CNB_GROUP_ID=0

Expand All @@ -41,7 +41,7 @@ LABEL summary="$SUMMARY" \
io.openshift.tags="builder,$NAME,${NAME}${NODEJS_VERSION}" \
io.openshift.s2i.scripts-url="image:///usr/libexec/s2i" \
io.s2i.scripts-url="image:///usr/libexec/s2i" \
io.buildpacks.stack.id="com.redhat.stacks.ubi9-nodejs-18" \
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" \
Expand Down
Loading

0 comments on commit 333745c

Please sign in to comment.