Skip to content

Commit

Permalink
[sophora-image-ai]: add Sophora Image AI (#59)
Browse files Browse the repository at this point in the history
* add chart for sophora-image-ai

* let's not confuse things

* add configmap.yaml checksum annotation
  • Loading branch information
blizzy78 authored Nov 2, 2023
1 parent 7a796eb commit 735f589
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/sophora-image-ai/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/sophora-image-ai/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: sophora-image-ai
description: Sophora Image AI
type: application
version: 1.0.0
appVersion: 4.0.0
28 changes: 28 additions & 0 deletions charts/sophora-image-ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Sophora Image AI

The [Image AI] module supports the editorial team in creating image variants in image documents.
Instead of manually selecting clips for each image variant, the clips are calculated automatically
using Google Cloud Vision.

## Secrets

This chart requires secrets to be created prior to installation. In particular, the credentials for
your Google Cloud Platform project must be stored in a secret.

To create the credentials secret, have your credentials JSON file ready. You can export this file
in the IAM section in Google Cloud Platform.

To create the secret, run the following command:

```
kubectl create secret generic sophora-image-ai-gcp-credentials \
--from-literal "credentials.json=$(cat my-project-credentials.json)"
```

Replace the path to `my-project-credentials.json` with the path to your actual credentials JSON file.

After creating the secret, you can proceed to install the chart.



[Image AI]: https://subshell.com/sophora/modules/sophora-image-ai100.html
64 changes: 64 additions & 0 deletions charts/sophora-image-ai/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "sophora-image-ai.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "sophora-image-ai.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "sophora-image-ai.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "sophora-image-ai.selectorLabels" -}}
app.kubernetes.io/name: {{ include "sophora-image-ai.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Renders a value that contains template.
Usage:
{{ include "common.tplvalues.render" ( dict "value" .Values.path.to.the.Value "context" $) }}
*/}}
{{- define "common.tplvalues.render" -}}
{{- if typeIs "string" .value }}
{{- tpl .value .context }}
{{- else }}
{{- tpl (.value | toYaml) .context }}
{{- end }}
{{- end -}}
8 changes: 8 additions & 0 deletions charts/sophora-image-ai/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "sophora-image-ai.fullname" . }}
labels:
{{- include "sophora-image-ai.labels" . | nindent 4 }}
data:
application.yaml: |- {{ toYaml (required "A valid application.yaml config is required" .Values.sophora.configuration) | nindent 4 }}
76 changes: 76 additions & 0 deletions charts/sophora-image-ai/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sophora-image-ai.fullname" . }}
labels:
{{- include "sophora-image-ai.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
{{- include "sophora-image-ai.selectorLabels" . | nindent 6 }}
template:
metadata:
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "sophora-image-ai.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: image-ai
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: config
mountPath: /config
readOnly: true
- name: gcp-credentials
mountPath: /gcp-credentials
readOnly: true
ports:
- name: http
protocol: TCP
containerPort: 8080
env:
- name: JDK_JAVA_OPTIONS
value: {{ .Values.javaOptions }}
- name: SOPHORA_CLIENT_SERVERCONNECTION_USERNAME
valueFrom:
secretKeyRef:
name: {{ required "A valid secret name must be provided in .Values.sophora.authentication.secret.name" .Values.sophora.authentication.secret.name | quote }}
key: {{ .Values.sophora.authentication.secret.usernameKey | quote }}
- name: SOPHORA_CLIENT_SERVERCONNECTION_PASSWORD
valueFrom:
secretKeyRef:
name: {{ required "A valid secret name must be provided in .Values.sophora.authentication.secret.name" .Values.sophora.authentication.secret.name | quote }}
key: {{ .Values.sophora.authentication.secret.passwordKey | quote }}
{{- if .Values.imageAI.extraEnv }}
{{- toYaml .Values.imageAI.extraEnv | nindent 12 }}
{{- end }}
startupProbe:
httpGet:
port: http
path: /actuator/health/liveness
periodSeconds: 1
failureThreshold: 30
livenessProbe:
httpGet:
port: http
path: /actuator/health/liveness
readinessProbe:
httpGet:
port: http
path: /actuator/health/readiness
volumes:
- name: config
configMap:
name: {{ include "sophora-image-ai.fullname" . }}
- name: gcp-credentials
secret:
secretName: sophora-image-ai-gcp-credentials
4 changes: 4 additions & 0 deletions charts/sophora-image-ai/templates/extra-list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- range .Values.extraDeploy }}
---
{{ include "common.tplvalues.render" (dict "value" . "context" $) }}
{{- end }}
41 changes: 41 additions & 0 deletions charts/sophora-image-ai/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "sophora-image-ai.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "sophora-image-ai.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.ingressClassName }}
ingressClassName: {{ .Values.ingress.ingressClassName }}
{{- end -}}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
- path: {{ .path }}
pathType: {{ default "ImplementationSpecific" .pathType }}
backend:
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
18 changes: 18 additions & 0 deletions charts/sophora-image-ai/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "sophora-image-ai.fullname" . }}
labels:
{{- include "sophora-image-ai.labels" . | nindent 4 }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
selector:
{{- include "sophora-image-ai.selectorLabels" . | nindent 4 }}
type: {{ .Values.service.type }}
ports:
- protocol: TCP
targetPort: http
port: {{ .Values.service.port }}
46 changes: 46 additions & 0 deletions charts/sophora-image-ai/test-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
nameOverride: image-ai

image:
repository: docker.subshell.com/sophora/imageai
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: latest

imagePullSecrets:
- name: docker-subshell

sophora:
authentication:
secret:
name: sophora-secret

configuration:
sophora:
client:
server-connection:
urls:
- https://sophora-server.example.com:1196
username: # in secret
password: # in secret

spring:
cloud:
gcp:
# GCP project ID
project-id: my-project

credentials:
# path to GCP credentials file - do not change
location: file:/gcp-credentials/credentials.json

imageAI:
extraEnv:

podAnnotations: {}

ingress:
enabled: true
ingressClassName: nginx
annotations: {}
hosts:
tls: []
58 changes: 58 additions & 0 deletions charts/sophora-image-ai/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
nameOverride: ""
fullnameOverride: ""

image:
repository: docker.subshell.com/sophora/imageai
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "4.0.0"

imagePullSecrets: []

javaOptions: -XX:+ExitOnOutOfMemoryError -XX:+PerfDisableSharedMem

sophora:
authentication:
secret:
name: ""
usernameKey: username
passwordKey: password

# Represents the application.yaml of Sophora Image AI
configuration:
# Settings for the Sophora server connection.
sophora:
client:
server-connection:
urls: []
username: # in secret
password: # in secret

spring:
cloud:
gcp:
# GCP project ID
project-id: my-project

credentials:
# path to GCP credentials file - do not change
location: file:/gcp-credentials/credentials.json

imageAI:
extraEnv:

service:
type: ClusterIP
port: 8080
annotations: {}

ingress:
enabled: false
ingressClassName: nginx
annotations: {}
hosts:
tls: []

extraDeploy: []

podAnnotations: {}

0 comments on commit 735f589

Please sign in to comment.