Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
feat: add option to build the image in cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Coufal <tcoufal@redhat.com>
  • Loading branch information
tumido committed Apr 3, 2023
1 parent b5c5f1e commit fe8c7df
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 2 deletions.
2 changes: 1 addition & 1 deletion charts/backstage/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0
version: 1.0.1

dependencies:
- name: common
Expand Down
40 changes: 39 additions & 1 deletion charts/backstage/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Janus-IDP Backstage Helm Chart

![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)
![Version: 1.0.1](https://img.shields.io/badge/Version-1.0.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square)

A Helm chart for deploying a Backstage application

Expand Down Expand Up @@ -88,6 +88,23 @@ The command removes all the Kubernetes components associated with the chart and

| Key | Description | Type | Default |
|-----|-------------|------|---------|
| build.buildConfig.annotations | | object | `{}` |
| build.buildConfig.contextDir | | string | `""` |
| build.buildConfig.failedBuildsHistoryLimit | | int | `5` |
| build.buildConfig.pullSecrets | | list | `[]` |
| build.buildConfig.ref | | string | `"main"` |
| build.buildConfig.resources.limits.cpu | | string | `"500m"` |
| build.buildConfig.resources.limits.memory | | string | `"2Gi"` |
| build.buildConfig.sourceSecretName | | string | `""` |
| build.buildConfig.strategy.docker.dockerfilePath | | string | `"./Dockerfile"` |
| build.buildConfig.strategy.source.sourceScripts | | string | `"https://raw.githubusercontent.com/janus-idp/redhat-backstage-build/add-s2i/.s2i/bin/"` |
| build.buildConfig.strategy.type | | string | `"Source"` |
| build.buildConfig.successfulBuildsHistoryLimit | | int | `5` |
| build.buildConfig.triggers[0].type | | string | `"ConfigChange"` |
| build.buildConfig.triggers[1].type | | string | `"ImageChange"` |
| build.buildConfig.uri | | string | `"https://github.com/janus-idp/redhat-backstage-build.git"` |
| build.enabled | | bool | `false` |
| build.imageStream.annotations | | object | `{}` |
| route | OpenShift Route parameters | object | `{"annotations":{},"enabled":false,"host":"","path":"/","tls":{"caCertificate":"","certificate":"","destinationCACertificate":"","enabled":false,"insecureEdgeTerminationPolicy":"Redirect","key":"","termination":"edge"},"wildcardPolicy":"None"}` |
| route.annotations | Route specific annotations | object | `{}` |
| route.enabled | Enable the creation of the route resource | bool | `false` |
Expand Down Expand Up @@ -142,3 +159,24 @@ route:
global:
host: backstage.apps.example.com
```

### OpenShift Build

In addition to providing a complete image for deployment, this feature allows user to refence a Backstage repository instead. This repository will be turned into an image in-cluster through OpenShift BuildConfig. In order to properly propagate the image to the Deployment, use following values as a baseline:

```yaml
upstream:
backstage:
image:
registry: 'image-registry.openshift-image-registry.svc:5000'
repository: '{{ .Release.Namespace }}/{{ include "common.names.fullname" . }}'

annotations:
image.openshift.io/triggers: |
[{"from":{"kind":"ImageStreamTag","name":"{{ include "common.names.fullname" . }}"},"fieldPath":"spec.template.spec.containers[0].image"}]
build:
enabled: true
```

The process can be furtner customized through the `build` value in `values.yaml` file. For more details see [Values section](#values) above.
21 changes: 21 additions & 0 deletions charts/backstage/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,24 @@ route:
global:
host: backstage.apps.example.com
```

### OpenShift Build

In addition to providing a complete image for deployment, this feature allows user to refence a Backstage repository instead. This repository will be turned into an image in-cluster through OpenShift BuildConfig. In order to properly propagate the image to the Deployment, use following values as a baseline:

```yaml
upstream:
backstage:
image:
registry: 'image-registry.openshift-image-registry.svc:5000'
repository: '{{"{{"}} .Release.Namespace {{"}}"}}/{{"{{"}} include "common.names.fullname" . {{"}}"}}'

annotations:
image.openshift.io/triggers: |
[{"from":{"kind":"ImageStreamTag","name":"{{"{{"}} include "common.names.fullname" . {{"}}"}}"},"fieldPath":"spec.template.spec.containers[0].image"}]

build:
enabled: true
```

The process can be furtner customized through the `build` value in `values.yaml` file. For more details see [Values section](#values) above.
18 changes: 18 additions & 0 deletions charts/backstage/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{/*
Return the proper Docker Image Registry Secret Names
*/}}
{{- define "janusIdp.renderImageBuildPullSecrets" -}}
{{- include "common.images.renderPullSecrets" (dict "images" (list .Values.build.buildConfig) "context" $) -}}
{{- end -}}


{{/*
Return the proper image name
THIS IS AN OVERRIDE of upstream helper!
https://github.com/backstage/charts/blob/13a408cc070005a9960a5e2a3f6ebfdd8c77d8d2/charts/backstage/templates/_helpers.tpl#L4
*/}}
{{- define "backstage.image" -}}
{{- $templatedImage := include "common.images.image" (dict "imageRoot" .Values.backstage.image "global" .Values.global) -}}
{{ include "common.tplvalues.render" ( dict "value" $templatedImage "context" $ ) }}
{{- end -}}
66 changes: 66 additions & 0 deletions charts/backstage/templates/buildconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{- if .Values.build.enabled }}
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: {{ include "common.names.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
app.kubernetes.io/component: backstage
{{- if .Values.upstream.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.upstream.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if or .Values.upstream.commonAnnotations .Values.build.buildConfig.annotations }}
annotations:
{{- if .Values.build.buildConfig.annotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.build.buildConfig.annotations "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.upstream.commonAnnotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.upstream.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
{{- end }}
spec:
resources:
{{- include "common.tplvalues.render" ( dict "value" .Values.build.buildConfig.resources "context" $) | nindent 4 }}
failedBuildsHistoryLimit: {{ .Values.build.buildConfig.failedBuildsHistoryLimit }}
successfulBuildsHistoryLimit: {{ .Values.build.buildConfig.successfulBuildsHistoryLimit }}
output:
to:
kind: ImageStreamTag
name: {{ include "common.names.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
runPolicy: Serial
source:
type: Git
git:
uri: {{ .Values.build.buildConfig.uri }}
ref: {{ .Values.build.buildConfig.ref }}
{{- if .Values.build.buildConfig.contextDir }}
contextDir: {{ .Values.build.buildConfig.contextDir }}
{{- end }}
{{- if .Values.build.buildConfig.sourceSecretName }}
sourceSecret:
name: {{ .Values.build.buildConfig.sourceSecretName }}
{{- end }}
strategy:
{{- if not (has .Values.build.buildConfig.strategy.type (list "Docker" "Source")) }}
{{- fail "value 'build.buildConfig.type' must be either 'Docker' or 'Source'" }}
{{- end }}
{{- if eq .Values.build.buildConfig.strategy.type "Docker" }}
type: Docker
dockerStrategy:
dockerfilePath: {{ .Values.build.buildConfig.strategy.docker.dockerfilePath }}
{{- include "janusIdp.renderImageBuildPullSecrets" . | nindent 6 }}
{{- else }}
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
name: "nodejs:latest"
namespace: openshift
{{- if .Values.build.buildConfig.strategy.source.sourceScripts }}
scripts: {{ .Values.build.buildConfig.strategy.source.sourceScripts }}
{{- end }}
{{- end }}
triggers:
{{- include "common.tplvalues.render" ( dict "value" .Values.build.buildConfig.triggers "context" $ ) | nindent 4 }}
{{- end }}
24 changes: 24 additions & 0 deletions charts/backstage/templates/imagestream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if .Values.build.enabled }}
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
name: {{ include "common.names.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
app.kubernetes.io/component: backstage
{{- if .Values.upstream.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.upstream.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if or .Values.upstream.commonAnnotations .Values.build.imageStream.annotations }}
annotations:
{{- if .Values.build.imageStream.annotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.build.imageStream.annotations "context" $) | nindent 4 }}
{{- end }}
{{- if .Values.upstream.commonAnnotations }}
{{- include "common.tplvalues.render" ( dict "value" .Values.upstream.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
{{- end }}
spec:
lookupPolicy:
local: true
{{- end }}
43 changes: 43 additions & 0 deletions charts/backstage/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,46 @@ route:
# -- Indicates the desired behavior for insecure connections to a route.
# <br /> While each router may make its own decisions on which ports to expose, this is normally port 80. The only valid values are None, Redirect, or empty for disabled.
insecureEdgeTerminationPolicy: "Redirect"


#-- Build Backstage image in-cluster
build:

#
enabled: false

imageStream:
annotations: {}

buildConfig:
annotations: {}

uri: "https://github.com/janus-idp/redhat-backstage-build.git"

ref: "main"

contextDir: ""

sourceSecretName: ""

pullSecrets: []

failedBuildsHistoryLimit: 5

successfulBuildsHistoryLimit: 5

resources:
limits:
cpu: "500m"
memory: "2Gi"

strategy:
type: "Source" # Source or Docker allowed
source:
sourceScripts: "https://raw.githubusercontent.com/janus-idp/redhat-backstage-build/add-s2i/.s2i/bin/"
docker:
dockerfilePath: "./Dockerfile"

triggers:
- type: ConfigChange
- type: ImageChange

0 comments on commit fe8c7df

Please sign in to comment.