一个伪linux粉丝的blog

  1. 首页
  2. unix/linux
  3. 正文

change gitlab webhook url

10 5 月, 2021 948点热度 0人点赞 0条评论

1. 背景

某客户准备修改 CI/CD 流程中原有的 公网 ip 地址为 弹性ip,想了解涉及修改的各个方面,告知客户有如下地方会有改动( 原有流水线的自动触发、 harbor上对应的webhook、制品仓库对应的webhook、gitlab这边的webhook),

经过简单演示,发现难点是 gitlab 这边如何批量更换新的 webhook 地址,所有应用全部手动点一圈显然比较繁琐,于是有了下面的测试。

2. 步骤

 

2.1. 思考 webook 存放位置

通过模拟环境,检查发现这些 webhook 地址是以数据的形式存放在 gitlab对应的postgres数据库里面。

对应的数据库为 gitlabhq_production,表为  web_hooks,还有一个表 web_hook_logs 是存放webhook相关的历史记录等完整信息。

 

2.2. 数据单独修改测试

2.2.1. 定位gitlab-postgresql 数据库名

kubectl get po -n 某名字ns

2.2.2. 进入容器操作数据库

kubectl exec -it -n 某名字ns gitlab-postgresql-6995884f-dl92s sh

2.2.3. 切换用户和库等操作

换用户
# su - postgres
# 数据备份
postgres@gitlab-postgresql-6995884f-dl92s:~$ pg_dump gitlabhq_production > gitlab.sql
# 查看备份
postgres@gitlab-postgresql-6995884f-dl92s:~$ ls -lh
total 472K
drwx------ 3 postgres postgres   18 Apr 29  2020 10
-rw-rw-r-- 1 postgres postgres 461K May  8 16:24 gitlab.sql
# 另一个终端,将 sql 备份文件拷贝到本地
kubectl cp 某名字ns/gitlab-postgresql-6995884f-dl92s:gitlab.sql /root/gitlab.sql
# 进入psql命令模式
postgres@gitlab-postgresql-6995884f-dl92s:~$ psql
psql (10.4 (Ubuntu 10.4-2.pgdg18.04+1))
Type "help" for help.
postgres=# \x
Expanded display is on.
# 查数据列表
postgres=# \l
List of databases
-[ RECORD 1 ]-----+----------------------
Name              | gitlabhq_production
Owner             | postgres
Encoding          | UTF8
Collate           | C
Ctype             | C
Access privileges | =Tc/postgres         +
                  | postgres=CTc/postgres+
                  | gitlab=CTc/postgres
# 换库
postgres=# \c gitlabhq_production;
# 查询记录
gitlabhq_production=# select * from web_hooks;
-[ RECORD 1 ]--------------+-----------------------------------------------------------------
id                         | 4
url                        | http://10.23.5.53:8089/hook/28a369a1-17f9-4b98-b766-439df6d1c6b3
project_id                 | 2
created_at                 | 2021-05-07 17:44:52.392552
updated_at                 | 2021-05-07 17:44:52.392552
type                       | ProjectHook
service_id                 |
push_events                | t
issues_events              | f
merge_requests_events      | t
tag_push_events            | t
note_events                | f
enable_ssl_verification    | f
wiki_page_events           | f
token                      | aec78a4e-dc82-4f3c-be84-7415dc57349d
pipeline_events            | f
confidential_issues_events | f
repository_update_events   | f
job_events                 | f
confidential_note_events   |
-[ RECORD 2 ]--------------+-----------------------------------------------------------------
id                         | 5
url                        | http://10.23.5.53:8089/hook/e0e9dec8-915a-4eff-972c-89de9094046a
project_id                 | 4
created_at                 | 2021-05-08 10:23:23.036441
updated_at                 | 2021-05-08 10:23:23.036441
type                       | ProjectHook
service_id                 |
push_events                | t
issues_events              | f
merge_requests_events      | t
tag_push_events            | t
note_events                | f
enable_ssl_verification    | f
wiki_page_events           | f
token                      | cfc46dc9-faed-434a-88f4-c6113e9f9a2e
pipeline_events            | f
confidential_issues_events | f
repository_update_events   | f
job_events                 | f
confidential_note_events   |

# 单个替换 url,简单将8089端口替换为8088

update web_hooks set url='http://10.23.5.53:8088/hook/28a369a1-17f9-4b98-b766-439df6d1c6b3';
UPDATE 1

 

2.2.4.  地址源头如下

图这里忽略,也就是 http://10.23.5.53:8089修改为 http://10.23.5.53:8088

2.3. 数据批量修改测试

# 进入数据库容器
kubectl exec -it -n 某名字ns gitlab-postgresql-6995884f-dl92s sh
# 换用户
# su - postgres
# 换库
postgres=# \c gitlabhq_production;
# 查询记录
gitlabhq_production=# select * from web_hooks;
# 替换url地址
gitlabhq_production=# UPDATE web_hooks SET url = replace (url,'10.23.5.53:8089','10.23.5.53:8088');
UPDATE 2
# 再次查询记录
gitlabhq_production=# select * from web_hooks;

 

2.4. 检查修改效果

 

2.4.1. gitlab界面查看地址是否变动正常。

修改前 端口8089

修改后,端口8088,符合预期

 

2.4.2.  改完测试验证效果

点击test,测试效果

hook execution successfully : http 200

输出hook 正常,符合预期。

ps. 如果异常,这里会返回提示连接拒绝

Hook execution failed: Failed to open TCP connection to 10.23.5.53:8088 (Connection refused - connect(2) for "10.23.5.53" port 8088)

调度

 

2.4.3. 流水线制品测试

CI/CD  跑流水线,制品仓库是否有正常推送的制品。

镜像拉取测试正常

至此gitlab 下 webhook 批量修改成功,验证通过。

本文为12月第二周网站忘记续费后从webcache里面找回的

2022-05-10,有人问起,原来内网还写了一篇,有图,哈哈,补上。

相关文章:

  1. gitlab with ldap
  2. crontab log error
  3. SSHTunnel Provides a Secure Internet Connection for Your Android
  4. debian-lighttpd-install
标签: gitlab webhook
最后更新:11 5 月, 2022

wanjie

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

This site uses Akismet to reduce spam. Learn how your comment data is processed.

归档
分类
  • network / 332篇
  • Uncategorized / 116篇
  • unix/linux / 121篇
  • 业界资讯 / 38篇
  • 公司杂事 / 11篇
  • 数码影像 / 12篇
  • 美剧 / 3篇
  • 美图共赏 / 21篇
  • 英语学习 / 3篇
标签聚合
openssl ssh debian 浏览器 jira dreamhost空间 postgres dreamhost nexus wget 网站运营 squid d90 Nginx 邮件归档 kubectl Google Voice kernel ldap k8s 泰国 虚拟主机 google-chrome Ubuntu 天翼live Google VPS gitlab deepseek docker

COPYRIGHT © 2008-2025 wanjie.info. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang