Document package architecture (#972)

to make it easier for devs to find the right place for code

close #655

Co-authored-by: Anbraten <anton@ju60.de>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
6543 2022-06-16 15:35:58 +02:00 committed by GitHub
parent 3d8ea2e2c9
commit 0ab5182402
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 75 additions and 17 deletions

View file

@ -6,4 +6,44 @@
## System architecture ## System architecture
### main package hirarchie
| package | meaning | imports
|------------|--------------------------------------------------------------|----------
| `cmd/**` | parse commanline args & environment to stat server/cli/agent | all other
| `agent/**` | code only agent (remote worker) will need | `pipeline`, `shared`
| `cli/**` | code only cli tool does need | `pipeline`, `shared`, `woodpecker-go`
| `server/**`| code only server will need | `pipeline`, `shared`
| `shared/**`| code shared for all three main tools (go help utils) | only std and external libs
| `woodpecker-go/**` | go client for server rest api | std
### Server
| package | meaning | imports
|---------------------|-------------------------------------------------|----------
| `server/api/**` | handle web requests from `server/router` | `pipeline`, `../badges`, `../ccmenue`, `../logging`, `../model`, `../pubsub`, `../queue`, `../remote`, `../shared`, `../store`, `shared`, (TODO: mv `server/router/middleware/session`)
| `server/badges/**` | generate svg badges for pipelines | `../model`
| `server/ccmenu/**` | generate xml ccmenu for pipelines | `../model`
| `server/grpc/**` | gRPC server agents can connect to | `pipeline/rpc/**`, `../logging`, `../model`, `../pubsub`, `../queue`, `../remote`, `../pipeline`, `../store`
| `server/logging/**` | logging lib for gPRC server to stream logs while running | std
| `server/model/**` | structs for store (db) and api (json) | std
| `server/plugins/**` | plugins for server | `../model`, `../remote`
| `server/pipeline/**`| orchistrate pipelines | `pipeline`, `../model`, `../pubsub`, `../queue`, `../remote`, `../store`, `../plugins`
| `server/pubsub/**` | pubsub lib for server to push changes to the WebUI | std
| `server/queue/**` | queue lib for server where agents pull new pipelines from via gRPC | `server/model`
| `server/remote/**` | remote lib for server to connect and handle forge specific stuff | `shared`, `server/model`
| `server/router/**` | handle requests to REST API (and all middleware) and serve UI and WebUI config | `shared`, `../api`, `../model`, `../remote`, `../store`, `../web`
| `server/store/**` | handle database | `server/model`
| `server/shared/**` | TODO: move and split [#974](https://github.com/woodpecker-ci/woodpecker/issues/974) |
| `server/web/**` | server SPA |
* `../` = `server/`
### Agent
TODO
### CLI
TODO TODO

View file

@ -57,3 +57,7 @@ type Build struct {
func (Build) TableName() string { func (Build) TableName() string {
return "builds" return "builds"
} }
type UpdateBuildStore interface {
UpdateBuild(*Build) error
}

View file

@ -48,6 +48,10 @@ type Proc struct {
Children []*Proc `json:"children,omitempty" xorm:"-"` Children []*Proc `json:"children,omitempty" xorm:"-"`
} }
type UpdateProcStore interface {
ProcUpdate(*Proc) error
}
// TableName return database table name for xorm // TableName return database table name for xorm
func (Proc) TableName() string { func (Proc) TableName() string {
return "procs" return "procs"

View file

@ -20,37 +20,35 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/model"
) )
type UpdateBuildStore interface { // TODO(974) move to server/pipeline/*
UpdateBuild(*model.Build) error
}
func UpdateToStatusRunning(store UpdateBuildStore, build model.Build, started int64) (*model.Build, error) { func UpdateToStatusRunning(store model.UpdateBuildStore, build model.Build, started int64) (*model.Build, error) {
build.Status = model.StatusRunning build.Status = model.StatusRunning
build.Started = started build.Started = started
return &build, store.UpdateBuild(&build) return &build, store.UpdateBuild(&build)
} }
func UpdateToStatusPending(store UpdateBuildStore, build model.Build, reviewer string) (*model.Build, error) { func UpdateToStatusPending(store model.UpdateBuildStore, build model.Build, reviewer string) (*model.Build, error) {
build.Reviewer = reviewer build.Reviewer = reviewer
build.Status = model.StatusPending build.Status = model.StatusPending
build.Reviewed = time.Now().Unix() build.Reviewed = time.Now().Unix()
return &build, store.UpdateBuild(&build) return &build, store.UpdateBuild(&build)
} }
func UpdateToStatusDeclined(store UpdateBuildStore, build model.Build, reviewer string) (*model.Build, error) { func UpdateToStatusDeclined(store model.UpdateBuildStore, build model.Build, reviewer string) (*model.Build, error) {
build.Reviewer = reviewer build.Reviewer = reviewer
build.Status = model.StatusDeclined build.Status = model.StatusDeclined
build.Reviewed = time.Now().Unix() build.Reviewed = time.Now().Unix()
return &build, store.UpdateBuild(&build) return &build, store.UpdateBuild(&build)
} }
func UpdateStatusToDone(store UpdateBuildStore, build model.Build, status model.StatusValue, stopped int64) (*model.Build, error) { func UpdateStatusToDone(store model.UpdateBuildStore, build model.Build, status model.StatusValue, stopped int64) (*model.Build, error) {
build.Status = status build.Status = status
build.Finished = stopped build.Finished = stopped
return &build, store.UpdateBuild(&build) return &build, store.UpdateBuild(&build)
} }
func UpdateToStatusError(store UpdateBuildStore, build model.Build, err error) (*model.Build, error) { func UpdateToStatusError(store model.UpdateBuildStore, build model.Build, err error) (*model.Build, error) {
build.Error = err.Error() build.Error = err.Error()
build.Status = model.StatusError build.Status = model.StatusError
build.Started = time.Now().Unix() build.Started = time.Now().Unix()
@ -58,7 +56,7 @@ func UpdateToStatusError(store UpdateBuildStore, build model.Build, err error) (
return &build, store.UpdateBuild(&build) return &build, store.UpdateBuild(&build)
} }
func UpdateToStatusKilled(store UpdateBuildStore, build model.Build) (*model.Build, error) { func UpdateToStatusKilled(store model.UpdateBuildStore, build model.Build) (*model.Build, error) {
build.Status = model.StatusKilled build.Status = model.StatusKilled
build.Finished = time.Now().Unix() build.Finished = time.Now().Unix()
return &build, store.UpdateBuild(&build) return &build, store.UpdateBuild(&build)

View file

@ -22,6 +22,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/model"
) )
// TODO(974) move to server/pipeline/*
type mockUpdateBuildStore struct{} type mockUpdateBuildStore struct{}
func (m *mockUpdateBuildStore) UpdateBuild(build *model.Build) error { func (m *mockUpdateBuildStore) UpdateBuild(build *model.Build) error {

View file

@ -18,6 +18,8 @@ type ConfigFetcher interface {
Fetch(ctx context.Context) (files []*remote.FileMeta, err error) Fetch(ctx context.Context) (files []*remote.FileMeta, err error)
} }
// TODO(974) move to new package
type configFetcher struct { type configFetcher struct {
remote remote.Remote remote remote.Remote
user *model.User user *model.User

View file

@ -23,6 +23,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/shared" "github.com/woodpecker-ci/woodpecker/server/shared"
) )
// TODO(974) move to new package
func TestFetch(t *testing.T) { func TestFetch(t *testing.T) {
t.Parallel() t.Parallel()

View file

@ -35,6 +35,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/remote" "github.com/woodpecker-ci/woodpecker/server/remote"
) )
// TODO(974) move to pipeline/*
// ProcBuilder 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

View file

@ -22,6 +22,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/remote" "github.com/woodpecker-ci/woodpecker/server/remote"
) )
// TODO(974) move to pipeline/*
func TestMultilineEnvsubst(t *testing.T) { func TestMultilineEnvsubst(t *testing.T) {
t.Parallel() t.Parallel()

View file

@ -21,11 +21,9 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/model"
) )
type UpdateProcStore interface { // TODO(974) move to server/pipeline/*
ProcUpdate(*model.Proc) error
}
func UpdateProcStatus(store UpdateProcStore, proc model.Proc, state rpc.State, started int64) (*model.Proc, error) { func UpdateProcStatus(store model.UpdateProcStore, proc model.Proc, state rpc.State, started int64) (*model.Proc, error) {
if state.Exited { if state.Exited {
proc.Stopped = state.Finished proc.Stopped = state.Finished
proc.ExitCode = state.ExitCode proc.ExitCode = state.ExitCode
@ -48,13 +46,13 @@ func UpdateProcStatus(store UpdateProcStore, proc model.Proc, state rpc.State, s
return &proc, store.ProcUpdate(&proc) return &proc, store.ProcUpdate(&proc)
} }
func UpdateProcToStatusStarted(store UpdateProcStore, proc model.Proc, state rpc.State) (*model.Proc, error) { func UpdateProcToStatusStarted(store model.UpdateProcStore, proc model.Proc, state rpc.State) (*model.Proc, error) {
proc.Started = state.Started proc.Started = state.Started
proc.State = model.StatusRunning proc.State = model.StatusRunning
return &proc, store.ProcUpdate(&proc) return &proc, store.ProcUpdate(&proc)
} }
func UpdateProcToStatusSkipped(store UpdateProcStore, proc model.Proc, stopped int64) (*model.Proc, error) { func UpdateProcToStatusSkipped(store model.UpdateProcStore, proc model.Proc, stopped int64) (*model.Proc, error) {
proc.State = model.StatusSkipped proc.State = model.StatusSkipped
if proc.Started != 0 { if proc.Started != 0 {
proc.State = model.StatusSuccess // for daemons that are killed proc.State = model.StatusSuccess // for daemons that are killed
@ -63,7 +61,7 @@ func UpdateProcToStatusSkipped(store UpdateProcStore, proc model.Proc, stopped i
return &proc, store.ProcUpdate(&proc) return &proc, store.ProcUpdate(&proc)
} }
func UpdateProcStatusToDone(store UpdateProcStore, proc model.Proc, state rpc.State) (*model.Proc, error) { func UpdateProcStatusToDone(store model.UpdateProcStore, proc model.Proc, state rpc.State) (*model.Proc, error) {
proc.Stopped = state.Finished proc.Stopped = state.Finished
proc.Error = state.Error proc.Error = state.Error
proc.ExitCode = state.ExitCode proc.ExitCode = state.ExitCode
@ -78,7 +76,7 @@ func UpdateProcStatusToDone(store UpdateProcStore, proc model.Proc, state rpc.St
return &proc, store.ProcUpdate(&proc) return &proc, store.ProcUpdate(&proc)
} }
func UpdateProcToStatusKilled(store UpdateProcStore, proc model.Proc) (*model.Proc, error) { func UpdateProcToStatusKilled(store model.UpdateProcStore, proc model.Proc) (*model.Proc, error) {
proc.State = model.StatusKilled proc.State = model.StatusKilled
proc.Stopped = time.Now().Unix() proc.Stopped = time.Now().Unix()
if proc.Started == 0 { if proc.Started == 0 {

View file

@ -22,6 +22,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/model" "github.com/woodpecker-ci/woodpecker/server/model"
) )
// TODO(974) move to server/pipeline/*
type mockUpdateProcStore struct{} type mockUpdateProcStore struct{}
func (m *mockUpdateProcStore) ProcUpdate(build *model.Proc) error { func (m *mockUpdateProcStore) ProcUpdate(build *model.Proc) error {

View file

@ -24,6 +24,8 @@ import (
"github.com/woodpecker-ci/woodpecker/server/store" "github.com/woodpecker-ci/woodpecker/server/store"
) )
// TODO(974) move to new package
// UserSyncer syncs the user repository and permissions. // UserSyncer syncs the user repository and permissions.
type UserSyncer interface { type UserSyncer interface {
Sync(ctx context.Context, user *model.User) error Sync(ctx context.Context, user *model.User) error