Skip to content

Commit bfb8c8c

Browse files
Merge pull request #1 from opsta/replace-with-onechart
Sync onechart&cnpg template
2 parents 2bc8bbc + f96fc2c commit bfb8c8c

46 files changed

Lines changed: 703 additions & 290 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- '*'
6+
pull_request:
7+
branches:
8+
- '*'
9+
10+
jobs:
11+
build:
12+
name: Build
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: 1.16
20+
cache: false
21+
22+
- name: Deps
23+
run: |
24+
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
25+
chmod 700 get_helm.sh
26+
./get_helm.sh
27+
28+
wget https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-linux-amd64.tar.gz
29+
tar xf kubeval-linux-amd64.tar.gz
30+
sudo cp kubeval /usr/local/bin
31+
32+
helm plugin install https://github.com/helm-unittest/helm-unittest
33+
34+
- name: Check out
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 1
38+
39+
- name: Test
40+
run: |
41+
make lint
42+
make kubeval
43+
make test

.github/workflows/release.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
13+
permissions:
14+
contents: write
15+
packages: write
16+
17+
steps:
18+
19+
- name: Checkout main
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Extract tag version
25+
id: versioning
26+
run: |
27+
tag=${GITHUB_REF/refs\/tags\//}
28+
tag=${tag#v}
29+
echo "tag_version=$tag" >> $GITHUB_OUTPUT
30+
31+
- name: Extract chart versions
32+
id: chart_versions
33+
run: |
34+
ONECHART_VERSION=$(grep '^version:' charts/onechart/Chart.yaml | awk '{print $2}')
35+
CRON_JOB_VERSION=$(grep '^version:' charts/cron-job/Chart.yaml | awk '{print $2}')
36+
STATIC_SITE_VERSION=$(grep '^version:' charts/static-site/Chart.yaml | awk '{print $2}')
37+
38+
echo "onechart_version=$ONECHART_VERSION" >> $GITHUB_OUTPUT
39+
echo "cron_job_version=$CRON_JOB_VERSION" >> $GITHUB_OUTPUT
40+
echo "static_site_version=$STATIC_SITE_VERSION" >> $GITHUB_OUTPUT
41+
42+
- name: Ensure tag and chart versions match
43+
run: |
44+
echo "Tag version: $TAG_VERSION"
45+
echo "onechart version: $ONECHART_VERSION"
46+
echo "cron-job version: $CRON_JOB_VERSION"
47+
echo "static-site version: $STATIC_SITE_VERSION"
48+
49+
if [ "$TAG_VERSION" != "$ONECHART_VERSION" ]; then
50+
echo "::error::Tag version ($TAG_VERSION) does not match onechart version ($ONECHART_VERSION)"
51+
exit 1
52+
fi
53+
if [ "$TAG_VERSION" != "$CRON_JOB_VERSION" ]; then
54+
echo "::error::Tag version ($TAG_VERSION) does not match cron-job version ($CRON_JOB_VERSION)"
55+
exit 1
56+
fi
57+
if [ "$TAG_VERSION" != "$STATIC_SITE_VERSION" ]; then
58+
echo "::error::Tag version ($TAG_VERSION) does not match static-site version ($STATIC_SITE_VERSION)"
59+
exit 1
60+
fi
61+
echo "All versions match!"
62+
env:
63+
TAG_VERSION: ${{ steps.versioning.outputs.tag_version }}
64+
ONECHART_VERSION: ${{ steps.chart_versions.outputs.onechart_version }}
65+
CRON_JOB_VERSION: ${{ steps.chart_versions.outputs.cron_job_version }}
66+
STATIC_SITE_VERSION: ${{ steps.chart_versions.outputs.static_site_version }}
67+
68+
- name: Create a Release
69+
uses: elgohr/Github-Release-Action@v5
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
with:
73+
title: Release ${{ github.ref }}
74+
75+
- name: Publishing to the Helm repository
76+
run: |
77+
git config --global user.email "action@github.com"
78+
git config --global user.name "Github Action"
79+
git checkout main
80+
make package
81+
git add .
82+
git commit -m "Publishing $TAG_VERSION to the Helm repository"
83+
git push origin main
84+
env:
85+
TAG_VERSION: ${{ steps.versioning.outputs.tag_version }}
86+
87+
- name: Publish to GHCR
88+
run: |
89+
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io \
90+
--username ${{ github.repository_owner }} \
91+
--password-stdin
92+
93+
helm push docs/cnpg-chart-${{ env.TAG_VERSION }}.tgz oci://ghcr.io/${{ github.repository_owner }}
94+
95+
env:
96+
TAG_VERSION: ${{ steps.versioning.outputs.tag_version }}
97+
98+
- name: Preparing the next release version
99+
run: |
100+
git config --global user.email "action@github.com"
101+
git config --global user.name "Github Action"
102+
git checkout main
103+
104+
CURRENT_VERSION=${{ env.TAG_VERSION }}
105+
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{printf "%d.%d.0", $1, $2+1}')
106+
107+
echo "Current version: $CURRENT_VERSION"
108+
echo "New version will be $NEW_VERSION"
109+
110+
sed -i "s/^\(version:\s*\)$CURRENT_VERSION/\1$NEW_VERSION/" charts/onechart/Chart.yaml
111+
sed -i "s/^\(version:\s*\)$CURRENT_VERSION/\1$NEW_VERSION/" charts/cron-job/Chart.yaml
112+
sed -i "s/^\(version:\s*\)$CURRENT_VERSION/\1$NEW_VERSION/" charts/static-site/Chart.yaml
113+
114+
sed -i "s/$CURRENT_VERSION/$NEW_VERSION/" README.md
115+
sed -i "s/$CURRENT_VERSION/$NEW_VERSION/" docs/onechart.md
116+
117+
git status
118+
git add .
119+
git commit -m "Prepare next release version $NEW_VERSION"
120+
git push origin main
121+
env:
122+
TAG_VERSION: ${{ steps.versioning.outputs.tag_version }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
manifests
3+
website/site
4+
website/awesome_venv

.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ OneChart is a generic Helm Chart for web applications. The idea is that most Kub
1414

1515
You can also template and install onechart from an OCI repository as follows:
1616

17-
> **Note:** The examples use version `0.77.0`. This will be the unreleased version if you are at the `main` branch.
17+
> **Note:** The examples use version `0.80.0`. This will be the unreleased version if you are at the `main` branch.
1818
1919
> You can find the latest released version in the [releases](https://github.com/opsta/onechart/releases) page.
2020
2121
Check the generated Kubernetes yaml:
2222

2323
```bash
24-
helm template my-release oci://ghcr.io/opsta/onechart --version 0.77.0 \
24+
helm template my-release oci://ghcr.io/opsta/onechart --version 0.80.0 \
2525
--set image.repository=nginx \
2626
--set image.tag=1.19.3
2727
```
2828

2929
Deploy with Helm:
3030

3131
```bash
32-
helm install my-release oci://ghcr.io/opsta/onechart --version 0.77.0 \
32+
helm install my-release oci://ghcr.io/opsta/onechart --version 0.80.0 \
3333
--set image.repository=nginx \
3434
--set image.tag=1.19.3
3535
```
3636

3737
The example below deploys your application image, sets environment variables and configures the Kubernetes Ingress domain name:
3838

3939
```bash
40-
helm template my-release oci://ghcr.io/opsta/onechart --version 0.77.0 -f values.yaml
40+
helm template my-release oci://ghcr.io/opsta/onechart --version 0.80.0 -f values.yaml
4141

4242
# values.yaml
4343
image:

charts/cnpg/Chart.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
apiVersion: v1
2-
description: CNPG (China Postgres)
2+
description: Cloud Native Postgres
33
name: cnpg
44
version: 0.1.0
55
appVersion: 0.1.0
6-
home: /
76
maintainers:
87
- name: Developer
98
email: dev@opsta.in.th

charts/cnpg/templates/cluster.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if .Values.enabled -}}
1+
{{- if .Values.enabled }}
22
#{{- $cnpg := .Values.cnpg -}}
33
{{- $backup := .Values.backup -}}
44
{{- $bos := $backup.barmanObjectStore -}}
@@ -10,7 +10,7 @@
1010

1111
{{- if and $backup.enabled (not $s3SecretName) -}}
1212
{{- fail "backup.enabled=true but S3 secret name resolved empty (unexpected)" -}}
13-
{{- end -}}
13+
{{ end }}
1414

1515
apiVersion: postgresql.cnpg.io/v1
1616
kind: Cluster
@@ -23,13 +23,13 @@ spec:
2323
{{- if .Values.superuser.enabled }}
2424
enableSuperuserAccess: true
2525
superuserSecret:
26-
name: {{ printf "%s-cnpg-admin-creds" .Release.Name | trunc 63 | trimSuffix "-" | quote }}
27-
{{- end }}
26+
name: {{ printf "%s-cnpg-superuser-secret" .Release.Name | trunc 63 | trimSuffix "-" | quote }}
27+
{{ end }}
2828

2929
{{- with .Values.cluster.resources }}
3030
resources:
3131
{{- toYaml . | nindent 4 }}
32-
{{- end }}
32+
{{ end }}
3333

3434
storage:
3535
size: {{ .Values.cluster.storage.size | quote }}
@@ -57,13 +57,13 @@ spec:
5757
compression: {{ $bos.compression.data | quote }}
5858
wal:
5959
compression: {{ $bos.compression.wal | quote }}
60-
{{- end }}
60+
{{ end }}
6161

6262
{{- if .Values.bootstrap.enabled }}
6363
bootstrap:
6464
initdb:
65-
{{- toYaml .Values.bootstrap.initdb | nindent 6 }}
66-
secretName:
65+
{{- toYaml .Values.bootstrap.initdb | nindent 6 }}
66+
secret:
6767
name: {{ printf "%s-cnpg-app-creds" .Release.Name | trunc 63 | trimSuffix "-" | quote }}
68-
{{- end }}
69-
{{- end -}}
68+
{{ end }}
69+
{{ end }}
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
{{- if and .Values.enabled .Values.superuser.enabled (.Values.superuser.secretName) }}
1+
{{- if and .Values.enabled .Values.superuser.enabled }}
2+
{{- $secretName := printf "%s-cnpg-superuser-secret" .Release.Name | trunc 63 | trimSuffix "-" }}
3+
{{- $existing := lookup "v1" "Secret" .Release.Namespace $secretName }}
24
apiVersion: v1
35
kind: Secret
46
metadata:
5-
name: {{ printf "%s-cnpg-admin-creds" .Release.Name | trunc 63 | trimSuffix "-" | quote }}
6-
type: kubernetes.io/basic-auth
7+
name: {{ $secretName | quote }}
8+
type: {{ default "kubernetes.io/basic-auth" }}
79
stringData:
8-
password: {{ randAlphaNum 16 | quote }}
10+
username: postgres
11+
password: {{- if .Values.superuser.password }}
12+
{{ .Values.superuser.password | quote }}
13+
{{- else if $existing }}
14+
{{ index $existing.data "password" | b64dec | quote }}
15+
{{- else }}
16+
{{ randAlphaNum 32 | quote }}
17+
{{- end }}
918
{{- end }}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
{{- if and .Values.enabled .Values.postgresAuth.create }}
2+
{{- $secretName := printf "%s-cnpg-app-creds" .Release.Name | trunc 63 | trimSuffix "-" }}
3+
{{- $existing := lookup "v1" "Secret" .Release.Namespace $secretName }}
24
apiVersion: v1
35
kind: Secret
46
metadata:
5-
name: {{ printf "%s-cnpg-app-creds" .Release.Name | trunc 63 | trimSuffix "-" | quote }}
7+
name: {{ $secretName | quote }}
68
type: {{ .Values.postgresAuth.type | default "kubernetes.io/basic-auth" }}
79
stringData:
810
username: {{ .Values.postgresAuth.username | quote }}
9-
password: {{ .Values.postgresAuth.password | quote }}
11+
password: {{- if .Values.postgresAuth.password }}
12+
{{ .Values.postgresAuth.password | quote }}
13+
{{- else if $existing }}
14+
{{ index $existing.data "password" | b64dec | quote }}
15+
{{- else }}
16+
{{ randAlphaNum 32 | quote }}
17+
{{- end }}
1018
{{- end }}

charts/cnpg/values.yaml

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ cluster:
2222

2323
postgresAuth:
2424
create: true
25-
username: cnpg
26-
password: ch@ngem3#
25+
username:
26+
password:
2727

2828
backup:
2929
enabled: true
3030
retentionPolicy: "7d"
3131
barmanObjectStore:
32-
destinationPath: s3://postgres-backup/
33-
endpointURL: https://seaweed-dso.mea-poc.opsta.in.th/buckets/
32+
destinationPath: s3://postgres-backups/
33+
endpointURL: https://opsta.in.th/buckets/
3434
s3Credentials:
35-
create: true
36-
accessKeyValue: admin
37-
secretKeyValue: ch@ngem3#
35+
create: false
36+
accessKeyValue:
37+
secretKeyValue:
3838
compression:
3939
data: gzip
4040
wal: gzip
@@ -50,10 +50,4 @@ bootstrap:
5050
initdb:
5151
database: cnpg
5252
owner: cnpg
53-
localeCollate: 'en_US'
54-
localeCType: 'en_US'
55-
encoding: 'UTF8'
56-
postInitSQL:
57-
postInitApplicationSQLRefs:
58-
secretRefs:
59-
configMapRefs:
53+

0 commit comments

Comments
 (0)