二丫讲梵 二丫讲梵
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)

二丫讲梵

行者常至,为者常成
首页
  • 最佳实践
  • 迎刃而解
  • Nginx
  • Php
  • Zabbix
  • AWS
  • Prometheus
  • Grafana
  • CentOS
  • Systemd
  • Docker
  • Rancher
  • Ansible
  • Ldap
  • Gitlab
  • GitHub
  • Etcd
  • Consul
  • RabbitMQ
  • Kafka
  • MySql
  • MongoDB
  • OpenVPN
  • KVM
  • VMware
  • Other
  • ELK
  • K8S
  • LLM
  • Nexus
  • Jenkins
  • 随写编年
  • 家人物语
  • 追忆青春
  • 父亲的朋友圈
  • 电影音乐
  • 效率工具
  • 博客相关
  • Shell
  • 前端实践
  • Vue学习笔记
  • Golang学习笔记
  • Golang编程技巧
  • 学习周刊
  • Obsidian插件周刊
关于
友链
  • 本站索引

    • 分类
    • 标签
    • 归档
  • 本站页面

    • 导航
    • 打赏
  • 我的工具

    • 备忘录清单 (opens new window)
    • json2go (opens new window)
    • gopher (opens new window)
    • 微信MD编辑 (opens new window)
    • 国内镜像 (opens new window)
    • 出口IP查询 (opens new window)
    • 代码高亮工具 (opens new window)
  • 外站页面

    • 开往 (opens new window)
    • ldapdoc (opens new window)
    • HowToStartOpenSource (opens new window)
    • vdoing-template (opens new window)
GitHub (opens new window)
  • 最佳实践

    • 运维最佳实践

      • 一句话经验
      • 基于CNAME解析实践的域名优雅方案
      • 如何配置历史命令中有详细的时间戳
      • 建设一个运维外挂的最佳实践
      • 关于打包压缩几种格式(gzip,bzip2,xz)的试验对比
      • 利用谷歌浏览器自定义agent监听日志来调试服务
      • fdisk,parted使用非交互式方式对磁盘进行分区操作
      • GitLab部署的最佳实践
      • GitLab全局搜索之SourceGraph
        • 0. 前言
        • 1. 安装部署 SourceGraph
          • 1.1 安装部署
          • 1.2 配置 Nginx 代理
          • 1.3 访问页面
        • 2. 配置 Sourcegraph 网站
          • 2.1 配置仓库
          • 2.2 配置 GitLab 仓库
          • 2.3 配置 GitLab 授权访问 SourceGraph
          • 2.3.1 配置 gitlab 的授权应用程序,
        • 3. 查询结果导出
        • 4. 小结
      • vector实践-性能吊打logstash
      • 规范编码之利用pre-commit给项目添加提交前检查
      • CMDB平台建设指南
      • 用上赛博菩萨CNB,咱直接起飞
    • 成本优化实践

  • 迎刃而解

  • Nginx

  • Php

  • Zabbix

  • AWS

  • Prometheus

  • Grafana

  • Loki

  • CentOS

  • Supervisord

  • Systemd

  • Docker

  • Docker-Compose

  • Rancher

  • Ansible

  • OpenLdap

  • GitLab

  • GitHub

  • Etcd

  • Consul

  • RabbitMQ

  • Kafka

  • Mysql

  • MongoDB

  • OpenVPN

  • Kvm

  • VMware

  • 配置文件详解

  • Other

  • 运维观止
  • 最佳实践
  • 运维最佳实践
现代伪诗人陆游
2021-11-14
1.6k
6.7m
8140
目录
0. 前言
1. 安装部署 SourceGraph
1.1 安装部署
1.2 配置 Nginx 代理
1.3 访问页面
2. 配置 Sourcegraph 网站
2.1 配置仓库
2.2 配置 GitLab 仓库
2.3 配置 GitLab 授权访问 SourceGraph
2.3.1 配置 gitlab 的授权应用程序,
3. 查询结果导出
4. 小结

GitLab全局搜索之SourceGraph

文章发布较早,内容可能过时,阅读注意甄别。

# 0. 前言

​ 现如今,我们很多公司都会将代码托管在自建的 GitLab 仓库中,很适合团队协作。但随之而来的这种开源版本的工具在一定程度上存在缺陷,比如诗人 (opens new window)今天要折腾的 SourceGraph 这个工具,就是来解决开源版本 GitLab 不支持的全局检索功能。

# 1. 安装部署 SourceGraph

​ 部署参考链接 (opens new window)

# 1.1 安装部署

直接按照官方操作傻瓜式安装,以下安装是为了快速体验特性,官方推荐生产部署采用 docker-compose 或者直接部署在 k8s 中,参考 (opens new window)

docker run -d --publish 7080:7080 --publish 127.0.0.1:3370:3370 --rm --volume ~/.sourcegraph/config:/etc/sourcegraph --volume ~/.sourcegraph/data:/var/opt/sourcegraph sourcegraph/server:3.33.0
1

--publish就是我们大家习惯的暴露端口的-p哦

7080是访问sourceGraph服务端口,3370是Grafana的端口

# 1.2 配置 Nginx 代理

​ 配置完成后,我们需要配置 Nginx 来将其服务进行代理,当然也可以访问本机http://x.x.x.x:7080;

location  / {
        proxy_set_header session-name $http_session-name;
        proxy_set_header userId $http_userId;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://10.6.6.26:7080;
    }
1
2
3
4
5
6
7
8
9

# 1.3 访问页面

​ 访问如下代表成功,首次进入是可以注册一个管理员身份快速体验,按页面提示操作即可。

​

# 2. 配置 Sourcegraph 网站

# 2.1 配置仓库

入口:Site admin > Repositories > Manage code hosts

# 2.2 配置 GitLab 仓库

点击上图中GitLab Self-Managed,下图中的配置参考官网 (opens new window),下面的代码 SourceGraph 本身提供给了我们,这点还是很不错的,因为他的官方文档写的很生硬;当我们点击了GitLab Self-Managed之后,会出现如下图中画圈的部分,你想要添加那种类型的仓库,都可以直接生成代码,完事后添加即可,等待其同步完成。

​ 创建 gitlab 的 token 参考链接 (opens new window),建议授权范围设置为 read_user, read_api, read_repository

{
"url": "https://<你的gitlab域名>",
"token": "<access token>",
"projectQuery": [
 "projects?membership=true&archived=no"
]
}
1
2
3
4
5
6
7

若你配置了 GitLab 授权登录(诗人 (opens new window)下文即将介绍),希望查找的仓库权限能跟授权账号走。可以在仓库配置中加入 Enforce permissions (OAuth)

{
  "authorization": {
    "identityProvider": {
      "type": "oauth"
    }
  }
}
1
2
3
4
5
6
7

申明

原创文章eryajf,未经授权,严禁转载,侵权必究!此乃文中随机水印,敬请读者谅解。

Copyright 二丫讲梵 (opens new window) 版权所有

# 2.3 配置 GitLab 授权访问 SourceGraph

SourceGraph 支持与 GitLab 权限打通,这样我们就不需要自己维护用户规则,全部采用 GitLab 的权限,即使 GitLab 是通过 Ldap,且继承用户所用的的权限,所以在代码检索时请注意,只能搜索自己有权限的仓库。配置参考官网链接 (opens new window),还支持很多种认证方式。

入口:Site admin > Configuration > Site configuration

# 2.3.1 配置 gitlab 的授权应用程序,

参考GitLab 授权链接 (opens new window)

提示

  1. 在 GitLab 右上角选择你的头像
  2. 选择 Settings (或是 Edit profile)
  3. 在左侧边栏选择 Applications
  4. 输入 Name,Redirect URI,Scopes(授权范围设置为 api、read_user)。Redirect URI 是用户授权回调的地址,形如:http://sgdev2.example.com/.auth/gitlab/callback,仅仅替换域名即可 点击保存,就能看到 Application ID 和 Secret。
  5. 此处的小坑,诗人 (opens new window)是采用 nginx 代理的,所以我的 443 是在 nginx 上,真正的 sourceGraph 是没有 https 的,故回调 url 不要填写 https

如下图,便是诗人 (opens new window)配置好的 GitLab 的

然后,回到 sourcegraph 网站站点进行配置。

提示

  1. 在你的 sourcegraph 站点的右上角选择你的头像
  2. 选择 Site admin
  3. 在左侧边栏选择 Site configuration
  4. 点击 Add GitLab sign-in,会自动添加如下授权代码。

当然,此处 sourceGraph 也是有代码提示,如下图

{
  "auth.providers": [
    {
      // See https://docs.sourcegraph.com/admin/auth#gitlab for instructions
      "type": "gitlab",
      "displayName": "GitLab",
      "url": "<GitLab URL>",
      "clientID": "<client ID>",
      "clientSecret": "<client secret>"
    }
  ]
}
1
2
3
4
5
6
7
8
9
10
11
12

type 和 displayName 保持默认。<GitLab URL> 改为你的 GitLab 地址,<client ID> 改为之前获得的 Application ID,<client secret> 改为 Secret,保存即可。

此时你退出,再登录就会出现,GitLab 授权按钮。

# 3. 查询结果导出

​ sourceGraph 是支持查询结果导出的,支持 csv 插件,配置参考 (opens new window)

# 4. 小结

按理安装完 Sourcegraph,进行仓库配置后,站点就能正常投入使用了。关于用户授权,是诗人 (opens new window)经历一番探索的总结,为有此需求的人在阅读官方文档中即将陷入迷茫提供的一个提示。

温馨提示:

  • 若是你通过 GitLab 授权管理用户,需确保网站管理员为代码仓库的管理员,这样能保证用户的搜索池全面。
  • 免费版的 Sourcegraph 只能注册 10 个用户哦!
  • 升级应该在 Sourcegraph 的连续次要版本之间进行。例如,如果您正在运行 Sourcegraph 3.1,并且想要升级到 3.3,则应该先升级到 3.2,再升级到 3.3。
  • 查询语法请参考官方文档哦,查询语法 (opens new window)
  • 当然如果您觉得页面查询不爽,source 官方也是只吃了命令行查询工具,什么版本的都支持,可操考其 github 进行配置,非常简单,诗人 (opens new window)懒得写了。诗人 (opens new window)平时喜欢用命令行,然后通过 jq 工具来处理。
    • 官网 api 查询,链接 (opens new window)
    • 客户端配置,链接 (opens new window)
微信 支付宝
上次更新: 2024/07/04, 22:40:37
GitLab部署的最佳实践
vector实践-性能吊打logstash

← GitLab部署的最佳实践 vector实践-性能吊打logstash→

最近更新
01
睡着的人不关灯
06-12
02
学习周刊-总第215期-2025年第24周
06-12
03
学习周刊-总第214期-2025年第23周
06-05
更多文章>
Theme by Vdoing | Copyright © 2017-2025 | 点击查看十年之约 | 浙ICP备18057030号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式