roles/gitlab: add gitlab-pre-install.sh

This commit is contained in:
Haitao Pan 2023-05-12 18:58:31 +08:00
parent 30ed9977ca
commit ea097560e6
7 changed files with 37 additions and 150 deletions

View File

@ -46,7 +46,7 @@ jobs:
mkdir -pv hosts/
cat > hosts/inventory << EOF
[master]
gitlab.onwalk.net ansible_host=20.222.214.219
common-gitlab.apollo-ev.com ansible_host=161.189.79.201
[all:vars]
ansible_port=8022
@ -55,7 +55,7 @@ jobs:
ansible_host_key_checking=False
dns_ak=$DNS_AK
dns_sk=$DNS_SK
ingress_ip=20.222.214.219
ingress_ip=161.189.79.201
smtp_password=$SMTP_PASSWORD
gitlab_odic_client_token=$GITLAB_OIDC_CLIENT_TOKEN
EOF
@ -89,7 +89,7 @@ jobs:
mkdir -pv hosts/
cat > hosts/inventory << EOF
[master]
common-artifact.apollo-ev.com ansible_host=52.83.75.244
common-gitlab.apollo-ev.com ansible_host=20.222.214.219
[all:vars]
ansible_port=22
@ -100,7 +100,7 @@ jobs:
ali_sk=$ALI_SK
dns_ak=$DNS_AK
dns_sk=$DNS_SK
ingress_ip=10.1.1.206
ingress_ip=20.222.214.219
harbor_admin_password=$HARBOR_ADMIN_PASSWORD
harbor_odic_client_token=$HARBOR_OIDC_CLIENT_TOKEN
EOF

View File

@ -0,0 +1,5 @@
#!/bin/bash
export namespace=$1
export POSTGRES_PASSWORD=`kubectl get secret --namespace $namespace postgresql -o jsonpath="{.data.postgres-password}" | base64 -d`
kubectl run postgresql-client --rm --tty -i --restart='Never' --namespace $namespace --image docker.io/bitnami/postgresql:15.2.0-debian-11-r11 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host postgresql -U postgres -d postgres -p 5432 -w -c "CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE EXTENSION IF NOT EXISTS btree_gist; CREATE DATABASE gitlabhq_production OWNER gitlab;" || echo true

View File

@ -1,118 +0,0 @@
#!/bin/bash
check_empty() {
if [ -z "$1" ]; then
echo "$2"
exit 1
fi
}
check_empty "$1" "Please provide a domain name as the first argument"
check_empty "$2" "Please provide a namespace as the second argument"
check_empty "$3" "Please provide a GitLab secret as the third argument"
check_empty "$4" "Please provide a GitLab database secret as the fourth argument"
check_empty "$5" "Please provide a GitLab SSO secret as the fifth argument"
check_empty "$6" "Please provide a GitLab SMTP secret as the sixth argument"
check_empty "$7" "Please provide a GitLab Redis secret as the seventh argument"
domain=$1
namespace=$2
gitlab_secret=$3
gitlab_db_secret=$4
gitlab_sso_secret=$5
gitlab_smtp_secret=$6
gitlab_redis_secret=$7
cat > gitlab-values.yaml <<EOF
global:
edition: ce
hosts:
domain: $domain
gitlab:
name: gitlab.$domain
https: true
ingress:
class: nginx
configureCertmanager: false
enabled: true
tls:
enabled: true
secretName: $gitlab_secret
minio:
enabled: true
gitaly:
persistence:
enabled: true
psql:
host: postgresql.database.svc.cluster.local
port: 5432
username: gitlab
database: gitlabhq_production
password:
secret: $gitlab_db_secret
key: password
redis:
host: redis-master.redis.svc.cluster.local
port: 6379
password:
enabled: true
secret: $gitlab_redis_secret
key: password
appConfig:
email:
from: 'manbuzhe2009@qq.com'
display_name: GitLab-System
smtp:
tls: true
enabled: true
port: 465
domain: exmail.qq.com
address: smtp.exmail.qq.com
user_name: 'manbuzhe2009@qq.com'
password:
secret: $gitlab_smtp_secret
key: password
authentication: "login"
starttls_auto: false
openssl_verify_mode: "peer"
pool: true
appConfig:
omniauth:
enabled: true
autoLinkLdapUser: false
autoLinkSamlUser: false
blockAutoCreatedUsers: false
autoSignInWithProvider: null
autoLinkUser:
- 'openid_connect'
allowSingleSignOn:
- 'openid_connect'
providers:
- secret: $gitlab_sso_secret
key: provider
certmanager:
install: false
installCRDs: false
startupapicheck:
enabled: false
postgresql:
install: false
redis:
install: false
kas:
enabled: false
nginx-ingress:
enabled: false
gitlab-exporter:
enabled: false
prometheus:
install: false
upgradeCheck:
enabled: false
EOF
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
helm repo add gitlab https://charts.gitlab.io/
helm repo up
kubectl create namespace gitlab || true
helm upgrade --install gitlab gitlab/gitlab --version=6.6.1 --namespace gitlab -f gitlab-values.yaml --timeout=3m --debug

View File

@ -10,18 +10,18 @@ check_empty() {
check_empty "$1" "Please provide a domain name as the first argument"
check_empty "$2" "Please provide a namespace as the second argument"
check_empty "$3" "Please provide a GitLab secret as the third argument"
#check_empty "$4" "Please provide a GitLab database secret as the fourth argument"
check_empty "$4" "Please provide a GitLab SSO secret as the fifth argument"
check_empty "$5" "Please provide a GitLab SMTP secret as the sixth argument"
check_empty "$6" "Please provide a GitLab Redis secret as the seventh argument"
check_empty "$4" "Please provide a GitLab database secret as the fourth argument"
check_empty "$5" "Please provide a GitLab SSO secret as the fifth argument"
check_empty "$6" "Please provide a GitLab SMTP secret as the sixth argument"
check_empty "$7" "Please provide a GitLab Redis secret as the seventh argument"
domain=$1
namespace=$2
gitlab_secret=$3
#gitlab_db_secret=$4
gitlab_sso_secret=$4
gitlab_smtp_secret=$5
gitlab_redis_secret=$6
gitlab_db_secret=$4
gitlab_sso_secret=$5
gitlab_smtp_secret=$6
gitlab_redis_secret=$7
cat > gitlab-values.yaml <<EOF
global:
@ -43,14 +43,14 @@ global:
gitaly:
persistence:
enabled: true
#psql:
# host: postgresql.database.svc.cluster.local
# port: 5432
# username: gitlab
# database: gitlabhq_production
# password:
# secret: $gitlab_db_secret
# key: password
psql:
host: postgresql.database.svc.cluster.local
port: 5432
username: gitlab
database: gitlabhq_production
password:
secret: $gitlab_db_secret
key: password
redis:
host: redis-master.redis.svc.cluster.local
port: 6379
@ -96,7 +96,7 @@ certmanager:
startupapicheck:
enabled: false
postgresql:
install: true
install: false
redis:
install: false
kas:

View File

@ -30,10 +30,10 @@
loop:
- { secret_name: 'gitlab-sso-secret', key: 'provider', value: "/tmp/provider.yaml" }
#- name: "cluster {{ ClusterContext }} Create New Generic Secret from Key/Vaule"
# shell: 'kubectl delete secret {{ item.secret_name }} -n {{ namespace }} || echo true; kubectl create secret generic {{ item.secret_name }} --from-literal={{ item.key }}="{{ hostvars[groups[group][0]].pg_db_password }}" -n {{ namespace }}'
# loop:
# - { secret_name: 'gitlab-db-secret', key: 'password' }
- name: "cluster {{ ClusterContext }} Create New Generic Secret from Key/Vaule"
shell: 'kubectl delete secret {{ item.secret_name }} -n {{ namespace }} || echo true; kubectl create secret generic {{ item.secret_name }} --from-literal={{ item.key }}="{{ hostvars[groups[group][0]].pg_db_password }}" -n {{ namespace }}'
loop:
- { secret_name: 'gitlab-db-secret', key: 'password' }
- name: "cluster {{ ClusterContext }} Create New Generic Secret from Key/Vaule"
shell: 'kubectl delete secret {{ item.secret_name }} -n {{ namespace }} || echo true; kubectl create secret generic {{ item.secret_name }} --from-literal={{ item.key }}="{{ hostvars[groups[group][0]].redis_password }}" -n {{ namespace }}'
@ -45,6 +45,10 @@
loop:
- { secret_name: 'gitlab-smtp-secret', key: 'password' }
- name: Setup Gitlab Server
script: files/setup.sh {{ domain }} {{ namespace }} 'gitlab-tls' 'gitlab-sso-secret' 'gitlab-smtp-secret' 'gitlab-redis-secret'
- name: DB Pre Setup for Gitlab Server
script: files/gitlab-pre-install.sh {{ db_namespace }}
when: inventory_hostname in groups[group]
- name: Setup Gitlab Server
script: files/setup.sh {{ domain }} {{ namespace }} 'gitlab-tls' 'gitlab-db-secret' 'gitlab-sso-secret' 'gitlab-smtp-secret' 'gitlab-redis-secret'
when: inventory_hostname in groups[group]

View File

@ -2,7 +2,7 @@
export namespace=$1
export POSTGRES_PASSWORD=$(kubectl get secret --namespace $namespace postgresql -o jsonpath="{.data.postgres-password}" | base64 -d)
kubectl run postgresql-client --rm --tty -i --restart='Never' --namespace $namespace --image docker.io/bitnami/postgresql:15.2.0-debian-11-r11 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host postgresql -U postgres -d postgres -p 5432 -w -c "CREATE DATABASE gitlabhq_production;" || echo true
kubectl run postgresql-client --rm --tty -i --restart='Never' --namespace $namespace --image docker.io/bitnami/postgresql:15.2.0-debian-11-r11 --env="PGPASSWORD=$POSTGRES_PASSWORD" --command -- psql --host postgresql -U postgres -d postgres -p 5432 -w -c "CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE EXTENSION IF NOT EXISTS btree_gist; CREATE DATABASE gitlabhq_production OWNER gitlab;" || echo true
#create user gitlab with encrypted password 'xxxxxx'
#grant all privileges on database gitlabhq_production to gitlab;

View File

@ -1,7 +1,3 @@
- name: Install PostgreSQL Server
script: files/setup-postgresql.sh {{ db_namespace }}
when: inventory_hostname in groups[group]
- name: Post Setup PostgreSQL Server
script: files/post-setup.sh {{ db_namespace }}
when: inventory_hostname in groups[group]