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

Backport few changes previously done in RHOAR container #226

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions 10/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ENV NODEJS_VERSION=10 \
NPM_RUN=start \
NAME=nodejs \
NPM_CONFIG_PREFIX=$HOME/.npm-global \
DEBUG_PORT=5858 \
CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nodejs \
NODEJS_PREFIX=/opt/rh/rh-$NAME$NODEJS_VERSION/root/usr \
PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH

ENV SUMMARY="Platform for building and running Node.js $NODEJS_VERSION applications" \
Expand All @@ -40,7 +43,7 @@ LABEL summary="$SUMMARY" \
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.dev-mode.port="DEBUG_PORT:${DEBUG_PORT}"\
com.redhat.component="rh-$NAME$NODEJS_VERSION-container" \
name="centos/$NAME-$NODEJS_VERSION-centos7" \
version="$NODEJS_VERSION" \
Expand All @@ -51,7 +54,6 @@ LABEL summary="$SUMMARY" \
RUN yum install -y centos-release-scl-rh && \
( [ "rh-${NAME}${NODEJS_VERSION}" != "${NODEJS_SCL}" ] && yum remove -y ${NODEJS_SCL}\* || : ) && \
INSTALL_PKGS="rh-nodejs${NODEJS_VERSION} rh-nodejs${NODEJS_VERSION}-npm rh-nodejs${NODEJS_VERSION}-nodejs-nodemon nss_wrapper" && \
ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
yum -y clean all --enablerepo='*'
Expand All @@ -62,9 +64,8 @@ COPY ./s2i/bin/ $STI_SCRIPTS_PATH
# 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
# Run further installation commands
RUN ${CONTAINER_SCRIPTS_PATH}/nodejs_container_install

USER 1001

Expand Down
12 changes: 7 additions & 5 deletions 10/Dockerfile.fedora
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM registry.fedoraproject.org/f29/s2i-base:latest
FROM registry.fedoraproject.org/f31/s2i-base:latest

# This image provides a Node.JS environment you can use to run your Node.JS
# applications.
Expand All @@ -20,6 +20,9 @@ ENV NODEJS_VERSION=10 \
NPM_RUN=start \
NAME=nodejs \
NPM_CONFIG_PREFIX=$HOME/.npm-global \
DEBUG_PORT=5858 \
CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nodejs \
NODEJS_PREFIX=/usr \
PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH

ENV SUMMARY="Platform for building and running Node.js $NODEJS_VERSION applications" \
Expand All @@ -40,7 +43,7 @@ LABEL summary="$SUMMARY" \
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.dev-mode.port="DEBUG_PORT:${DEBUG_PORT}"\
com.redhat.component="$NAME" \
name="$FGC/$NAME" \
version="$VERSION" \
Expand Down Expand Up @@ -68,9 +71,8 @@ COPY ./s2i/bin/ $STI_SCRIPTS_PATH
# 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
# Run further installation commands
RUN ${CONTAINER_SCRIPTS_PATH}/nodejs_container_install

USER 1001

Expand Down
11 changes: 6 additions & 5 deletions 10/Dockerfile.rhel7
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ENV NODEJS_VERSION=10 \
NPM_RUN=start \
NAME=nodejs \
NPM_CONFIG_PREFIX=$HOME/.npm-global \
DEBUG_PORT=5858 \
CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nodejs \
NODEJS_PREFIX=/opt/rh/rh-$NAME$NODEJS_VERSION/root/usr \
PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH

ENV SUMMARY="Platform for building and running Node.js $NODEJS_VERSION applications" \
Expand All @@ -40,7 +43,7 @@ LABEL summary="$SUMMARY" \
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.dev-mode.port="DEBUG_PORT:${DEBUG_PORT}"\
com.redhat.component="rh-${NAME}${NODEJS_VERSION}-container" \
name="rhscl/$NAME-$NODEJS_VERSION-rhel7" \
version="1" \
Expand All @@ -53,7 +56,6 @@ RUN yum install -y yum-utils && \
prepare-yum-repositories rhel-server-rhscl-7-rpms && \
( [ "rh-${NAME}${NODEJS_VERSION}" != "${NODEJS_SCL}" ] && yum remove -y ${NODEJS_SCL}\* || : ) && \
INSTALL_PKGS="rh-nodejs${NODEJS_VERSION} rh-nodejs${NODEJS_VERSION}-npm rh-nodejs${NODEJS_VERSION}-nodejs-nodemon nss_wrapper" && \
ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
yum -y clean all --enablerepo='*'
Expand All @@ -64,9 +66,8 @@ COPY ./s2i/bin/ $STI_SCRIPTS_PATH
# 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
# Run further installation commands
RUN ${CONTAINER_SCRIPTS_PATH}/nodejs_container_install

USER 1001

Expand Down
11 changes: 6 additions & 5 deletions 10/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ENV NODEJS_VERSION=10 \
NPM_RUN=start \
NAME=nodejs \
NPM_CONFIG_PREFIX=$HOME/.npm-global \
DEBUG_PORT=5858 \
CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nodejs \
NODEJS_PREFIX=/usr \
PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH

ENV SUMMARY="Platform for building and running Node.js $NODEJS_VERSION applications" \
Expand All @@ -40,7 +43,7 @@ LABEL summary="$SUMMARY" \
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.dev-mode.port="DEBUG_PORT:${DEBUG_PORT}"\
com.redhat.component="${NAME}-${NODEJS_VERSION}-container" \
name="ubi8/$NAME-$NODEJS_VERSION" \
version="1" \
Expand All @@ -51,7 +54,6 @@ LABEL summary="$SUMMARY" \

RUN yum -y module enable nodejs:$NODEJS_VERSION && \
INSTALL_PKGS="nodejs npm nodejs-nodemon nss_wrapper" && \
ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \
yum remove -y $INSTALL_PKGS && \
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
rpm -V $INSTALL_PKGS && \
Expand All @@ -63,9 +65,8 @@ COPY ./s2i/bin/ $STI_SCRIPTS_PATH
# 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
# Run further installation commands
RUN ${CONTAINER_SCRIPTS_PATH}/nodejs_container_install

USER 1001

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

set -e

# Ensure git uses https instead of ssh for NPM install
# See: https://github.com/npm/npm/issues/5257
echo -e "Setting git config rules"
git config --system url."https://github.com".insteadOf git@github.com:
git config --global url."https://github.com".insteadOf ssh://git@github.com
git config --system url."https://".insteadOf git://
git config --system url."https://".insteadOf ssh://
git config --list

# Since the shebang in the *.js files below is !#/usr/bin/env node, we can
# just create symlinks and if needed, SCL environment is gonna be enabled properly

# Make sure npx is available on standard path
if [ ! -h /usr/bin/npx ] ; then
ln -s "${NODEJS_PREFIX}/lib/node_modules/npm/bin/npx-cli.js" /usr/bin/npx
fi

# Make sure nodemon is available on standard path
if [ ! -h /usr/bin/nodemon ] ; then
ln -s "${NODEJS_PREFIX}/lib/node_modules/nodemon/bin/nodemon.js" /usr/bin/nodemon
fi

# Drop the root user and make the content of /opt/app-root owned by user 1001
echo "---> Setting directory write permissions"
fix-permissions "${APP_ROOT}"

# Fix permissions for files installed by RPM
rpm-file-permissions
43 changes: 36 additions & 7 deletions 10/s2i/bin/assemble
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ mv /tmp/src/* ./
# Fix source directory permissions
fix-permissions ./

if [ "$DEV_MODE" == true ] ; then
set -x
fi

if [ ! -z $HTTP_PROXY ]; then
echo "---> Setting npm http proxy to" $(safeLogging $HTTP_PROXY)
npm config set proxy $HTTP_PROXY
Expand All @@ -60,6 +64,7 @@ fi

# Change the npm registry mirror if provided
if [ -n "$NPM_MIRROR" ]; then
echo "---> Setting the npm package mirror to $NPM_MIRROR"
npm config set registry $NPM_MIRROR
fi

Expand All @@ -78,19 +83,37 @@ if [ -z "$NODE_ENV" ]; then
fi
fi

if [ "$NODE_ENV" != "production" ]; then
echo -e "Current git config"
git config --list

if [ -n "$YARN_ENABLED" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation of YARN_ENABLED is fine. But we will have the same problem with NEXUS_REGISTRY.
I would prefer to add to the condition NPM_MIRROR also yarn config set registry or define a new variable called YARN_MIRROR.

echo "---> Using 'yarn install' with YARN_ARGS"
yarn install $YARN_ARGS

elif [ "$NODE_ENV" != "production" ]; then

echo "---> Building your Node application from source"
npm install

# Do not fail when there is no build script
echo "---> Building in development mode"
npm run build --if-present
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 build --if-present
HAS_BUILD=$(node -e "console.log(require('./package.json').scripts.build ? true : false)")

# Check to see if there is a build script by inspecting the package.json
if [ "$HAS_BUILD" == true ]; then
# Do a npm install to get the dev depdencies
echo "---> Installing dev dependencies"
NODE_ENV=development npm install
# Do not fail when there is no build script
echo "---> Building in production mode"
npm run build --if-present
else
echo "---> Using 'npm install -s --only=production'"
npm install -s --only=production
fi

echo "---> Pruning the development dependencies"
npm prune
Expand All @@ -112,5 +135,11 @@ else

fi

# TODO: Do we need cache or not actually?
# based on the following commit, it doesn't seem so:
# https://github.com/sclorg/s2i-nodejs-container/commit/0e9b5cbb2fe719c447ed3a96fd534f6b2e2ca888
# echo "---> Cleaning up npm cache"
# rm -rf .npm

# Fix source directory permissions
fix-permissions ./
13 changes: 10 additions & 3 deletions 10/s2i/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,32 @@ if [ -e "/opt/app-root/etc/generate_container_user" ]; then
source /opt/app-root/etc/generate_container_user
fi

export GIT_COMMITTER_NAME="${GIT_COMMITTER_NAME:-unknown}"
export GIT_COMMITTER_EMAIL="${GIT_COMMITTER_EMAIL:-unknown@localhost.com}"
git --version

# 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}"
echo -e "Running as user $(id)"
if [ "$DEV_MODE" == true ]; then
echo "Installing dev dependencies..."
npm install
echo "Launching via nodemon..."
exec nodemon --inspect="$DEBUG_PORT"
exec npx nodemon --inspect="$DEBUG_PORT"
else
echo "Launching via npm..."
exec npm run -d $NPM_RUN
fi
}

#Set the debug port to 5858 by default.
# 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.
# Set the DEV_MODE to false by default.
if [ -z "$DEV_MODE" ]; then
export DEV_MODE=false
fi
Expand Down
4 changes: 2 additions & 2 deletions 10/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-8 ${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=8/test/test-app/ ${NAMESPACE}/nodejs-8-${DISTRO}7 nodejs-sample-app
s2i build https://github.com/sclorg/s2i-nodejs-container.git --context-dir=${NODEJS_VERSION}/test/test-app/ ${NAMESPACE}/nodejs-${NODEJS_VERSION}-${DISTRO} nodejs-sample-app

You can then run the resulting image via:
podman run -p 8080:8080 nodejs-sample-app
Expand Down
11 changes: 6 additions & 5 deletions 12/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ENV NODEJS_VERSION=12 \
NPM_RUN=start \
NAME=nodejs \
NPM_CONFIG_PREFIX=$HOME/.npm-global \
DEBUG_PORT=5858 \
CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nodejs \
NODEJS_PREFIX=/opt/rh/rh-$NAME$NODEJS_VERSION/root/usr \
PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH

ENV SUMMARY="Platform for building and running Node.js $NODEJS_VERSION applications" \
Expand All @@ -40,7 +43,7 @@ LABEL summary="$SUMMARY" \
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.dev-mode.port="DEBUG_PORT:${DEBUG_PORT}"\
com.redhat.component="rh-$NAME$NODEJS_VERSION-container" \
name="centos/$NAME-$NODEJS_VERSION-centos7" \
version="$NODEJS_VERSION" \
Expand All @@ -51,7 +54,6 @@ LABEL summary="$SUMMARY" \
RUN yum install -y centos-release-scl-rh && \
( [ "rh-${NAME}${NODEJS_VERSION}" != "${NODEJS_SCL}" ] && yum remove -y ${NODEJS_SCL}\* || : ) && \
INSTALL_PKGS="rh-nodejs${NODEJS_VERSION} rh-nodejs${NODEJS_VERSION}-npm rh-nodejs${NODEJS_VERSION}-nodejs-nodemon nss_wrapper" && \
ln -s /usr/lib/node_modules/nodemon/bin/nodemon.js /usr/bin/nodemon && \
yum-config-manager --add-repo https://cbs.centos.org/repos/sclo7-rh-nodejs${NODEJS_VERSION}-rh-candidate/x86_64/os/ && \
echo gpgcheck=0 >> /etc/yum.repos.d/cbs.centos.org_repos_sclo7-rh-nodejs${NODEJS_VERSION}-rh-candidate_x86_64_os_.repo && \
yum install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \
Expand All @@ -64,9 +66,8 @@ COPY ./s2i/bin/ $STI_SCRIPTS_PATH
# 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
# Run further installation commands
RUN ${CONTAINER_SCRIPTS_PATH}/nodejs_container_install

USER 1001

Expand Down
10 changes: 6 additions & 4 deletions 12/Dockerfile.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ ENV NODEJS_VERSION=12 \
NPM_RUN=start \
NAME=nodejs \
NPM_CONFIG_PREFIX=$HOME/.npm-global \
DEBUG_PORT=5858 \
CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/nodejs \
NODEJS_PREFIX=/usr \
PATH=$HOME/node_modules/.bin/:$HOME/.npm-global/bin/:$PATH

ENV SUMMARY="Platform for building and running Node.js $NODEJS_VERSION applications" \
Expand All @@ -40,7 +43,7 @@ LABEL summary="$SUMMARY" \
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.dev-mode.port="DEBUG_PORT:${DEBUG_PORT}"\
com.redhat.component="$NAME" \
name="$FGC/$NAME" \
version="$VERSION" \
Expand Down Expand Up @@ -68,9 +71,8 @@ COPY ./s2i/bin/ $STI_SCRIPTS_PATH
# 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
# Run further installation commands
RUN ${CONTAINER_SCRIPTS_PATH}/nodejs_container_install

USER 1001

Expand Down
Loading