Skip to content

Commit e585e01

Browse files
committed
Draft create
1 parent 747cb3f commit e585e01

18 files changed

+417
-0
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
draft.toml
2+
charts/
3+
NOTICE
4+
LICENSE
5+
README.md

.helmignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
*.png
23+
24+
# known compile time folders
25+
target/
26+
node_modules/
27+
vendor/

Jenkinsfile

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
pipeline {
2+
agent {
3+
label "jenkins-python"
4+
}
5+
environment {
6+
ORG = 'gitcoinco'
7+
APP_NAME = 'web'
8+
CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum')
9+
}
10+
stages {
11+
stage('CI Build and push snapshot') {
12+
when {
13+
branch 'PR-*'
14+
}
15+
environment {
16+
PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER"
17+
PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase()
18+
HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase()
19+
}
20+
steps {
21+
container('python') {
22+
sh "python -m unittest"
23+
24+
sh 'export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml'
25+
26+
27+
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION"
28+
}
29+
30+
dir ('./charts/preview') {
31+
container('python') {
32+
sh "make preview"
33+
sh "jx preview --app $APP_NAME --dir ../.."
34+
}
35+
}
36+
}
37+
}
38+
stage('Build Release') {
39+
when {
40+
branch 'master'
41+
}
42+
steps {
43+
container('python') {
44+
// ensure we're not on a detached head
45+
sh "git checkout master"
46+
sh "git config --global credential.helper store"
47+
48+
sh "jx step git credentials"
49+
// so we can retrieve the version in later steps
50+
sh "echo \$(jx-release-version) > VERSION"
51+
}
52+
dir ('./charts/web') {
53+
container('python') {
54+
sh "make tag"
55+
}
56+
}
57+
container('python') {
58+
sh "python -m unittest"
59+
60+
sh 'export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml'
61+
62+
sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)"
63+
}
64+
}
65+
}
66+
stage('Promote to Environments') {
67+
when {
68+
branch 'master'
69+
}
70+
steps {
71+
dir ('./charts/web') {
72+
container('python') {
73+
sh 'jx step changelog --version v\$(cat ../../VERSION)'
74+
75+
// release the helm chart
76+
sh 'jx step helm release'
77+
78+
// promote through all 'Auto' promotion Environments
79+
sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION)'
80+
}
81+
}
82+
}
83+
}
84+
}
85+
post {
86+
always {
87+
cleanWs()
88+
}
89+
}
90+
}

charts/preview/Chart.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
description: A Helm chart for Kubernetes
3+
icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/python.png
4+
name: preview
5+
version: 0.1.0-SNAPSHOT

charts/preview/Makefile

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
OS := $(shell uname)
2+
3+
preview:
4+
ifeq ($(OS),Darwin)
5+
sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml
6+
sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml
7+
sed -i "" -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml
8+
else ifeq ($(OS),Linux)
9+
sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml
10+
sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml
11+
sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)\/gitcoinco\/web|" values.yaml
12+
sed -i -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml
13+
else
14+
echo "platfrom $(OS) not supported to release from"
15+
exit -1
16+
endif
17+
echo " version: $(PREVIEW_VERSION)" >> requirements.yaml
18+
jx step helm build

charts/preview/requirements.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
dependencies:
3+
- alias: expose
4+
name: exposecontroller
5+
repository: https://chartmuseum.build.cd.jenkins-x.io
6+
version: 2.3.56
7+
- alias: cleanup
8+
name: exposecontroller
9+
repository: https://chartmuseum.build.cd.jenkins-x.io
10+
version: 2.3.56
11+
- alias: preview
12+
name: web
13+
repository: file://../web

charts/preview/values.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
expose:
3+
Annotations:
4+
helm.sh/hook: post-install,post-upgrade
5+
helm.sh/hook-delete-policy: hook-succeeded
6+
config:
7+
exposer: Ingress
8+
http: true
9+
tlsacme: false
10+
11+
cleanup:
12+
Args:
13+
- --cleanup
14+
Annotations:
15+
helm.sh/hook: pre-delete
16+
helm.sh/hook-delete-policy: hook-succeeded
17+
18+
preview:
19+
image:
20+
repository:
21+
tag:
22+
pullPolicy: IfNotPresent

charts/web/.helmignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj

charts/web/Chart.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
description: A Helm chart for Kubernetes
3+
name: web
4+
version: v0.1.0

charts/web/Makefile

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
CHART_REPO := http://jenkins-x-chartmuseum:8080
2+
CURRENT=$(pwd)
3+
NAME := web
4+
OS := $(shell uname)
5+
RELEASE_VERSION := $(shell cat ../../VERSION)
6+
7+
build: clean
8+
rm -rf requirements.lock
9+
helm dependency build
10+
helm lint
11+
12+
install: clean build
13+
helm install . --name ${NAME}
14+
15+
upgrade: clean build
16+
helm upgrade ${NAME} .
17+
18+
delete:
19+
helm delete --purge ${NAME}
20+
21+
clean:
22+
rm -rf charts
23+
rm -rf ${NAME}*.tgz
24+
25+
release: clean
26+
helm dependency build
27+
helm lint
28+
helm init --client-only
29+
helm package .
30+
curl --fail -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts
31+
rm -rf ${NAME}*.tgz%
32+
33+
tag:
34+
ifeq ($(OS),Darwin)
35+
sed -i "" -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
36+
sed -i "" -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
37+
else ifeq ($(OS),Linux)
38+
sed -i -e "s/version:.*/version: $(RELEASE_VERSION)/" Chart.yaml
39+
sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)\/gitcoinco\/web|" values.yaml
40+
sed -i -e "s/tag: .*/tag: $(RELEASE_VERSION)/" values.yaml
41+
else
42+
echo "platfrom $(OS) not supported to release from"
43+
exit -1
44+
endif
45+
git add --all
46+
git commit -m "release $(RELEASE_VERSION)" --allow-empty # if first release then no verion update is performed
47+
git tag -fa v$(RELEASE_VERSION) -m "Release version $(RELEASE_VERSION)"
48+
git push origin v$(RELEASE_VERSION)

charts/web/templates/NOTES.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
{{- if contains "NodePort" .Values.service.type }}
3+
Get the application URL by running these commands:
4+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
5+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
6+
echo http://$NODE_IP:$NODE_PORT/login
7+
{{- else if contains "LoadBalancer" .Values.service.type }}
8+
Get the application URL by running these commands:
9+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
10+
You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}'
11+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
12+
echo http://$SERVICE_IP:{{ .Values.service.externalPort }}
13+
{{- else }}
14+
http://{{ .Release.Name }}.{{ .Values.basedomain }} to access your application
15+
{{- end }}

charts/web/templates/_helpers.tpl

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
*/}}
13+
{{- define "fullname" -}}
14+
{{- $name := default .Chart.Name .Values.nameOverride -}}
15+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
16+
{{- end -}}

charts/web/templates/deployment.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: {{ template "fullname" . }}
5+
labels:
6+
draft: {{ default "draft-app" .Values.draft }}
7+
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
8+
spec:
9+
replicas: {{ .Values.replicaCount }}
10+
template:
11+
metadata:
12+
labels:
13+
draft: {{ default "draft-app" .Values.draft }}
14+
app: {{ template "fullname" . }}
15+
{{- if .Values.podAnnotations }}
16+
annotations:
17+
{{ toYaml .Values.podAnnotations | indent 8 }}
18+
{{- end }}
19+
spec:
20+
containers:
21+
- name: {{ .Chart.Name }}
22+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
23+
imagePullPolicy: {{ .Values.image.pullPolicy }}
24+
ports:
25+
- containerPort: {{ .Values.service.internalPort }}
26+
resources:
27+
{{ toYaml .Values.resources | indent 12 }}

charts/web/templates/ingress.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- if .Values.ingress.enabled -}}
2+
apiVersion: extensions/v1beta1
3+
kind: Ingress
4+
metadata:
5+
name: {{ template "fullname" . }}
6+
labels:
7+
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
8+
spec:
9+
rules:
10+
- host: {{ .Release.Name }}.{{ .Values.basedomain }}
11+
http:
12+
paths:
13+
- path: /
14+
backend:
15+
serviceName: {{ template "fullname" . }}
16+
servicePort: {{ .Values.service.externalPort }}
17+
{{- end -}}

charts/web/templates/service.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
{{- if .Values.service.name }}
5+
name: {{ .Values.service.name }}
6+
{{- else }}
7+
name: {{ template "fullname" . }}
8+
{{- end }}
9+
labels:
10+
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
11+
{{- if .Values.service.annotations }}
12+
annotations:
13+
{{ toYaml .Values.service.annotations | indent 4 }}
14+
{{- end }}
15+
spec:
16+
type: {{ .Values.service.type }}
17+
ports:
18+
- port: {{ .Values.service.externalPort }}
19+
targetPort: {{ .Values.service.internalPort }}
20+
protocol: TCP
21+
name: http
22+
selector:
23+
app: {{ template "fullname" . }}

charts/web/values.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Default values for python.
2+
# This is a YAML-formatted file.
3+
# Declare variables to be passed into your templates.
4+
replicaCount: 1
5+
image:
6+
repository: draft
7+
tag: dev
8+
pullPolicy: IfNotPresent
9+
service:
10+
name: web
11+
type: ClusterIP
12+
externalPort: 80
13+
internalPort: 8080
14+
annotations:
15+
fabric8.io/expose: "true"
16+
fabric8.io/ingress.annotations: "kubernetes.io/ingress.class: nginx"
17+
resources:
18+
limits:
19+
cpu: 100m
20+
memory: 128Mi
21+
requests:
22+
cpu: 100m
23+
memory: 128Mi
24+
ingress:
25+
enabled: false

0 commit comments

Comments
 (0)