From fa7656af88ddfbc4ee17c103ada32dbb5956a32f Mon Sep 17 00:00:00 2001
From: GoshaDo <86723475+GoshaDo@users.noreply.github.com>
Date: Sun, 10 Nov 2024 16:25:28 +0200
Subject: [PATCH] ci: add local gitlab at localhost:8080 (#24)

* ci: add gitlab local support

* ci: add gitlab local support

* ci: add gitlab local support

* ci: fix e2e test
---
 gitlab.values.yaml             | 52 ++++++++++++++++++++++++++++++++++
 makefile                       |  4 +++
 scripts/init-argo-workflows.sh | 29 +++++++++++++++++++
 scripts/init-gitlab.sh         | 10 +++++++
 scripts/init-kind.sh           |  3 ++
 workflows.values.yaml          |  6 +++-
 6 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 gitlab.values.yaml
 create mode 100644 scripts/init-gitlab.sh

diff --git a/gitlab.values.yaml b/gitlab.values.yaml
new file mode 100644
index 0000000..1cad99a
--- /dev/null
+++ b/gitlab.values.yaml
@@ -0,0 +1,52 @@
+gitlab:
+  toolbox:
+    enabled: false
+  gitlab-shell:
+    enabled: false
+  gitlab-pages:
+    enabled: false
+  gitlab-exporter:
+    enabled: false
+  kas:
+    minReplicas: 1
+  webservice:
+    minReplicas: 1
+    ingress:
+      requireBasePath: false
+global:
+  hosts:
+    domain: localhost
+    https: false
+    gitlab:
+      name: localhost
+      https: false
+  ingress:
+    enabled: true
+    configureCertmanager: false
+    tls:
+      enabled: false
+  redis:
+    install: false
+traefik:
+  enabled: false
+gitlab-runner:
+  install: false
+registry:
+  enabled: false
+prometheus:
+  install: false
+certmanager:
+  installCRDs: false
+  install: false
+
+nginx-ingress:
+  controller:
+    ingressClassResource:
+      name: gitlab-nginx
+      controllerValue: "k8s.io/ingress-nginx-gitlab"
+    replicaCount: 1
+    minAavailable: 1
+    service:
+      type: NodePort
+      nodePorts:
+        http: 32080
diff --git a/makefile b/makefile
index 8e952ed..bca3f7a 100644
--- a/makefile
+++ b/makefile
@@ -34,6 +34,10 @@ init-argo-workflows: init-kind
 init-piper: init-kind local-build
 	sh ./scripts/init-piper.sh
 
+.PHONY: init-gitlab
+init-gitlab: init-kind
+	sh ./scripts/init-gitlab.sh
+
 .PHONY: deploy
 deploy: init-kind init-nginx init-argo-workflows local-build local-push init-piper
 
diff --git a/scripts/init-argo-workflows.sh b/scripts/init-argo-workflows.sh
index 64e7a02..2237396 100644
--- a/scripts/init-argo-workflows.sh
+++ b/scripts/init-argo-workflows.sh
@@ -8,3 +8,32 @@ if [ -z "$(helm list -n workflows | grep argo-workflow)" ]; then
 else
   echo "Workflows release exists, skipping installation"
 fi
+
+
+cat <<EOF | kubectl apply -n workflows -f -
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: argo-workflows-sa
+automountServiceAccountToken: true
+---
+apiVersion: v1
+kind: Secret
+metadata:
+  name: argo-workflows-sa.service-account-token
+  annotations:
+    kubernetes.io/service-account.name: argo-workflows-sa
+type: kubernetes.io/service-account-token
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: RoleBinding
+metadata:
+  name: argo-workflows-sa
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: Role
+  name: argo-workflow-argo-workflows-workflow
+subjects:
+  - kind: ServiceAccount
+    name: argo-workflows-sa
+EOF
\ No newline at end of file
diff --git a/scripts/init-gitlab.sh b/scripts/init-gitlab.sh
new file mode 100644
index 0000000..8662bf5
--- /dev/null
+++ b/scripts/init-gitlab.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+set -o errexit
+
+if [ -z "$(helm list -n gitlab | grep gitlab)" ]; then
+  # 8. Install gitlab
+  helm repo add gitlab https://charts.gitlab.io/
+  helm upgrade --install gitlab --create-namespace -n gitlab gitlab/gitlab -f gitlab.values.yaml
+else
+  echo "Gitlab release exists, skipping installation"
+fi
\ No newline at end of file
diff --git a/scripts/init-kind.sh b/scripts/init-kind.sh
index ec81173..f1fb2c5 100644
--- a/scripts/init-kind.sh
+++ b/scripts/init-kind.sh
@@ -31,6 +31,9 @@ nodes:
   - containerPort: 443
     hostPort: 443
     protocol: TCP
+  - containerPort: 32080
+    hostPort: 8080
+    listenAddress: "0.0.0.0"
 containerdConfigPatches:
 - |-
   [plugins."io.containerd.grpc.v1.cri".registry]
diff --git a/workflows.values.yaml b/workflows.values.yaml
index fccf550..472b1f0 100644
--- a/workflows.values.yaml
+++ b/workflows.values.yaml
@@ -1,6 +1,9 @@
 controller:
   workflowNamespaces:
     - workflows
+  workflowDefaults:
+    spec:
+      serviceAccountName: argo-workflows-sa
 server:
   baseHref: /argo/
   serviceAccount:
@@ -15,4 +18,5 @@ server:
       nginx.ingress.kubernetes.io/backend-protocol: HTTP
     paths:
       - /argo/(.*)
-      - /argo
\ No newline at end of file
+      - /argo
+    pathType: ImplementationSpecific
\ No newline at end of file