Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support c10s nodejs 22 #443

Merged
merged 12 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion 20-minimal/test/check_imagestreams.py

This file was deleted.

105 changes: 105 additions & 0 deletions 20-minimal/test/check_imagestreams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/env python3

# MIT License
#
# Copyright (c) 2018-2019 Red Hat, Inc.

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import sys
import json
import logging
import os

from pathlib import Path
from typing import Dict, List, Any

IMAGESTREAMS_DIR: str = "imagestreams"


class ImageStreamChecker(object):
version: str = ""

def __init__(self, version: str):
self.version = version
self.results: Dict[Any, Any] = {}

def load_json_file(self, filename: Path) -> Any:
with open(str(filename)) as f:
data = json.load(f)
isinstance(data, Dict)
return data

def check_version(self, json_dict: Dict[Any, Any]) -> List[str]:
res = []
for tags in json_dict["spec"]["tags"]:
print(
f"check_version: Compare tags['name']:'{tags['name']}' against version:'{self.version}'"
)
# The name can be"<stream>" or "<stream>-elX" or "<stream>-ubiX"
if tags["name"] == self.version or tags["name"].startswith(
self.version + "-"
):
res.append(tags)
return res

def check_latest_tag(self, json_dict: Dict[Any, Any]) -> bool:
latest_tag_correct: bool = False
for tags in json_dict["spec"]["tags"]:
if tags["name"] != "latest":
continue
print(
f"check_latest_tag: Compare tags['name']:'{tags['name']}' against version:'{self.version}'"
)
# The latest can link to either "<stream>" or "<stream>-elX" or "<stream>-ubiX"
if tags["from"]["name"] == self.version or tags["from"]["name"].startswith(
self.version + "-"
):
latest_tag_correct = True
print(f"Latest tag found.")
return latest_tag_correct

def check_imagestreams(self) -> int:
p = Path(".")
json_files = p.glob(f"{IMAGESTREAMS_DIR}/*.json")
if not json_files:
print(f"No json files present in {IMAGESTREAMS_DIR}.")
return 0
for f in json_files:
print(f"Checking file {str(f)}.")
json_dict = self.load_json_file(f)
if not (self.check_version(json_dict) and self.check_latest_tag(json_dict)):
print(
f"The latest version is not present in {str(f)} or in latest tag."
)
self.results[f] = False
if self.results:
return 1
print("Imagestreams contains the latest version.")
return 0


if __name__ == "__main__":
if len(sys.argv) != 2:
logging.fatal("%s: %s", sys.argv[0], "VERSION as an argument was not provided")
sys.exit(1)

print(f"Version to check is {sys.argv[1]}.")
isc = ImageStreamChecker(version=sys.argv[1])
sys.exit(isc.check_imagestreams())
2 changes: 2 additions & 0 deletions 20-minimal/test/examples/from-dockerfile/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app-src

16 changes: 16 additions & 0 deletions 20-minimal/test/examples/from-dockerfile/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM registry.access.redhat.com/ubi8/nodejs-16

# Add application sources
ADD app-src .

# In case you run into permission errors during build (eg. by use of umask)
# running the fix-permission script will make sure all bits are as expected by the image
USER 0
RUN fix-permissions ./
USER 1001

# Install the dependencies
RUN npm install

# Run script uses standard ways to run the application
CMD npm run -d start
25 changes: 25 additions & 0 deletions 20-minimal/test/examples/from-dockerfile/Dockerfile.s2i
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM registry.access.redhat.com/ubi8/nodejs-16

# This image supports the Source-to-Image
# (see more at https://docs.openshift.com/container-platform/3.11/creating_images/s2i.html).
# In order to support the Source-to-Image framework, there are some interesting
# scripts inside the builder image, that can be run in a Dockerfile directly as well:
# * The `/usr/libexec/s2i/assemble` script inside the image is run in order
# 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.
# * The `/usr/libexec/s2i/run` script executes the application and is set as
# a default command in the resulting container image.

# 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

# Let the assemble script to install the dependencies
RUN /usr/libexec/s2i/assemble

# Run script uses standard ways to run the application
CMD /usr/libexec/s2i/run
22 changes: 22 additions & 0 deletions 20-minimal/test/examples/from-dockerfile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Dockerfile examples
===================

This directory contains example Dockerfiles that demonstrate how to use the image with a Dockerfile and `docker build`.

For demonstration, we use an application code available at https://github.com/sclorg/nodejs-ex.git.

Pull the source to the local machine first:
```
git clone https://github.com/sclorg/nodejs-ex.git app-src
```

Then, build a new image from a Dockerfile in this directory:
```
docker build -f Dockerfile -t node-app .
```

And run the resulting image with the final application:
```
docker run -ti --rm node-app
```

77 changes: 77 additions & 0 deletions 20-minimal/test/imagestreams/imagestreams.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
- name: nodejs
pretty_name: Node.js
sample_repo: https://github.com/sclorg/nodejs-ex.git
category: builder
description: >-
Build and run Node.js APP_VERSION applications on DISTRO_NAME. For more information
about using this builder image, including OpenShift considerations, see
https://github.com/sclorg/s2i-nodejs-container/blob/master/APP_VERSION/README.md.
imagestream_files:
- filename: nodejs-centos.json
latest: "20-ubi9"
distros:
- name: UBI 8
app_versions: ["18", "18-minimal", "20", "20-minimal"]

- name: UBI 9
app_versions: ["18", "18-minimal", "20", "20-minimal"]
custom_tags:
- name: "18-ubi8-minimal"
distro: UBI 8
app_version: "18-minimal"
- name: "20-ubi8-minimal"
distro: UBI 8
app_version: "20-minimal"
- name: "18-ubi9-minimal"
distro: UBI 9
app_version: "18-minimal"
- name: "20-ubi9-minimal"
distro: UBI 9
app_version: "20-minimal"

- filename: nodejs-rhel.json
latest: "20-ubi9"
distros:
- name: UBI 8
app_versions: ["18", "18-minimal", "20", "20-minimal"]

- name: UBI 9
app_versions: ["18", "18-minimal", "20", "20-minimal"]
# these are non standard tags, maintained for backwards compatibility
custom_tags:
- name: "18-ubi8-minimal"
distro: UBI 8
app_version: "18-minimal"
- name: "20-ubi8-minimal"
distro: UBI 8
app_version: "20-minimal"
- name: "18-ubi9-minimal"
distro: UBI 9
app_version: "18-minimal"
- name: "20-ubi9-minimal"
distro: UBI 9
app_version: "20-minimal"

- filename: nodejs-rhel-aarch64.json
latest: "20-ubi9"
distros:
- name: UBI 8
app_versions: ["18", "18-minimal", "20", "20-minimal"]

- name: UBI 9
app_versions: ["18", "18-minimal", "20", "20-minimal"]
custom_tags:
- name: "18-ubi8-minimal"
distro: UBI 8
app_version: "18-minimal"
- name: "20-ubi8-minimal"
distro: UBI 8
app_version: "20-minimal"
- name: "18-ubi9-minimal"
distro: UBI 9
app_version: "18-minimal"
- name: "20-ubi9-minimal"
distro: UBI 9
app_version: "20-minimal"
...
Loading