diff --git a/.github/workflows/setup-k3s-with-existed-vhost.yml b/.github/workflows/setup-k3s-with-existed-vhost.yml index 6b9781eb..dfc6403f 100644 --- a/.github/workflows/setup-k3s-with-existed-vhost.yml +++ b/.github/workflows/setup-k3s-with-existed-vhost.yml @@ -27,8 +27,45 @@ defaults: working-directory: ./playbook jobs: + setup-k3s: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Setup Gitlab in K3S + shell: bash + run: | + export ANSIBLE_HOST_KEY_CHECKING=False + sudo apt install jq ansible -y + + mkdir -pv ~/.ssh/ + cat > ~/.ssh/id_rsa << EOF + ${SSH_PRIVATE_KEY} + EOF + sudo chmod 0400 ~/.ssh/id_rsa + md5sum ~/.ssh/id_rsa + + mkdir -pv hosts/ + cat > hosts/inventory << EOF + [master] + k3s ansible_host=20.89.154.216 + + [all:vars] + ansible_port=8022 + ansible_ssh_user=ubuntu + ansible_ssh_private_key_file=~/.ssh/id_rsa + ansible_host_key_checking=False + dns_ak=$DNS_AK + dns_sk=$DNS_SK + ingress_ip=20.89.154.216 + smtp_password=$SMTP_PASSWORD + gitlab_oidc_client_token=$GITLAB_OIDC_CLIENT_TOKEN + EOF + ansible-playbook -i hosts/inventory jobs/init_k3s_cluster -D setup-keycloak: runs-on: ubuntu-latest + needs: [setup-k3s] steps: - uses: actions/checkout@v3 @@ -67,7 +104,9 @@ jobs: ansible-playbook -i hosts/inventory jobs/init_keycloak -D Setup-Gitlab: runs-on: ubuntu-latest - needs: [setup-keycloak] + needs: + - setup-k3s + - setup-keycloak steps: - uses: actions/checkout@v3 @@ -101,17 +140,12 @@ jobs: smtp_password=$SMTP_PASSWORD gitlab_oidc_client_token=$GITLAB_OIDC_CLIENT_TOKEN EOF - ansible-playbook -i hosts/inventory jobs/init_k3s_cluster -D ansible-playbook -i hosts/inventory jobs/init_gitlab -D - #ansible-playbook -i hosts/inventory jobs/init_ssl_cert -D - #ansible-playbook -i hosts/inventory jobs/init_chatwithgpt -D - #ansible-playbook -i hosts/inventory jobs/init_harbor -D - #ansible-playbook -i hosts/inventory jobs/init_keycloak -D - #ansible-playbook -i hosts/inventory jobs/init_cert_manager -D - #ansible-playbook -i hosts/inventory jobs/init_openldap -D Setup-Harbor: runs-on: ubuntu-latest - needs: [setup-keycloak] + needs: + - setup-k3s + - setup-keycloak steps: - uses: actions/checkout@v3 @@ -147,11 +181,12 @@ jobs: harbor_admin_password=$ADMIN_INIT_PASSWORD harbor_odic_client_token=$HARBOR_OIDC_CLIENT_TOKEN EOF - ansible-playbook -i hosts/inventory jobs/init_k3s_cluster -D ansible-playbook -i hosts/inventory jobs/init_harbor -D -C Setup-Grafana: runs-on: ubuntu-latest - needs: [setup-keycloak] + needs: + - setup-k3s + - setup-keycloak steps: - uses: actions/checkout@v3 @@ -185,11 +220,11 @@ jobs: dns_sk=$DNS_SK ingress_ip=20.89.154.216 EOF - #ansible-playbook -i hosts/inventory jobs/init_k3s_cluster -D ansible-playbook -i hosts/inventory jobs/init_observability-server -D Setup-Agent: runs-on: ubuntu-latest needs: + - setup-k3s - setup-harbor - setup-gitlab - setup-grafana diff --git a/playbook/roles/gitlab/files/gitlab-pre-install.sh b/playbook/roles/gitlab/files/gitlab-pre-install.sh index 4d59ddf9..a09ed250 100755 --- a/playbook/roles/gitlab/files/gitlab-pre-install.sh +++ b/playbook/roles/gitlab/files/gitlab-pre-install.sh @@ -1,5 +1,7 @@ #!/bin/bash +set +x + export namespace=$1 -export POSTGRES_PASSWORD=$(kubectl get secret --namespace \$namespace postgresql -o jsonpath="{.data.postgres-password}" | base64 -d) +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 plpgsql;CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE EXTENSION IF NOT EXISTS btree_gist; CREATE DATABASE gitlabhq_production OWNER postgres;" || echo true