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

Commit

Permalink
feat: Add BuildConfig 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 Nov 17, 2022
1 parent 18aeef7 commit 92c1fac
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 8 deletions.
2 changes: 1 addition & 1 deletion charts/backstage/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
name: backstage
description: A helm chart for deploying Backstage
version: 0.1.4
version: 0.1.5
appVersion: "v1.7.0"
kubeVersion: ">= 1.19.0-0"
home: https://github.com/redhat-developer/helm-backstage
Expand Down
9 changes: 8 additions & 1 deletion charts/backstage/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# backstage

![Version: 0.1.3](https://img.shields.io/badge/Version-0.1.3-informational?style=flat-square) ![AppVersion: v1.7.0](https://img.shields.io/badge/AppVersion-v1.7.0-informational?style=flat-square)
![Version: 0.1.5](https://img.shields.io/badge/Version-0.1.5-informational?style=flat-square) ![AppVersion: v1.7.0](https://img.shields.io/badge/AppVersion-v1.7.0-informational?style=flat-square)

A helm chart for deploying Backstage

Expand Down Expand Up @@ -41,6 +41,13 @@ Replace `<RELEASE>` with the name of the Helm release that was used when install
| backstage.catalog.rules[0].allow[3] | string | `"Resource"` | |
| backstage.catalog.rules[0].allow[4] | string | `"Location"` | |
| backstage.companyname | string | `"Red Hat Backstage Helm Chart"` | |
| build.contextDir | string | `""` | |
| build.dockerfilePath | string | `""` | |
| build.enabled | bool | `true` | |
| build.mode | string | `"source"` | |
| build.ref | string | `"master"` | |
| build.sourceScripts | string | `"https://raw.githubusercontent.com/redhat-developer/redhat-backstage-build/main/.s2i/bin/"` | |
| build.uri | string | `"https://github.com/backstage/demo.git"` | |
| fullnameOverride | string | `""` | |
| image.pullPolicy | string | `"Always"` | |
| image.registry | string | `"ghcr.io"` | |
Expand Down
10 changes: 9 additions & 1 deletion charts/backstage/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,18 @@ Expand the name of the chart.
{{- default .Values.backstage.baseUrl | trimPrefix "https://" | trimPrefix "http://" }}
{{- end }}

{{- define "backstage.image" -}}
{{- if .Values.build.enabled -}}
{{ include "backstage.fullname" . }}:latest
{{- else -}}
{{ template "parseImage" .Values.image }}
{{- end -}}
{{- end -}}

{{/*
Create the image path for the passed in image field
*/}}
{{- define "backstage.image" -}}
{{- define "parseImage" -}}
{{- if eq (substr 0 7 .version) "sha256:" -}}
{{- printf "%s/%s@%s" .registry .repository .version -}}
{{- else -}}
Expand Down
54 changes: 54 additions & 0 deletions charts/backstage/templates/build/buildconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- if .Values.build.enabled }}
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
labels:
{{- include "backstage.labels" . | nindent 4 }}
name: {{ include "backstage.fullname" . }}
namespace: {{ .Release.Namespace }}
spec:
resources:
limits:
cpu: "500m"
memory: "2Gi"
failedBuildsHistoryLimit: 5
output:
to:
kind: ImageStreamTag
name: "{{ include "backstage.image" . }}"
runPolicy: Serial
source:
type: Git
git:
uri: {{ .Values.build.uri }}
ref: {{ .Values.build.ref }}
{{- if .Values.build.contextDir }}
contextDir: {{ .Values.build.contextDir }}
{{- end }}
strategy:
{{- if not (has .Values.build.mode (list "docker" "source")) }}
{{- fail "value 'build.mode' must be either 'docker' or 'source'" }}
{{- end }}
{{- if eq .Values.build.mode "docker" }}
type: Docker
dockerStrategy:
dockerfilePath: {{ .Values.build.dockerfilePath | default "./Dockerfile "}}
{{- if .Values.build.pullSecret }}
pullSecret:
name: {{ .Values.build.pullSecret }}
{{- end }}
{{ else }}
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
name: "nodejs:latest"
namespace: openshift
{{- if .Values.build.sourceScripts }}
scripts: {{ .Values.build.sourceScripts }}
{{- end }}
{{- end }}
successfulBuildsHistoryLimit: 5
triggers:
- type: ConfigChange
{{- end }}
12 changes: 12 additions & 0 deletions charts/backstage/templates/build/imagestream.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.build.enabled }}
apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
labels:
{{- include "backstage.labels" . | nindent 4 }}
name: {{ include "backstage.fullname" . }}
namespace: {{ .Release.Namespace }}
spec:
lookupPolicy:
local: true
{{- end }}
6 changes: 4 additions & 2 deletions charts/backstage/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ spec:
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
{{- end }}
image: "{{ template "backstage.image" .Values.image }}"
image: "{{ include "backstage.image" . }}"
{{- if not .Values.build.enabled }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ['node', 'packages/backend', '--config', '/config/app-config.yaml']
{{- end }}
command: ['node', 'packages/backend', '--config', '/config/app-config.yaml']
env:
- name: POSTGRES_ADMIN_PASSWORD
valueFrom:
Expand Down
2 changes: 1 addition & 1 deletion charts/backstage/templates/postgresql/postgresql-ss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
{{- end }}
terminationMessagePolicy: File
imagePullPolicy: {{ .Values.postgres.image.pullPolicy }}
image: "{{ template "backstage.image" .Values.postgres.image }}"
image: "{{ template "parseImage" .Values.postgres.image }}"
serviceAccount: {{ include "backstage.serviceAccountName" . }}
{{- if .Values.postgres.storage.enabled }}
volumes:
Expand Down
113 changes: 111 additions & 2 deletions charts/backstage/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"title": "Root Schema",
"required": [
"replicaCount",
"image",
"imagePullSecrets",
"nameOverride",
"fullnameOverride",
"service",
Expand All @@ -20,6 +18,37 @@
"securityContext",
"backstage"
],
"oneOf": [
{
"required": [
"image"
],
"properties": {
"build": {
"properties": {
"enabled": {
"enum": [
false
]
}
}
}
}
},
{
"properties": {
"build": {
"properties": {
"enabled": {
"enum": [
true
]
}
}
}
}
}
],
"properties": {
"replicaCount": {
"type": "integer",
Expand Down Expand Up @@ -82,6 +111,77 @@
}
]
},
"build": {
"type": "object",
"default": {},
"title": "The build Schema",
"required": [
"enabled"
],
"properties": {
"enabled": {
"type": "boolean",
"default": false,
"title": "The enabled Schema",
"examples": [
true
]
},
"ref": {
"type": "string",
"default": "",
"title": "The ref Schema",
"examples": [
""
]
},
"url": {
"type": "string",
"default": "",
"title": "The url Schema",
"examples": [
""
]
},
"contextDir": {
"type": "string",
"default": "",
"title": "The contextDir Schema",
"examples": [
""
]
},
"mode": {
"type": "string",
"default": "",
"title": "The mode Schema",
"examples": [
""
]
},
"dockerfilePath": {
"type": "string",
"default": "",
"title": "The dockerfilePath Schema",
"examples": [
""
]
},
"sourceScripts": {
"type": "string",
"default": "",
"title": "The sourceScripts Schema",
"examples": [
""
]
}
},
"examples": [
{
"enabled": false
}
]
},
"imagePullSecrets": {
"type": "array",
"default": [],
Expand Down Expand Up @@ -905,6 +1005,15 @@
"version": "latest"
},
"imagePullSecrets": [],
"build": {
"enabled": false,
"ref": "master",
"uri": "https://github.com/backstage/demo.git",
"contextDir": "",
"mode": "source",
"dockerfilePath": "",
"sourceScripts": "https://raw.githubusercontent.com/redhat-developer/redhat-backstage-build/main/.s2i/bin/"
},
"nameOverride": "",
"fullnameOverride": "",
"service": {
Expand Down
16 changes: 16 additions & 0 deletions charts/backstage/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ image:
repository: redhat-developer/redhat-backstage-build
version: "latest"

build:
## If set to true the "image" section is ignored. Instead the image is built in cluster
enabled: false
## Git reference for the source repository
ref: master
## URI to the source repository
uri: https://github.com/backstage/demo.git
## Optional path within the repository. Defaults to repository root.
contextDir: ""
## Build mode selector, either set to "docker" to build from a local (in repo) Dockerfile or to "source" to build via source-to-image
mode: "source"
## Custom path to the Dockerfile. Defaults to current context path within the repo. Applicable only if mode == "docker"
dockerfilePath: ""
## Optional custom path to source-to-image assemble/run/etc. scripts. If set to blank, scripts need to be defined in your source repository
sourceScripts: "https://raw.githubusercontent.com/redhat-developer/redhat-backstage-build/main/.s2i/bin/"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
Expand Down

0 comments on commit 92c1fac

Please sign in to comment.