Skip to content

Commit

Permalink
Fixing (hopefully) packaging script to keep old chart versions (#15)
Browse files Browse the repository at this point in the history
* Fixing (hopefully) packaging script to keep old chart versions

* Rolling back to stable dir for charts

* Fixing dir structure for mock chart

* Adding missing fields for mock chart manifest

* Real maintainer for mock chart manifest

* Fixing packaging script one more time

* Fixing packaging script one more time 2

* Fixing git clone chart repo

* Fixing git clone chart repo 2
  • Loading branch information
hatemosphere authored Aug 20, 2019
1 parent 156a2f6 commit b814185
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist: xenial
dist: bionic
sudo: true

install: true
Expand All @@ -21,7 +21,7 @@ deploy:
skip_cleanup: true
github_token: $GITHUB_TOKEN
keep_history: true
local_dir: dist-repo
local_dir: dist-repo/out
committer_from_gh: true
on:
branch: master
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ clean:
build: lint
cd package && \
docker-compose build && \
docker-compose run --rm package ./package/package.sh "${CHARTS_URL}" dist-repo
docker-compose run --rm package ./package/package.sh \
"${CHARTS_URL}" "${UPSTREAM_GIT_REPO}" ${GITHUB_TOKEN} dist-repo
36 changes: 25 additions & 11 deletions package/package.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
#!/usr/bin/env bash
# USAGE: package.sh <helm-repo-url> <output-dir>
# USAGE: package.sh <helm-repo-url> <git-repo> <output-dir>
# GITHUB_USER and GITHUB_TOKEN environment variables should contain valid username and token to clone chart repo

set -euo pipefail

HELM_REPO_URL="$1"
OUTPUT_DIR="$2"
GIT_REPO="$2"
GITHUB_TOKEN="$3"
BUILD_DIR="$4"
DEFAULT_GITHUB_USER=koalificationio-bot
TARGET_BRANCH=gh-pages

helm init --client-only

# add helm repos for charts in requirements
helm repo add jetstack https://charts.jetstack.io/

mkdir -p "${OUTPUT_DIR}"

mkdir -p "${BUILD_DIR}"
for chart in ./stable/*; do
echo "--- Packaging $chart into $OUTPUT_DIR"
helm dep update "$chart" || true
helm package --destination "$OUTPUT_DIR" "$chart"
echo "--- Packaging ${chart} into ${BUILD_DIR}"
helm dep update "${chart}" || true
helm package --destination "${BUILD_DIR}" "${chart}"
done
ls "${BUILD_DIR}"

git clone "https://${GITHUB_USER:-$DEFAULT_GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GIT_REPO}" out
cd out
git checkout "${TARGET_BRANCH}" || git checkout --orphan "${TARGET_BRANCH}"
cd ..

echo "--- Reindexing $OUTPUT_DIR"
cp out/index.yaml "${BUILD_DIR}" || true
pushd "${BUILD_DIR}"
echo "--- Reindexing ${BUILD_DIR}"
if [ -f index.yaml ]; then
helm repo index --url "$HELM_REPO_URL" --merge index.yaml "$OUTPUT_DIR"
helm repo index --url "${HELM_REPO_URL}" --merge index.yaml .
else
helm repo index --url "$HELM_REPO_URL" "$OUTPUT_DIR"
helm repo index --url "${HELM_REPO_URL}" .
fi
ls "$OUTPUT_DIR"
popd

cp "${BUILD_DIR}"/* out/
22 changes: 22 additions & 0 deletions stable/mock-chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
11 changes: 11 additions & 0 deletions stable/mock-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
name: mock-chart
version: 0.1.0
appVersion: "1.0"
description: A Helm chart for Kubernetes
home: https://github.com/koalificationio/charts
sources:
- https://github.com/koalificationio/charts
maintainers:
- name: hatemosphere
email: [email protected]
21 changes: 21 additions & 0 deletions stable/mock-chart/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "mock-chart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "mock-chart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "mock-chart.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "mock-chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
45 changes: 45 additions & 0 deletions stable/mock-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "mock-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 "mock-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 "mock-chart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "mock-chart.labels" -}}
app.kubernetes.io/name: {{ include "mock-chart.name" . }}
helm.sh/chart: {{ include "mock-chart.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
52 changes: 52 additions & 0 deletions stable/mock-chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mock-chart.fullname" . }}
labels:
{{ include "mock-chart.labels" . | indent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "mock-chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "mock-chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
36 changes: 36 additions & 0 deletions stable/mock-chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "mock-chart.fullname" . -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{ include "mock-chart.labels" . | indent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- 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:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions stable/mock-chart/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "mock-chart.fullname" . }}
labels:
{{ include "mock-chart.labels" . | indent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "mock-chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
15 changes: 15 additions & 0 deletions stable/mock-chart/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "mock-chart.fullname" . }}-test-connection"
labels:
{{ include "mock-chart.labels" . | indent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "mock-chart.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
50 changes: 50 additions & 0 deletions stable/mock-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Default values for mock-chart.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

service:
type: ClusterIP
port: 80

ingress:
enabled: false
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths: []

tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

nodeSelector: {}

tolerations: []

affinity: {}

0 comments on commit b814185

Please sign in to comment.