Skip to content

Commit

Permalink
chore: document how to run the plugin locally [OSM-2184]
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek-rzrz committed Oct 24, 2024
1 parent 3e42217 commit a233261
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 103 deletions.
92 changes: 2 additions & 90 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,6 @@
For information about the Artifactory Gatekeeper plugin, see the Snyk user
docs, [Artifactory Gatekeeper plugin](https://docs.snyk.io/integrations/private-registry-gatekeeper-plugins/artifactory-gatekeeper-plugin-overview).

## Setup local development environment

### Download an Artifactory Docker image:

```
docker pull releases-docker.jfrog.io/jfrog/artifactory-pro:latest
```

Does not have to be `pro`, but in this example we'll do it.

### Create a `$JFROG_HOME` folder

```
mkdir -p ~/.jfrog/artifactory/var/
```

Export it to your environment for ease of use

```
echo export JFROG_HOME=~/.jfrog >> ~/.zshrc
```

### Build the plugin

Depends a lot on your system. But something like

```
mvn install -DskipTests
```

Will probably work. Per default, you'll find a baked `.zip`
in `~/.m2/repository/io/snyk/plugins/artifactory/distribution/LOCAL-SNAPSHOT`.

Unzip it. Inside is a `.groovy` file, a `.properties` file, as well as the actual `.jar` inside `/lib`.

Edit the `.properties`, add something like this to the properties for a minimum working solution:

```
snyk.api.token=<INSERT_TOKEN>
snyk.api.organization=<INSERT_ORG_ID>
```

Also, if you want to test against your local Registry, but you're running on Docker:

```
snyk.api.url=http://host.docker.internal:8000/api/v1/
```

At least if you're on OSX, you cannot probe against `localhost` from within a Docker container.

Also, remember to activate some of the scanners depending on what you're debugging:

```
snyk.scanner.packageType.maven=true
snyk.scanner.packageType.npm=true
snyk.scanner.packageType.pypi=true
```

### Enable debugging JVM options

```
vim $JFROG_HOME/artifactory/var/etc/system.yaml
```

Add `extraJavaOpts`

```
shared:
## Java 17 distribution to use
#javaHome: "JFROG_HOME/artifactory/app/third-party/java"
## Extra Java options to pass to the JVM. These values add to or override the defaults.
#extraJavaOpts: "-Xms512m -Xmx4g"
extraJavaOpts: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
```

### Run the Docker image

And ensure you expose debugging ports, in this case, `5005`

```
docker run -d --name artifactory -p 8888:8082 -p 8081:8081 -p 5005:5005 -v $JFROG_HOME/artifactory/var/:/var/opt/jfrog/artifactory releases-docker.jfrog.io/jfrog/artifactory-pro:latest
```

Wait until the Docker has loaded, it can take a while. Check the progress with `docker logs -f <id>`.

#### Notice for M1 Macs

You'll have a ton of trouble if you default to building your Docker images as `linux/amd64`. At least I had. Ensure you
do not have a env variable like `DOCKER_DEFAULT_PLATFORM=linux/amd64` enabled when pulling and/or running the image.
## Local development environment
See [the docs](./local-dev/README.md).

13 changes: 0 additions & 13 deletions docker-compose.yml

This file was deleted.

1 change: 1 addition & 0 deletions local-dev/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
artifactory-docker-compose/
26 changes: 26 additions & 0 deletions local-dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Local development

## Running artifactory locally
Artifactory pro is required to run this plugin. If you want to try it out,
you can sign up for free on the [JFrog website](https://jfrog.com/start-free/)
and download a self-hosted version powered by Docker Compose.

Follow the installation instructions to run artifactory.
The `artifactory-docker-compose` folder, which is .gitignored,
can be used to extract artifactory to.

## Installing the plugin
Build it first:

```shell
mvn install -DskipTests
```

Unpack the release into artifactory's plugins folder:

```shell
unzip -o distribution/target/artifactory-snyk-security-plugin-LOCAL-SNAPSHOT.zip -d local-dev/artifactory-docker-compose/artifactory/var/etc/artifactory/
```

Restart Artifactory and check the logs to confirm the plugin gets loaded.

0 comments on commit a233261

Please sign in to comment.