From 4996728daa1eb1b8185d42e2fa1af8e1bff288e0 Mon Sep 17 00:00:00 2001 From: Denis Gukov Date: Sun, 17 Nov 2024 05:47:04 -0500 Subject: [PATCH] project runners (#2547) * feat: add feature flag * feat(runners): pro runners ui * feat(runner): api for project level * fix(ui): key of list * feat(be): add mocks for project runners * feat: pro alert * feat(pro): upgrade button * feat(pro): upgrade button * feat(pro): icon and color * feat(pro): change color --- api/projects/runners.go | 51 +++++++++++++++++++++++ api/router.go | 16 ++++++- api/runners.go | 8 ---- web/src/App.vue | 1 + web/src/components/ArgsPicker.vue | 3 +- web/src/components/DashboardMenu.vue | 42 +++++++++++++++++++ web/src/components/RestoreProjectForm.vue | 2 +- web/src/components/TemplateForm.vue | 1 + web/src/lang/en.js | 2 +- web/src/router/index.js | 4 ++ web/src/views/Runners.vue | 44 ++++++++++++++++++- web/src/views/project/Activity.vue | 22 ++++------ web/src/views/project/History.vue | 24 ++++------- web/src/views/project/Settings.vue | 17 ++++---- 14 files changed, 183 insertions(+), 54 deletions(-) create mode 100644 api/projects/runners.go create mode 100644 web/src/components/DashboardMenu.vue diff --git a/api/projects/runners.go b/api/projects/runners.go new file mode 100644 index 00000000..12d474cb --- /dev/null +++ b/api/projects/runners.go @@ -0,0 +1,51 @@ +package projects + +import ( + "github.com/gorilla/context" + "github.com/semaphoreui/semaphore/api/helpers" + "github.com/semaphoreui/semaphore/db" + "net/http" +) + +func GetRunners(w http.ResponseWriter, r *http.Request) { + project := context.Get(r, "project").(db.Project) + runners, err := helpers.Store(r).GetRunners(project.ID) + + if err != nil { + panic(err) + } + + var result = make([]db.Runner, 0) + + for _, runner := range runners { + result = append(result, runner) + } + + helpers.WriteJSON(w, http.StatusOK, result) +} + +func AddRunner(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) +} + +func RunnerMiddleware(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + next.ServeHTTP(w, r) + }) +} + +func GetRunner(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) +} + +func UpdateRunner(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) +} + +func DeleteRunner(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) +} + +func SetRunnerActive(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusNotFound) +} diff --git a/api/router.go b/api/router.go index 6ee3972e..98b68920 100644 --- a/api/router.go +++ b/api/router.go @@ -12,13 +12,13 @@ import ( "github.com/semaphoreui/semaphore/api/runners" + "github.com/gorilla/mux" "github.com/semaphoreui/semaphore/api/helpers" "github.com/semaphoreui/semaphore/api/projects" "github.com/semaphoreui/semaphore/api/sockets" "github.com/semaphoreui/semaphore/api/tasks" "github.com/semaphoreui/semaphore/db" "github.com/semaphoreui/semaphore/util" - "github.com/gorilla/mux" ) var startTime = time.Now().UTC() @@ -222,6 +222,16 @@ func Route() *mux.Router { projectUserAPI.Path("/integrations").HandlerFunc(projects.AddIntegration).Methods("POST") projectUserAPI.Path("/backup").HandlerFunc(projects.GetBackup).Methods("GET", "HEAD") + projectUserAPI.Path("/runners").HandlerFunc(projects.GetRunners).Methods("GET", "HEAD") + projectUserAPI.Path("/runners").HandlerFunc(projects.AddRunner).Methods("POST") + + projectRunnersAPI := projectUserAPI.PathPrefix("/runners").Subrouter() + projectRunnersAPI.Use(globalRunnerMiddleware) + projectRunnersAPI.Path("/{runner_id}").HandlerFunc(projects.GetRunner).Methods("GET", "HEAD") + projectRunnersAPI.Path("/{runner_id}").HandlerFunc(projects.UpdateRunner).Methods("PUT", "POST") + projectRunnersAPI.Path("/{runner_id}/active").HandlerFunc(projects.SetRunnerActive).Methods("POST") + projectRunnersAPI.Path("/{runner_id}").HandlerFunc(projects.DeleteRunner).Methods("DELETE") + // // Updating and deleting project projectAdminAPI := authenticatedAPI.Path("/project/{project_id}").Subrouter() @@ -475,6 +485,10 @@ func getSystemInfo(w http.ResponseWriter, r *http.Request) { "ansible": util.AnsibleVersion(), "web_host": host, "use_remote_runner": util.Config.UseRemoteRunner, + + "premium_features": map[string]bool{ + "project_runners": false, + }, } helpers.WriteJSON(w, http.StatusOK, body) diff --git a/api/runners.go b/api/runners.go index 831fb843..0440af1b 100644 --- a/api/runners.go +++ b/api/runners.go @@ -9,14 +9,6 @@ import ( "github.com/gorilla/context" ) -//type minimalGlobalRunner struct { -// ID int `json:"id"` -// Name string `json:"name"` -// Active bool `json:"active"` -// Webhook string `db:"webhook" json:"webhook"` -// MaxParallelTasks int `db:"max_parallel_tasks" json:"max_parallel_tasks"` -//} - func getGlobalRunners(w http.ResponseWriter, r *http.Request) { runners, err := helpers.Store(r).GetGlobalRunners(false) diff --git a/web/src/App.vue b/web/src/App.vue index 0288657b..46924272 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -528,6 +528,7 @@ :isAdmin="(user || {}).admin" :webHost="(systemInfo || {}).web_host" :version="(systemInfo || {version: ''}).version.split('-')[0]" + :premiumFeatures="((systemInfo || {premium_features: {}}).premium_features)" :user="user" > diff --git a/web/src/components/ArgsPicker.vue b/web/src/components/ArgsPicker.vue index e1fae95e..a46b6b11 100644 --- a/web/src/components/ArgsPicker.vue +++ b/web/src/components/ArgsPicker.vue @@ -64,7 +64,7 @@ 'rgba(200, 200, 200, 0.38)' : 'rgba(0, 0, 0, 0.38)' }"> - {{ $t('Args') }} + {{ title || $t('Args') }} + + {{ $t('history') }} + + {{ $t('activity') }} + {{ $t('settings') }} + + + {{ $t('runners') }} + + mdi-professional-hexagon + + + + diff --git a/web/src/components/RestoreProjectForm.vue b/web/src/components/RestoreProjectForm.vue index be3bc0c9..6e2b392f 100644 --- a/web/src/components/RestoreProjectForm.vue +++ b/web/src/components/RestoreProjectForm.vue @@ -59,7 +59,7 @@ export default { }, getItemsUrl() { - return '/api/projects/restore'; + return '/api/project/restore'; }, }, }; diff --git a/web/src/components/TemplateForm.vue b/web/src/components/TemplateForm.vue index 846adcad..0ac3e0f0 100644 --- a/web/src/components/TemplateForm.vue +++ b/web/src/components/TemplateForm.vue @@ -274,6 +274,7 @@
+ + + + + {{ $t('dashboard2') }} + + + + + - + mdi-arrow-left + {{ $t('runners') }} + + Project Runners available only in PRO version. + Upgrade + + {{ $t('dashboard') }} - - {{ $t('history') }} - {{ $t('activity') }} - - {{ $t('settings') }} - - +