Skip to content

Commit 5b9fa9c

Browse files
authored
Update README with pre-receive installation guide (#76)
* Update REDMEA with pre-receive installation guide * update url to reference production environment * Add API URL documentation. * Pre commit readme code review comments * update link
1 parent 1ac8922 commit 5b9fa9c

1 file changed

Lines changed: 64 additions & 1 deletion

File tree

README.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,69 @@ repos:
166166
> Successful hook installation will result in the message:<br/>
167167
`Pre-commit installed at .git/hooks/pre-commit`
168168

169+
## Pre-receive Hook
170+
171+
### Prerequisites
172+
173+
1. Install Cycode CLI on your Git server - Install the Cycode CLI by running `pip3 install cycode --user`. Check that the CLI installed successfully by running `cycode`. If you get `cycode: command not found`, you need to add the installation path to the `PATH` environment variable.
174+
3. Cycode service account
175+
176+
### Instructions
177+
178+
#### Install for a specific repository
179+
180+
1. Find the repository location in the Git server instance.
181+
- For GitLab Enterprise: [Git server hooks | GitLab](https://docs.gitlab.com/ee/administration/server_hooks.html)
182+
183+
2. Create the pre-receive hook.
184+
- Create a new file in the repository's Git hook location under the repository location you found in step 1, and name it `pre-receive`.
185+
- Copy the following script to the `pre-recive` file:
186+
187+
```sh
188+
#!/bin/sh
189+
190+
# optional
191+
# Update the server URL only if you have Cycode self managed
192+
# export CYCODE_API_URL = "<cycode server url>"
193+
export CYCODE_CLIENT_ID="<client_id>"
194+
export CYCODE_CLIENT_SECRET="<client_secret>"
195+
196+
set -e
197+
cycode scan pre_receive
198+
```
199+
200+
- Make the file executable by running `chmod +x pre-receive`.
201+
- Change the file owner and owner group to `git` user:
202+
- `chown git pre-receive` (change file owner).
203+
- `chgrp git pre-receive` (change file group owner).
204+
- Verify it by running `ls -l`. The output should be `-rwxr-xr-x 1 git git 662 Mar 2 09:15 pre-receive` (first `git` is the file's owner, second `git` is the file's group owner).
205+
206+
3. Configure the Cycode token.
207+
- There are two methods to set it:
208+
- In the script above, fill in the client ID and secret.
209+
- Set environment variables on the instance.
210+
211+
4. [Optional] Update Cycode API url (relevant only for on-prem customers) - Update `CYCODE_API_URL` in the pre-receive file.
212+
213+
#### Install pre-recive hook globaly (For all the repositories)
214+
215+
1. Set the global hooks directory in the Git server instance.
216+
- For GitLab Enterprise (https://docs.gitlab.com/ee/administration/server_hooks.html#create-global-server-hooks-for-all-repositories) :
217+
- Set in `/etc/gitlab/gitlab.rb` the `gitaly['custom_hooks_dir']` value or just use the default location by uncommenting it.
218+
- Run `gitlab-ctl reconfigure`.
219+
- Follow the steps [here](#install-for-a-specific-repository)
220+
221+
2. Add the pre-receive hook according to the Git server requirements.
222+
- For GitLab Enterprise:
223+
- Go to the directory and create a directory named `pre-receive.d`.
224+
- Inside the directory, follow the steps of "Install for a specific repository" above.
225+
226+
#### Skipping the pre-receive hook
227+
228+
Cycode's pre-receive hook can be skipped easily by adding `-o skip-cycode-scan` to the `git push` command.
229+
230+
> **Notice:** Verify that the option `receive.advertisePushOptions` is enabled in the instance Git configuration. For enabling it, run `git config receive.advertisePushOptions true`. It seems that in GitLab, it's enabled by default.
231+
169232
# Cycode Command
170233
171234
The following are the options and commands available with the Cycode CLI application:
@@ -450,4 +513,4 @@ For example, to see options available for a Path Scan, you would simply enter:
450513

451514
To see the options available for the ignore scan function, use this command:
452515

453-
`cycode ignore --help`
516+
`cycode ignore --help`

0 commit comments

Comments
 (0)