diff --git a/.claude/CLAUDE.md b/.claude/CLAUDE.md new file mode 100644 index 00000000..3b6025ed --- /dev/null +++ b/.claude/CLAUDE.md @@ -0,0 +1,157 @@ +# s2i-nodejs-container Project Guide + +## Overview + +This repository contains the source for building various versions of Node.js container images using source-to-image (s2i). It supports multiple distributions (RHEL, CentOS Stream, Fedora) and uses distgen for template-based multi-distro generation. + +## Repository Structure + +``` +. +├── specs/ +│ └── multispec.yml # Version and distro configuration +├── manifest.yml # File generation rules for standard images +├── manifest-minimal.yml # File generation rules for minimal images +├── src/ # Jinja2 template files +│ ├── Dockerfile # Main Dockerfile template +│ ├── Dockerfile.minimal # Minimal Dockerfile template +│ ├── README.md # README template +│ └── s2i/ # S2I script templates +├── / # Generated version directories (e.g., 22/, 24/, 26/) +│ ├── Dockerfile.rhel8 +│ ├── Dockerfile.rhel9 +│ ├── Dockerfile.rhel10 +│ ├── Dockerfile.c9s +│ ├── Dockerfile.c10s +│ ├── Dockerfile.fedora +│ ├── README.md +│ └── ... +├── -minimal/ # Generated minimal variant directories +└── common/ # Git submodule with shared scripts +``` + +## Distgen Workflow + +This project uses **distgen** to generate Dockerfiles and other files from templates: + +1. **Templates** in `src/` use Jinja2 syntax with variables like `{{ spec.* }}` +2. **Configuration** in `specs/multispec.yml` defines: + - `distroinfo`: Configuration for each distribution (rhel8, rhel9, rhel10, c9s, c10s, fedora) + - `version`: Configuration for each Node.js version + - `matrix`: Which versions are built for which distros +3. **Manifest files** (`manifest.yml`, `manifest-minimal.yml`) define rules for generating/copying files +4. **Generation** creates version-specific directories with Dockerfiles for each distro + +### Key Distgen Concepts + +- **Modern distros** (RHEL10, C10S, Fedora): Use versioned packages like `nodejs$NODEJS_VERSION` +- **Legacy distros** (RHEL8/9, C9S): Use DNF modules like `dnf module enable nodejs:$VERSION` +- **Minimal variants**: Use `microdnf` and minimal base images for smaller footprint +- **Template variables**: Accessed via `{{ spec.variable_name }}` in templates +- **Conditionals**: Use `{% if spec.prod == 'fedora' %}...{% endif %}` for distro-specific logic + +## Available Skills + +### `/add-distgen-version` + +Add a new Node.js version to this repository. This skill guides you through: + +1. Updating `specs/multispec.yml` with new version definition +2. Adding version to the distribution matrix +3. Generating Dockerfiles for all supported distros +4. Running verification and tests + +**Usage:** Invoke when adding a new Node.js version (e.g., Node.js 26, 28, etc.) + +**Example:** +``` +User: "Add Node.js 26 support" +Assistant: [Invokes /add-distgen-version skill] +``` + +## Common Tasks + +### Adding a New Version + +Use the `/add-distgen-version` skill to guide you through the process. + +### Regenerating Files + +After modifying templates or configuration: + +```bash +# Generate files for a specific version +make distgen VERSION=26 + +# Or generate all versions +make distgen +``` + +### Testing + +```bash +# Build a specific version for a specific distro +make build TARGET=c9s VERSIONS=26 + +# Test a specific version +make test TARGET=c9s VERSIONS=26 + +# Test all versions +make test +``` + +### Verification + +```bash +# Run distgen integration verification +./verify-distgen-integration.sh +``` + +## Important Patterns + +### Version Numbering +- Standard versions: "22", "24", "26" +- Minimal versions: "22-minimal", "24-minimal", "26-minimal" + +### Supported Distributions +- **RHEL 8** (`rhel8`): Legacy, uses DNF modules +- **RHEL 9** (`rhel9`): Legacy, uses DNF modules +- **RHEL 10** (`rhel10`): Modern, uses versioned packages +- **CentOS Stream 9** (`c9s`): Legacy, uses DNF modules +- **CentOS Stream 10** (`c10s`): Modern, uses versioned packages +- **Fedora** (`fedora`): Modern, uses versioned packages + +### File Generation Rules + +From `manifest.yml`: +- `DISTGEN_MULTI_RULES`: Files generated for each (version, distro) combination +- `DISTGEN_RULES`: Files generated once per version +- `COPY_RULES`: Files copied without template processing +- `SYMLINK_RULES`: Symbolic links created + +## Git Workflow + +- **Main branch**: `master` +- **Current branch**: `add-nodejs-26` (adding Node.js 26 support) +- **Feature branches**: Create for new versions or features + +## Dependencies + +- **distgen**: Template generation tool (`pip install distgen`) +- **common submodule**: Shared scripts and tools (`git submodule update --init`) +- **make**: Build automation +- **podman/docker**: Container runtime for testing + +## References + +- [Source-to-Image (S2I)](https://github.com/openshift/source-to-image) +- [sclorg Community](https://github.com/sclorg) +- [Distgen Documentation](https://github.com/devexp-db/distgen) +- [PostgreSQL Container Example](https://github.com/sclorg/postgresql-container) + +## Notes + +- Never run `git push` - this is configured in memory preferences +- Always test on at least one distro before generating all variants +- Check upstream package availability before adding new distros to matrix +- Verify templates before running full distgen to catch errors early diff --git a/.claude/skills/add-distgen-version.md b/.claude/skills/add-distgen-version.md new file mode 100644 index 00000000..c3d25b60 --- /dev/null +++ b/.claude/skills/add-distgen-version.md @@ -0,0 +1,317 @@ +--- +name: add-distgen-version +description: Add a new version to distgen-enabled sclorg container repositories +trigger: always +--- + +# Add New Version to Distgen-Enabled Container + +This skill helps add a new version to any sclorg container repository that uses distgen for multi-distro support (e.g., nodejs, postgresql, mariadb, redis, etc.). + +## Prerequisites + +Before starting, gather the following information from the user: + +1. **New version number** (e.g., "26" for Node.js 26) +2. **Previous version number** to use as a template (e.g., "24") +3. **Whether minimal variant is needed** (yes/no) +4. **Package-specific information**: + - Package names for different distros (if they differ from previous version) + - Build dependencies (if they changed) + - Any version-specific requirements or constraints + +## Distgen Structure Overview + +Distgen-enabled repositories have this structure: + +``` +repository/ +├── specs/ +│ └── multispec.yml # Version and distro definitions +├── manifest.yml # File generation rules for standard images +├── manifest-minimal.yml # File generation rules for minimal images (if applicable) +├── src/ # Template files with Jinja2 syntax +│ ├── Dockerfile # Main Dockerfile template +│ ├── Dockerfile.minimal # Minimal Dockerfile template (if applicable) +│ ├── README.md # README template +│ └── ... # Other template files +├── / # Generated directories for each version +│ ├── Dockerfile.rhel8 +│ ├── Dockerfile.rhel9 +│ ├── Dockerfile.c9s +│ └── ... +└── verify-distgen-integration.sh # Verification script +``` + +## Step-by-Step Process + +### 1. Read and Understand Current Configuration + +First, read the existing configuration to understand the repository structure: + +```bash +# Read the multispec configuration +Read specs/multispec.yml + +# Read manifest files +Read manifest.yml +# If minimal images exist: +Read manifest-minimal.yml +``` + +### 2. Identify the Previous Version Configuration + +Find the most recent version definition in `specs/multispec.yml` that will serve as a template. Look under the `specs.version` section for the previous version (e.g., "24") and note: + +- Package names (`pkgs`) +- Build dependencies (`build_deps`) +- Minimal packages (`minimal_pkgs`) if applicable +- Base image references +- Special flags or features + +### 3. Add New Version Definition + +Add the new version to `specs/multispec.yml` in the `specs.version` section: + +**For standard variant:** +```yaml +"": + version: "" + prev_version: "" + short: "" + prev_short: "" + common_image_name: "{{ spec.org }}/-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/-{{ spec.short }}" + latest_fedora: "f45" # Update as needed + fedora_base: "quay.io/fedora/s2i-core:44" # Update as needed + pkg_manager: "dnf" + pkgs: >- + {% if spec.prod in ['rhel10', 'c10s', 'fedora'] -%} + # List versioned packages for modern distros + {%- else -%} + # List non-versioned packages for legacy distros + {%- endif %} + build_deps: >- + {% if spec.prod == 'rhel8' -%} + # RHEL8-specific build deps + {%- elif spec.prod == 'fedora' -%} + # Fedora-specific build deps + {%- elif spec.prod in ['rhel9', 'c9s'] -%} + # RHEL9/C9S-specific build deps + {%- else -%} + # Default build deps + {%- endif %} +``` + +**For minimal variant (if applicable):** +```yaml +"-minimal": + version: "" + prev_version: "" + short: "-minimal" + prev_short: "-minimal" + common_image_name: "{{ spec.org }}/-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/-{{ spec.short }}" + latest_fedora: "f45" + fedora_minimal_base: "quay.io/fedora/fedora-minimal:44" + pkg_manager: "microdnf" + minimal_pkgs: >- + {% if spec.prod in ['rhel10', 'c10s', 'fedora'] -%} + # Minimal packages for modern distros + {%- else -%} + # Minimal packages for legacy distros + {%- endif %} + # Copy pkgs and build_deps from standard variant +``` + +### 4. Update the Distribution Matrix + +Add the new version to the `matrix.include` section at the end of `specs/multispec.yml`: + +```yaml +matrix: + include: + # ... existing versions ... + - version: "" + distros: + - rhel-8-x86_64 # If supported + - rhel-9-x86_64 + - rhel-10-x86_64 # Modern RHEL + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 # Modern CentOS + - fedora-43-x86_64 # Update Fedora version as needed + + # If minimal variant exists: + - version: "-minimal" + distros: + # Same distro list as standard variant +``` + +**Important:** Check which distros are supported for the new version: +- Modern versions (22+) typically support rhel10 and c10s +- Older versions may not support these modern distros +- Check upstream package availability for each distro + +### 5. Generate Dockerfiles Using Distgen + +After updating `specs/multispec.yml`, generate the Dockerfiles using the distgen tool: + +```bash +# Install distgen if not available +python3 -m pip install distgen --user + +# Generate files for all versions +dg --multispec specs/multispec.yml \ + --multispec-combinations version= \ + --distro fedora-43-x86_64 \ + --template src/Dockerfile \ + --output /Dockerfile.fedora + +# Or use the common make target if available +make generate-all +# Or +make distgen +``` + +Typically, you should run distgen for each combination of (version, distro): +- For each distro in the matrix for your version +- For both standard and minimal variants (if applicable) + +### 6. Verify Generated Files + +Check that the generated files are correct: + +```bash +# List generated files +ls / + +# Check a sample Dockerfile +Read /Dockerfile.c9s + +# Verify template variables were substituted correctly +grep "NODEJS_VERSION=" /Dockerfile.c9s +``` + +### 7. Run Verification Script + +If a verification script exists, run it: + +```bash +./verify-distgen-integration.sh +``` + +If the script doesn't exist or needs updating for the new version, update it to check: +- New version directories exist +- Dockerfiles contain correct version numbers +- Required distros are present +- Template variables were substituted + +### 8. Update README and Documentation + +Update the main README.md to include the new version: + +```bash +# The README is typically generated from src/README.md template +# Regenerate it using distgen, or manually update the version table +``` + +### 9. Test Build + +Test that the new version builds correctly: + +```bash +# Test with one distro first +make build TARGET=c9s VERSIONS= + +# Test all distros for the new version +make build VERSIONS= + +# Test the minimal variant if applicable +make build VERSIONS=-minimal +``` + +## Common Patterns by Repository Type + +### Node.js-style repositories +- Versions include both standard and minimal variants +- Modern distros (rhel10, c10s, fedora) use versioned packages: `nodejs$NODEJS_VERSION` +- Legacy distros (rhel8, rhel9, c9s) use DNF modules: `dnf module enable nodejs:$VERSION` +- Special build tools for newer versions (gcc-toolset-13 for rhel8) + +### PostgreSQL-style repositories +- Version numbers may be different format (e.g., "16", "15") +- May use SCL (Software Collections) for RHEL +- Database-specific configuration in templates + +### General patterns +- Always copy structure from the previous version +- Check if package names changed upstream +- Verify base image versions are current +- Test on at least one distro before generating all + +## Troubleshooting + +### Template variables not substituted +- Check that the variable name matches what's defined in multispec.yml +- Verify Jinja2 syntax: `{{ spec.variable_name }}` +- Check conditional blocks: `{% if %}...{% endif %}` + +### Distgen command fails +- Ensure distgen is installed: `python3 -m pip install distgen` +- Check YAML syntax in multispec.yml: `yamllint specs/multispec.yml` +- Verify template file exists: `ls src/Dockerfile*` + +### Missing distros +- Check the matrix section includes all desired distros +- Verify distro names match exactly (e.g., `fedora-43-x86_64`) +- Check if distro is defined in the `distroinfo` section + +### Generated files have wrong values +- Review the version definition in multispec.yml +- Check conditional logic in templates (`{% if spec.prod == 'fedora' %}`) +- Verify package names are correct for that distro version + +## Example: Adding Node.js 26 + +```bash +# 1. Edit specs/multispec.yml to add version "26" and "26-minimal" +Edit specs/multispec.yml + +# 2. Add to matrix section +Edit specs/multispec.yml # Add matrix entry + +# 3. Generate Dockerfiles +make distgen + +# 4. Verify +./verify-distgen-integration.sh + +# 5. Test build +make build TARGET=c9s VERSIONS=26 + +# 6. Create PR +git add specs/multispec.yml 26/ 26-minimal/ +git commit -m "Add support for Node.js 26 and 26-minimal" +``` + +## Output + +After completing this process, you should have: + +1. ✅ Updated `specs/multispec.yml` with new version definition(s) +2. ✅ New version directory with Dockerfiles for all supported distros +3. ✅ New minimal version directory (if applicable) +4. ✅ Verification script passing +5. ✅ Successfully tested build on at least one distro +6. ✅ Updated README and documentation + +## Notes + +- Always base the new version on the most recent previous version +- Test on one distro before generating all to catch template errors early +- Check upstream package availability before adding distros to the matrix +- Modern distros (RHEL10+, C10S+, Fedora) typically use versioned packages +- Legacy distros (RHEL8/9, C9S) often use DNF modules or SCL +- Some repositories may have custom scripts for running distgen - check the Makefile diff --git a/26-minimal/Dockerfile.c10s b/26-minimal/Dockerfile.c10s new file mode 100644 index 00000000..ede0ce37 --- /dev/null +++ b/26-minimal/Dockerfile.c10s @@ -0,0 +1,68 @@ +FROM quay.io/centos/centos:stream10-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="c10s" \ + NODEJS_VERSION=26 \ + 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}-container-minimal" \ + name="sclorg/$NAME-$NODEJS_VERSION-minimal-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" + +# 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" && \ + microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + rm -f /usr/bin/node && ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + rm -f /usr/bin/npm && ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + rm -f /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" && \ + 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 \ No newline at end of file diff --git a/26-minimal/Dockerfile.c9s b/26-minimal/Dockerfile.c9s new file mode 100644 index 00000000..cdf06e92 --- /dev/null +++ b/26-minimal/Dockerfile.c9s @@ -0,0 +1,67 @@ +FROM quay.io/centos/centos:stream9-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="c9s" \ + NODEJS_VERSION=26 \ + 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}-container-minimal" \ + name="sclorg/$NAME-$NODEJS_VERSION-minimal-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" + +# 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 \ No newline at end of file diff --git a/26-minimal/Dockerfile.fedora b/26-minimal/Dockerfile.fedora new file mode 100644 index 00000000..453729dc --- /dev/null +++ b/26-minimal/Dockerfile.fedora @@ -0,0 +1,70 @@ +FROM quay.io/fedora/fedora-minimal:44 + +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=26 \ + 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}-container-minimal" \ + name="fedora/$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_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n nodejs$NODEJS_VERSION-npm findutils tar which" && \ + microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + rm -f /usr/bin/node && ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + rm -f /usr/bin/npm && ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + rm -f /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" && \ + 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 \ No newline at end of file diff --git a/26-minimal/Dockerfile.rhel10 b/26-minimal/Dockerfile.rhel10 new file mode 100644 index 00000000..c3f87cc8 --- /dev/null +++ b/26-minimal/Dockerfile.rhel10 @@ -0,0 +1,68 @@ +FROM ubi10/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="ubi10" \ + NODEJS_VERSION=26 \ + 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}-container-minimal" \ + name="ubi10/$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_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n nodejs$NODEJS_VERSION-npm findutils tar which" && \ + microdnf -y --nodocs --setopt=install_weak_deps=0 install $INSTALL_PKGS && \ + rm -f /usr/bin/node && ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + rm -f /usr/bin/npm && ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + rm -f /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" && \ + 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 \ No newline at end of file diff --git a/26-minimal/Dockerfile.rhel8 b/26-minimal/Dockerfile.rhel8 new file mode 100644 index 00000000..31aaf8a3 --- /dev/null +++ b/26-minimal/Dockerfile.rhel8 @@ -0,0 +1,67 @@ +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="ubi8" \ + NODEJS_VERSION=26 \ + 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}-container-minimal" \ + 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 -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 \ No newline at end of file diff --git a/26-minimal/Dockerfile.rhel9 b/26-minimal/Dockerfile.rhel9 new file mode 100644 index 00000000..2729ca55 --- /dev/null +++ b/26-minimal/Dockerfile.rhel9 @@ -0,0 +1,67 @@ +FROM ubi9/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="ubi9" \ + NODEJS_VERSION=26 \ + 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}-container-minimal" \ + 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 \ No newline at end of file diff --git a/26-minimal/README.md b/26-minimal/README.md new file mode 100644 index 00000000..c3c2ecca --- /dev/null +++ b/26-minimal/README.md @@ -0,0 +1,376 @@ +NodeJS 26 minimal container image +========================= + +This container image includes Node.JS 26 on top of a minimal base image for your Node.JS 26 applications. This image is designed to be used +with the full-sized s2i-enabled Node.JS 26 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 26 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 26 available as a minimal container is a base platform for +running various Node.js 26 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-26` image, available via `nodejs:26-ubi8` imagestream tag in Openshift +to build the application, as well as the `ubi8/nodejs-26-minimal` image, available via `nodejs:26-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:26-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:26-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:26-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-26 +podman pull ubi8/nodejs-26-minimal +``` + +The UBI images `ubi8/nodejs-26` and `ubi8/nodejs-26-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-26 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-26-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-26 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-26-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` environment variable is specified, then `init-wrapper` script will use the value of `NODE_CMD` to start your application. + +#### Additional variables used in the full-sized image + +**`HTTP_PROXY`** + Use an npm proxy during assembly + +**`HTTPS_PROXY`** + Use an npm proxy during assembly + +**`NPM_MIRROR`** + Use a custom NPM registry mirror to download packages during the build process + +**`NPM_TOKEN`** + Use authentication token for a custom NPM registry mirror + +One way to define a set of environment variables is to include them as key-value pairs in your repo's `.s2i/environment` file. + +Example: DATABASE_USER=sampleUser + +#### NOTE: Define your own "`DEV_MODE`": + +The following `package.json` example includes a `scripts.dev` entry. You can define your own custom [`NPM_RUN`](https://docs.npmjs.com/cli/run-script) scripts in your application's `package.json` file. + +#### Note: Setting logging output verbosity +To alter the level of logs output during an `npm install` the npm_config_loglevel environment variable can be set. See [npm-config](https://docs.npmjs.com/misc/config). + +Development Mode +---------------- +This image supports development mode. This mode can be switched on and off with the environment variable `DEV_MODE`. `DEV_MODE` can either be set to `true` or `false`. +Development mode supports two features: +* Hot Deploy +* Debugging + +The debug port can be specified with the environment variable `DEBUG_PORT`. `DEBUG_PORT` is only valid if `DEV_MODE=true`. + +A simple example command for running the container in development mode is: +``` +podman run --env DEV_MODE=true my-image-id +``` + +To run the container in development mode with a debug port of 5454, run: +``` +$ podman run --env DEV_MODE=true --env 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 source 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", + "dependencies": { + }, + "devDependencies": { + "nodemon": "*" + }, + "engine": { + "node": "*", + "npm": "*" + }, + "scripts": { + "dev": "nodemon --ignore node_modules/ server.js", + "start": "node server.js" + }, + "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 available 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=true -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 other 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/26-minimal/root/usr/bin/fix-permissions b/26-minimal/root/usr/bin/fix-permissions new file mode 100755 index 00000000..ddd33ace --- /dev/null +++ b/26-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/26-minimal/s2i/bin/assemble b/26-minimal/s2i/bin/assemble new file mode 100755 index 00000000..3230d038 --- /dev/null +++ b/26-minimal/s2i/bin/assemble @@ -0,0 +1,123 @@ +#!/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 + +# Change the npm authentication token if provided +if [ -n "$NPM_TOKEN" ]; then + echo "---> Setting npm authentication token for $NPM_MIRROR" + INTERNAL_NPM_REGISTRY=$(echo "$NPM_MIRROR" | sed -n 's|https://||p') + npm config set "//${INTERNAL_NPM_REGISTRY:-registry.npmjs.org}:_auth" $NPM_TOKEN +fi + +# Set the DEV_MODE to false by default. +if [ -z "$DEV_MODE" ]; then + export DEV_MODE=false +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/26-minimal/s2i/bin/init-wrapper b/26-minimal/s2i/bin/init-wrapper new file mode 100755 index 00000000..24e0d078 --- /dev/null +++ b/26-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/26-minimal/s2i/bin/run b/26-minimal/s2i/bin/run new file mode 100755 index 00000000..62255c5b --- /dev/null +++ b/26-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 \ No newline at end of file diff --git a/26-minimal/s2i/bin/save-artifacts b/26-minimal/s2i/bin/save-artifacts new file mode 100755 index 00000000..16be05e7 --- /dev/null +++ b/26-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/26-minimal/s2i/bin/usage b/26-minimal/s2i/bin/usage new file mode 100755 index 00000000..b8c1dca8 --- /dev/null +++ b/26-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/26-minimal/test/__init__.py b/26-minimal/test/__init__.py new file mode 120000 index 00000000..d0f4746a --- /dev/null +++ b/26-minimal/test/__init__.py @@ -0,0 +1 @@ +../../test/__init__.py \ No newline at end of file diff --git a/26-minimal/test/check_imagestreams.py b/26-minimal/test/check_imagestreams.py new file mode 120000 index 00000000..56bb2be7 --- /dev/null +++ b/26-minimal/test/check_imagestreams.py @@ -0,0 +1 @@ +../../common/check_imagestreams.py \ No newline at end of file diff --git a/26-minimal/test/conftest.py b/26-minimal/test/conftest.py new file mode 120000 index 00000000..3f2d7840 --- /dev/null +++ b/26-minimal/test/conftest.py @@ -0,0 +1 @@ +../../test/conftest.py \ No newline at end of file diff --git a/26-minimal/test/examples b/26-minimal/test/examples new file mode 120000 index 00000000..da7b1965 --- /dev/null +++ b/26-minimal/test/examples @@ -0,0 +1 @@ +../../examples/ \ No newline at end of file diff --git a/26-minimal/test/imagestreams b/26-minimal/test/imagestreams new file mode 120000 index 00000000..0dcbe9e0 --- /dev/null +++ b/26-minimal/test/imagestreams @@ -0,0 +1 @@ +../../imagestreams/ \ No newline at end of file diff --git a/26-minimal/test/run b/26-minimal/test/run new file mode 120000 index 00000000..f446a740 --- /dev/null +++ b/26-minimal/test/run @@ -0,0 +1 @@ +../../test/run-minimal \ No newline at end of file diff --git a/26-minimal/test/run-openshift-remote-cluster b/26-minimal/test/run-openshift-remote-cluster new file mode 120000 index 00000000..1bffcba8 --- /dev/null +++ b/26-minimal/test/run-openshift-remote-cluster @@ -0,0 +1 @@ +../../test/run-openshift-remote-cluster \ No newline at end of file diff --git a/26-minimal/test/run-pytest b/26-minimal/test/run-pytest new file mode 120000 index 00000000..efe32b48 --- /dev/null +++ b/26-minimal/test/run-pytest @@ -0,0 +1 @@ +../../test/run-pytest \ No newline at end of file diff --git a/26-minimal/test/test-app b/26-minimal/test/test-app new file mode 120000 index 00000000..6ba4f290 --- /dev/null +++ b/26-minimal/test/test-app @@ -0,0 +1 @@ +../../test/test-app \ No newline at end of file diff --git a/26-minimal/test/test-binary b/26-minimal/test/test-binary new file mode 120000 index 00000000..cd7b631f --- /dev/null +++ b/26-minimal/test/test-binary @@ -0,0 +1 @@ +../../test/test-binary \ No newline at end of file diff --git a/26-minimal/test/test-express-webapp b/26-minimal/test/test-express-webapp new file mode 120000 index 00000000..6a5bbd41 --- /dev/null +++ b/26-minimal/test/test-express-webapp @@ -0,0 +1 @@ +../../test/test-express-webapp \ No newline at end of file diff --git a/26-minimal/test/test-fips b/26-minimal/test/test-fips new file mode 120000 index 00000000..fbe9489f --- /dev/null +++ b/26-minimal/test/test-fips @@ -0,0 +1 @@ +../../test/test-fips \ No newline at end of file diff --git a/26-minimal/test/test-hw b/26-minimal/test/test-hw new file mode 120000 index 00000000..ad784558 --- /dev/null +++ b/26-minimal/test/test-hw @@ -0,0 +1 @@ +../../test/test-hw \ No newline at end of file diff --git a/26-minimal/test/test-incremental b/26-minimal/test/test-incremental new file mode 120000 index 00000000..0a357b1f --- /dev/null +++ b/26-minimal/test/test-incremental @@ -0,0 +1 @@ +../../test/test-incremental \ No newline at end of file diff --git a/26-minimal/test/test-lib-nodejs.sh b/26-minimal/test/test-lib-nodejs.sh new file mode 120000 index 00000000..8915d844 --- /dev/null +++ b/26-minimal/test/test-lib-nodejs.sh @@ -0,0 +1 @@ +../../test/test-lib-nodejs.sh \ No newline at end of file diff --git a/26-minimal/test/test-lib-openshift.sh b/26-minimal/test/test-lib-openshift.sh new file mode 120000 index 00000000..4f9f2996 --- /dev/null +++ b/26-minimal/test/test-lib-openshift.sh @@ -0,0 +1 @@ +../../common/test-lib-openshift.sh \ No newline at end of file diff --git a/26-minimal/test/test-lib-remote-openshift.sh b/26-minimal/test/test-lib-remote-openshift.sh new file mode 120000 index 00000000..92ad2f4d --- /dev/null +++ b/26-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/26-minimal/test/test-lib.sh b/26-minimal/test/test-lib.sh new file mode 120000 index 00000000..1ac99b93 --- /dev/null +++ b/26-minimal/test/test-lib.sh @@ -0,0 +1 @@ +../../common/test-lib.sh \ No newline at end of file diff --git a/26-minimal/test/test-openshift.yaml b/26-minimal/test/test-openshift.yaml new file mode 120000 index 00000000..8613fbba --- /dev/null +++ b/26-minimal/test/test-openshift.yaml @@ -0,0 +1 @@ +../../common/test-openshift.yaml \ No newline at end of file diff --git a/26-minimal/test/test_container_apps.py b/26-minimal/test/test_container_apps.py new file mode 120000 index 00000000..9870de8e --- /dev/null +++ b/26-minimal/test/test_container_apps.py @@ -0,0 +1 @@ +../../test/test_container_apps.py \ No newline at end of file diff --git a/26-minimal/test/test_container_basics.py b/26-minimal/test/test_container_basics.py new file mode 120000 index 00000000..b85dc139 --- /dev/null +++ b/26-minimal/test/test_container_basics.py @@ -0,0 +1 @@ +../../test/test_container_basics.py \ No newline at end of file diff --git a/26/Dockerfile.c10s b/26/Dockerfile.c10s new file mode 100644 index 00000000..29a76725 --- /dev/null +++ b/26/Dockerfile.c10s @@ -0,0 +1,73 @@ +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 + +ENV NODEJS_VERSION=26 \ + 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-26 \ + 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-26" \ + 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" \ + 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 sclorg/$NAME-$NODEJS_VERSION-c10s " + +RUN INSTALL_PKGS="make gcc gcc-c++ git openssl-devel nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm nss_wrapper-libs which" && \ + dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + rm -f /usr/bin/node && ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + rm -f /usr/bin/npm && ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + rm -f /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 $STI_SCRIPTS_PATH/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/26/Dockerfile.c9s b/26/Dockerfile.c9s new file mode 100644 index 00000000..912a6d8a --- /dev/null +++ b/26/Dockerfile.c9s @@ -0,0 +1,74 @@ +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 + +ENV NODEJS_VERSION=26 \ + 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-26 \ + 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-26" \ + 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" \ + 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 sclorg/$NAME-$NODEJS_VERSION-c9s " + +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 reinstall tzdata || dnf -y update tzdata ) &&\ + 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 $STI_SCRIPTS_PATH/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/26/Dockerfile.fedora b/26/Dockerfile.fedora new file mode 100644 index 00000000..3a427408 --- /dev/null +++ b/26/Dockerfile.fedora @@ -0,0 +1,73 @@ +FROM quay.io/fedora/s2i-core:44 +# 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 + +ENV NODEJS_VERSION=26 \ + 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.fedora-nodejs-26 \ + 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.fedora-nodejs-26" \ + 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="fedora/$NAME-$NODEJS_VERSION" \ + 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/fedora/$NAME-$NODEJS_VERSION:latest " + +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 && \ + rm -f /usr/bin/node && ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + rm -f /usr/bin/npm && ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + rm -f /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 $STI_SCRIPTS_PATH/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/26/Dockerfile.rhel10 b/26/Dockerfile.rhel10 new file mode 100644 index 00000000..9372bd0e --- /dev/null +++ b/26/Dockerfile.rhel10 @@ -0,0 +1,73 @@ +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 + +ENV NODEJS_VERSION=26 \ + 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.ubi10-nodejs-26 \ + 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.ubi10-nodejs-26" \ + 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" \ + 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 " + +RUN INSTALL_PKGS="make gcc gcc-c++ git openssl-devel nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm nss_wrapper-libs which" && \ + dnf install -y --setopt=tsflags=nodocs $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + rm -f /usr/bin/node && ln -s /usr/bin/node-$NODEJS_VERSION /usr/bin/node && \ + rm -f /usr/bin/npm && ln -s /usr/bin/npm-$NODEJS_VERSION /usr/bin/npm && \ + rm -f /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 $STI_SCRIPTS_PATH/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/26/Dockerfile.rhel8 b/26/Dockerfile.rhel8 new file mode 100644 index 00000000..a3c3a3af --- /dev/null +++ b/26/Dockerfile.rhel8 @@ -0,0 +1,78 @@ +FROM ubi8/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 + +ENV NODEJS_VERSION=26 \ + 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-26 \ + 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-26" \ + 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" \ + 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 " + +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 reinstall tzdata || dnf -y update tzdata ) &&\ + 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 $STI_SCRIPTS_PATH/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/26/Dockerfile.rhel9 b/26/Dockerfile.rhel9 new file mode 100644 index 00000000..eeaa5baf --- /dev/null +++ b/26/Dockerfile.rhel9 @@ -0,0 +1,74 @@ +FROM ubi9/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 + +ENV NODEJS_VERSION=26 \ + 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-26 \ + 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-26" \ + 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" \ + 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 " + +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 reinstall tzdata || dnf -y update tzdata ) &&\ + 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 $STI_SCRIPTS_PATH/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/26/README.md b/26/README.md new file mode 100644 index 00000000..2b7dc888 --- /dev/null +++ b/26/README.md @@ -0,0 +1,305 @@ +NodeJS 26 container image +========================= + +This container image includes Node.JS 26 as a [S2I](https://github.com/openshift/source-to-image) base image for your Node.JS 26 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 26 available as container is a base platform for +building and running various Node.js 26 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-26` image, available via `nodejs:26` 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:26~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-26 +``` + +An UBI image `ubi8/nodejs-26` 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-26 + +# 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-26 + +# 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` environment variable is specified, then `init-wrapper` script will use the value of `NODE_CMD` to start your application. + +**`NPM_RUN`** + Select an alternate / custom runtime mode, defined in your `package.json` file's [`scripts`](https://docs.npmjs.com/misc/scripts) section (default: npm run "start"). These user-defined run-scripts are unavailable while `DEV_MODE` is in use. + +**`HTTP_PROXY`** + Use an npm proxy during assembly + +**`HTTPS_PROXY`** + Use an npm proxy during assembly + +**`NPM_MIRROR`** + Use a custom NPM registry mirror to download packages during the build process + +**`NPM_TOKEN`** + Use authentication token for a custom NPM registry mirror + +One way to define a set of environment variables is to include them as key-value pairs in your repo's `.s2i/environment` file. + +Example: DATABASE_USER=sampleUser + +#### NOTE: Define your own "`DEV_MODE`": + +The following `package.json` example includes a `scripts.dev` entry. You can define your own custom [`NPM_RUN`](https://docs.npmjs.com/cli/run-script) scripts in your application's `package.json` file. + +#### Note: Setting logging output verbosity +To alter the level of logs output during an `npm install` the npm_config_loglevel environment variable can be set. See [npm-config](https://docs.npmjs.com/misc/config). + +Development Mode +---------------- +This image supports development mode. This mode can be switched on and off with the environment variable `DEV_MODE`. `DEV_MODE` can either be set to `true` or `false`. +Development mode supports two features: +* Hot Deploy +* Debugging + +The debug port can be specified with the environment variable `DEBUG_PORT`. `DEBUG_PORT` is only valid if `DEV_MODE=true`. + +A simple example command for running the container in development mode is: +``` +podman run --env DEV_MODE=true my-image-id +``` + +To run the container in development mode with a debug port of 5454, run: +``` +$ podman run --env DEV_MODE=true --env 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 source 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", + "dependencies": { + }, + "devDependencies": { + "nodemon": "*" + }, + "engine": { + "node": "*", + "npm": "*" + }, + "scripts": { + "dev": "nodemon --ignore node_modules/ server.js", + "start": "node server.js" + }, + "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 available 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=true -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 other 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/26/root/opt/app-root/etc/generate_container_user b/26/root/opt/app-root/etc/generate_container_user new file mode 100644 index 00000000..b28a7a3d --- /dev/null +++ b/26/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/26/root/opt/app-root/etc/npm_global_module_list b/26/root/opt/app-root/etc/npm_global_module_list new file mode 100644 index 00000000..005e1501 --- /dev/null +++ b/26/root/opt/app-root/etc/npm_global_module_list @@ -0,0 +1,5 @@ +async +mime +mkdirp +qs +minimatch diff --git a/26/root/opt/app-root/etc/scl_enable b/26/root/opt/app-root/etc/scl_enable new file mode 100644 index 00000000..4bfebea0 --- /dev/null +++ b/26/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/26/s2i/bin/assemble b/26/s2i/bin/assemble new file mode 100755 index 00000000..3230d038 --- /dev/null +++ b/26/s2i/bin/assemble @@ -0,0 +1,123 @@ +#!/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 + +# Change the npm authentication token if provided +if [ -n "$NPM_TOKEN" ]; then + echo "---> Setting npm authentication token for $NPM_MIRROR" + INTERNAL_NPM_REGISTRY=$(echo "$NPM_MIRROR" | sed -n 's|https://||p') + npm config set "//${INTERNAL_NPM_REGISTRY:-registry.npmjs.org}:_auth" $NPM_TOKEN +fi + +# Set the DEV_MODE to false by default. +if [ -z "$DEV_MODE" ]; then + export DEV_MODE=false +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/26/s2i/bin/init-wrapper b/26/s2i/bin/init-wrapper new file mode 100755 index 00000000..24e0d078 --- /dev/null +++ b/26/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/26/s2i/bin/run b/26/s2i/bin/run new file mode 100755 index 00000000..44d2faa9 --- /dev/null +++ b/26/s2i/bin/run @@ -0,0 +1,85 @@ +#!/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 + + if [ -f "package.json" ]; 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) + fi + + 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/26/s2i/bin/save-artifacts b/26/s2i/bin/save-artifacts new file mode 100755 index 00000000..16be05e7 --- /dev/null +++ b/26/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/26/s2i/bin/usage b/26/s2i/bin/usage new file mode 100755 index 00000000..b8c1dca8 --- /dev/null +++ b/26/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/26/test b/26/test new file mode 120000 index 00000000..419df4f9 --- /dev/null +++ b/26/test @@ -0,0 +1 @@ +../test \ No newline at end of file diff --git a/Makefile b/Makefile index 424a5eab..8e3a2cfb 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Include common Makefile code. BASE_IMAGE_NAME = nodejs -VERSIONS = 22 22-minimal 24 24-minimal +VERSIONS = 22 22-minimal 24 24-minimal 26 26-minimal OPENSHIFT_NAMESPACES = # HACK: Ensure that 'git pull' for old clones doesn't cause confusion. diff --git a/specs/multispec.yml b/specs/multispec.yml index 26499111..e8d5e529 100644 --- a/specs/multispec.yml +++ b/specs/multispec.yml @@ -178,6 +178,34 @@ specs: make gcc gcc-c++ git openssl-devel {%- endif %} + "26": + version: "26" + prev_version: "24" + short: "26" + prev_short: "24" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + fedora_base: "quay.io/fedora/s2i-core:44" + pkg_manager: "dnf" + pkgs: >- + {% if spec.prod in ['rhel10', 'c10s', 'fedora'] -%} + nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm nss_wrapper-libs which + {%- else -%} + nodejs npm nodejs-nodemon nss_wrapper-libs which + {%- endif %} + build_deps: >- + {% if spec.prod == 'rhel8' -%} + make gcc-toolset-13-gcc gcc-toolset-13-gcc-c++ gcc-toolset-13-runtime libatomic_ops git openssl-devel python3.12 + {%- elif spec.prod == 'fedora' -%} + make gcc gcc-c++ libatomic_ops git openssl-devel + {%- elif spec.prod in ['rhel9', 'c9s'] -%} + make gcc gcc-c++ git openssl-devel + {%- else -%} + make gcc gcc-c++ git openssl-devel + {%- endif %} + "20-minimal": version: "20" short: "20-minimal" @@ -273,6 +301,38 @@ specs: make gcc gcc-c++ git openssl-devel {%- endif %} + "26-minimal": + version: "26" + prev_version: "24" + short: "26-minimal" + prev_short: "24-minimal" + common_image_name: "{{ spec.org }}/nodejs-{{ spec.short }}-{{ spec.prod }}" + c9s_image_name: "sclorg/nodejs-{{ spec.short }}-c9s" + rhel_image_name: "rhel9/nodejs-{{ spec.short }}" + latest_fedora: "f45" + fedora_minimal_base: "quay.io/fedora/fedora-minimal:44" + pkg_manager: "microdnf" + minimal_pkgs: >- + {% if spec.prod in ['rhel10', 'c10s', 'fedora'] -%} + nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-full-i18n nodejs$NODEJS_VERSION-npm findutils tar which + {%- else -%} + nodejs nodejs-nodemon nodejs-full-i18n npm findutils tar which + {%- endif %} + pkgs: >- + {% if spec.prod in ['rhel10', 'c10s', 'fedora'] -%} + nodejs$NODEJS_VERSION nodejs-nodemon nodejs$NODEJS_VERSION-npm nss_wrapper-libs which + {%- else -%} + nodejs npm nodejs-nodemon nss_wrapper-libs which + {%- endif %} + build_deps: >- + {% if spec.prod == 'fedora' -%} + make gcc gcc-c++ libatomic_ops git openssl-devel + {%- elif spec.prod in ['rhel8', 'rhel9', 'c9s'] -%} + make gcc gcc-c++ libatomic_ops git openssl-devel + {%- else -%} + make gcc gcc-c++ git openssl-devel + {%- endif %} + matrix: include: - version: "20" @@ -319,3 +379,19 @@ matrix: - centos-stream-9-x86_64 - centos-stream-10-x86_64 - fedora-43-x86_64 + - version: "26" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 + - version: "26-minimal" + distros: + - rhel-8-x86_64 + - rhel-9-x86_64 + - rhel-10-x86_64 + - centos-stream-9-x86_64 + - centos-stream-10-x86_64 + - fedora-43-x86_64 diff --git a/verify-distgen-integration.sh b/verify-distgen-integration.sh index e6dd69f9..07a9c156 100755 --- a/verify-distgen-integration.sh +++ b/verify-distgen-integration.sh @@ -116,7 +116,7 @@ fi echo echo "7. Checking CNB environment variables..." -for version in 22 24; do +for version in 22 24 26; do for distro in fedora rhel8 rhel9; do dockerfile="$version/Dockerfile.$distro" if [ -f "$dockerfile" ]; then @@ -178,10 +178,12 @@ echo "9. Checking version matrix coverage..." expected_v20=4 # rhel8, rhel9, c9s, fedora expected_v22=6 # rhel8, rhel9, rhel10, c9s, c10s, fedora expected_v24=6 # rhel8, rhel9, rhel10, c9s, c10s, fedora +expected_v26=6 # rhel8, rhel9, rhel10, c9s, c10s, fedora actual_v20=$(ls 20/Dockerfile.* 2>/dev/null | wc -l) actual_v22=$(ls 22/Dockerfile.* 2>/dev/null | wc -l) actual_v24=$(ls 24/Dockerfile.* 2>/dev/null | wc -l) +actual_v26=$(ls 26/Dockerfile.* 2>/dev/null | wc -l) if [ "$actual_v20" -eq "$expected_v20" ]; then check_pass "v20 has $expected_v20 distros" @@ -201,6 +203,12 @@ else check_fail "v24 has $actual_v24 distros, expected $expected_v24" fi +if [ "$actual_v26" -eq "$expected_v26" ]; then + check_pass "v26 has $expected_v26 distros" +else + check_fail "v26 has $actual_v26 distros, expected $expected_v26" +fi + echo echo "10. Checking for common submodule..." if [ -d "common/.git" ] || [ -f "common/.git" ]; then