Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding NODE_CMD option as env variable for specifying run command. #359

Merged
merged 23 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1cd9274
fix: adding 14 tested images
pacostas Sep 21, 2022
cb39449
fix: adding 14 minimal tested images
pacostas Sep 21, 2022
f16a731
fix: adding 16 tested images
pacostas Sep 21, 2022
60fafae
fix: adding 16 minimal tested images
pacostas Sep 21, 2022
a0662c8
fix: adding 18 tested images
pacostas Sep 14, 2022
f400f8b
adding documentation about NODE_CMD option
pacostas Oct 18, 2022
a2c283d
adding INIT_WRAPPER option on node 16
pacostas Nov 21, 2022
8e9cb24
adding INIT_WRAPPER option on node 14 and 18
pacostas Nov 22, 2022
07b8ff0
adding docs for init-wrapper script
pacostas Nov 22, 2022
44dc326
Apply suggestions from code review
pacostas Nov 25, 2022
15fe7f6
Applying suggestions from code review
pacostas Nov 25, 2022
d50fdbd
fix: updating run script
pacostas Jan 3, 2023
a5a7fe0
fix: adding init-wrapper scipt on node 18
pacostas Jan 3, 2023
24c9bce
fix: removing blank spaces
pacostas Jan 4, 2023
e71126f
fix: updating run script for readablility and catching edge cases on …
Jul 24, 2023
51ae0a2
test: adding tests for NODE_CMD and INIT_WRAPPER options
Jul 24, 2023
7da4160
fix: adding init-wrapper for node version 20
pacostas Sep 12, 2023
61ebc3d
fix: removing duplicate code and using absolute path on change chmod …
Oct 3, 2023
8d2a34f
fix: usring on 14 rhel7 absolute path instead of STI_SCRIPTS_PATH var…
Oct 17, 2023
8aa1b86
fix: adding absolute path on copying scripts. rhel 7 node 14
Nov 10, 2023
f3a8baa
excluding init wrapper from rhel7
Jun 4, 2024
7578c8a
Rebasing and adding inti-wrapper for node 22
Sep 20, 2024
45048fd
adding missing library
Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 14-minimal/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ RUN INSTALL_PKGS="nodejs nodejs-nodemon npm findutils tar" && \
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/ /
Expand Down
2 changes: 1 addition & 1 deletion 14-minimal/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NodeJS 14 minimal container image
=========================

**The NodeJS 14 minimal image is deprecated.**
**The NodeJS 14 minimal image is deprecated.**
18 changes: 18 additions & 0 deletions 14-minimal/s2i/bin/init-wrapper
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions 14-minimal/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,29 @@ run_node() {
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
Expand Down
1 change: 1 addition & 0 deletions 14/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ RUN yum install -y centos-release-scl-rh && \

# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
RUN chmod +x $STI_SCRIPTS_PATH/init-wrapper
pacostas marked this conversation as resolved.
Show resolved Hide resolved

# Copy extra files to the image, including help file.
COPY ./root/ /
Expand Down
1 change: 1 addition & 0 deletions 14/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ RUN yum -y module enable nodejs:$NODEJS_VERSION && \

# 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/ /
Expand Down
1 change: 1 addition & 0 deletions 14/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ RUN yum -y module enable nodejs:$NODEJS_VERSION && \

# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
RUN chmod +x $STI_SCRIPTS_PATH/init-wrapper
pacostas marked this conversation as resolved.
Show resolved Hide resolved

# Copy extra files to the image.
COPY ./root/ /
Expand Down
2 changes: 1 addition & 1 deletion 14/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NodeJS 14 container image
=========================

**The NodeJS 14 image is deprecated.**
**The NodeJS 14 image is deprecated.**
18 changes: 18 additions & 0 deletions 14/s2i/bin/init-wrapper
Original file line number Diff line number Diff line change
@@ -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
25 changes: 24 additions & 1 deletion 14/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,34 @@ run_node() {
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
Expand Down
1 change: 1 addition & 0 deletions 16-minimal/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which
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/ /
Expand Down
1 change: 1 addition & 0 deletions 16-minimal/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which
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/ /
Expand Down
18 changes: 18 additions & 0 deletions 16-minimal/s2i/bin/init-wrapper
Original file line number Diff line number Diff line change
@@ -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
25 changes: 24 additions & 1 deletion 16-minimal/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,34 @@ run_node() {
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
Expand Down
1 change: 1 addition & 0 deletions 16/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ RUN MODULE_DEPS="make gcc gcc-c++ git openssl-devel" && \

# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
RUN chmod +x $STI_SCRIPTS_PATH/init-wrapper

# Copy extra files to the image.
COPY ./root/ /
Expand Down
1 change: 1 addition & 0 deletions 16/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ RUN MODULE_DEPS="make gcc gcc-c++ libatomic_ops git openssl-devel" && \

# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
RUN chmod +x $STI_SCRIPTS_PATH/init-wrapper
pacostas marked this conversation as resolved.
Show resolved Hide resolved

# Copy extra files to the image, including help file.
COPY ./root/ /
Expand Down
3 changes: 2 additions & 1 deletion 16/Dockerfile.rhel8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubi8/s2i-core:1
FROM registry.access.redhat.com/ubi8/s2i-core:1

# This image provides a Node.JS environment you can use to run your Node.JS
# applications.
Expand Down Expand Up @@ -65,6 +65,7 @@ RUN yum -y module enable nodejs:$NODEJS_VERSION && \

# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
RUN chmod +x $STI_SCRIPTS_PATH/init-wrapper
pacostas marked this conversation as resolved.
Show resolved Hide resolved

# Copy extra files to the image.
COPY ./root/ /
Expand Down
1 change: 1 addition & 0 deletions 16/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ RUN MODULE_DEPS="make gcc gcc-c++ git openssl-devel" && \

# Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH
COPY ./s2i/bin/ $STI_SCRIPTS_PATH
RUN chmod +x $STI_SCRIPTS_PATH/init-wrapper

# Copy extra files to the image.
COPY ./root/ /
Expand Down
2 changes: 1 addition & 1 deletion 16/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NodeJS 16 container image
=========================

**The NodeJS 16 image is deprecated.**
**The NodeJS 16 image is deprecated.**
18 changes: 18 additions & 0 deletions 16/s2i/bin/init-wrapper
Original file line number Diff line number Diff line change
@@ -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
25 changes: 24 additions & 1 deletion 16/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,34 @@ run_node() {
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
Expand Down
2 changes: 2 additions & 0 deletions 18-minimal/Dockerfile.c8s
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which

COPY ./s2i/bin/ /usr/libexec/s2i

RUN chmod +x /usr/libexec/s2i/init-wrapper

# Copy extra files to the image.
COPY ./root/ /

Expand Down
1 change: 1 addition & 0 deletions 18-minimal/Dockerfile.c9s
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which
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/ /
Expand Down
1 change: 1 addition & 0 deletions 18-minimal/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n nodejs-npm findutils ta
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/ /
Expand Down
2 changes: 2 additions & 0 deletions 18-minimal/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which

COPY ./s2i/bin/ /usr/libexec/s2i

RUN chmod +x /usr/libexec/s2i/init-wrapper

# Copy extra files to the image.
COPY ./root/ /

Expand Down
2 changes: 2 additions & 0 deletions 18-minimal/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ RUN INSTALL_PKGS="nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which

COPY ./s2i/bin/ /usr/libexec/s2i

RUN chmod +x /usr/libexec/s2i/init-wrapper

# Copy extra files to the image.
COPY ./root/ /

Expand Down
Loading