Skip to content

Commit

Permalink
update nodejs chart to fix failures (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash Cripps authored Sep 28, 2021
1 parent 3c99a81 commit 1711b55
Show file tree
Hide file tree
Showing 12 changed files with 625 additions and 0 deletions.
8 changes: 8 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v2
name: nodejs
version: 0.0.2
kubeVersion: '>= 1.21.0-0'
description: A Helm chart to build and deploy Node.js applications
keywords:
- runtimes
- nodejs
60 changes: 60 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Node.js Helm Chart
A Helm chart for building and deploying a [Node.js](https://nodejs.org/) application on OpenShift.

## Prerequisites
Below are prerequisites that may apply to your use case.

### Push Secret
You will need to create a push secret if you want to push your image to an external registry. Use the following command as a reference to create your push secret:
```bash
oc create secret docker-registry my-push-secret --docker-server=$SERVER_URL --docker-username=$USERNAME --docker-password=$PASSWORD --docker-email=$EMAIL
```

You can use this secret by passing `--set build.output.pushSecret=my-push-secret` and `--set build.output.kind=DockerImage` to `helm install`, or you can configure these in a values file:
```yaml
build:
output:
kind: DockerImage
pushSecret: my-push-secret
```
## Values
This section describes the Values used to configure this chart.
Below is a table the values used to configure this chart.
| Value | Description | Default | Additional Information |
| ----- | ----------- | ------- | ---------------------- |
| `image.name` | Name of the image you want to build/deploy | Defaults to the Helm release name. | The chart will create/reference an [ImageStream](https://docs.openshift.com/container-platform/4.6/openshift_images/image-streams-manage.html) based on this value. |
| `image.tag` | Tag that you want to build/deploy | `latest` | The chart will create/reference an [ImageStreamTag](https://docs.openshift.com/container-platform/4.6/openshift_images/image-streams-manage.html#images-using-imagestream-tags_image-streams-managing) based on the name provided |
| `build.enabled` | Determines if build-related resources should be created. | `true` | Set this to `false` if you want to deploy a previously built image. Leave this set to `true` if you want to build and deploy a new image. |
| `build.uri` | Git URI that references your git repo | https://github.com/nodeshift-starters/nodejs-rest-http | This value defaults to a sample application. Be sure to override this if you want to build and deploy your own application. |
| `build.ref` | Git ref containing the application you want to build | main | - |
| `build.contextDir` | The sub-directory where the application source code exists | - | - |
| `build.output.kind` | Determines if the image will be pushed to an ImageStreamTag or a DockerImage (external registry) | ImageStreamTag | More information: More information: https://docs.openshift.com/container-platform/4.6/builds/managing-build-output.html |
| `build.output.pushSecret` | Push secret name | - | Used only if build.output.kind == 'DockerImage' |
| `build.pullSecret` | Image pull secret | - | More information: https://docs.openshift.com/container-platform/4.6/openshift_images/managing_images/using-image-pull-secrets.html |
| `build.env` | Freeform `env` stanza | - | More information: https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/ |
| `build.resources` | Freeform `resources` stanza | - | More information: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ |
| `deploy.replicas` | Number of pod replicas to deploy | `1` | - |
| `deploy.resources` | Freeform `resources` stanza | - | More information: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ |
| `deploy.serviceType` | Type of service to create | `ClusterIP` | More information: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types |
| `deploy.ports` | Freeform service `ports` stanza. | See [values.yaml](./values.yaml) | More information: https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service |
| `deploy.route.enabled` | Determines if a Route should be created | `true` | Allows clients outside of OpenShift to access your application |
| `deploy.route.targetPort` | The port that the Route should target traffic to | `http` | - |
| `deploy.route.tls.enabled` | Determines if the Route should be TLS-encrypted | `true` | More information: https://docs.openshift.com/container-platform/4.6/networking/routes/secured-routes.html |
| `deploy.route.tls.termination` | Determines the type of TLS termination to use | `edge` | Options: `edge`, `reencrypt`, `passthrough` |
| `deploy.route.tls.insecureEdgeTerminationPolicy` | Determines if insecure traffic should be redirected | `Redirect` | Options: "Allow", "Disable", "Redirect" |
| `deploy.route.tls.key` | Provides key file contents | - | This is a secret. Do not check this value into git. |
| `deploy.route.tls.caCertificate` | Provides the cert authority certificate contents | - | - |
| `deploy.route.tls.certificate` | Provides certificate contents | - | - |
| `deploy.route.tls.destinationCACertificate` | Provides the destination CA Certificate for reencrypt routes | - | - |
| `deploy.livenessProbe` | Freeform `livenessProbe` stanza. | See [values.yaml](./values.yaml) | More information: https://docs.openshift.com/container-platform/4.6/applications/application-health.html#application-health-about_application-health |
| `deploy.readinessProbe` | Freeform `readinessProbe` stanza. | See [values.yaml](./values.yaml) | More information: https://docs.openshift.com/container-platform/4.6/applications/application-health.html#application-health-about_application-health |
| `deploy.env` | Freeform `env` stanza | - | More information: https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/ |
| `deploy.envFrom` | Freeform `envFrom` stanza | - | More information: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables |
| `deploy.volumeMounts` | Freeform volume mounts | - | More information: https://kubernetes.io/docs/concepts/storage/volumes/ |
| `deploy.volumes` | Freeform volumes | - | More information: https://kubernetes.io/docs/concepts/storage/volumes/ |
| `deploy.initContainers` | Freeform init containers | - | More information: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ |
| `deploy.extraContainers` | Freeform containers | - | More information: https://kubernetes.io/docs/concepts/workloads/pods/#pod-templates |
| `global.nameOverride` | Overrides the release name | - | Resources are named after the release name. Set this value if you want to override the release name. |
7 changes: 7 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- if .Release.IsInstall }}
Your Node.js app is building! To view the build logs, run:

oc logs bc/{{ include "nodejs.name" . }} --follow

Note that your Deployment will report "ErrImagePull" and "ImagePullBackOff" until the build is complete. Once the build is complete, your image will be automatically rolled out.
{{- end }}
21 changes: 21 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- define "nodejs.name" -}}
{{ default .Release.Name .Values.global.nameOverride }}
{{- end -}}

{{- define "nodejs.labels" -}}
helm.sh/chart: {{ .Chart.Name }}
{{ include "nodejs.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{- define "nodejs.selectorLabels" -}}
app.kubernetes.io/name: {{ include "nodejs.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{- define "nodejs.imageName" -}}
{{ default (include "nodejs.name" .) .Values.image.name }}:{{ .Values.image.tag }}
{{- end -}}
46 changes: 46 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/templates/buildconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{- if .Values.build.enabled }}
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: {{ include "nodejs.name" . }}
labels:
{{- include "nodejs.labels" . | nindent 4 }}
spec:
source:
type: Git
git:
uri: {{ .Values.build.uri }}
ref: {{ .Values.build.ref }}
{{- if .Values.build.contextDir }}
contextDir: {{ .Values.build.contextDir }}
{{- end }}
strategy:
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
namespace: {{ .Values.build.source.namespace }}
name: {{ .Values.build.source.name }}
{{- if .Values.build.pullSecret }}
pullSecret:
name: {{ .Values.build.pullSecret }}
{{- end }}
{{- if .Values.build.env }}
env:
{{- tpl (toYaml .Values.build.env) . | nindent 8 }}
{{- end }}
output:
to:
kind: {{ .Values.build.output.kind }}
name: {{ include "nodejs.imageName" . }}
{{- if and (eq .Values.build.output.kind "DockerImage") .Values.build.output.pushSecret }}
pushSecret:
name: {{ .Values.build.output.pushSecret }}
{{- end }}
{{- if .Values.build.resources }}
resources:
{{- toYaml .Values.build.resources | nindent 4 }}
{{- end }}
triggers:
- type: ConfigChange
{{- end }}
78 changes: 78 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "nodejs.name" . }}
labels:
{{- include "nodejs.labels" . | nindent 4 }}
{{- if and .Values.build.enabled (eq .Values.build.output.kind "ImageStreamTag") }}
annotations:
image.openshift.io/triggers: |-
[
{
"from":{
"kind":"ImageStreamTag",
"name":"{{ include "nodejs.imageName" . }}"
},
"fieldPath":"spec.template.spec.containers[0].image"
}
]
{{- end }}
spec:
replicas: {{ .Values.deploy.replicas }}
selector:
matchLabels:
{{- include "nodejs.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "nodejs.labels" . | nindent 8 }}
spec:
{{- if .Values.deploy.initContainers }}
initContainers:
{{- tpl (toYaml .Values.deploy.initContainers) . | nindent 8 }}
{{- end }}
containers:
- name: web
image: {{ include "nodejs.imageName" . }}
ports:
{{- range .Values.deploy.ports }}
- name: {{ .name }}
containerPort: {{ .targetPort }}
protocol: {{ .protocol }}
{{- end }}
{{- if .Values.deploy.resources }}
resources:
{{- toYaml .Values.deploy.resources | nindent 12 }}
{{- end }}
{{- if .Values.deploy.livenessProbe }}
livenessProbe:
{{- tpl (toYaml .Values.deploy.livenessProbe) . | nindent 12 }}
{{- end }}
{{- if .Values.deploy.readinessProbe }}
readinessProbe:
{{- tpl (toYaml .Values.deploy.readinessProbe) . | nindent 12 }}
{{- end }}
{{- if .Values.deploy.env }}
env:
{{- tpl (toYaml .Values.deploy.env) . | nindent 12 }}
{{- end }}
{{- if .Values.deploy.envFrom }}
envFrom:
{{- tpl (toYaml .Values.deploy.envFrom) . | nindent 12 }}
{{- end }}
volumeMounts:
{{- if .Values.deploy.volumeMounts }}
{{- tpl (toYaml .Values.deploy.volumeMounts) . | nindent 12 }}
{{- end }}
{{- if .Values.deploy.extraContainers }}
{{- tpl (toYaml .Values.deploy.extraContainers) . | nindent 8 }}
{{- end }}
volumes:
{{- if .Values.deploy.applicationProperties.enabled }}
- name: application-properties
configMap:
name: {{ include "nodejs.name" . }}
{{- end }}
{{- if .Values.deploy.volumes }}
{{- tpl (toYaml .Values.deploy.volumes) . | nindent 8 }}
{{- end }}
11 changes: 11 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/templates/imagestream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if and .Values.build.enabled (eq .Values.build.output.kind "ImageStreamTag") }}
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: {{ include "nodejs.name" . }}
labels:
{{- include "nodejs.labels" . | nindent 4 }}
spec:
lookupPolicy:
local: true
{{- end }}
35 changes: 35 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/templates/route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if .Values.deploy.route.enabled }}
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: {{ include "nodejs.name" . }}
labels:
{{- include "nodejs.labels" . | nindent 4 }}
spec:
to:
kind: Service
name: {{ include "nodejs.name" . }}
port:
targetPort: {{ tpl .Values.deploy.route.targetPort . }}
{{- if .Values.deploy.route.tls.enabled }}
tls:
termination: {{ .Values.deploy.route.tls.termination }}
insecureEdgeTerminationPolicy: {{ .Values.deploy.route.tls.insecureEdgeTerminationPolicy }}
{{- if .Values.deploy.route.tls.key }}
key: |-
{{- .Values.deploy.route.tls.key | nindent 6 }}
{{- end }}
{{- if .Values.deploy.route.tls.destinationCACertificate }}
destinationCACertificate: |-
{{- .Values.deploy.route.tls.destinationCACertificate | nindent 6 }}
{{- end }}
{{- if .Values.deploy.route.tls.caCertificate }}
caCertificate: |-
{{- .Values.deploy.route.tls.caCertificate | nindent 6 }}
{{- end }}
{{- if .Values.deploy.route.tls.certificate }}
certificate: |-
{{- .Values.deploy.route.tls.certificate | nindent 6 }}
{{- end }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/redhat/redhat/nodejs/0.0.2/src/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "nodejs.name" . }}
labels:
{{- include "nodejs.labels" . | nindent 4 }}
spec:
type: {{ .Values.deploy.serviceType }}
selector:
{{- include "nodejs.selectorLabels" . | nindent 4 }}
ports:
{{- tpl (toYaml .Values.deploy.ports) . | nindent 4 }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ .Release.Name }}-test"
namespace: {{ .Release.Namespace }}
annotations:
"helm.sh/hook": test
spec:
{{- if .Values.build.pullSecret }}
{{- include "imagePullSecrets" . | nindent 2 }}
{{- end }}
containers:
- name: {{ .Release.Name }}-test
image: image-registry.openshift-image-registry.svc:5000/default/{{ .Release.Name }}:{{ .Values.image.tag | default "latest" }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/sh
- -c
- |
echo "Checking for node process"
npm start&
PROCESS=`ps -ef | grep node | grep -v grep`
echo "$PROCESS"
if [ -z "$PROCESS" ]
then
echo "Process not found"
exit 1
fi
echo "Process Found"
exit 0
restartPolicy: Never
Loading

0 comments on commit 1711b55

Please sign in to comment.