Add env vars for overriding GitHub / GitLab hostnames in the .netrc file. (#26)

* Add env vars for overriding GitLab / GitHub hostnames used in the .netrc file. (GITLAB_HOSTNAME, GITHUB_HOSTNAME)

* Add docs

* Add changelog entry
This commit is contained in:
Brendan Kellam 2024-10-03 14:06:24 -07:00 committed by GitHub
parent bc20ff6d2b
commit d7b6829a42
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 86 additions and 11 deletions

View file

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Added `GITLAB_HOSTNAME` and `GITHUB_HOSTNAME` environment variables to allow overriding the default hostnames for GitLab and GitHub.
## [1.0.0] - 2024-10-01
### Added

View file

@ -35,6 +35,9 @@ ENV DATA_DIR=/data
ENV CONFIG_PATH=$DATA_DIR/config.json
ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot
ENV GITHUB_HOSTNAME=github.com
ENV GITLAB_HOSTNAME=gitlab.com
# @note: This is also set in .env
ENV NEXT_PUBLIC_POSTHOG_KEY=phc_VFn4CkEGHRdlVyOOw8mfkoj1DKVoG6y1007EClvzAnS

View file

@ -176,6 +176,65 @@ docker run -p 3000:3000 --rm --name sourcebot -e <b>GITLAB_TOKEN=[your-gitlab-to
</div>
## Using a self-hosted GitLab / GitHub instance
If you're using a self-hosted GitLab or GitHub instance with a custom domain, there is some additional config required:
<div>
<details>
<summary>
<picture>
<source media="(prefers-color-scheme: dark)" srcset=".github/images/github-favicon-inverted.png">
<img src="https://github.com/favicon.ico" width="16" height="16" alt="GitHub icon">
</picture> GitHub
</summary>
1. In your config, add the `GitHubURL` field to point to your deployment's URL. For example:
```json
{
"$schema": "https://raw.githubusercontent.com/sourcebot-dev/sourcebot/main/schemas/index.json",
"Configs": [
{
"Type": "github",
"GitHubUrl": "https://github.example.com"
}
]
}
2. Set the `GITHUB_HOSTNAME` environment variable to your deployment's hostname. For example:
<pre>
docker run -e <b>GITHUB_HOSTNAME=github.example.com</b> /* additional args */ ghcr.io/sourcebot-dev/sourcebot:latest
</pre>
</details>
<details>
<summary><img src="https://gitlab.com/favicon.ico" width="16" height="16" /> GitLab</summary>
1. In your config, add the `GitLabURL` field to point to your deployment's URL. For example:
```json
{
"$schema": "https://raw.githubusercontent.com/sourcebot-dev/sourcebot/main/schemas/index.json",
"Configs": [
{
"Type": "gitlab",
"GitLabURL": "https://gitlab.example.com"
}
]
}
```
2. Set the `GITLAB_HOSTNAME` environment variable to your deployment's hostname. For example:
<pre>
docker run -e <b>GITLAB_HOSTNAME=gitlab.example.com</b> /* additional args */ ghcr.io/sourcebot-dev/sourcebot:latest
</pre>
</details>
</div>
## Build from source
>[!NOTE]

View file

@ -47,7 +47,8 @@ if [ -n "$GITHUB_TOKEN" ]; then
chmod 600 "$HOME/.github-token"
# Configure Git with the provided GITHUB_TOKEN
echo "machine github.com
echo -e "\e[34m[Info] Configuring GitHub credentials with hostname '$GITHUB_HOSTNAME'.\e[0m"
echo "machine ${GITHUB_HOSTNAME}
login oauth
password ${GITHUB_TOKEN}" >> "$HOME/.netrc"
chmod 600 "$HOME/.netrc"
@ -61,7 +62,8 @@ if [ -n "$GITLAB_TOKEN" ]; then
chmod 600 "$HOME/.gitlab-token"
# Configure Git with the provided GITLAB_TOKEN
echo "machine gitlab.com
echo -e "\e[34m[Info] Configuring GitLab credentials with hostname '$GITLAB_HOSTNAME'.\e[0m"
echo "machine ${GITLAB_HOSTNAME}
login oauth
password ${GITLAB_TOKEN}" >> "$HOME/.netrc"
chmod 600 "$HOME/.netrc"

View file

@ -7,6 +7,12 @@
"Type": "github",
"GitHubOrg": "my-org"
},
// Index all repos in self-hosted GitHub instance.
// @note: the environment variable GITHUB_HOSTNAME must be set. See README.
{
"Type": "github",
"GitHubUrl": "https://github.example.com"
},
// Index all repos in user "my-user".
{
"Type": "github",
@ -56,10 +62,11 @@
"Type": "gitlab"
},
// Index all repos visible to the GITLAB_TOKEN (custom GitLab URL).
// @note: the environment variable GITLAB_HOSTNAME must also be set. See README.
{
"Type": "gitlab",
"GitLabURL": "https://gitlab.example.com/api/v4/" /* default: https://gitlab.com/api/v4/ */
}
"GitLabURL": "https://gitlab.example.com"
},
// Index all repos (public only) visible to the GITLAB_TOKEN.
{
"Type": "gitlab",