add Model

This commit is contained in:
Antoine 2020-09-17 00:37:33 +02:00
parent 70fb42a677
commit 4a4f5323a7
Signed by: antoine
GPG Key ID: 098FB66FC0475E70
16 changed files with 378 additions and 6 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.idea/
*.iml
target/
testGit/

View File

@ -2,6 +2,10 @@
NATIVE_VERSION=1.0.0
start-runner:
docker run -d --name gitlab-runner --restart unless-stopped -v /var/run/docker.sock:/var/run/docker.sock \
-v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:latest
build:
./mvnw compile

View File

@ -3,26 +3,31 @@
## start gitlab runner
```shell script
$ docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:latest
docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v gitlab-runner-config:/etc/gitlab-runner gitlab/gitlab-runner:latest
```
## register new runner
```shell script
$ gitlab-runner register -non-interactive --description "manualy registered gitlab runner" --url "http://172.17.0.1:8080/" --registration-token "3b79eb1f-32f3-4db2-ad1b-6
702e476d839" --tag-list "docker,manual" --executor shell
gitlab-runner register -non-interactive --description "manualy registered gitlab runner" --url "http://172.17.0.1:8080/" --registration-token "3b79eb1f-32f3-4db2-ad1b-6702e476d839" --tag-list "docker,manual" --executor shell
```
with curl
```shell script
$ curl --request POST -H 'Content-Type: application/json' "http://localhost:8080/api/v4/runners" -d '{"description":"manualy registered gitlab runner","tag_list":"docker,manual","run_untagged":false,"locked":true,"active":true,"info":{"name":"gitlab-runner","version":"13.3.1","revision":"738bbe5a","platform":"linux","architecture":"amd64","features":{"variables":false,"image":false,"services":false,"artifacts":false,"cache":false,"shared":false,"upload_multiple_artifacts":false,"upload_raw_artifacts":false,"session":false,"terminal":false,"refspecs":false,"masking":false,"proxy":false,"raw_variables":false,"artifacts_exclude":false,"multi_build_steps":false}},"token":"registration_token"}'
curl --request POST -H 'Content-Type: application/json' "http://localhost:8080/api/v4/runners" -d '{"description":"manualy registered gitlab runner","tag_list":"docker,manual","run_untagged":false,"locked":true,"active":true,"info":{"name":"gitlab-runner","version":"13.3.1","revision":"738bbe5a","platform":"linux","architecture":"amd64","features":{"variables":false,"image":false,"services":false,"artifacts":false,"cache":false,"shared":false,"upload_multiple_artifacts":false,"upload_raw_artifacts":false,"session":false,"terminal":false,"refspecs":false,"masking":false,"proxy":false,"raw_variables":false,"artifacts_exclude":false,"multi_build_steps":false}},"token":"registration_token"}'
```
## unregister runner
```shell script
gitlab-runner unregister --url "http://172.17.0.1:8080/" --token "3b79eb1f-32f3-4db2-ad1b-6702e476d839"
```
## list runners
```shell script
$ gitlab-runner list
gitlab-runner list
```
local listing :
@ -31,5 +36,5 @@ cf => /etc/gitlab-runner/config.toml
## verify which runner is always alive
```shell script
$ gitlab-runner verify --delete
gitlab-runner verify --delete
```

View File

@ -0,0 +1,115 @@
{
"secret": "toto",
"ref": "refs/heads/master",
"before": "1831a5d892851ec601c3f1b6c26245f18a9bcb58",
"after": "526300af0655f2eeb43c6dc553be4b64d96701c7",
"compare_url": "https://antoine-roux.ml/projects/antoine/testGit/compare/1831a5d892851ec601c3f1b6c26245f18a9bcb58...526300af0655f2eeb43c6dc553be4b64d96701c7",
"commits": [
{
"id": "526300af0655f2eeb43c6dc553be4b64d96701c7",
"message": "test trigger webhook\n",
"url": "https://antoine-roux.ml/projects/antoine/testGit/commit/526300af0655f2eeb43c6dc553be4b64d96701c7",
"author": {
"name": "Antoine",
"email": "antoinroux@hotmail.fr",
"username": "antoine"
},
"committer": {
"name": "Antoine",
"email": "antoinroux@hotmail.fr",
"username": "antoine"
},
"verification": null,
"timestamp": "2020-09-16T23:23:16+02:00",
"added": [
"toto"
],
"removed": [],
"modified": []
}
],
"head_commit": null,
"repository": {
"id": 124,
"owner": {
"id": 1,
"login": "antoine",
"full_name": "",
"email": "antoinroux@hotmail.fr",
"avatar_url": "https://antoine-roux.ml/projects/user/avatar/antoine/-1",
"language": "fr-FR",
"is_admin": true,
"last_login": "2020-09-15T21:45:21Z",
"created": "2018-08-26T06:16:47Z",
"username": "antoine"
},
"name": "testGit",
"full_name": "antoine/testGit",
"description": "repository for test some git feature",
"empty": false,
"private": true,
"fork": false,
"template": false,
"parent": null,
"mirror": false,
"size": 24,
"html_url": "https://antoine-roux.ml/projects/antoine/testGit",
"ssh_url": "gitolite@antoine-roux.ml:antoine/testGit.git",
"clone_url": "https://antoine-roux.ml/projects/antoine/testGit.git",
"original_url": "",
"website": "",
"stars_count": 0,
"forks_count": 0,
"watchers_count": 1,
"open_issues_count": 0,
"open_pr_counter": 0,
"release_counter": 0,
"default_branch": "master",
"archived": false,
"created_at": "2018-11-05T22:35:38Z",
"updated_at": "2020-09-16T21:23:48Z",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"has_issues": true,
"internal_tracker": {
"enable_time_tracker": true,
"allow_only_contributors_to_track_time": true,
"enable_issue_dependencies": true
},
"has_wiki": true,
"has_pull_requests": true,
"ignore_whitespace_conflicts": false,
"allow_merge_commits": true,
"allow_rebase": true,
"allow_rebase_explicit": false,
"allow_squash_merge": false,
"avatar_url": ""
},
"pusher": {
"id": 1,
"login": "antoine",
"full_name": "",
"email": "antoinroux@hotmail.fr",
"avatar_url": "https://antoine-roux.ml/projects/user/avatar/antoine/-1",
"language": "fr-FR",
"is_admin": true,
"last_login": "2020-09-15T21:45:21Z",
"created": "2018-08-26T06:16:47Z",
"username": "antoine"
},
"sender": {
"id": 1,
"login": "antoine",
"full_name": "",
"email": "antoinroux@hotmail.fr",
"avatar_url": "https://antoine-roux.ml/projects/user/avatar/antoine/-1",
"language": "fr-FR",
"is_admin": true,
"last_login": "2020-09-15T21:45:21Z",
"created": "2018-08-26T06:16:47Z",
"username": "antoine"
}
}

View File

@ -33,6 +33,7 @@
<start-class>tk.antoine_roux.wiki.MainLauncher</start-class>
<spring-graalvm-native.version>0.8.0</spring-graalvm-native.version>
<native-image-maven-plugin.version>20.2.0</native-image-maven-plugin.version>
<jackson-datatype.version>2.11.2</jackson-datatype.version>
</properties>
<dependencies>
@ -59,6 +60,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -9,8 +9,10 @@ import org.springframework.web.bind.annotation.*;
import tk.antoine_roux.wiki.annotation.ApiPrefix;
import tk.antoine_roux.wiki.annotation.ApiVersion;
import tk.antoine_roux.wiki.configuration.Exception.DeleteRunnerException;
import tk.antoine_roux.wiki.model.HookEvent;
import tk.antoine_roux.wiki.model.Runner;
import tk.antoine_roux.wiki.model.request.AddRunner;
import tk.antoine_roux.wiki.model.request.JobRequest;
import tk.antoine_roux.wiki.model.request.TokenRunner;
import tk.antoine_roux.wiki.model.response.RegisterRunnerResponse;
import tk.antoine_roux.wiki.utilitary.Boolean;
@ -91,4 +93,16 @@ public class ControllerHandlers {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
}
@ApiVersion(API_VERSION)
@PostMapping("/jobs/request")
public ResponseEntity<Void> jobRequest(@RequestBody JobRequest jobRequest) {
return ResponseEntity.ok().build();
}
@ApiVersion(API_VERSION)
@PostMapping("/webhook")
public ResponseEntity<Void> webhook(@RequestBody HookEvent webHookData) {
return ResponseEntity.ok().build();
}
}

View File

@ -0,0 +1,10 @@
package tk.antoine_roux.wiki;
/**
* model about repository permission
*/
public class Permission {
public boolean admin;
public boolean push;
public boolean pull;
}

View File

@ -0,0 +1,22 @@
package tk.antoine_roux.wiki.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.ZonedDateTime;
import java.util.List;
public class Commit {
public String id;
public String message;
public String url;
public UserReduced author;
public UserReduced committer;
public String verification;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssXXX")
public ZonedDateTime timestamp;
public List<String> added;
public List<String> removed;
public List<String> modified;
}

View File

@ -0,0 +1,20 @@
package tk.antoine_roux.wiki.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;
public class HookEvent {
public String secret;
public String ref;
public String before;
public String after;
@JsonProperty("compare_url")
public String compareUrl;
public List<Commit> commits;
@JsonProperty("head_commit")
public String headCommit;
public Repository repository;
public User pusher;
public User sender;
}

View File

@ -0,0 +1,15 @@
package tk.antoine_roux.wiki.model;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* model representation of gitea tracker
*/
public class InternalTracker {
@JsonProperty("enable_time_tracker")
public boolean enableTimeTracker;
@JsonProperty("allow_only_contributors_to_track_time")
public boolean allowOnlyContributorsToTrackTime;
@JsonProperty("enable_issue_dependencies")
public boolean enableIssueDependencies;
}

View File

@ -0,0 +1,72 @@
package tk.antoine_roux.wiki.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import tk.antoine_roux.wiki.Permission;
import java.time.ZonedDateTime;
public class Repository {
public String id;
public User owner;
public String name;
@JsonProperty("full_name")
public String fullName;
public String description;
public boolean empty;
@JsonProperty("private")
public boolean isPrivate;
public boolean fork;
public boolean template;
public String parent;
public boolean mirror;
public int size;
@JsonProperty("html_url")
public String htmlUrl;
@JsonProperty("ssh_url")
public String sshUrl;
@JsonProperty("clone_url")
public String cloneUrl;
@JsonProperty("original_url")
public String originalUrl;
public String website;
@JsonProperty("stars_count")
public int starsCount;
@JsonProperty("forks_count")
public int forksCount;
@JsonProperty("watchers_count")
public int watchersCount;
@JsonProperty("open_issues_count")
public int openIssuesCount;
@JsonProperty("open_pr_count")
public int openPRCount;
@JsonProperty("release_counter")
public int releaseCounter;
@JsonProperty("default_branch")
public String defaultBranch;
public boolean archived;
@JsonProperty("created_at")
public ZonedDateTime createdAt;
@JsonProperty("updated_at")
public ZonedDateTime updatedAt;
public Permission permissions;
@JsonProperty("has_issues")
public boolean hasIssues;
@JsonProperty("internal_tracker")
public InternalTracker internalTracker;
@JsonProperty("has_wiki")
public boolean hasWiki;
@JsonProperty("has_pull_requests")
public boolean hasPullRequests;
@JsonProperty("ignore_whitespace_conflicts")
public boolean ignoreWhitespaceConflicts;
@JsonProperty("allow_merge_commits")
public boolean allowMergeCommits;
@JsonProperty("allow_rebase")
public boolean allowRebase;
@JsonProperty("allow_rebase_explicit")
public boolean allowRebaseExplicit;
@JsonProperty("allow_squash_merge")
public boolean allowSquashMerge;
@JsonProperty("avatar_url")
public String avatarUrl;
}

View File

@ -0,0 +1,37 @@
package tk.antoine_roux.wiki.model;
import java.util.Map;
public class RunnerInfo {
public String name;
public String version;
public String revision;
public String platform;
public String architecture;
public String executor;
public String shell;
/**
* features can contains :
* <ul>
* <li>variables</li>
* <li>image</li>
* <li>services</li>
* <li>artifacts</li>
* <li>cache</li>
* <li>shared</li>
* <li>upload_multiple_artifacts</li>
* <li>upload_raw_artifacts</li>
* <li>session</li>
* <li>terminal</li>
* <li>refspecs</li>
* <li>masking</li>
* <li>proxy</li>
* <li>raw_variables</li>
* <li>artifacts_exclude</li>
* <li>multi_build_steps</li>
* </ul>
*/
public Map<String, Boolean> features;
}

View File

@ -0,0 +1,25 @@
package tk.antoine_roux.wiki.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.ZonedDateTime;
/**
* pusher sender user information
*/
public class User {
public String id;
public String login;
public String username;
@JsonProperty("full_name")
public String fullName;
public String email;
@JsonProperty("avatar_url")
public String avatarUrl;
public String language;
@JsonProperty("is_admin")
public boolean isAdmin;
@JsonProperty("last_login")
public ZonedDateTime lastLogin;
public ZonedDateTime created;
}

View File

@ -0,0 +1,10 @@
package tk.antoine_roux.wiki.model;
/**
* Reduced user information
*/
public class UserReduced {
public String name;
public String email;
public String username;
}

View File

@ -1,6 +1,7 @@
package tk.antoine_roux.wiki.model.request;
import com.fasterxml.jackson.annotation.JsonProperty;
import tk.antoine_roux.wiki.model.RunnerInfo;
import java.util.Arrays;
import java.util.List;
@ -15,6 +16,11 @@ public class AddRunner {
public String description;
public List<String> tags;
public UUID token;
@JsonProperty("run_untagged")
public Boolean runUntagged;
public Boolean locked;
public Boolean active;
public RunnerInfo info;
@JsonProperty("tag_list")
public void setTags(String tags) {

View File

@ -0,0 +1,10 @@
package tk.antoine_roux.wiki.model.request;
import tk.antoine_roux.wiki.model.RunnerInfo;
/**
* Job Request compose from {@link RunnerInfo} and token field
*/
public class JobRequest extends TokenRunner {
public RunnerInfo info;
}