Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bitbucket and gitlab support #1

Merged
merged 3 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bitbucket/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
certs/*
21 changes: 21 additions & 0 deletions bitbucket/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
13 changes: 13 additions & 0 deletions bitbucket/1_deploy_bitbucket.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

helm install --create-namespace --namespace bitbucket bitbucket --values values.yaml .

oc rollout status deployment/bitbucket -n bitbucket
17 changes: 17 additions & 0 deletions bitbucket/2_generate_keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

rm -rf ./certs
mkdir certs
openssl genrsa -out ./certs/private.pem 2048
openssl rsa -in ./certs/private.pem -pubout > ./certs/public.pub
openssl pkcs8 -topk8 -inform pem -outform pem -nocrypt -in ./certs/private.pem -out ./certs/privatepkcs8.pem
openssl rand -base64 24 > ./certs/bitbucket_server_consumer_key
openssl rand -base64 24 > ./certs/bitbucket_shared_secret
45 changes: 45 additions & 0 deletions bitbucket/3_configure_links.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

source .././utils.sh
define_namespace

oc project $NAMESPACE
CHE_ROUTE=$(oc get route/che --namespace=$NAMESPACE -o=jsonpath={'.spec.host'})
BITBUCKET_ROUTE=$(oc get route/bitbucket --namespace=bitbucket -o=jsonpath={'.spec.host'})
CHE_SERVER_URL='https://'${CHE_ROUTE}
BITBUCKET_URL='https://'${BITBUCKET_ROUTE}
PUB_KEY=$(cat ./certs/public.pub | sed 's/-----BEGIN PUBLIC KEY-----//g' | sed 's/-----END PUBLIC KEY-----//g' | tr -d '\n')
CONSUMER_KEY=$(cat ./certs/bitbucket_server_consumer_key)
SHARED_SECRET=$(cat ./certs/bitbucket_shared_secret)
echo ' '
echo ' '
echo ' Open '$BITBUCKET_URL
echo ' '
echo ' '
echo ' Go to Administration -> Application Links'
echo ' Enter ->> '$CHE_SERVER_URL'/dashboard/ in the 'application url' field and press the 'Create new link' button and `Continue`.'
echo ' After that in `Link applications` window'
echo ' Application Name: Che'
echo ' Application Type: Generic Application'
echo ' Service Provider Name: Che'
echo ' Consumer key: '$CONSUMER_KEY
echo ' Shared secret: '$SHARED_SECRET
echo ' Request Token URL: '$BITBUCKET_URL'/plugins/servlet/oauth/request-token'
echo ' Access token URL: '$BITBUCKET_URL'/plugins/servlet/oauth/access-token'
echo ' Authorize URL: '$BITBUCKET_URL'/plugins/servlet/oauth/authorize'
echo ' Create incoming link: true'
echo ' '
echo ' Next screen '
echo ' '
echo ' Consumer Key: '$CONSUMER_KEY
echo ' Consumer Name: Che'
echo ' Public Key : '$PUB_KEY

47 changes: 47 additions & 0 deletions bitbucket/4_setupche.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
#
# Copyright (c) 2022 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#

source .././utils.sh
define_namespace

CONSUMER_KEY=$(cat ./certs/bitbucket_server_consumer_key)
SHARED_SECRET=$(cat ./certs/bitbucket_shared_secret)
PRIVATE_KEY=$(cat ./certs/privatepkcs8.pem | sed 's/-----BEGIN PRIVATE KEY-----//g' | sed 's/-----END PRIVATE KEY-----//g' | tr -d '\n')
BITBUCKET_HOST=$(oc get routes -n bitbucket -o json | jq -r '.items[0].spec.host')
unameOut="$(uname -s)"

case "${unameOut}" in
Linux*) BASE64_FUNC='base64 -w 0';;
Darwin*) BASE64_FUNC='base64';;
CYGWIN*) BASE64_FUNC='base64 -w 0';;
MINGW*) BASE64_FUNC='base64 -w 0';;
*) BASE64_FUNC='base64 -w 0'
esac

oc project $NAMESPACE
oc delete secret bitbucket-oauth-config --ignore-not-found=false

cat <<EOF | oc apply -n $NAMESPACE -f -
kind: Secret
apiVersion: v1
metadata:
name: bitbucket-oauth-config
labels:
app.kubernetes.io/part-of: che.eclipse.org
app.kubernetes.io/component: oauth-scm-configuration
annotations:
che.eclipse.org/oauth-scm-server: bitbucket
che.eclipse.org/scm-server-endpoint: https://$BITBUCKET_HOST
type: Opaque
data:
private.key: $(echo -n $PRIVATE_KEY | $BASE64_FUNC)
consumer.key: $(echo -n $CONSUMER_KEY | $BASE64_FUNC)
shared_secret: $(echo -n $SHARED_SECRET | $BASE64_FUNC)
EOF
5 changes: 5 additions & 0 deletions bitbucket/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for bitbucket kubernetes
name: bitbucket
version: 0.1.0
10 changes: 10 additions & 0 deletions bitbucket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Helm Chart For Bitbucket

1. 1_deploy_bitbucket.sh
2. 2_generate_keys.sh
3. 3_configure_links.sh
4. 4_setupche.sh

Prerequisites:
* kubectl, helm, oc
* Authorised oc connection to an Openshift cluster
19 changes: 19 additions & 0 deletions bitbucket/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "bitbucket.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 svc -w {{ include "bitbucket.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "bitbucket.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={{ include "bitbucket.name" . }},release={{ .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 }}
32 changes: 32 additions & 0 deletions bitbucket/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "bitbucket.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 "bitbucket.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 "bitbucket.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
62 changes: 62 additions & 0 deletions bitbucket/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: {{ .Values.namespace }}
name: {{ include "bitbucket.fullname" . }}
labels:
app: {{ include "bitbucket.name" . }}
chart: {{ include "bitbucket.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ include "bitbucket.name" . }}
release: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ include "bitbucket.name" . }}
release: {{ .Release.Name }}
spec:
volumes:
- name: bitbucket-vol
persistentVolumeClaim:
claimName: {{ default (include "bitbucket.fullname" .) }}-data
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: SERVER_PORT
value: '7990'
- name: SERVER_SCHEME
value: https
- name: SERVER_SECURE
value: 'true'
- name: SERVER_PROXY_PORT
value: '443'
- name: SERVER_PROXY_NAME
value: '{{ .Values.proxyName }}'
volumeMounts:
- name: bitbucket-vol
mountPath: /var/atlassian/application-data/bitbucket
ports:
- name: bitbucket
containerPort: 7990
protocol: TCP
resources:
{{ toYaml .Values.resources | indent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
38 changes: 38 additions & 0 deletions bitbucket/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "bitbucket.fullname" . -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app: {{ include "bitbucket.name" . }}
chart: {{ include "bitbucket.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 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: {{ . | quote }}
http:
paths:
- path: {{ $ingressPath }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}
17 changes: 17 additions & 0 deletions bitbucket/templates/pvc-bit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: bitbucket-data
namespace: {{ .Values.namespace }}
spec:
accessModes:
{{- range .Values.persistence.accessModes }}
- {{ . | quote }}
{{- end }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
storageClassName: {{ .Values.persistence.storageClassName }}
{{- end -}}

22 changes: 22 additions & 0 deletions bitbucket/templates/route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: {{ include "bitbucket.fullname" . }}
labels:
app: {{ include "bitbucket.name" . }}
chart: {{ include "bitbucket.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
to:
kind: Service
name: {{ include "bitbucket.fullname" . }}
tls:
insecureEdgeTerminationPolicy: Redirect
termination: edge
port:
targetPort: 7990
20 changes: 20 additions & 0 deletions bitbucket/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
namespace: {{ .Values.namespace }}
name: {{ include "bitbucket.fullname" . }}
labels:
app: {{ include "bitbucket.name" . }}
chart: {{ include "bitbucket.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: 7990
protocol: TCP
name: http
selector:
app: {{ include "bitbucket.name" . }}
release: {{ .Release.Name }}
Loading