mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-01 14:21:07 +00:00
Reorganize code into server/{api,grpc,shared} packages (#337)
* move api code to server/api * move grpc server for agent communication to server/grpc * move server.Config to server/config.go as it is used by both server/api and server/grpc * move shared code used by server/api and server/grpc to server/shared
This commit is contained in:
parent
4fd8a1ef42
commit
35a45b7961
29 changed files with 356 additions and 308 deletions
|
@ -31,7 +31,7 @@ func main() {
|
||||||
app.Name = "woodpecker-server"
|
app.Name = "woodpecker-server"
|
||||||
app.Version = version.String()
|
app.Version = version.String()
|
||||||
app.Usage = "woodpecker server"
|
app.Usage = "woodpecker server"
|
||||||
app.Action = server
|
app.Action = loop
|
||||||
app.Flags = flags
|
app.Flags = flags
|
||||||
app.Before = before
|
app.Before = before
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,8 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/remote"
|
"github.com/woodpecker-ci/woodpecker/remote"
|
||||||
"github.com/woodpecker-ci/woodpecker/router"
|
"github.com/woodpecker-ci/woodpecker/router"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware"
|
"github.com/woodpecker-ci/woodpecker/router/middleware"
|
||||||
droneserver "github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
woodpeckerGrpcServer "github.com/woodpecker-ci/woodpecker/server/grpc"
|
||||||
"github.com/woodpecker-ci/woodpecker/store"
|
"github.com/woodpecker-ci/woodpecker/store"
|
||||||
|
|
||||||
"github.com/gin-gonic/contrib/ginrus"
|
"github.com/gin-gonic/contrib/ginrus"
|
||||||
|
@ -49,7 +50,7 @@ import (
|
||||||
oldcontext "golang.org/x/net/context"
|
oldcontext "golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
func server(c *cli.Context) error {
|
func loop(c *cli.Context) error {
|
||||||
|
|
||||||
// debug level if requested by user
|
// debug level if requested by user
|
||||||
if c.Bool("debug") {
|
if c.Bool("debug") {
|
||||||
|
@ -123,7 +124,14 @@ func server(c *cli.Context) error {
|
||||||
MinTime: c.Duration("keepalive-min-time"),
|
MinTime: c.Duration("keepalive-min-time"),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
droneServer := droneserver.NewDroneServer(remote_, droneserver.Config.Services.Queue, droneserver.Config.Services.Logs, droneserver.Config.Services.Pubsub, store_, droneserver.Config.Server.Host)
|
droneServer := woodpeckerGrpcServer.NewDroneServer(
|
||||||
|
remote_,
|
||||||
|
server.Config.Services.Queue,
|
||||||
|
server.Config.Services.Logs,
|
||||||
|
server.Config.Services.Pubsub,
|
||||||
|
store_,
|
||||||
|
server.Config.Server.Host,
|
||||||
|
)
|
||||||
proto.RegisterDroneServer(grpcServer, droneServer)
|
proto.RegisterDroneServer(grpcServer, droneServer)
|
||||||
|
|
||||||
err = grpcServer.Serve(lis)
|
err = grpcServer.Serve(lis)
|
||||||
|
@ -201,45 +209,45 @@ func server(c *cli.Context) error {
|
||||||
func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) {
|
func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) {
|
||||||
|
|
||||||
// storage
|
// storage
|
||||||
droneserver.Config.Storage.Files = v
|
server.Config.Storage.Files = v
|
||||||
droneserver.Config.Storage.Config = v
|
server.Config.Storage.Config = v
|
||||||
|
|
||||||
// services
|
// services
|
||||||
droneserver.Config.Services.Queue = setupQueue(c, v)
|
server.Config.Services.Queue = setupQueue(c, v)
|
||||||
droneserver.Config.Services.Logs = logging.New()
|
server.Config.Services.Logs = logging.New()
|
||||||
droneserver.Config.Services.Pubsub = pubsub.New()
|
server.Config.Services.Pubsub = pubsub.New()
|
||||||
droneserver.Config.Services.Pubsub.Create(context.Background(), "topic/events")
|
server.Config.Services.Pubsub.Create(context.Background(), "topic/events")
|
||||||
droneserver.Config.Services.Registries = setupRegistryService(c, v)
|
server.Config.Services.Registries = setupRegistryService(c, v)
|
||||||
droneserver.Config.Services.Secrets = setupSecretService(c, v)
|
server.Config.Services.Secrets = setupSecretService(c, v)
|
||||||
droneserver.Config.Services.Senders = sender.New(v, v)
|
server.Config.Services.Senders = sender.New(v, v)
|
||||||
droneserver.Config.Services.Environ = setupEnvironService(c, v)
|
server.Config.Services.Environ = setupEnvironService(c, v)
|
||||||
|
|
||||||
if endpoint := c.String("gating-service"); endpoint != "" {
|
if endpoint := c.String("gating-service"); endpoint != "" {
|
||||||
droneserver.Config.Services.Senders = sender.NewRemote(endpoint)
|
server.Config.Services.Senders = sender.NewRemote(endpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
// limits
|
// limits
|
||||||
droneserver.Config.Pipeline.Limits.MemSwapLimit = c.Int64("limit-mem-swap")
|
server.Config.Pipeline.Limits.MemSwapLimit = c.Int64("limit-mem-swap")
|
||||||
droneserver.Config.Pipeline.Limits.MemLimit = c.Int64("limit-mem")
|
server.Config.Pipeline.Limits.MemLimit = c.Int64("limit-mem")
|
||||||
droneserver.Config.Pipeline.Limits.ShmSize = c.Int64("limit-shm-size")
|
server.Config.Pipeline.Limits.ShmSize = c.Int64("limit-shm-size")
|
||||||
droneserver.Config.Pipeline.Limits.CPUQuota = c.Int64("limit-cpu-quota")
|
server.Config.Pipeline.Limits.CPUQuota = c.Int64("limit-cpu-quota")
|
||||||
droneserver.Config.Pipeline.Limits.CPUShares = c.Int64("limit-cpu-shares")
|
server.Config.Pipeline.Limits.CPUShares = c.Int64("limit-cpu-shares")
|
||||||
droneserver.Config.Pipeline.Limits.CPUSet = c.String("limit-cpu-set")
|
server.Config.Pipeline.Limits.CPUSet = c.String("limit-cpu-set")
|
||||||
|
|
||||||
// server configuration
|
// server configuration
|
||||||
droneserver.Config.Server.Cert = c.String("server-cert")
|
server.Config.Server.Cert = c.String("server-cert")
|
||||||
droneserver.Config.Server.Key = c.String("server-key")
|
server.Config.Server.Key = c.String("server-key")
|
||||||
droneserver.Config.Server.Pass = c.String("agent-secret")
|
server.Config.Server.Pass = c.String("agent-secret")
|
||||||
droneserver.Config.Server.Host = c.String("server-host")
|
server.Config.Server.Host = c.String("server-host")
|
||||||
droneserver.Config.Server.Port = c.String("server-addr")
|
server.Config.Server.Port = c.String("server-addr")
|
||||||
droneserver.Config.Server.RepoConfig = c.String("repo-config")
|
server.Config.Server.RepoConfig = c.String("repo-config")
|
||||||
droneserver.Config.Server.SessionExpires = c.Duration("session-expires")
|
server.Config.Server.SessionExpires = c.Duration("session-expires")
|
||||||
droneserver.Config.Pipeline.Networks = c.StringSlice("network")
|
server.Config.Pipeline.Networks = c.StringSlice("network")
|
||||||
droneserver.Config.Pipeline.Volumes = c.StringSlice("volume")
|
server.Config.Pipeline.Volumes = c.StringSlice("volume")
|
||||||
droneserver.Config.Pipeline.Privileged = c.StringSlice("escalate")
|
server.Config.Pipeline.Privileged = c.StringSlice("escalate")
|
||||||
|
|
||||||
// prometheus
|
// prometheus
|
||||||
droneserver.Config.Prometheus.AuthToken = c.String("prometheus-auth-token")
|
server.Config.Prometheus.AuthToken = c.String("prometheus-auth-token")
|
||||||
}
|
}
|
||||||
|
|
||||||
type authorizer struct {
|
type authorizer struct {
|
||||||
|
@ -271,7 +279,7 @@ func (a *authorizer) authorize(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func redirect(w http.ResponseWriter, req *http.Request) {
|
func redirect(w http.ResponseWriter, req *http.Request) {
|
||||||
var serverHost string = droneserver.Config.Server.Host
|
var serverHost string = server.Config.Server.Host
|
||||||
serverHost = strings.TrimPrefix(serverHost, "http://")
|
serverHost = strings.TrimPrefix(serverHost, "http://")
|
||||||
serverHost = strings.TrimPrefix(serverHost, "https://")
|
serverHost = strings.TrimPrefix(serverHost, "https://")
|
||||||
req.URL.Scheme = "https"
|
req.URL.Scheme = "https"
|
||||||
|
|
|
@ -35,7 +35,7 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/remote/gitlab"
|
"github.com/woodpecker-ci/woodpecker/remote/gitlab"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote/gitlab3"
|
"github.com/woodpecker-ci/woodpecker/remote/gitlab3"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote/gogs"
|
"github.com/woodpecker-ci/woodpecker/remote/gogs"
|
||||||
droneserver "github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/web"
|
"github.com/woodpecker-ci/woodpecker/server/web"
|
||||||
"github.com/woodpecker-ci/woodpecker/store"
|
"github.com/woodpecker-ci/woodpecker/store"
|
||||||
"github.com/woodpecker-ci/woodpecker/store/datastore"
|
"github.com/woodpecker-ci/woodpecker/store/datastore"
|
||||||
|
@ -257,7 +257,7 @@ func setupMetrics(g *errgroup.Group, store_ store.Store) {
|
||||||
|
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
for {
|
for {
|
||||||
stats := droneserver.Config.Services.Queue.Info(nil)
|
stats := server.Config.Services.Queue.Info(nil)
|
||||||
pendingJobs.Set(float64(stats.Stats.Pending))
|
pendingJobs.Set(float64(stats.Stats.Pending))
|
||||||
waitingJobs.Set(float64(stats.Stats.WaitingOnDeps))
|
waitingJobs.Set(float64(stats.Stats.WaitingOnDeps))
|
||||||
runningJobs.Set(float64(stats.Stats.Running))
|
runningJobs.Set(float64(stats.Stats.Running))
|
||||||
|
|
120
router/router.go
120
router/router.go
|
@ -23,9 +23,9 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/header"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/header"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/token"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/token"
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server/api"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/debug"
|
"github.com/woodpecker-ci/woodpecker/server/api/debug"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/metrics"
|
"github.com/woodpecker-ci/woodpecker/server/api/metrics"
|
||||||
"github.com/woodpecker-ci/woodpecker/server/web"
|
"github.com/woodpecker-ci/woodpecker/server/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -52,27 +52,27 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
|
||||||
mux.ServeHTTP(c.Writer, req)
|
mux.ServeHTTP(c.Writer, req)
|
||||||
})
|
})
|
||||||
|
|
||||||
e.GET("/logout", server.GetLogout)
|
e.GET("/logout", api.GetLogout)
|
||||||
e.GET("/login", server.HandleLogin)
|
e.GET("/login", api.HandleLogin)
|
||||||
|
|
||||||
user := e.Group("/api/user")
|
user := e.Group("/api/user")
|
||||||
{
|
{
|
||||||
user.Use(session.MustUser())
|
user.Use(session.MustUser())
|
||||||
user.GET("", server.GetSelf)
|
user.GET("", api.GetSelf)
|
||||||
user.GET("/feed", server.GetFeed)
|
user.GET("/feed", api.GetFeed)
|
||||||
user.GET("/repos", server.GetRepos)
|
user.GET("/repos", api.GetRepos)
|
||||||
user.POST("/token", server.PostToken)
|
user.POST("/token", api.PostToken)
|
||||||
user.DELETE("/token", server.DeleteToken)
|
user.DELETE("/token", api.DeleteToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
users := e.Group("/api/users")
|
users := e.Group("/api/users")
|
||||||
{
|
{
|
||||||
users.Use(session.MustAdmin())
|
users.Use(session.MustAdmin())
|
||||||
users.GET("", server.GetUsers)
|
users.GET("", api.GetUsers)
|
||||||
users.POST("", server.PostUser)
|
users.POST("", api.PostUser)
|
||||||
users.GET("/:login", server.GetUser)
|
users.GET("/:login", api.GetUser)
|
||||||
users.PATCH("/:login", server.PatchUser)
|
users.PATCH("/:login", api.PatchUser)
|
||||||
users.DELETE("/:login", server.DeleteUser)
|
users.DELETE("/:login", api.DeleteUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo := e.Group("/api/repos/:owner/:name")
|
repo := e.Group("/api/repos/:owner/:name")
|
||||||
|
@ -81,62 +81,62 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
|
||||||
repo.Use(session.SetPerm())
|
repo.Use(session.SetPerm())
|
||||||
repo.Use(session.MustPull)
|
repo.Use(session.MustPull)
|
||||||
|
|
||||||
repo.POST("", session.MustRepoAdmin(), server.PostRepo)
|
repo.POST("", session.MustRepoAdmin(), api.PostRepo)
|
||||||
repo.GET("", server.GetRepo)
|
repo.GET("", api.GetRepo)
|
||||||
repo.GET("/builds", server.GetBuilds)
|
repo.GET("/builds", api.GetBuilds)
|
||||||
repo.GET("/builds/:number", server.GetBuild)
|
repo.GET("/builds/:number", api.GetBuild)
|
||||||
repo.GET("/logs/:number/:pid", server.GetProcLogs)
|
repo.GET("/logs/:number/:pid", api.GetProcLogs)
|
||||||
repo.GET("/logs/:number/:pid/:proc", server.GetBuildLogs)
|
repo.GET("/logs/:number/:pid/:proc", api.GetBuildLogs)
|
||||||
|
|
||||||
repo.GET("/files/:number", server.FileList)
|
repo.GET("/files/:number", api.FileList)
|
||||||
repo.GET("/files/:number/:proc/*file", server.FileGet)
|
repo.GET("/files/:number/:proc/*file", api.FileGet)
|
||||||
|
|
||||||
// requires push permissions
|
// requires push permissions
|
||||||
repo.GET("/secrets", session.MustPush, server.GetSecretList)
|
repo.GET("/secrets", session.MustPush, api.GetSecretList)
|
||||||
repo.POST("/secrets", session.MustPush, server.PostSecret)
|
repo.POST("/secrets", session.MustPush, api.PostSecret)
|
||||||
repo.GET("/secrets/:secret", session.MustPush, server.GetSecret)
|
repo.GET("/secrets/:secret", session.MustPush, api.GetSecret)
|
||||||
repo.PATCH("/secrets/:secret", session.MustPush, server.PatchSecret)
|
repo.PATCH("/secrets/:secret", session.MustPush, api.PatchSecret)
|
||||||
repo.DELETE("/secrets/:secret", session.MustPush, server.DeleteSecret)
|
repo.DELETE("/secrets/:secret", session.MustPush, api.DeleteSecret)
|
||||||
|
|
||||||
// requires push permissions
|
// requires push permissions
|
||||||
repo.GET("/registry", session.MustPush, server.GetRegistryList)
|
repo.GET("/registry", session.MustPush, api.GetRegistryList)
|
||||||
repo.POST("/registry", session.MustPush, server.PostRegistry)
|
repo.POST("/registry", session.MustPush, api.PostRegistry)
|
||||||
repo.GET("/registry/:registry", session.MustPush, server.GetRegistry)
|
repo.GET("/registry/:registry", session.MustPush, api.GetRegistry)
|
||||||
repo.PATCH("/registry/:registry", session.MustPush, server.PatchRegistry)
|
repo.PATCH("/registry/:registry", session.MustPush, api.PatchRegistry)
|
||||||
repo.DELETE("/registry/:registry", session.MustPush, server.DeleteRegistry)
|
repo.DELETE("/registry/:registry", session.MustPush, api.DeleteRegistry)
|
||||||
|
|
||||||
// requires admin permissions
|
// requires admin permissions
|
||||||
repo.PATCH("", session.MustRepoAdmin(), server.PatchRepo)
|
repo.PATCH("", session.MustRepoAdmin(), api.PatchRepo)
|
||||||
repo.DELETE("", session.MustRepoAdmin(), server.DeleteRepo)
|
repo.DELETE("", session.MustRepoAdmin(), api.DeleteRepo)
|
||||||
repo.POST("/chown", session.MustRepoAdmin(), server.ChownRepo)
|
repo.POST("/chown", session.MustRepoAdmin(), api.ChownRepo)
|
||||||
repo.POST("/repair", session.MustRepoAdmin(), server.RepairRepo)
|
repo.POST("/repair", session.MustRepoAdmin(), api.RepairRepo)
|
||||||
repo.POST("/move", session.MustRepoAdmin(), server.MoveRepo)
|
repo.POST("/move", session.MustRepoAdmin(), api.MoveRepo)
|
||||||
|
|
||||||
repo.POST("/builds/:number", session.MustPush, server.PostBuild)
|
repo.POST("/builds/:number", session.MustPush, api.PostBuild)
|
||||||
repo.DELETE("/builds/:number", session.MustPush, server.DeleteBuild)
|
repo.DELETE("/builds/:number", session.MustPush, api.DeleteBuild)
|
||||||
repo.POST("/builds/:number/approve", session.MustPush, server.PostApproval)
|
repo.POST("/builds/:number/approve", session.MustPush, api.PostApproval)
|
||||||
repo.POST("/builds/:number/decline", session.MustPush, server.PostDecline)
|
repo.POST("/builds/:number/decline", session.MustPush, api.PostDecline)
|
||||||
repo.DELETE("/builds/:number/:job", session.MustPush, server.DeleteBuild)
|
repo.DELETE("/builds/:number/:job", session.MustPush, api.DeleteBuild)
|
||||||
repo.DELETE("/logs/:number", session.MustPush, server.DeleteBuildLogs)
|
repo.DELETE("/logs/:number", session.MustPush, api.DeleteBuildLogs)
|
||||||
}
|
}
|
||||||
|
|
||||||
badges := e.Group("/api/badges/:owner/:name")
|
badges := e.Group("/api/badges/:owner/:name")
|
||||||
{
|
{
|
||||||
badges.GET("/status.svg", server.GetBadge)
|
badges.GET("/status.svg", api.GetBadge)
|
||||||
badges.GET("/cc.xml", server.GetCC)
|
badges.GET("/cc.xml", api.GetCC)
|
||||||
}
|
}
|
||||||
|
|
||||||
e.POST("/hook", server.PostHook)
|
e.POST("/hook", api.PostHook)
|
||||||
e.POST("/api/hook", server.PostHook)
|
e.POST("/api/hook", api.PostHook)
|
||||||
|
|
||||||
sse := e.Group("/stream")
|
sse := e.Group("/stream")
|
||||||
{
|
{
|
||||||
sse.GET("/events", server.EventStreamSSE)
|
sse.GET("/events", api.EventStreamSSE)
|
||||||
sse.GET("/logs/:owner/:name/:build/:number",
|
sse.GET("/logs/:owner/:name/:build/:number",
|
||||||
session.SetRepo(),
|
session.SetRepo(),
|
||||||
session.SetPerm(),
|
session.SetPerm(),
|
||||||
session.MustPull,
|
session.MustPull,
|
||||||
server.LogStreamSSE,
|
api.LogStreamSSE,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,33 +144,33 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
|
||||||
{
|
{
|
||||||
queue.GET("/info",
|
queue.GET("/info",
|
||||||
session.MustAdmin(),
|
session.MustAdmin(),
|
||||||
server.GetQueueInfo,
|
api.GetQueueInfo,
|
||||||
)
|
)
|
||||||
queue.GET("/pause",
|
queue.GET("/pause",
|
||||||
session.MustAdmin(),
|
session.MustAdmin(),
|
||||||
server.PauseQueue,
|
api.PauseQueue,
|
||||||
)
|
)
|
||||||
queue.GET("/resume",
|
queue.GET("/resume",
|
||||||
session.MustAdmin(),
|
session.MustAdmin(),
|
||||||
server.ResumeQueue,
|
api.ResumeQueue,
|
||||||
)
|
)
|
||||||
queue.GET("/norunningbuilds",
|
queue.GET("/norunningbuilds",
|
||||||
session.MustAdmin(),
|
session.MustAdmin(),
|
||||||
server.BlockTilQueueHasRunningItem,
|
api.BlockTilQueueHasRunningItem,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
auth := e.Group("/authorize")
|
auth := e.Group("/authorize")
|
||||||
{
|
{
|
||||||
auth.GET("", server.HandleAuth)
|
auth.GET("", api.HandleAuth)
|
||||||
auth.POST("", server.HandleAuth)
|
auth.POST("", api.HandleAuth)
|
||||||
auth.POST("/token", server.GetLoginToken)
|
auth.POST("/token", api.GetLoginToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
builds := e.Group("/api/builds")
|
builds := e.Group("/api/builds")
|
||||||
{
|
{
|
||||||
builds.Use(session.MustAdmin())
|
builds.Use(session.MustAdmin())
|
||||||
builds.GET("", server.GetBuildQueue)
|
builds.GET("", api.GetBuildQueue)
|
||||||
}
|
}
|
||||||
|
|
||||||
debugger := e.Group("/api/debug")
|
debugger := e.Group("/api/debug")
|
||||||
|
@ -193,8 +193,8 @@ func Load(mux *httptreemux.ContextMux, middleware ...gin.HandlerFunc) http.Handl
|
||||||
monitor.GET("", metrics.PromHandler())
|
monitor.GET("", metrics.PromHandler())
|
||||||
}
|
}
|
||||||
|
|
||||||
e.GET("/version", server.Version)
|
e.GET("/version", api.Version)
|
||||||
e.GET("/healthz", server.Health)
|
e.GET("/healthz", api.Health)
|
||||||
|
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
//
|
//
|
||||||
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -24,6 +24,7 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
"github.com/woodpecker-ci/woodpecker/store"
|
"github.com/woodpecker-ci/woodpecker/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ func GetCC(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, builds[0].Number)
|
url := fmt.Sprintf("%s/%s/%d", server.Config.Server.Host, repo.FullName, builds[0].Number)
|
||||||
cc := model.NewCC(repo, builds[0], url)
|
cc := model.NewCC(repo, builds[0], url)
|
||||||
c.XML(200, cc)
|
c.XML(200, cc)
|
||||||
}
|
}
|
|
@ -15,7 +15,7 @@
|
||||||
//
|
//
|
||||||
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -35,6 +35,8 @@ import (
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetBuilds(c *gin.Context) {
|
func GetBuilds(c *gin.Context) {
|
||||||
|
@ -98,7 +100,7 @@ func GetBuildLogs(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
|
|
||||||
// parse the build number and job sequence number from
|
// parse the build number and job sequence number from
|
||||||
// the repquest parameter.
|
// the request parameter.
|
||||||
num, _ := strconv.Atoi(c.Params.ByName("number"))
|
num, _ := strconv.Atoi(c.Params.ByName("number"))
|
||||||
ppid, _ := strconv.Atoi(c.Params.ByName("pid"))
|
ppid, _ := strconv.Atoi(c.Params.ByName("pid"))
|
||||||
name := c.Params.ByName("proc")
|
name := c.Params.ByName("proc")
|
||||||
|
@ -131,7 +133,7 @@ func GetProcLogs(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
|
|
||||||
// parse the build number and job sequence number from
|
// parse the build number and job sequence number from
|
||||||
// the repquest parameter.
|
// the request parameter.
|
||||||
num, _ := strconv.Atoi(c.Params.ByName("number"))
|
num, _ := strconv.Atoi(c.Params.ByName("number"))
|
||||||
pid, _ := strconv.Atoi(c.Params.ByName("pid"))
|
pid, _ := strconv.Atoi(c.Params.ByName("pid"))
|
||||||
|
|
||||||
|
@ -195,27 +197,27 @@ func DeleteBuild(c *gin.Context) {
|
||||||
procToEvict = append(procToEvict, fmt.Sprint(proc.ID))
|
procToEvict = append(procToEvict, fmt.Sprint(proc.ID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Config.Services.Queue.EvictAtOnce(context.Background(), procToEvict)
|
server.Config.Services.Queue.EvictAtOnce(context.Background(), procToEvict)
|
||||||
Config.Services.Queue.ErrorAtOnce(context.Background(), procToEvict, queue.ErrCancel)
|
server.Config.Services.Queue.ErrorAtOnce(context.Background(), procToEvict, queue.ErrCancel)
|
||||||
Config.Services.Queue.ErrorAtOnce(context.Background(), procToCancel, queue.ErrCancel)
|
server.Config.Services.Queue.ErrorAtOnce(context.Background(), procToCancel, queue.ErrCancel)
|
||||||
|
|
||||||
// Then update the DB status for pending builds
|
// Then update the DB status for pending builds
|
||||||
// Running ones will be set when the agents stop on the cancel signal
|
// Running ones will be set when the agents stop on the cancel signal
|
||||||
for _, proc := range procs {
|
for _, proc := range procs {
|
||||||
if proc.State == model.StatusPending {
|
if proc.State == model.StatusPending {
|
||||||
if proc.PPID != 0 {
|
if proc.PPID != 0 {
|
||||||
if _, err = UpdateProcToStatusSkipped(store.FromContext(c), *proc, 0); err != nil {
|
if _, err = shared.UpdateProcToStatusSkipped(store.FromContext(c), *proc, 0); err != nil {
|
||||||
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
|
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, err = UpdateProcToStatusKilled(store.FromContext(c), *proc); err != nil {
|
if _, err = shared.UpdateProcToStatusKilled(store.FromContext(c), *proc); err != nil {
|
||||||
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
|
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
killedBuild, err := UpdateToStatusKilled(store.FromContext(c), *build)
|
killedBuild, err := shared.UpdateToStatusKilled(store.FromContext(c), *build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(500, err)
|
c.AbortWithError(500, err)
|
||||||
return
|
return
|
||||||
|
@ -257,7 +259,7 @@ func PostApproval(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the build file from the database
|
// fetch the build file from the database
|
||||||
configs, err := Config.Storage.Config.ConfigsForBuild(build.ID)
|
configs, err := server.Config.Storage.Config.ConfigsForBuild(build.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("failure to get build config for %s. %s", repo.FullName, err)
|
logrus.Errorf("failure to get build config for %s. %s", repo.FullName, err)
|
||||||
c.AbortWithError(404, err)
|
c.AbortWithError(404, err)
|
||||||
|
@ -270,7 +272,7 @@ func PostApproval(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if build, err = UpdateToStatusPending(store.FromContext(c), *build, user.Login); err != nil {
|
if build, err = shared.UpdateToStatusPending(store.FromContext(c), *build, user.Login); err != nil {
|
||||||
c.String(500, "error updating build. %s", err)
|
c.String(500, "error updating build. %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -280,17 +282,17 @@ func PostApproval(c *gin.Context) {
|
||||||
// get the previous build so that we can send
|
// get the previous build so that we can send
|
||||||
// on status change notifications
|
// on status change notifications
|
||||||
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
||||||
secs, err := Config.Services.Secrets.SecretListBuild(repo, build)
|
secs, err := server.Config.Services.Secrets.SecretListBuild(repo, build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
regs, err := Config.Services.Registries.RegistryList(repo)
|
regs, err := server.Config.Services.Registries.RegistryList(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
envs := map[string]string{}
|
envs := map[string]string{}
|
||||||
if Config.Services.Environ != nil {
|
if server.Config.Services.Environ != nil {
|
||||||
globals, _ := Config.Services.Environ.EnvironList(repo)
|
globals, _ := server.Config.Services.Environ.EnvironList(repo)
|
||||||
for _, global := range globals {
|
for _, global := range globals {
|
||||||
envs[global.Name] = global.Value
|
envs[global.Name] = global.Value
|
||||||
}
|
}
|
||||||
|
@ -301,25 +303,25 @@ func PostApproval(c *gin.Context) {
|
||||||
yamls = append(yamls, &remote.FileMeta{Data: []byte(y.Data), Name: y.Name})
|
yamls = append(yamls, &remote.FileMeta{Data: []byte(y.Data), Name: y.Name})
|
||||||
}
|
}
|
||||||
|
|
||||||
b := procBuilder{
|
b := shared.ProcBuilder{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Curr: build,
|
Curr: build,
|
||||||
Last: last,
|
Last: last,
|
||||||
Netrc: netrc,
|
Netrc: netrc,
|
||||||
Secs: secs,
|
Secs: secs,
|
||||||
Regs: regs,
|
Regs: regs,
|
||||||
Link: Config.Server.Host,
|
Link: server.Config.Server.Host,
|
||||||
Yamls: yamls,
|
Yamls: yamls,
|
||||||
Envs: envs,
|
Envs: envs,
|
||||||
}
|
}
|
||||||
buildItems, err := b.Build()
|
buildItems, err := b.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, err = UpdateToStatusError(store.FromContext(c), *build, err); err != nil {
|
if _, err = shared.UpdateToStatusError(store.FromContext(c), *build, err); err != nil {
|
||||||
logrus.Errorf("Error setting error status of build for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Errorf("Error setting error status of build for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
build = setBuildStepsOnBuild(b.Curr, buildItems)
|
build = shared.SetBuildStepsOnBuild(b.Curr, buildItems)
|
||||||
|
|
||||||
err = store.FromContext(c).ProcCreate(build.Procs)
|
err = store.FromContext(c).ProcCreate(build.Procs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -328,7 +330,7 @@ func PostApproval(c *gin.Context) {
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, item := range buildItems {
|
for _, item := range buildItems {
|
||||||
uri := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, build.Number)
|
uri := fmt.Sprintf("%s/%s/%d", server.Config.Server.Host, repo.FullName, build.Number)
|
||||||
if len(buildItems) > 1 {
|
if len(buildItems) > 1 {
|
||||||
err = remote_.Status(user, repo, build, uri, item.Proc)
|
err = remote_.Status(user, repo, build, uri, item.Proc)
|
||||||
} else {
|
} else {
|
||||||
|
@ -364,12 +366,12 @@ func PostDecline(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = UpdateToStatusDeclined(store.FromContext(c), *build, user.Login); err != nil {
|
if _, err = shared.UpdateToStatusDeclined(store.FromContext(c), *build, user.Login); err != nil {
|
||||||
c.String(500, "error updating build. %s", err)
|
c.String(500, "error updating build. %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, build.Number)
|
uri := fmt.Sprintf("%s/%s/%d", server.Config.Server.Host, repo.FullName, build.Number)
|
||||||
err = remote_.Status(user, repo, build, uri, nil)
|
err = remote_.Status(user, repo, build, uri, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err)
|
logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err)
|
||||||
|
@ -430,7 +432,7 @@ func PostBuild(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the pipeline config from database
|
// fetch the pipeline config from database
|
||||||
configs, err := Config.Storage.Config.ConfigsForBuild(build.ID)
|
configs, err := server.Config.Storage.Config.ConfigsForBuild(build.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("failure to get build config for %s. %s", repo.FullName, err)
|
logrus.Errorf("failure to get build config for %s. %s", repo.FullName, err)
|
||||||
c.AbortWithError(404, err)
|
c.AbortWithError(404, err)
|
||||||
|
@ -490,16 +492,16 @@ func PostBuild(c *gin.Context) {
|
||||||
// get the previous build so that we can send
|
// get the previous build so that we can send
|
||||||
// on status change notifications
|
// on status change notifications
|
||||||
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
||||||
secs, err := Config.Services.Secrets.SecretListBuild(repo, build)
|
secs, err := server.Config.Services.Secrets.SecretListBuild(repo, build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
regs, err := Config.Services.Registries.RegistryList(repo)
|
regs, err := server.Config.Services.Registries.RegistryList(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
if Config.Services.Environ != nil {
|
if server.Config.Services.Environ != nil {
|
||||||
globals, _ := Config.Services.Environ.EnvironList(repo)
|
globals, _ := server.Config.Services.Environ.EnvironList(repo)
|
||||||
for _, global := range globals {
|
for _, global := range globals {
|
||||||
buildParams[global.Name] = global.Value
|
buildParams[global.Name] = global.Value
|
||||||
}
|
}
|
||||||
|
@ -510,14 +512,14 @@ func PostBuild(c *gin.Context) {
|
||||||
yamls = append(yamls, &remote.FileMeta{Data: []byte(y.Data), Name: y.Name})
|
yamls = append(yamls, &remote.FileMeta{Data: []byte(y.Data), Name: y.Name})
|
||||||
}
|
}
|
||||||
|
|
||||||
b := procBuilder{
|
b := shared.ProcBuilder{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Curr: build,
|
Curr: build,
|
||||||
Last: last,
|
Last: last,
|
||||||
Netrc: netrc,
|
Netrc: netrc,
|
||||||
Secs: secs,
|
Secs: secs,
|
||||||
Regs: regs,
|
Regs: regs,
|
||||||
Link: Config.Server.Host,
|
Link: server.Config.Server.Host,
|
||||||
Yamls: yamls,
|
Yamls: yamls,
|
||||||
Envs: buildParams,
|
Envs: buildParams,
|
||||||
}
|
}
|
||||||
|
@ -530,7 +532,7 @@ func PostBuild(c *gin.Context) {
|
||||||
c.JSON(500, build)
|
c.JSON(500, build)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
build = setBuildStepsOnBuild(b.Curr, buildItems)
|
build = shared.SetBuildStepsOnBuild(b.Curr, buildItems)
|
||||||
|
|
||||||
err = store.FromContext(c).ProcCreate(build.Procs)
|
err = store.FromContext(c).ProcCreate(build.Procs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -593,7 +595,7 @@ func persistBuildConfigs(configs []*model.Config, buildID int64) error {
|
||||||
ConfigID: conf.ID,
|
ConfigID: conf.ID,
|
||||||
BuildID: buildID,
|
BuildID: buildID,
|
||||||
}
|
}
|
||||||
err := Config.Storage.Config.BuildConfigCreate(buildConfig)
|
err := server.Config.Storage.Config.BuildConfigCreate(buildConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
|
@ -15,7 +15,7 @@
|
||||||
//
|
//
|
||||||
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -40,6 +40,8 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/cncd/pipeline/pipeline/rpc"
|
"github.com/woodpecker-ci/woodpecker/cncd/pipeline/pipeline/rpc"
|
||||||
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
|
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
|
||||||
"github.com/woodpecker-ci/woodpecker/cncd/queue"
|
"github.com/woodpecker-ci/woodpecker/cncd/queue"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`)
|
var skipRe = regexp.MustCompile(`\[(?i:ci *skip|skip *ci)\]`)
|
||||||
|
@ -50,23 +52,23 @@ func init() {
|
||||||
|
|
||||||
func GetQueueInfo(c *gin.Context) {
|
func GetQueueInfo(c *gin.Context) {
|
||||||
c.IndentedJSON(200,
|
c.IndentedJSON(200,
|
||||||
Config.Services.Queue.Info(c),
|
server.Config.Services.Queue.Info(c),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PauseQueue(c *gin.Context) {
|
func PauseQueue(c *gin.Context) {
|
||||||
Config.Services.Queue.Pause()
|
server.Config.Services.Queue.Pause()
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResumeQueue(c *gin.Context) {
|
func ResumeQueue(c *gin.Context) {
|
||||||
Config.Services.Queue.Resume()
|
server.Config.Services.Queue.Resume()
|
||||||
c.Status(http.StatusOK)
|
c.Status(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BlockTilQueueHasRunningItem(c *gin.Context) {
|
func BlockTilQueueHasRunningItem(c *gin.Context) {
|
||||||
for {
|
for {
|
||||||
info := Config.Services.Queue.Info(c)
|
info := server.Config.Services.Queue.Info(c)
|
||||||
if info.Stats.Running == 0 {
|
if info.Stats.Running == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -159,7 +161,7 @@ func PostHook(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch the build file from the remote
|
// fetch the build file from the remote
|
||||||
configFetcher := &configFetcher{remote_: remote_, user: user, repo: repo, build: build}
|
configFetcher := shared.NewConfigFetcher(remote_, user, repo, build)
|
||||||
remoteYamlConfigs, err := configFetcher.Fetch()
|
remoteYamlConfigs, err := configFetcher.Fetch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error: %s: cannot find %s in %s: %s", repo.FullName, repo.Config, build.Ref, err)
|
logrus.Errorf("error: %s: cannot find %s in %s: %s", repo.FullName, repo.Config, build.Ref, err)
|
||||||
|
@ -221,19 +223,19 @@ func PostHook(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
envs := map[string]string{}
|
envs := map[string]string{}
|
||||||
if Config.Services.Environ != nil {
|
if server.Config.Services.Environ != nil {
|
||||||
globals, _ := Config.Services.Environ.EnvironList(repo)
|
globals, _ := server.Config.Services.Environ.EnvironList(repo)
|
||||||
for _, global := range globals {
|
for _, global := range globals {
|
||||||
envs[global.Name] = global.Value
|
envs[global.Name] = global.Value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
secs, err := Config.Services.Secrets.SecretListBuild(repo, build)
|
secs, err := server.Config.Services.Secrets.SecretListBuild(repo, build)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting secrets for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
regs, err := Config.Services.Registries.RegistryList(repo)
|
regs, err := server.Config.Services.Registries.RegistryList(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Debugf("Error getting registry credentials for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
|
@ -241,7 +243,7 @@ func PostHook(c *gin.Context) {
|
||||||
// get the previous build so that we can send status change notifications
|
// get the previous build so that we can send status change notifications
|
||||||
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
last, _ := store.GetBuildLastBefore(c, repo, build.Branch, build.ID)
|
||||||
|
|
||||||
b := procBuilder{
|
b := shared.ProcBuilder{
|
||||||
Repo: repo,
|
Repo: repo,
|
||||||
Curr: build,
|
Curr: build,
|
||||||
Last: last,
|
Last: last,
|
||||||
|
@ -249,17 +251,17 @@ func PostHook(c *gin.Context) {
|
||||||
Secs: secs,
|
Secs: secs,
|
||||||
Regs: regs,
|
Regs: regs,
|
||||||
Envs: envs,
|
Envs: envs,
|
||||||
Link: Config.Server.Host,
|
Link: server.Config.Server.Host,
|
||||||
Yamls: remoteYamlConfigs,
|
Yamls: remoteYamlConfigs,
|
||||||
}
|
}
|
||||||
buildItems, err := b.Build()
|
buildItems, err := b.Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, err = UpdateToStatusError(store.FromContext(c), *build, err); err != nil {
|
if _, err = shared.UpdateToStatusError(store.FromContext(c), *build, err); err != nil {
|
||||||
logrus.Errorf("Error setting error status of build for %s#%d. %s", repo.FullName, build.Number, err)
|
logrus.Errorf("Error setting error status of build for %s#%d. %s", repo.FullName, build.Number, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
build = setBuildStepsOnBuild(b.Curr, buildItems)
|
build = shared.SetBuildStepsOnBuild(b.Curr, buildItems)
|
||||||
|
|
||||||
err = store.FromContext(c).ProcCreate(build.Procs)
|
err = store.FromContext(c).ProcCreate(build.Procs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -268,7 +270,7 @@ func PostHook(c *gin.Context) {
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, item := range buildItems {
|
for _, item := range buildItems {
|
||||||
uri := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, build.Number)
|
uri := fmt.Sprintf("%s/%s/%d", server.Config.Server.Host, repo.FullName, build.Number)
|
||||||
if len(buildItems) > 1 {
|
if len(buildItems) > 1 {
|
||||||
err = remote_.Status(user, repo, build, uri, item.Proc)
|
err = remote_.Status(user, repo, build, uri, item.Proc)
|
||||||
} else {
|
} else {
|
||||||
|
@ -300,7 +302,7 @@ func branchFiltered(build *model.Build, remoteYamlConfigs []*remote.FileMeta) (b
|
||||||
}
|
}
|
||||||
|
|
||||||
func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
|
func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
|
||||||
b := procBuilder{
|
b := shared.ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: build,
|
Curr: build,
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -324,18 +326,18 @@ func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
|
||||||
|
|
||||||
func findOrPersistPipelineConfig(repo *model.Repo, build *model.Build, remoteYamlConfig *remote.FileMeta) (*model.Config, error) {
|
func findOrPersistPipelineConfig(repo *model.Repo, build *model.Build, remoteYamlConfig *remote.FileMeta) (*model.Config, error) {
|
||||||
sha := shasum(remoteYamlConfig.Data)
|
sha := shasum(remoteYamlConfig.Data)
|
||||||
conf, err := Config.Storage.Config.ConfigFindIdentical(build.RepoID, sha)
|
conf, err := server.Config.Storage.Config.ConfigFindIdentical(build.RepoID, sha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conf = &model.Config{
|
conf = &model.Config{
|
||||||
RepoID: build.RepoID,
|
RepoID: build.RepoID,
|
||||||
Data: string(remoteYamlConfig.Data),
|
Data: string(remoteYamlConfig.Data),
|
||||||
Hash: sha,
|
Hash: sha,
|
||||||
Name: sanitizePath(remoteYamlConfig.Name),
|
Name: shared.SanitizePath(remoteYamlConfig.Name),
|
||||||
}
|
}
|
||||||
err = Config.Storage.Config.ConfigCreate(conf)
|
err = server.Config.Storage.Config.ConfigCreate(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// retry in case we receive two hooks at the same time
|
// retry in case we receive two hooks at the same time
|
||||||
conf, err = Config.Storage.Config.ConfigFindIdentical(build.RepoID, sha)
|
conf, err = server.Config.Storage.Config.ConfigFindIdentical(build.RepoID, sha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -346,7 +348,7 @@ func findOrPersistPipelineConfig(repo *model.Repo, build *model.Build, remoteYam
|
||||||
ConfigID: conf.ID,
|
ConfigID: conf.ID,
|
||||||
BuildID: build.ID,
|
BuildID: build.ID,
|
||||||
}
|
}
|
||||||
err = Config.Storage.Config.BuildConfigCreate(buildConfig)
|
err = server.Config.Storage.Config.BuildConfigCreate(buildConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -369,10 +371,10 @@ func publishToTopic(c *gin.Context, build *model.Build, repo *model.Repo, event
|
||||||
Repo: *repo,
|
Repo: *repo,
|
||||||
Build: buildCopy,
|
Build: buildCopy,
|
||||||
})
|
})
|
||||||
Config.Services.Pubsub.Publish(c, "topic/events", message)
|
server.Config.Services.Pubsub.Publish(c, "topic/events", message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func queueBuild(build *model.Build, repo *model.Repo, buildItems []*buildItem) {
|
func queueBuild(build *model.Build, repo *model.Repo, buildItems []*shared.BuildItem) {
|
||||||
var tasks []*queue.Task
|
var tasks []*queue.Task
|
||||||
for _, item := range buildItems {
|
for _, item := range buildItems {
|
||||||
if item.Proc.State == model.StatusSkipped {
|
if item.Proc.State == model.StatusSkipped {
|
||||||
|
@ -396,13 +398,13 @@ func queueBuild(build *model.Build, repo *model.Repo, buildItems []*buildItem) {
|
||||||
Timeout: repo.Timeout,
|
Timeout: repo.Timeout,
|
||||||
})
|
})
|
||||||
|
|
||||||
Config.Services.Logs.Open(context.Background(), task.ID)
|
server.Config.Services.Logs.Open(context.Background(), task.ID)
|
||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
}
|
}
|
||||||
Config.Services.Queue.PushAtOnce(context.Background(), tasks)
|
server.Config.Services.Queue.PushAtOnce(context.Background(), tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
func taskIds(dependsOn []string, buildItems []*buildItem) []string {
|
func taskIds(dependsOn []string, buildItems []*shared.BuildItem) []string {
|
||||||
taskIds := []string{}
|
taskIds := []string{}
|
||||||
for _, dep := range dependsOn {
|
for _, dep := range dependsOn {
|
||||||
for _, buildItem := range buildItems {
|
for _, buildItem := range buildItems {
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote"
|
"github.com/woodpecker-ci/woodpecker/remote"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/httputil"
|
"github.com/woodpecker-ci/woodpecker/shared/httputil"
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/token"
|
"github.com/woodpecker-ci/woodpecker/shared/token"
|
||||||
"github.com/woodpecker-ci/woodpecker/store"
|
"github.com/woodpecker-ci/woodpecker/store"
|
||||||
|
@ -131,7 +132,7 @@ func HandleAuth(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exp := time.Now().Add(Config.Server.SessionExpires).Unix()
|
exp := time.Now().Add(server.Config.Server.SessionExpires).Unix()
|
||||||
token := token.New(token.SessToken, u.Login)
|
token := token.New(token.SessToken, u.Login)
|
||||||
tokenstr, err := token.SignExpires(u.Hash, exp)
|
tokenstr, err := token.SignExpires(u.Hash, exp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -176,7 +177,7 @@ func GetLoginToken(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
exp := time.Now().Add(Config.Server.SessionExpires).Unix()
|
exp := time.Now().Add(server.Config.Server.SessionExpires).Unix()
|
||||||
token := token.New(token.SessToken, user.Login)
|
token := token.New(token.SessToken, user.Login)
|
||||||
tokenstr, err := token.SignExpires(user.Hash, exp)
|
tokenstr, err := token.SignExpires(user.Hash, exp)
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -12,13 +12,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -30,7 +31,7 @@ func GetRegistry(c *gin.Context) {
|
||||||
repo = session.Repo(c)
|
repo = session.Repo(c)
|
||||||
name = c.Param("registry")
|
name = c.Param("registry")
|
||||||
)
|
)
|
||||||
registry, err := Config.Services.Registries.RegistryFind(repo, name)
|
registry, err := server.Config.Services.Registries.RegistryFind(repo, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(404, "Error getting registry %q. %s", name, err)
|
c.String(404, "Error getting registry %q. %s", name, err)
|
||||||
return
|
return
|
||||||
|
@ -59,7 +60,7 @@ func PostRegistry(c *gin.Context) {
|
||||||
c.String(400, "Error inserting registry. %s", err)
|
c.String(400, "Error inserting registry. %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := Config.Services.Registries.RegistryCreate(repo, registry); err != nil {
|
if err := server.Config.Services.Registries.RegistryCreate(repo, registry); err != nil {
|
||||||
c.String(500, "Error inserting registry %q. %s", in.Address, err)
|
c.String(500, "Error inserting registry %q. %s", in.Address, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -80,7 +81,7 @@ func PatchRegistry(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
registry, err := Config.Services.Registries.RegistryFind(repo, name)
|
registry, err := server.Config.Services.Registries.RegistryFind(repo, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(404, "Error getting registry %q. %s", name, err)
|
c.String(404, "Error getting registry %q. %s", name, err)
|
||||||
return
|
return
|
||||||
|
@ -102,7 +103,7 @@ func PatchRegistry(c *gin.Context) {
|
||||||
c.String(400, "Error updating registry. %s", err)
|
c.String(400, "Error updating registry. %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := Config.Services.Registries.RegistryUpdate(repo, registry); err != nil {
|
if err := server.Config.Services.Registries.RegistryUpdate(repo, registry); err != nil {
|
||||||
c.String(500, "Error updating registry %q. %s", in.Address, err)
|
c.String(500, "Error updating registry %q. %s", in.Address, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -113,7 +114,7 @@ func PatchRegistry(c *gin.Context) {
|
||||||
// to the response in json format.
|
// to the response in json format.
|
||||||
func GetRegistryList(c *gin.Context) {
|
func GetRegistryList(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
list, err := Config.Services.Registries.RegistryList(repo)
|
list, err := server.Config.Services.Registries.RegistryList(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(500, "Error getting registry list. %s", err)
|
c.String(500, "Error getting registry list. %s", err)
|
||||||
return
|
return
|
||||||
|
@ -132,7 +133,7 @@ func DeleteRegistry(c *gin.Context) {
|
||||||
repo = session.Repo(c)
|
repo = session.Repo(c)
|
||||||
name = c.Param("registry")
|
name = c.Param("registry")
|
||||||
)
|
)
|
||||||
if err := Config.Services.Registries.RegistryDelete(repo, name); err != nil {
|
if err := server.Config.Services.Registries.RegistryDelete(repo, name); err != nil {
|
||||||
c.String(500, "Error deleting registry %q. %s", name, err)
|
c.String(500, "Error deleting registry %q. %s", name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote"
|
"github.com/woodpecker-ci/woodpecker/remote"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/token"
|
"github.com/woodpecker-ci/woodpecker/shared/token"
|
||||||
"github.com/woodpecker-ci/woodpecker/store"
|
"github.com/woodpecker-ci/woodpecker/store"
|
||||||
)
|
)
|
||||||
|
@ -70,7 +71,7 @@ func PostRepo(c *gin.Context) {
|
||||||
|
|
||||||
link := fmt.Sprintf(
|
link := fmt.Sprintf(
|
||||||
"%s/hook?access_token=%s",
|
"%s/hook?access_token=%s",
|
||||||
Config.Server.Host,
|
server.Config.Server.Host,
|
||||||
sig,
|
sig,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -186,7 +187,7 @@ func DeleteRepo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
remote.Deactivate(user, repo, Config.Server.Host)
|
remote.Deactivate(user, repo, server.Config.Server.Host)
|
||||||
c.JSON(200, repo)
|
c.JSON(200, repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +205,7 @@ func RepairRepo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// reconstruct the link
|
// reconstruct the link
|
||||||
host := Config.Server.Host
|
host := server.Config.Server.Host
|
||||||
link := fmt.Sprintf(
|
link := fmt.Sprintf(
|
||||||
"%s/hook?access_token=%s",
|
"%s/hook?access_token=%s",
|
||||||
host,
|
host,
|
||||||
|
@ -290,7 +291,7 @@ func MoveRepo(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// reconstruct the link
|
// reconstruct the link
|
||||||
host := Config.Server.Host
|
host := server.Config.Server.Host
|
||||||
link := fmt.Sprintf(
|
link := fmt.Sprintf(
|
||||||
"%s/hook?access_token=%s",
|
"%s/hook?access_token=%s",
|
||||||
host,
|
host,
|
|
@ -12,13 +12,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
@ -30,7 +31,7 @@ func GetSecret(c *gin.Context) {
|
||||||
repo = session.Repo(c)
|
repo = session.Repo(c)
|
||||||
name = c.Param("secret")
|
name = c.Param("secret")
|
||||||
)
|
)
|
||||||
secret, err := Config.Services.Secrets.SecretFind(repo, name)
|
secret, err := server.Config.Services.Secrets.SecretFind(repo, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(404, "Error getting secret %q. %s", name, err)
|
c.String(404, "Error getting secret %q. %s", name, err)
|
||||||
return
|
return
|
||||||
|
@ -58,7 +59,7 @@ func PostSecret(c *gin.Context) {
|
||||||
c.String(400, "Error inserting secret. %s", err)
|
c.String(400, "Error inserting secret. %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := Config.Services.Secrets.SecretCreate(repo, secret); err != nil {
|
if err := server.Config.Services.Secrets.SecretCreate(repo, secret); err != nil {
|
||||||
c.String(500, "Error inserting secret %q. %s", in.Name, err)
|
c.String(500, "Error inserting secret %q. %s", in.Name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -79,7 +80,7 @@ func PatchSecret(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
secret, err := Config.Services.Secrets.SecretFind(repo, name)
|
secret, err := server.Config.Services.Secrets.SecretFind(repo, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(404, "Error getting secret %q. %s", name, err)
|
c.String(404, "Error getting secret %q. %s", name, err)
|
||||||
return
|
return
|
||||||
|
@ -98,7 +99,7 @@ func PatchSecret(c *gin.Context) {
|
||||||
c.String(400, "Error updating secret. %s", err)
|
c.String(400, "Error updating secret. %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := Config.Services.Secrets.SecretUpdate(repo, secret); err != nil {
|
if err := server.Config.Services.Secrets.SecretUpdate(repo, secret); err != nil {
|
||||||
c.String(500, "Error updating secret %q. %s", in.Name, err)
|
c.String(500, "Error updating secret %q. %s", in.Name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -109,7 +110,7 @@ func PatchSecret(c *gin.Context) {
|
||||||
// to the response in json format.
|
// to the response in json format.
|
||||||
func GetSecretList(c *gin.Context) {
|
func GetSecretList(c *gin.Context) {
|
||||||
repo := session.Repo(c)
|
repo := session.Repo(c)
|
||||||
list, err := Config.Services.Secrets.SecretList(repo)
|
list, err := server.Config.Services.Secrets.SecretList(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(500, "Error getting secret list. %s", err)
|
c.String(500, "Error getting secret list. %s", err)
|
||||||
return
|
return
|
||||||
|
@ -128,7 +129,7 @@ func DeleteSecret(c *gin.Context) {
|
||||||
repo = session.Repo(c)
|
repo = session.Repo(c)
|
||||||
name = c.Param("secret")
|
name = c.Param("secret")
|
||||||
)
|
)
|
||||||
if err := Config.Services.Secrets.SecretDelete(repo, name); err != nil {
|
if err := server.Config.Services.Secrets.SecretDelete(repo, name); err != nil {
|
||||||
c.String(500, "Error deleting secret %q. %s", name, err)
|
c.String(500, "Error deleting secret %q. %s", name, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
|
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
"github.com/woodpecker-ci/woodpecker/store"
|
"github.com/woodpecker-ci/woodpecker/store"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -77,7 +78,7 @@ func EventStreamSSE(c *gin.Context) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
Config.Services.Pubsub.Subscribe(ctx, "topic/events", func(m pubsub.Message) {
|
server.Config.Services.Pubsub.Subscribe(ctx, "topic/events", func(m pubsub.Message) {
|
||||||
defer func() {
|
defer func() {
|
||||||
recover() // fix #2480
|
recover() // fix #2480
|
||||||
}()
|
}()
|
||||||
|
@ -189,7 +190,7 @@ func LogStreamSSE(c *gin.Context) {
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// TODO remove global variable
|
// TODO remove global variable
|
||||||
Config.Services.Logs.Tail(ctx, fmt.Sprint(proc.ID), func(entries ...*logging.Entry) {
|
server.Config.Services.Logs.Tail(ctx, fmt.Sprint(proc.ID), func(entries ...*logging.Entry) {
|
||||||
defer func() {
|
defer func() {
|
||||||
recover() // fix #2480
|
recover() // fix #2480
|
||||||
}()
|
}()
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote"
|
"github.com/woodpecker-ci/woodpecker/remote"
|
||||||
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
"github.com/woodpecker-ci/woodpecker/router/middleware/session"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/shared"
|
||||||
"github.com/woodpecker-ci/woodpecker/shared/token"
|
"github.com/woodpecker-ci/woodpecker/shared/token"
|
||||||
"github.com/woodpecker-ci/woodpecker/store"
|
"github.com/woodpecker-ci/woodpecker/store"
|
||||||
)
|
)
|
||||||
|
@ -47,11 +48,11 @@ func GetFeed(c *gin.Context) {
|
||||||
|
|
||||||
config := ToConfig(c)
|
config := ToConfig(c)
|
||||||
|
|
||||||
sync := syncer{
|
sync := shared.Syncer{
|
||||||
remote: remote.FromContext(c),
|
Remote: remote.FromContext(c),
|
||||||
store: store.FromContext(c),
|
Store: store.FromContext(c),
|
||||||
perms: store.FromContext(c),
|
Perms: store.FromContext(c),
|
||||||
match: NamespaceFilter(config.OwnersWhitelist),
|
Match: shared.NamespaceFilter(config.OwnersWhitelist),
|
||||||
}
|
}
|
||||||
if err := sync.Sync(user); err != nil {
|
if err := sync.Sync(user); err != nil {
|
||||||
logrus.Debugf("sync error: %s: %s", user.Login, err)
|
logrus.Debugf("sync error: %s: %s", user.Login, err)
|
||||||
|
@ -92,11 +93,11 @@ func GetRepos(c *gin.Context) {
|
||||||
|
|
||||||
config := ToConfig(c)
|
config := ToConfig(c)
|
||||||
|
|
||||||
sync := syncer{
|
sync := shared.Syncer{
|
||||||
remote: remote.FromContext(c),
|
Remote: remote.FromContext(c),
|
||||||
store: store.FromContext(c),
|
Store: store.FromContext(c),
|
||||||
perms: store.FromContext(c),
|
Perms: store.FromContext(c),
|
||||||
match: NamespaceFilter(config.OwnersWhitelist),
|
Match: shared.NamespaceFilter(config.OwnersWhitelist),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := sync.Sync(user); err != nil {
|
if err := sync.Sync(user); err != nil {
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base32"
|
"encoding/base32"
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
71
server/config.go
Normal file
71
server/config.go
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
// Copyright 2018 Drone.IO Inc.
|
||||||
|
// Copyright 2021 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
//
|
||||||
|
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
||||||
|
|
||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/woodpecker-ci/woodpecker/cncd/logging"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/cncd/queue"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Config = struct {
|
||||||
|
Services struct {
|
||||||
|
Pubsub pubsub.Publisher
|
||||||
|
Queue queue.Queue
|
||||||
|
Logs logging.Log
|
||||||
|
Senders model.SenderService
|
||||||
|
Secrets model.SecretService
|
||||||
|
Registries model.RegistryService
|
||||||
|
Environ model.EnvironService
|
||||||
|
}
|
||||||
|
Storage struct {
|
||||||
|
// Users model.UserStore
|
||||||
|
// Repos model.RepoStore
|
||||||
|
// Builds model.BuildStore
|
||||||
|
// Logs model.LogStore
|
||||||
|
Config model.ConfigStore
|
||||||
|
Files model.FileStore
|
||||||
|
Procs model.ProcStore
|
||||||
|
// Registries model.RegistryStore
|
||||||
|
// Secrets model.SecretStore
|
||||||
|
}
|
||||||
|
Server struct {
|
||||||
|
Key string
|
||||||
|
Cert string
|
||||||
|
Host string
|
||||||
|
Port string
|
||||||
|
Pass string
|
||||||
|
RepoConfig string
|
||||||
|
SessionExpires time.Duration
|
||||||
|
// Open bool
|
||||||
|
// Orgs map[string]struct{}
|
||||||
|
// Admins map[string]struct{}
|
||||||
|
}
|
||||||
|
Prometheus struct {
|
||||||
|
AuthToken string
|
||||||
|
}
|
||||||
|
Pipeline struct {
|
||||||
|
Limits model.ResourceLimit
|
||||||
|
Volumes []string
|
||||||
|
Networks []string
|
||||||
|
Privileged []string
|
||||||
|
}
|
||||||
|
}{}
|
|
@ -15,7 +15,7 @@
|
||||||
//
|
//
|
||||||
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
// This file has been modified by Informatyka Boguslawski sp. z o.o. sp.k.
|
||||||
|
|
||||||
package server
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -24,11 +24,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
oldcontext "golang.org/x/net/context"
|
oldcontext "golang.org/x/net/context"
|
||||||
|
|
||||||
"google.golang.org/grpc/metadata"
|
grpcMetadata "google.golang.org/grpc/metadata"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
|
@ -38,6 +37,8 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/cncd/pipeline/pipeline/rpc/proto"
|
"github.com/woodpecker-ci/woodpecker/cncd/pipeline/pipeline/rpc/proto"
|
||||||
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
|
"github.com/woodpecker-ci/woodpecker/cncd/pubsub"
|
||||||
"github.com/woodpecker-ci/woodpecker/cncd/queue"
|
"github.com/woodpecker-ci/woodpecker/cncd/queue"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server/shared"
|
||||||
|
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote"
|
"github.com/woodpecker-ci/woodpecker/remote"
|
||||||
|
@ -46,50 +47,6 @@ import (
|
||||||
"github.com/woodpecker-ci/expr"
|
"github.com/woodpecker-ci/expr"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Config = struct {
|
|
||||||
Services struct {
|
|
||||||
Pubsub pubsub.Publisher
|
|
||||||
Queue queue.Queue
|
|
||||||
Logs logging.Log
|
|
||||||
Senders model.SenderService
|
|
||||||
Secrets model.SecretService
|
|
||||||
Registries model.RegistryService
|
|
||||||
Environ model.EnvironService
|
|
||||||
}
|
|
||||||
Storage struct {
|
|
||||||
// Users model.UserStore
|
|
||||||
// Repos model.RepoStore
|
|
||||||
// Builds model.BuildStore
|
|
||||||
// Logs model.LogStore
|
|
||||||
Config model.ConfigStore
|
|
||||||
Files model.FileStore
|
|
||||||
Procs model.ProcStore
|
|
||||||
// Registries model.RegistryStore
|
|
||||||
// Secrets model.SecretStore
|
|
||||||
}
|
|
||||||
Server struct {
|
|
||||||
Key string
|
|
||||||
Cert string
|
|
||||||
Host string
|
|
||||||
Port string
|
|
||||||
Pass string
|
|
||||||
RepoConfig string
|
|
||||||
SessionExpires time.Duration
|
|
||||||
// Open bool
|
|
||||||
// Orgs map[string]struct{}
|
|
||||||
// Admins map[string]struct{}
|
|
||||||
}
|
|
||||||
Prometheus struct {
|
|
||||||
AuthToken string
|
|
||||||
}
|
|
||||||
Pipeline struct {
|
|
||||||
Limits model.ResourceLimit
|
|
||||||
Volumes []string
|
|
||||||
Networks []string
|
|
||||||
Privileged []string
|
|
||||||
}
|
|
||||||
}{}
|
|
||||||
|
|
||||||
type RPC struct {
|
type RPC struct {
|
||||||
remote remote.Remote
|
remote remote.Remote
|
||||||
queue queue.Queue
|
queue queue.Queue
|
||||||
|
@ -103,7 +60,7 @@ type RPC struct {
|
||||||
|
|
||||||
// Next implements the rpc.Next function
|
// Next implements the rpc.Next function
|
||||||
func (s *RPC) Next(c context.Context, filter rpc.Filter) (*rpc.Pipeline, error) {
|
func (s *RPC) Next(c context.Context, filter rpc.Filter) (*rpc.Pipeline, error) {
|
||||||
metadata, ok := metadata.FromIncomingContext(c)
|
metadata, ok := grpcMetadata.FromIncomingContext(c)
|
||||||
if ok {
|
if ok {
|
||||||
hostname, ok := metadata["hostname"]
|
hostname, ok := metadata["hostname"]
|
||||||
if ok && len(hostname) != 0 {
|
if ok && len(hostname) != 0 {
|
||||||
|
@ -168,7 +125,7 @@ func (s *RPC) Update(c context.Context, id string, state rpc.State) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata, ok := metadata.FromIncomingContext(c)
|
metadata, ok := grpcMetadata.FromIncomingContext(c)
|
||||||
if ok {
|
if ok {
|
||||||
hostname, ok := metadata["hostname"]
|
hostname, ok := metadata["hostname"]
|
||||||
if ok && len(hostname) != 0 {
|
if ok && len(hostname) != 0 {
|
||||||
|
@ -182,7 +139,7 @@ func (s *RPC) Update(c context.Context, id string, state rpc.State) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if proc, err = UpdateProcStatus(s.store, *proc, state, build.Started); err != nil {
|
if proc, err = shared.UpdateProcStatus(s.store, *proc, state, build.Started); err != nil {
|
||||||
log.Printf("error: rpc.update: cannot update proc: %s", err)
|
log.Printf("error: rpc.update: cannot update proc: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,7 +227,7 @@ func (s *RPC) Upload(c context.Context, id string, file *rpc.File) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Config.Storage.Files.FileCreate(
|
return server.Config.Storage.Files.FileCreate(
|
||||||
report,
|
report,
|
||||||
bytes.NewBuffer(file.Data),
|
bytes.NewBuffer(file.Data),
|
||||||
)
|
)
|
||||||
|
@ -288,7 +245,7 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error {
|
||||||
log.Printf("error: cannot find proc with id %d: %s", procID, err)
|
log.Printf("error: cannot find proc with id %d: %s", procID, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
metadata, ok := metadata.FromIncomingContext(c)
|
metadata, ok := grpcMetadata.FromIncomingContext(c)
|
||||||
if ok {
|
if ok {
|
||||||
hostname, ok := metadata["hostname"]
|
hostname, ok := metadata["hostname"]
|
||||||
if ok && len(hostname) != 0 {
|
if ok && len(hostname) != 0 {
|
||||||
|
@ -309,7 +266,7 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.Status == model.StatusPending {
|
if build.Status == model.StatusPending {
|
||||||
if build, err = UpdateToStatusRunning(s.store, *build, state.Started); err != nil {
|
if build, err = shared.UpdateToStatusRunning(s.store, *build, state.Started); err != nil {
|
||||||
log.Printf("error: init: cannot update build_id %d state: %s", build.ID, err)
|
log.Printf("error: init: cannot update build_id %d state: %s", build.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -329,7 +286,7 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error {
|
||||||
s.pubsub.Publish(c, "topic/events", message)
|
s.pubsub.Publish(c, "topic/events", message)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
_, err = UpdateProcToStatusStarted(s.store, *proc, state)
|
_, err = shared.UpdateProcToStatusStarted(s.store, *proc, state)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,7 +315,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if proc, err = UpdateProcStatusToDone(s.store, *proc, state); err != nil {
|
if proc, err = shared.UpdateProcStatusToDone(s.store, *proc, state); err != nil {
|
||||||
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
|
log.Printf("error: done: cannot update proc_id %d state: %s", proc.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,7 +333,7 @@ func (s *RPC) Done(c context.Context, id string, state rpc.State) error {
|
||||||
s.completeChildrenIfParentCompleted(procs, proc)
|
s.completeChildrenIfParentCompleted(procs, proc)
|
||||||
|
|
||||||
if !isThereRunningStage(procs) {
|
if !isThereRunningStage(procs) {
|
||||||
if build, err = UpdateStatusToDone(s.store, *build, buildStatus(procs), proc.Stopped); err != nil {
|
if build, err = shared.UpdateStatusToDone(s.store, *build, buildStatus(procs), proc.Stopped); err != nil {
|
||||||
log.Printf("error: done: cannot update build_id %d final state: %s", build.ID, err)
|
log.Printf("error: done: cannot update build_id %d final state: %s", build.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,7 +384,7 @@ func (s *RPC) Log(c context.Context, id string, line *rpc.Line) error {
|
||||||
func (s *RPC) completeChildrenIfParentCompleted(procs []*model.Proc, completedProc *model.Proc) {
|
func (s *RPC) completeChildrenIfParentCompleted(procs []*model.Proc, completedProc *model.Proc) {
|
||||||
for _, p := range procs {
|
for _, p := range procs {
|
||||||
if p.Running() && p.PPID == completedProc.PID {
|
if p.Running() && p.PPID == completedProc.PID {
|
||||||
if _, err := UpdateProcToStatusSkipped(s.store, *p, completedProc.Stopped); err != nil {
|
if _, err := shared.UpdateProcToStatusSkipped(s.store, *p, completedProc.Stopped); err != nil {
|
||||||
log.Printf("error: done: cannot update proc_id %d child state: %s", p.ID, err)
|
log.Printf("error: done: cannot update proc_id %d child state: %s", p.ID, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,7 +425,7 @@ func (s *RPC) updateRemoteStatus(repo *model.Repo, build *model.Build, proc *mod
|
||||||
s.store.UpdateUser(user)
|
s.store.UpdateUser(user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uri := fmt.Sprintf("%s/%s/%d", Config.Server.Host, repo.FullName, build.Number)
|
uri := fmt.Sprintf("%s/%s/%d", server.Config.Server.Host, repo.FullName, build.Number)
|
||||||
err = s.remote.Status(user, repo, build, uri, proc)
|
err = s.remote.Status(user, repo, build, uri, proc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err)
|
logrus.Errorf("error setting commit status for %s/%d: %v", repo.FullName, build.Number, err)
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
|
@ -1,4 +1,4 @@
|
||||||
package server
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
|
@ -1,4 +1,4 @@
|
||||||
package server_test
|
package shared_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote"
|
"github.com/woodpecker-ci/woodpecker/remote"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote/mocks"
|
"github.com/woodpecker-ci/woodpecker/remote/mocks"
|
||||||
"github.com/woodpecker-ci/woodpecker/server"
|
"github.com/woodpecker-ci/woodpecker/server/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFetch(t *testing.T) {
|
func TestFetch(t *testing.T) {
|
||||||
|
@ -179,7 +179,7 @@ func TestFetch(t *testing.T) {
|
||||||
r.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("File not found"))
|
r.On("File", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("File not found"))
|
||||||
r.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("Directory not found"))
|
r.On("Dir", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, fmt.Errorf("Directory not found"))
|
||||||
|
|
||||||
configFetcher := server.NewConfigFetcher(
|
configFetcher := shared.NewConfigFetcher(
|
||||||
r,
|
r,
|
||||||
&model.User{Token: "xxx"},
|
&model.User{Token: "xxx"},
|
||||||
repo,
|
repo,
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -31,10 +31,11 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/cncd/pipeline/pipeline/frontend/yaml/matrix"
|
"github.com/woodpecker-ci/woodpecker/cncd/pipeline/pipeline/frontend/yaml/matrix"
|
||||||
"github.com/woodpecker-ci/woodpecker/model"
|
"github.com/woodpecker-ci/woodpecker/model"
|
||||||
"github.com/woodpecker-ci/woodpecker/remote"
|
"github.com/woodpecker-ci/woodpecker/remote"
|
||||||
|
"github.com/woodpecker-ci/woodpecker/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Takes the hook data and the yaml and returns in internal data model
|
// ProcBuilder Takes the hook data and the yaml and returns in internal data model
|
||||||
type procBuilder struct {
|
type ProcBuilder struct {
|
||||||
Repo *model.Repo
|
Repo *model.Repo
|
||||||
Curr *model.Build
|
Curr *model.Build
|
||||||
Last *model.Build
|
Last *model.Build
|
||||||
|
@ -46,7 +47,7 @@ type procBuilder struct {
|
||||||
Envs map[string]string
|
Envs map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type buildItem struct {
|
type BuildItem struct {
|
||||||
Proc *model.Proc
|
Proc *model.Proc
|
||||||
Platform string
|
Platform string
|
||||||
Labels map[string]string
|
Labels map[string]string
|
||||||
|
@ -55,8 +56,8 @@ type buildItem struct {
|
||||||
Config *backend.Config
|
Config *backend.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *procBuilder) Build() ([]*buildItem, error) {
|
func (b *ProcBuilder) Build() ([]*BuildItem, error) {
|
||||||
var items []*buildItem
|
var items []*BuildItem
|
||||||
|
|
||||||
sort.Sort(remote.ByName(b.Yamls))
|
sort.Sort(remote.ByName(b.Yamls))
|
||||||
|
|
||||||
|
@ -79,7 +80,7 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
|
||||||
PGID: pidSequence,
|
PGID: pidSequence,
|
||||||
State: model.StatusPending,
|
State: model.StatusPending,
|
||||||
Environ: axis,
|
Environ: axis,
|
||||||
Name: sanitizePath(y.Name),
|
Name: SanitizePath(y.Name),
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata := metadataFromStruct(b.Repo, b.Curr, b.Last, proc, b.Link)
|
metadata := metadataFromStruct(b.Repo, b.Curr, b.Last, proc, b.Link)
|
||||||
|
@ -117,7 +118,7 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
item := &buildItem{
|
item := &BuildItem{
|
||||||
Proc: proc,
|
Proc: proc,
|
||||||
Config: ir,
|
Config: ir,
|
||||||
Labels: parsed.Labels,
|
Labels: parsed.Labels,
|
||||||
|
@ -139,8 +140,8 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
|
||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterItemsWithMissingDependencies(items []*buildItem) []*buildItem {
|
func filterItemsWithMissingDependencies(items []*BuildItem) []*BuildItem {
|
||||||
itemsToRemove := make([]*buildItem, 0)
|
itemsToRemove := make([]*BuildItem, 0)
|
||||||
|
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
for _, dep := range item.DependsOn {
|
for _, dep := range item.DependsOn {
|
||||||
|
@ -151,7 +152,7 @@ func filterItemsWithMissingDependencies(items []*buildItem) []*buildItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(itemsToRemove) > 0 {
|
if len(itemsToRemove) > 0 {
|
||||||
filtered := make([]*buildItem, 0)
|
filtered := make([]*BuildItem, 0)
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if !containsItemWithName(item.Proc.Name, itemsToRemove) {
|
if !containsItemWithName(item.Proc.Name, itemsToRemove) {
|
||||||
filtered = append(filtered, item)
|
filtered = append(filtered, item)
|
||||||
|
@ -164,7 +165,7 @@ func filterItemsWithMissingDependencies(items []*buildItem) []*buildItem {
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
func containsItemWithName(name string, items []*buildItem) bool {
|
func containsItemWithName(name string, items []*BuildItem) bool {
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if name == item.Proc.Name {
|
if name == item.Proc.Name {
|
||||||
return true
|
return true
|
||||||
|
@ -173,7 +174,7 @@ func containsItemWithName(name string, items []*buildItem) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *procBuilder) envsubst_(y string, environ map[string]string) (string, error) {
|
func (b *ProcBuilder) envsubst_(y string, environ map[string]string) (string, error) {
|
||||||
return envsubst.Eval(y, func(name string) string {
|
return envsubst.Eval(y, func(name string) string {
|
||||||
env := environ[name]
|
env := environ[name]
|
||||||
if strings.Contains(env, "\n") {
|
if strings.Contains(env, "\n") {
|
||||||
|
@ -183,7 +184,7 @@ func (b *procBuilder) envsubst_(y string, environ map[string]string) (string, er
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *procBuilder) environmentVariables(metadata frontend.Metadata, axis matrix.Axis) map[string]string {
|
func (b *ProcBuilder) environmentVariables(metadata frontend.Metadata, axis matrix.Axis) map[string]string {
|
||||||
environ := metadata.Environ()
|
environ := metadata.Environ()
|
||||||
for k, v := range metadata.EnvironDrone() {
|
for k, v := range metadata.EnvironDrone() {
|
||||||
environ[k] = v
|
environ[k] = v
|
||||||
|
@ -194,7 +195,7 @@ func (b *procBuilder) environmentVariables(metadata frontend.Metadata, axis matr
|
||||||
return environ
|
return environ
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *procBuilder) toInternalRepresentation(parsed *yaml.Config, environ map[string]string, metadata frontend.Metadata, procID int64) *backend.Config {
|
func (b *ProcBuilder) toInternalRepresentation(parsed *yaml.Config, environ map[string]string, metadata frontend.Metadata, procID int64) *backend.Config {
|
||||||
var secrets []compiler.Secret
|
var secrets []compiler.Secret
|
||||||
for _, sec := range b.Secs {
|
for _, sec := range b.Secs {
|
||||||
if !sec.Match(b.Curr.Event) {
|
if !sec.Match(b.Curr.Event) {
|
||||||
|
@ -220,10 +221,10 @@ func (b *procBuilder) toInternalRepresentation(parsed *yaml.Config, environ map[
|
||||||
return compiler.New(
|
return compiler.New(
|
||||||
compiler.WithEnviron(environ),
|
compiler.WithEnviron(environ),
|
||||||
compiler.WithEnviron(b.Envs),
|
compiler.WithEnviron(b.Envs),
|
||||||
compiler.WithEscalated(Config.Pipeline.Privileged...),
|
compiler.WithEscalated(server.Config.Pipeline.Privileged...),
|
||||||
compiler.WithResourceLimit(Config.Pipeline.Limits.MemSwapLimit, Config.Pipeline.Limits.MemLimit, Config.Pipeline.Limits.ShmSize, Config.Pipeline.Limits.CPUQuota, Config.Pipeline.Limits.CPUShares, Config.Pipeline.Limits.CPUSet),
|
compiler.WithResourceLimit(server.Config.Pipeline.Limits.MemSwapLimit, server.Config.Pipeline.Limits.MemLimit, server.Config.Pipeline.Limits.ShmSize, server.Config.Pipeline.Limits.CPUQuota, server.Config.Pipeline.Limits.CPUShares, server.Config.Pipeline.Limits.CPUSet),
|
||||||
compiler.WithVolumes(Config.Pipeline.Volumes...),
|
compiler.WithVolumes(server.Config.Pipeline.Volumes...),
|
||||||
compiler.WithNetworks(Config.Pipeline.Networks...),
|
compiler.WithNetworks(server.Config.Pipeline.Networks...),
|
||||||
compiler.WithLocal(false),
|
compiler.WithLocal(false),
|
||||||
compiler.WithOption(
|
compiler.WithOption(
|
||||||
compiler.WithNetrc(
|
compiler.WithNetrc(
|
||||||
|
@ -248,7 +249,7 @@ func (b *procBuilder) toInternalRepresentation(parsed *yaml.Config, environ map[
|
||||||
).Compile(parsed)
|
).Compile(parsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setBuildStepsOnBuild(build *model.Build, buildItems []*buildItem) *model.Build {
|
func SetBuildStepsOnBuild(build *model.Build, buildItems []*BuildItem) *model.Build {
|
||||||
var pidSequence int
|
var pidSequence int
|
||||||
for _, item := range buildItems {
|
for _, item := range buildItems {
|
||||||
build.Procs = append(build.Procs, item.Proc)
|
build.Procs = append(build.Procs, item.Proc)
|
||||||
|
@ -359,7 +360,7 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sanitizePath(path string) string {
|
func SanitizePath(path string) string {
|
||||||
path = filepath.Base(path)
|
path = filepath.Base(path)
|
||||||
path = strings.TrimSuffix(path, ".yml")
|
path = strings.TrimSuffix(path, ".yml")
|
||||||
path = strings.TrimPrefix(path, ".")
|
path = strings.TrimPrefix(path, ".")
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -25,7 +25,7 @@ import (
|
||||||
func TestMultilineEnvsubst(t *testing.T) {
|
func TestMultilineEnvsubst(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: &model.Build{
|
Curr: &model.Build{
|
||||||
Message: `aaa
|
Message: `aaa
|
||||||
|
@ -61,7 +61,7 @@ pipeline:
|
||||||
func TestMultiPipeline(t *testing.T) {
|
func TestMultiPipeline(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: &model.Build{},
|
Curr: &model.Build{},
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -95,7 +95,7 @@ pipeline:
|
||||||
func TestDependsOn(t *testing.T) {
|
func TestDependsOn(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: &model.Build{},
|
Curr: &model.Build{},
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -141,7 +141,7 @@ depends_on:
|
||||||
func TestRunsOn(t *testing.T) {
|
func TestRunsOn(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: &model.Build{},
|
Curr: &model.Build{},
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -177,7 +177,7 @@ runs_on:
|
||||||
func TestBranchFilter(t *testing.T) {
|
func TestBranchFilter(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: &model.Build{Branch: "dev"},
|
Curr: &model.Build{Branch: "dev"},
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -225,7 +225,7 @@ func TestZeroSteps(t *testing.T) {
|
||||||
|
|
||||||
build := &model.Build{Branch: "dev"}
|
build := &model.Build{Branch: "dev"}
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: build,
|
Curr: build,
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -259,7 +259,7 @@ func TestZeroStepsAsMultiPipelineDeps(t *testing.T) {
|
||||||
|
|
||||||
build := &model.Build{Branch: "dev"}
|
build := &model.Build{Branch: "dev"}
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: build,
|
Curr: build,
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -307,7 +307,7 @@ func TestZeroStepsAsMultiPipelineTransitiveDeps(t *testing.T) {
|
||||||
|
|
||||||
build := &model.Build{Branch: "dev"}
|
build := &model.Build{Branch: "dev"}
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: build,
|
Curr: build,
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -361,7 +361,7 @@ func TestTree(t *testing.T) {
|
||||||
|
|
||||||
build := &model.Build{}
|
build := &model.Build{}
|
||||||
|
|
||||||
b := procBuilder{
|
b := ProcBuilder{
|
||||||
Repo: &model.Repo{},
|
Repo: &model.Repo{},
|
||||||
Curr: build,
|
Curr: build,
|
||||||
Last: &model.Build{},
|
Last: &model.Build{},
|
||||||
|
@ -378,7 +378,7 @@ pipeline:
|
||||||
}
|
}
|
||||||
|
|
||||||
buildItems, err := b.Build()
|
buildItems, err := b.Build()
|
||||||
build = setBuildStepsOnBuild(build, buildItems)
|
build = SetBuildStepsOnBuild(build, buildItems)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@ func TestSanitizePath(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testTable {
|
for _, test := range testTable {
|
||||||
if test.sanitizedPath != sanitizePath(test.path) {
|
if test.sanitizedPath != SanitizePath(test.path) {
|
||||||
t.Fatal("Path hasn't been sanitized correctly")
|
t.Fatal("Path hasn't been sanitized correctly")
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package server
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
@ -22,16 +22,16 @@ import (
|
||||||
"github.com/woodpecker-ci/woodpecker/store"
|
"github.com/woodpecker-ci/woodpecker/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Syncer synces the user repository and permissions.
|
// UserSyncer syncs the user repository and permissions.
|
||||||
type Syncer interface {
|
type UserSyncer interface {
|
||||||
Sync(user *model.User) error
|
Sync(user *model.User) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type syncer struct {
|
type Syncer struct {
|
||||||
remote remote.Remote
|
Remote remote.Remote
|
||||||
store store.Store
|
Store store.Store
|
||||||
perms model.PermStore
|
Perms model.PermStore
|
||||||
match FilterFunc
|
Match FilterFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
// FilterFunc can be used to filter which repositories are
|
// FilterFunc can be used to filter which repositories are
|
||||||
|
@ -58,13 +58,13 @@ func noopFilter(*model.Repo) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFilter sets the filter function.
|
// SetFilter sets the filter function.
|
||||||
func (s *syncer) SetFilter(fn FilterFunc) {
|
func (s *Syncer) SetFilter(fn FilterFunc) {
|
||||||
s.match = fn
|
s.Match = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *syncer) Sync(user *model.User) error {
|
func (s *Syncer) Sync(user *model.User) error {
|
||||||
unix := time.Now().Unix() - (3601) // force immediate expiration. note 1 hour expiration is hard coded at the moment
|
unix := time.Now().Unix() - (3601) // force immediate expiration. note 1 hour expiration is hard coded at the moment
|
||||||
repos, err := s.remote.Repos(user)
|
repos, err := s.Remote.Repos(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ func (s *syncer) Sync(user *model.User) error {
|
||||||
var perms []*model.Perm
|
var perms []*model.Perm
|
||||||
|
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
if s.match(repo) {
|
if s.Match(repo) {
|
||||||
remote = append(remote, repo)
|
remote = append(remote, repo)
|
||||||
perm := model.Perm{
|
perm := model.Perm{
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
|
@ -89,12 +89,12 @@ func (s *syncer) Sync(user *model.User) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.store.RepoBatch(remote)
|
err = s.Store.RepoBatch(remote)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.store.PermBatch(perms)
|
err = s.Store.PermBatch(perms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -110,5 +110,5 @@ func (s *syncer) Sync(user *model.User) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.perms.PermFlush(user, unix)
|
return s.Perms.PermFlush(user, unix)
|
||||||
}
|
}
|
Loading…
Reference in a new issue