fix(runner): delete running for boltdb

This commit is contained in:
Denis Gukov 2024-10-12 22:56:45 +00:00
parent c9705d2df3
commit 216099d144
3 changed files with 28 additions and 4 deletions

View File

@ -0,0 +1,6 @@
{
"web_host": "http://localhost:3000",
"runner": {
"token_file": "/home/codespace/.semaphore-runner-token"
}
}

13
.vscode/launch.json vendored
View File

@ -12,6 +12,19 @@
"env": { "env": {
"PATH": "${workspaceFolder}/.venv/bin:${env:PATH}" "PATH": "${workspaceFolder}/.venv/bin:${env:PATH}"
} }
},
{
"name": "Launch Server with remote Runner",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "./cli/main.go",
"args": ["server", "--config", ".devcontainer/config.json"],
"cwd": "${workspaceFolder}",
"env": {
"PATH": "${workspaceFolder}/.venv/bin:${env:PATH}",
"SEMAPHORE_USE_REMOTE_RUNNER": "true"
}
} }
] ]
} }

View File

@ -1,8 +1,11 @@
package bolt package bolt
import ( import (
"encoding/base64"
"github.com/ansible-semaphore/semaphore/db" "github.com/ansible-semaphore/semaphore/db"
"github.com/ansible-semaphore/semaphore/util" "github.com/gorilla/securecookie"
"go.etcd.io/bbolt"
) )
func (d *BoltDb) GetRunner(projectID int, runnerID int) (runner db.Runner, err error) { func (d *BoltDb) GetRunner(projectID int, runnerID int) (runner db.Runner, err error) {
@ -47,7 +50,7 @@ func (d *BoltDb) GetGlobalRunner(runnerID int) (runner db.Runner, err error) {
func (d *BoltDb) GetGlobalRunners(activeOnly bool) (runners []db.Runner, err error) { func (d *BoltDb) GetGlobalRunners(activeOnly bool) (runners []db.Runner, err error) {
err = d.getObjects(0, db.GlobalRunnerProps, db.RetrieveQueryParams{}, func(i interface{}) bool { err = d.getObjects(0, db.GlobalRunnerProps, db.RetrieveQueryParams{}, func(i interface{}) bool {
runner := i.(*db.Runner) runner := i.(db.Runner)
if activeOnly { if activeOnly {
return runner.Active return runner.Active
} }
@ -57,7 +60,9 @@ func (d *BoltDb) GetGlobalRunners(activeOnly bool) (runners []db.Runner, err err
} }
func (d *BoltDb) DeleteGlobalRunner(runnerID int) (err error) { func (d *BoltDb) DeleteGlobalRunner(runnerID int) (err error) {
return return d.db.Update(func(tx *bbolt.Tx) error {
return d.deleteObject(0, db.GlobalRunnerProps, intObjectID(runnerID), tx)
})
} }
func (d *BoltDb) UpdateRunner(runner db.Runner) (err error) { func (d *BoltDb) UpdateRunner(runner db.Runner) (err error) {
@ -65,7 +70,7 @@ func (d *BoltDb) UpdateRunner(runner db.Runner) (err error) {
} }
func (d *BoltDb) CreateRunner(runner db.Runner) (newRunner db.Runner, err error) { func (d *BoltDb) CreateRunner(runner db.Runner) (newRunner db.Runner, err error) {
runner.Token = util.RandString(12) runner.Token = base64.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32))
res, err := d.createObject(0, db.GlobalRunnerProps, runner) res, err := d.createObject(0, db.GlobalRunnerProps, runner)
if err != nil { if err != nil {