Skip to content

Commit

Permalink
Merge pull request #4 from Byzanteam/feat/yangke/add-jet-factory-chart
Browse files Browse the repository at this point in the history
feat: add jet-factory-chart
  • Loading branch information
YkeLit authored Apr 3, 2024
2 parents f3bd898 + 1c903d3 commit b1ea763
Show file tree
Hide file tree
Showing 15 changed files with 471 additions and 0 deletions.
26 changes: 26 additions & 0 deletions charts/jet-factory-chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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/
# Test dirs
tests/
ci/
22 changes: 22 additions & 0 deletions charts/jet-factory-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# chart API 版本
apiVersion: v2
# chart名称
name: jet-factory-chart
# chart 描述
description: A Helm chart for Kubernetes
# chart 类型
type: application

# chart 版本
version: 1.0.0
# 项目源码的URL列表
sources:
- https://github.com/Byzanteam/jet-helm-chart
# 维护者信息
maintainers:
# 维护者名字
- name: YangKe
# 维护者邮箱
email: [email protected]
# 包含的应用版本
appVersion: "0.1.0"
95 changes: 95 additions & 0 deletions charts/jet-factory-chart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# jet-factory-chart
## Installation
### Edit $release_name.values.yaml
1. Set imageCredentials for image pulling

```yaml
# $release_name.values.yaml

imageCredentials:
registry: registry.cn-hangzhou.aliyuncs.com
username: deploy-man@skylark
password: changeit
```
2. Set image info for image pulling
```yaml
# $release_name.values.yaml

image:
repository: jet/jet-factory
tag: "latest"
pullPolicy: IfNotPresent
```
3. Set host for app
```yaml
# $release_name.values.yaml

# Application
jetFactoryHost: factory.jet.localhost

# 此处设置数据库相关配置
database:
host: postgresql
port: "5432"
user: postgres
password: postgres
database: factory
# initcontainer 使用的 postgresql 镜像, 用于创建应用所需数据库
image: postgres:latest
```
4. Set environments for app
```yaml
# $release_name.values.yaml

# jet-factory environment variable
env:
SECRET_KEY_BASE: ""
PHX_HOST: localhost
```
### Install
```bash
# set release-name install
helm install -f $release_name.values.yaml release-name ./
```

## HowTo

### Setup TLS

> 注:# 使用命令 `base64 -i tlsFile` 生成 `certificate``key` 的值
```yaml
# $release_name.values.yaml

jetFactoryTLSSecret:
certificate: |-
base64 encoded certificate
key: |-
base64 encoded key
```
### Uninstall
```bash
helm uninstall release-name
```

### Upgrade

```bash
helm upgrade -f $release_name.values.yaml release-name ./
```

### 指定 namespace 请使用一下参数

`--namespace jet-factory` : 指定名称空间

`--create-namespace` : 创建名称空间
3 changes: 3 additions & 0 deletions charts/jet-factory-chart/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fullnameOverride: jet-factory
image:
existingImageSecret: docker-registry-secret
74 changes: 74 additions & 0 deletions charts/jet-factory-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "jet-factory-chart.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 "jet-factory-chart.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 "jet-factory-chart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

{{/*
Selector labels
*/}}
{{- define "jet-factory-chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "jet-factory-chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Return the proper image name
*/}}
{{- define "jet-factory-chart.image" }}
{{- $registryName := .Values.imageCredentials.registry -}}
{{- $repositoryName := .Values.image.repository -}}
{{- $tag := .Values.image.tag | toString -}}
{{- printf "%s/%s:%s" $registryName $repositoryName $tag -}}
{{- end }}

{{/*
Return the DATABASE_URL
*/}}
{{- define "jet-factory-chart.database-url" }}
{{- $databaseUser := .Values.database.user -}}
{{- $databasePassword := .Values.database.password -}}
{{- $databaseHost := .Values.database.host -}}
{{- $databasePort := .Values.database.port -}}
{{- $databaseDatabase := .Values.database.database -}}
{{- printf "ecto://%s:%s@%s:%s/%s" $databaseUser $databasePassword $databaseHost $databasePort $databaseDatabase -}}
{{- end }}

10 changes: 10 additions & 0 deletions charts/jet-factory-chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
{{- include "jet-factory-chart.labels" . | nindent 4 }}
name: {{ .Chart.Name }}-env
data:
{{- .Values.env | toYaml | nindent 2}}
DATABASE_URL: {{ include "jet-factory-chart.database-url" . }}

55 changes: 55 additions & 0 deletions charts/jet-factory-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "jet-factory-chart.fullname" . }}
labels:
{{- include "jet-factory-chart.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "jet-factory-chart.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "jet-factory-chart.selectorLabels" . | nindent 8 }}
spec:
# TODO: <24-04-03, yangek> remove .Values.imageCredentials#
imagePullSecrets:
{{- if .Values.image.existingImageSecret }}
- name: {{ .Values.image.existingImageSecret }}
{{- else }}
- name: {{ include "jet-factory-chart.fullname" . }}-docker-registry-secret
{{- end }}
initContainers:
- name: {{ .Chart.Name }}-create-database
command: ["sh", "-c"]
args:
- |
psql -c "SELECT 1" \
"user={{ .Values.database.user }} password={{ .Values.database.password }} dbname={{ .Values.database.database }} host={{ .Values.database.host }}" || \
psql -c "CREATE DATABASE {{ .Values.database.database }}" \
"user={{ .Values.database.user }} password={{ .Values.database.password }} host={{ .Values.database.host }}"
image: {{ .Values.database.image }}
- name: {{ .Chart.Name }}-migrate-database
command: ["/bin/bash", "-c"]
args: ["/app/bin/db_migrate" ]
envFrom:
- configMapRef:
name: {{ .Chart.Name }}-env
image: {{ include "jet-factory-chart.image" . }}
containers:
- name: {{ .Chart.Name }}
envFrom:
- configMapRef:
name: {{ .Chart.Name }}-env
image: {{ include "jet-factory-chart.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: jet-factory
containerPort: 4000
protocol: TCP
resources:
{{- .Values.resources | toYaml | nindent 12 }}
16 changes: 16 additions & 0 deletions charts/jet-factory-chart/templates/secrets/docker-registry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# TODO: <24-04-03, yangek> remove .Values.imageCredentials#
{{- define "imagePullSecret" }}
{{- with .Values.imageCredentials }}
{{- printf "{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"email\":\"%s\",\"auth\":\"%s\"}}}" .registry .username .password .email (printf "%s:%s" .username .password | b64enc) | b64enc }}
{{- end }}
{{- end }}

apiVersion: v1
kind: Secret
metadata:
name: {{ include "jet-factory-chart.fullname" $ }}-docker-registry-secret
labels:
{{- include "jet-factory-chart.labels" $ | nindent 4 }}
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: {{ template "imagePullSecret" . }}
14 changes: 14 additions & 0 deletions charts/jet-factory-chart/templates/secrets/tls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if .Values.jetTLSSecret | empty | not }}
{{- with .Values.jetTLSSecret }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "jet-factory-chart.fullname" $ }}-tls-secret
labels:
{{ include "jet-factory-chart.labels" $ | nindent 4 }}
type: kubernetes.io/tls
data:
tls.crt: {{ required "Please provide `certificate` for appTLSSecret" .certificate | nindent 4 }}
tls.key: {{ required "Please provide `key` for appTLSSecret" .key | nindent 4 }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/jet-factory-chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "jet-factory-chart.fullname" . }}
labels:
{{- include "jet-factory-chart.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.port }}
protocol: TCP
name: {{ include "jet-factory-chart.fullname" . }}
selector:
{{- include "jet-factory-chart.selectorLabels" . | nindent 4 }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Enable gzip compression
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: {{ include "jet-factory-chart.fullname" . }}-compress
spec:
compress: {}
Loading

0 comments on commit b1ea763

Please sign in to comment.