20 changed files with 154 additions and 462 deletions
@ -1,112 +1,51 @@
|
||||
See https://docs.google.com/document/d/15yod6K_ZbNkJ_ern7gwpxjBkdJIlHXORfYZ3CGQhnEM/edit?usp=sharing for a full version with images |
||||
# code-with-quarkus |
||||
|
||||
# Introduction |
||||
Currently we rely on CPaaS to submit requests to PSSaaS which then invokes the PSSC scanning container. The idea behind the ScanChain api is to act as an interaction point for services to be able to directly access our scan tooling. |
||||
This project uses Quarkus, the Supersonic Subatomic Java Framework. |
||||
|
||||
Our api will be written in Quarkus for ease of use and deployment to OpenShift, we will also use Tekton to assist with CI/CD. |
||||
If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ . |
||||
|
||||
# How to build |
||||
## Running the application in dev mode |
||||
|
||||
To set up the environment. After cloning the repository: |
||||
|
||||
``` |
||||
cd <repository>/ |
||||
quarkus create app quarkus:dev |
||||
mvn -N io.takari:maven:wrapper |
||||
``` |
||||
|
||||
Also, it is necessary to create a local PostgreSQL instance. For development purposes, the parameters are: |
||||
``` |
||||
username = postgresql |
||||
password = password |
||||
``` |
||||
|
||||
ToDo: Create Database Model |
||||
|
||||
|
||||
|
||||
To run the Quarkus build in dev mode simply run: |
||||
```` |
||||
You can run your application in dev mode that enables live coding using: |
||||
```shell script |
||||
./mvnw compile quarkus:dev |
||||
```` |
||||
All end points should be avaliable on localhost:8080/{endpoint}. The endpoints are listed in the endpoints section |
||||
|
||||
|
||||
|
||||
# Deploying to OpenShift (https://quarkus.io/guides/deploying-to-openshift) |
||||
Part of the advantage of working with quarkus is the ease of which we can deploy it to OpenShift. We have the OpenShift extension already installed via the pom, |
||||
|
||||
All that should be required to build and deploy OpenShift is to login to OpenShift via the usual method (oc login (creds) for example). Before running a build command: |
||||
|
||||
You can then expose the routes (oc expose {route}), then your application should be accessible on the OpenShift cluster. This is verifiable either by using the console to request which services are running (oc get svc) or by using the web console which should display the service graphically. |
||||
|
||||
# Design diagram |
||||
API endpoint diagram with all endpoints DB links, connections to further services (PNC API etc) |
||||
|
||||
# API endpoints |
||||
|
||||
## /{scanId} - GET request for retrieving scans |
||||
This is a simple request for retrieving scans that are stored in our postgresql database. The assigned scanId will return the whole scan payload in JSON format. |
||||
|
||||
## / - POST request takes a JSON payload to start scans (Maybe isnt relevant/shouldnt be included in the future) |
||||
|
||||
Creating scans via passing fully formed JSON payloads. The standard JSON format should contain: |
||||
product-id |
||||
event-id |
||||
is-managed-service |
||||
component-list |
||||
See appendix 1 for a provided example |
||||
|
||||
## /scanRequest - Post request for starting scans |
||||
|
||||
There are several different types of build that should be retrieved from the backend source. Different inputs are required based off the build source. |
||||
|
||||
The required fields for BREW builds are: |
||||
buildSystemType |
||||
brewId |
||||
brewNVR - matches brewId |
||||
pncId |
||||
artifactType |
||||
fileName |
||||
builtFromSource |
||||
|
||||
The required fields for git builds are: |
||||
buildSystemType |
||||
repository |
||||
reference |
||||
commitId |
||||
|
||||
The required fields for PNC builds are: |
||||
buildSystemType |
||||
buildId |
||||
``` |
||||
|
||||
This information should allow us to have all the requirements for retrieving and then starting a scan when requested from the required sources. |
||||
> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/. |
||||
|
||||
## /startScan - PUT request to start off the relevant scan |
||||
## Packaging and running the application |
||||
|
||||
Only requires the scanId and should start off the relevant scan, should return a success only on finished or failure if there's no further response after timeout. |
||||
## /removeScan - DELETE request to remove a scan build from DB |
||||
The application can be packaged using: |
||||
```shell script |
||||
./mvnw package |
||||
``` |
||||
It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory. |
||||
Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory. |
||||
|
||||
Only requires the scanId should remove the relevant scan from our DB. Should return a success or failure. |
||||
The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`. |
||||
|
||||
# Expanded work to do |
||||
If you want to build an _über-jar_, execute the following command: |
||||
```shell script |
||||
./mvnw package -Dquarkus.package.type=uber-jar |
||||
``` |
||||
|
||||
## Jenkins |
||||
The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`. |
||||
|
||||
Haven't looked into the correct way for the API to interact with Jenkins needs more investigation. |
||||
## Creating a native executable |
||||
|
||||
## Jira tickets still to do: |
||||
https://issues.redhat.com/browse/PSSECMGT-1548 |
||||
https://issues.redhat.com/browse/PSSECMGT-1549 |
||||
https://issues.redhat.com/browse/PSSECMGT-1550 |
||||
https://issues.redhat.com/browse/PSSECMGT-1551 |
||||
https://issues.redhat.com/browse/PSSECMGT-1552 |
||||
https://issues.redhat.com/browse/PSSECMGT-1553 |
||||
https://issues.redhat.com/browse/PSSECMGT-1554 |
||||
You can create a native executable using: |
||||
```shell script |
||||
./mvnw package -Pnative |
||||
``` |
||||
|
||||
Or, if you don't have GraalVM installed, you can run the native executable build in a container using: |
||||
```shell script |
||||
./mvnw package -Pnative -Dquarkus.native.container-build=true |
||||
``` |
||||
|
||||
# Appendix |
||||
You can then execute your native executable with: `./target/code-with-quarkus-1.0.0-SNAPSHOT-runner` |
||||
|
||||
Appendix 1 |
||||
If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling. |
||||
|
||||
## Related Guides |
||||
|
||||
|
||||
Loading…
Reference in new issue