diff --git a/charts/redhat/nodejs-application/src/Chart.yaml b/charts/redhat/nodejs-application/src/Chart.yaml index 2610041..dfe0624 100644 --- a/charts/redhat/nodejs-application/src/Chart.yaml +++ b/charts/redhat/nodejs-application/src/Chart.yaml @@ -2,13 +2,13 @@ description: This content is experimental, do not use it in production. An examp about using this template, including OpenShift considerations, see https://github.com/sclorg/nodejs-ex/blob/master/README.md. name: nodejs-application tags: quickstart,nodejs -version: 0.0.1 +version: 0.0.2 kubeVersion: '>=1.20.0' annotations: charts.openshift.io/name: Red Hat Apache Rails application with no database (experimental) charts.openshift.io/provider: Red Hat charts.openshift.io/providerType: redhat apiVersion: v2 -appVersion: 0.0.1 +appVersion: 0.0.2 sources: - https://github.com/sclorg/helm-charts diff --git a/charts/redhat/nodejs-application/src/templates/buildconfig.yaml b/charts/redhat/nodejs-application/src/templates/buildconfig.yaml index 7969a79..056abe9 100644 --- a/charts/redhat/nodejs-application/src/templates/buildconfig.yaml +++ b/charts/redhat/nodejs-application/src/templates/buildconfig.yaml @@ -9,10 +9,19 @@ metadata: template: nodejs-example name: {{ .Values.name }} spec: + {{ if .Values.registry.enabled }} + output: + to: + kind: DockerImage + name: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest" + pushSecret: + name: {{ .Values.registry.push_secret }} + {{ else }} output: to: kind: ImageStreamTag name: {{ .Values.name }}:latest + {{ end }} source: contextDir: {{ .Values.context_dir }} git: diff --git a/charts/redhat/nodejs-application/src/templates/deployment.yaml b/charts/redhat/nodejs-application/src/templates/deployment.yaml index 1fb6d53..d7e50cb 100644 --- a/charts/redhat/nodejs-application/src/templates/deployment.yaml +++ b/charts/redhat/nodejs-application/src/templates/deployment.yaml @@ -3,6 +3,7 @@ kind: Deployment metadata: annotations: description: Defines how to deploy the application server + {{ if not .Values.registry.enabled }} image.openshift.io/triggers: |- [ { @@ -13,6 +14,7 @@ metadata: "fieldPath": "spec.template.spec.containers[0].image" } ] + {{ end }} template.alpha.openshift.io/wait-for-ready: "true" labels: app: nodejs-example @@ -32,14 +34,18 @@ spec: name: {{ .Values.name }} spec: containers: - - image: " " + - name: nodejs-example + {{ if .Values.registry.enabled }} + image: "{{ .Values.registry.name }}/{{ .Values.registry.namespace }}/{{ .Values.name }}:latest" + {{ else }} + image: " " + {{ end }} livenessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 30 timeoutSeconds: 3 - name: nodejs-example ports: - containerPort: 8080 readinessProbe: diff --git a/charts/redhat/nodejs-application/src/values.schema.json b/charts/redhat/nodejs-application/src/values.schema.json index c2e4943..31ecebb 100644 --- a/charts/redhat/nodejs-application/src/values.schema.json +++ b/charts/redhat/nodejs-application/src/values.schema.json @@ -49,6 +49,26 @@ "npm_mirror": { "type": "string", "description": "The custom NPM mirror URL." + }, + "registry": { + "type": "object", + "properties": { + "enabled": { + "type": "boolean" + }, + "name": { + "type": "string", + "description": "The name of registry that will be used for pushing built image." + }, + "namespace": { + "type": "string", + "description": "The namespace of registry that will be used for pushing built image." + }, + "push_secret": { + "type": "string", + "description": "The push secret to push image to registry." + } + } } } } diff --git a/charts/redhat/nodejs-application/src/values.yaml b/charts/redhat/nodejs-application/src/values.yaml index db91f68..b9e0480 100644 --- a/charts/redhat/nodejs-application/src/values.yaml +++ b/charts/redhat/nodejs-application/src/values.yaml @@ -9,3 +9,8 @@ nodejs_version: 20-ubi8 npm_mirror: "" # TODO: must define a default value for .npm_mirror source_repository_ref: "master" # TODO: must define a default value for .source_repository_ref source_repository_url: https://github.com/sclorg/nodejs-ex.git +registry: + enabled: false + name: "quay.io" + namespace: "something" + push_secret: "" diff --git a/tests/test_nodejs_application.py b/tests/test_nodejs_application.py index affddcf..ea59419 100644 --- a/tests/test_nodejs_application.py +++ b/tests/test_nodejs_application.py @@ -18,7 +18,20 @@ def setup_method(self): def teardown_method(self): self.hc_api.delete_project() - def test_curl_connection(self): + @pytest.mark.parametrize( + "version", + [ + "20-ubi9", + "20-ubi9-minimal" + "20-ubi8", + "20-ubi8-minimal", + "18-ubi9", + "18-ubi9-minimal", + "18-ubi8", + "18-ubi8-minimal", + ], + ) + def test_curl_connection(self, version): if self.hc_api.oc_api.shared_cluster: pytest.skip("Do NOT test on shared cluster") self.hc_api.package_name = "nodejs-imagestreams" @@ -26,29 +39,46 @@ def test_curl_connection(self): assert self.hc_api.helm_installation() self.hc_api.package_name = "nodejs-application" assert self.hc_api.helm_package() + pod_name = f"nodejs-ex-{version}".replace("-minimal", "") assert self.hc_api.helm_installation( values={ - "nodejs_version": "20-ubi8", - "namespace": self.hc_api.namespace + "nodejs_version": version, + "namespace": self.hc_api.namespace, + "name": pod_name } ) - assert self.hc_api.is_s2i_pod_running(pod_name_prefix="nodejs-example") + assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name) assert self.hc_api.test_helm_curl_output( - route_name="nodejs-example", + route_name=pod_name, expected_str="Node.js Crud Application" ) - def test_by_helm_test(self): + @pytest.mark.parametrize( + "version", + [ + "20-ubi9", + "20-ubi9-minimal" + "20-ubi8", + "20-ubi8-minimal", + "18-ubi9", + "18-ubi9-minimal", + "18-ubi8", + "18-ubi8-minimal", + ], + ) + def test_by_helm_test(self, version): self.hc_api.package_name = "nodejs-imagestreams" self.hc_api.helm_package() assert self.hc_api.helm_installation() self.hc_api.package_name = "nodejs-application" assert self.hc_api.helm_package() + pod_name = f"nodejs-ex-{version}".replace("-minimal", "") assert self.hc_api.helm_installation( values={ - "nodejs": "20-ubi8", - "namespace": self.hc_api.namespace + "nodejs": version, + "namespace": self.hc_api.namespace, + "name": pod_name } ) - assert self.hc_api.is_s2i_pod_running(pod_name_prefix="nodejs-example") + assert self.hc_api.is_s2i_pod_running(pod_name_prefix=pod_name) assert self.hc_api.test_helm_chart(expected_str=["Node.js Crud Application"])