-
-
Notifications
You must be signed in to change notification settings - Fork 579
Add log service addon #5507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add log service addon #5507
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f600f38
Show readable error
qwerty287 4c9ea3c
Add log service addon
qwerty287 66fe7e3
Merge branch 'main' into addon-logs
qwerty287 98fe3a7
25
qwerty287 52212dc
fmt
qwerty287 489964f
imports
qwerty287 c6066bd
Merge branch 'main' into addon-logs
qwerty287 4e3c0f6
general addon docs
qwerty287 115b961
fix mdlint
qwerty287 5a4c5f7
Merge branch 'main' into addon-logs
qwerty287 d213549
Add StepFinished to addon
qwerty287 1132e9c
generate openapi
qwerty287 0a531d6
move docs
qwerty287 08640b4
Merge branch 'main' into addon-logs
qwerty287 c86a15e
fix link
qwerty287 968a730
fix anchor
qwerty287 e764ed6
Merge branch 'main' into addon-logs
qwerty287 7392ef1
Update docs/docs/30-administration/10-configuration/10-server.md
qwerty287 ca753fa
Update docs/docs/92-development/100-addons.md
qwerty287 c500083
Merge branch 'main' into addon-logs
xoxys 4991381
Merge branch 'main' into addon-logs
xoxys 974bc54
Merge branch 'main' into addon-logs
xoxys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
docs/docs/30-administration/10-configuration/100-addons.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Addons | ||
|
|
||
| Addons can be used to extend the Woodpecker server. Currently, they can be used for forges and the log service. | ||
|
|
||
| :::warning | ||
| Addon forges are still experimental. Their implementation can change and break at any time. | ||
| ::: | ||
|
|
||
| :::danger | ||
| You must trust the author of the addon forge you are using. They may have access to authentication codes and other potentially sensitive information. | ||
| ::: | ||
|
|
||
| ## Usage | ||
|
|
||
| To use an addon forge, download the correct addon version. | ||
|
|
||
| ### Forge | ||
|
|
||
| Use this in your `.env`: | ||
|
|
||
| ```ini | ||
| WOODPECKER_ADDON_FORGE=/path/to/your/addon/forge/file | ||
| ``` | ||
|
|
||
| In case you run Woodpecker as container, you probably want to mount the addon binary to `/opt/addons/`. | ||
|
|
||
| #### List of addon forges | ||
|
|
||
| - [Radicle](https://radicle.xyz/): Open source, peer-to-peer code collaboration stack built on Git. Radicle addon for Woodpecker CI can be found at [this repo](https://explorer.radicle.gr/nodes/seed.radicle.gr/rad:z39Cf1XzrvCLRZZJRUZnx9D1fj5ws). | ||
|
|
||
| ### Log | ||
|
|
||
| Use this in your `.env`: | ||
|
|
||
| ```ini | ||
| WOODPECKER_LOG_STORE=addon | ||
| WOODPECKER_LOG_STORE_FILE_PATH=/path/to/your/addon/forge/file | ||
| ``` | ||
|
|
||
| ## Developing addon forges | ||
|
|
||
| See [Addons](../../92-development/100-addons.md). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Copyright 2025 Woodpecker Authors | ||
| // | ||
| // 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. | ||
|
|
||
| package addon | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/rpc" | ||
| "os/exec" | ||
|
|
||
| "github.com/hashicorp/go-plugin" | ||
| "github.com/rs/zerolog/log" | ||
|
|
||
| "go.woodpecker-ci.org/woodpecker/v3/server/model" | ||
| logService "go.woodpecker-ci.org/woodpecker/v3/server/services/log" | ||
| "go.woodpecker-ci.org/woodpecker/v3/shared/logger" | ||
| ) | ||
|
|
||
| // make sure RPC implements logService.Service. | ||
| var _ logService.Service = new(RPC) | ||
|
|
||
| func Load(file string) (logService.Service, error) { | ||
| client := plugin.NewClient(&plugin.ClientConfig{ | ||
| HandshakeConfig: HandshakeConfig, | ||
| Plugins: map[string]plugin.Plugin{ | ||
| pluginKey: &Plugin{}, | ||
| }, | ||
| Cmd: exec.Command(file), | ||
| Logger: &logger.AddonClientLogger{ | ||
| Logger: log.With().Str("addon", file).Logger(), | ||
| }, | ||
| }) | ||
| // TODO: defer client.Kill() | ||
|
|
||
| rpcClient, err := client.Client() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| raw, err := rpcClient.Dispense(pluginKey) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| extension, _ := raw.(logService.Service) | ||
| return extension, nil | ||
| } | ||
|
|
||
| type RPC struct { | ||
| client *rpc.Client | ||
| } | ||
|
|
||
| func (g *RPC) LogFind(step *model.Step) ([]*model.LogEntry, error) { | ||
| args, err := json.Marshal(step) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| var jsonResp []byte | ||
| err = g.client.Call("Plugin.LogFind", args, &jsonResp) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var resp []*model.LogEntry | ||
| err = json.Unmarshal(jsonResp, &resp) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return resp, nil | ||
| } | ||
|
|
||
| func (g *RPC) LogAppend(step *model.Step, logEntries []*model.LogEntry) error { | ||
| args, err := json.Marshal(&argumentsAppend{ | ||
| Step: step, | ||
| LogEntries: logEntries, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| var jsonResp []byte | ||
| return g.client.Call("Plugin.LogAppend", args, &jsonResp) | ||
| } | ||
|
|
||
| func (g *RPC) LogDelete(step *model.Step) error { | ||
| args, err := json.Marshal(step) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| var jsonResp []byte | ||
| return g.client.Call("Plugin.LogDelete", args, &jsonResp) | ||
| } | ||
|
|
||
| func (g *RPC) StepFinished(step *model.Step) { | ||
| args, err := json.Marshal(step) | ||
| if err != nil { | ||
| log.Error().Err(err).Msg("could not marshal json for log addon") | ||
| return | ||
| } | ||
| var jsonResp []byte | ||
| err = g.client.Call("Plugin.StepFinished", args, &jsonResp) | ||
| if err != nil { | ||
| log.Error().Err(err).Msg("StepFinished via addon failed") | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright 2025 Woodpecker Authors | ||
| // | ||
| // 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. | ||
|
|
||
| package addon | ||
|
|
||
| import ( | ||
| "net/rpc" | ||
|
|
||
| "github.com/hashicorp/go-plugin" | ||
|
|
||
| "go.woodpecker-ci.org/woodpecker/v3/server/services/log" | ||
| ) | ||
|
|
||
| const pluginKey = "log" | ||
|
|
||
| var HandshakeConfig = plugin.HandshakeConfig{ | ||
| ProtocolVersion: 1, | ||
| MagicCookieKey: "WOODPECKER_LOG_ADDON_PLUGIN", | ||
| MagicCookieValue: "woodpecker-plugin-magic-cookie-value", | ||
| } | ||
|
|
||
| type Plugin struct { | ||
| Impl log.Service | ||
| } | ||
|
|
||
| func (p *Plugin) Server(*plugin.MuxBroker) (any, error) { | ||
| return &RPCServer{Impl: p.Impl}, nil | ||
| } | ||
|
|
||
| func (*Plugin) Client(_ *plugin.MuxBroker, c *rpc.Client) (any, error) { | ||
| return &RPC{client: c}, nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.