Gitsense is a simple tool designed for GitHub users who want to automate custom actions triggered by webhooks. While it’s not a full-fledged deployment tool, Gitsense provides a straightforward way to execute scripts remotely over SSH whenever certain events occur in your GitHub repositories.
- A GitHub account with access to the repositories you want to manage.
- A Github
oauth2app. - A server or remote machine accessible via SSH where your scripts will be executed.
- The following information for your remote machine:
- IP address
- Username
- Private key
- Host key
- An environment ready for running Gitsense (e.g., a local or cloud server hosting Gitsense), with Go installed.
git clone https://github.com/Dyastin-0/gitsense.gitcd gitsenseThe respository has a custom build and deployment script which uses systemd and Caddy.
If you are familiar with these tools, consider using it. Create a Caddyfile:
sudo nano /etc/caddy/Caddyfile<your_domain_name> {
handle {
reverse_proxy localhost:3000
}
}
Or, if you are also planning to use the gitsense-client, a web app built with React.
It has a simple interface that uses gitsense, use:
<your_domain_name> {
handle /api/* {
reverse_proxy localhost: 3000 // gitsense
}
handle {
reverse_proxy localhost: 4173 // gitsense-client
}
}
Both gitsense and gitsesnse-client has a ./build.sh script that
runs them in the background as a service.
chmod +x ./build.sh./build.shSet-up a mongodb atlas and add the connection URI in the .env file:
MONGODB_URI=<connection_uri>-
PORTPort where the server will run -
VERSIONVersion that will be injected to the API endpoints, set it tov1 -
GITHUB_CLIENT_IDUsed to identify your Githuboauth2app -
GITHUB_CLIENT_SECRET -
GITHUB_RERDIRECT_URLGithuboauth2's callback url, set it tohttps://your_domain.com/api/v1/auth/github/callback -
GITHUB_API_URLGithub's base api URL,https://api.github.com -
MONGODB_URIYour mongoDB atlas' connection URI -
DOMAINUsed for setting the cookies, set it to your domain,your_domain.com -
BASE_SERVER_URLYour server's URL,https://your_domain.com, used to construct the webhook's endpoint -
BASE_CLIENT_URLYour client's URL,https://your_domain.com, used for redirect when authenticated -
ENCRYPTION_KEYUsed by theaesalgorithm for encryption and decryptionBoth
refreshandaccesstoken are only used to access data from the database, where webhook's configurations are stored including thesshconfiguration. -
REFRESH_TOKEN_KEY -
ACCESS_TOKEN_KEY
BASE_API_URLSet it tohttps://your_domain.com/api/v1PORTPort where the server will run, default is4173
Once Gitsense is up and running, you can create webhooks for your GitHub repositories.
-
Log in at
gitsense-clientusing your Github account -
Select a repository, each repository has a custom context menu; right click and select add webhook
-
NameA unique name that identifies yourwebhook -
SecretUsed to verify the request coming in for thewebhook -
IP addressIP address of the remote machine-
Used to identify your remote machine
-
to get your remote machine's IP open the terminal and execute:
curl ifconfig.me
-
-
Private keyThe private key used tosshinto your remote machine-
Typically stored in
.sshdirectory, in your local machine open the terminal and execute:cd .sshls
-
The private key is encrypted using
aesalgorithm.
-
-
Host keyHost key of the remote machine-
Host key will be used to verify the ssh connection, and prevent
MITMattacks. -
Typically this is stored on the remote machine's
/etc/sshdirectory, open the terminal and execute:cd /etc/sshls
Find out which algorithm is used on your private key and select the approriate one.
sudo cat ssh_host_<algorithm>_key.pub
-
-
ScriptThe script that will be executed on the remote machine-
Sample script:
cd <project_directory> git pull ./build.sh ./deploy.sh
-
To run on development mode, make sure you got air installed, on gitsense's root directory execute:
airTo test an ssh connection, set your ssh configuration in the .env file:
PRIVATE_KEY=<private_key>
HOST_KEY=<host_key>
INSTANCE_IP=<ip_address>
USER=<username>
cd pkg/util/sshgo test