Skip to content
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

Rework addons (use rpc) #3268

Merged
merged 72 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
37e04a4
Add go plugins
qwerty287 Jan 24, 2024
fb00d8f
Merge branch 'main' into rework-addons
qwerty287 Jan 28, 2024
2c7e26c
Support registry service
qwerty287 Jan 28, 2024
734daa3
Support env service
qwerty287 Jan 28, 2024
cb6b9d0
Remove old types
qwerty287 Jan 28, 2024
2592705
Merge branch 'main' into rework-addons
qwerty287 Jan 28, 2024
2489471
reformat
qwerty287 Jan 28, 2024
6f6e72a
Add secret service
qwerty287 Jan 28, 2024
2ae103a
Move pipeline error types to own package
qwerty287 Jan 28, 2024
2784acf
fix flag types
qwerty287 Jan 28, 2024
24a4138
Merge branch 'main' into rework-addons
qwerty287 Feb 8, 2024
5a19988
Merge branch 'main' into rework-addons
qwerty287 Feb 8, 2024
6df50b0
Add basic forge addon stuff (wip)
qwerty287 Feb 8, 2024
1a89814
Merge branch 'main' into rework-addons
qwerty287 Feb 8, 2024
a1a8d21
continue forge addon
qwerty287 Feb 9, 2024
19169ab
Merge branch 'main' into rework-addons
qwerty287 Feb 9, 2024
bce1ad3
fix id
qwerty287 Feb 9, 2024
b930832
replace goplugins
qwerty287 Feb 9, 2024
e12f208
Merge branch 'main' into rework-addons
qwerty287 Feb 10, 2024
325e3e5
Merge branch 'main' into rework-addons
qwerty287 Feb 11, 2024
458b687
fix merge
qwerty287 Feb 11, 2024
e842ae7
move addon pkg
qwerty287 Feb 11, 2024
ad8d25b
Remove moularity
qwerty287 Feb 11, 2024
b17a6d4
complete hook func
qwerty287 Feb 11, 2024
cfa2e5d
Merge branch 'main' into rework-addons
qwerty287 Feb 13, 2024
f2b1bee
finish basic work
qwerty287 Feb 13, 2024
21d1ab3
add copyright
qwerty287 Feb 13, 2024
e06a520
fix json on user model
qwerty287 Feb 13, 2024
92f5391
fix for repos & rework
qwerty287 Feb 13, 2024
d03814e
rename pkg
qwerty287 Feb 13, 2024
14ab7fe
fix repo struct
qwerty287 Feb 13, 2024
5fe0108
Merge branch 'main' into rework-addons
qwerty287 Feb 15, 2024
daa80a5
Merge branch 'main' into rework-addons
qwerty287 Feb 17, 2024
5b7bd63
return error on failed type
qwerty287 Feb 17, 2024
73ac116
Merge branch 'main' into rework-addons
qwerty287 Feb 17, 2024
8fb3f3c
Add addon logger
qwerty287 Feb 17, 2024
1a9fcbe
Revert "return error on failed type"
qwerty287 Feb 17, 2024
2526575
Update addon docs
qwerty287 Feb 17, 2024
1aeb25f
Update docs
qwerty287 Feb 17, 2024
4902893
fix lint
qwerty287 Feb 17, 2024
cfacb1c
update link
qwerty287 Feb 18, 2024
b3d1fc1
[pre-commit.ci] auto fixes from pre-commit.com hooks [CI SKIP]
pre-commit-ci[bot] Feb 18, 2024
70e2845
update docs
qwerty287 Feb 18, 2024
b56a859
update link
qwerty287 Feb 18, 2024
1ca2621
Merge branch 'main' into rework-addons
qwerty287 Feb 18, 2024
1fe20f3
Merge branch 'main' into rework-addons
qwerty287 Feb 19, 2024
4c6e185
fix link
qwerty287 Feb 19, 2024
7dc2912
update swagger
qwerty287 Feb 19, 2024
2fcc67b
replace radicle with info
qwerty287 Feb 19, 2024
389df9c
Rename flag
qwerty287 Feb 19, 2024
3cfe954
Merge branch 'main' into rework-addons
qwerty287 Feb 22, 2024
4b915b8
Merge branch 'main' into rework-addons
qwerty287 Feb 24, 2024
6cc1b7b
Merge branch 'main' into rework-addons
qwerty287 Feb 26, 2024
c06d834
fix yaml syntax
qwerty287 Feb 26, 2024
ba3b14c
Merge branch 'main' into rework-addons
qwerty287 Mar 3, 2024
1327839
fix build
qwerty287 Mar 3, 2024
e3edc0f
prettier
qwerty287 Mar 3, 2024
e1e2f9c
fix renovate pr label
qwerty287 Mar 4, 2024
5bb62bd
Merge branch 'main' into rework-addons
qwerty287 Mar 4, 2024
dc464d5
Merge branch 'main' into rework-addons
qwerty287 Mar 8, 2024
09f086b
update some docs
qwerty287 Mar 8, 2024
aee656d
Update prettier
qwerty287 Mar 8, 2024
d1b18fa
Revert "Update prettier"
qwerty287 Mar 8, 2024
e422dc4
Merge branch 'main' into rework-addons
qwerty287 Mar 11, 2024
413eadb
Merge branch 'main' into rework-addons
qwerty287 Mar 16, 2024
07c5f9b
Merge branch 'main' into rework-addons
qwerty287 Mar 20, 2024
29ceeab
Merge branch 'main' into rework-addons
qwerty287 Mar 22, 2024
15d9782
Merge branch 'main' into rework-addons
qwerty287 Mar 24, 2024
0274437
Merge branch 'main' into rework-addons
qwerty287 Mar 29, 2024
2d9ba42
Merge branch 'main' into rework-addons
qwerty287 Apr 15, 2024
e008d27
Merge branch 'main' into rework-addons
anbraten Apr 15, 2024
57e3448
Update docs/docs/30-administration/11-forges/100-addon.md
qwerty287 Apr 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"packageRules": [
{
"matchManagers": ["docker-compose"],
"matchFileNames": ["docker-compose.gitpod.yml"],
"matchFileNames": ["docker-compose.gitpod.yaml"],
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
"addLabels": ["devx"]
},
{
Expand Down
2 changes: 1 addition & 1 deletion cli/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func lintFile(_ *cli.Context, file string) error {
hasErrors = true
}

if data := err.GetLinterData(); data != nil {
if data := pipeline_errors.GetLinterData(err); data != nil {
line = fmt.Sprintf("%s %s\t%s", line, output.String(data.Field).Bold(), err.Message)
} else {
line = fmt.Sprintf("%s %s", line, err.Message)
Expand Down
80 changes: 40 additions & 40 deletions cmd/server/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3922,7 +3922,7 @@ const docTemplate = `{
"errors": {
"type": "array",
"items": {
"$ref": "#/definitions/errors.PipelineError"
"$ref": "#/definitions/types.PipelineError"
}
},
"event": {
Expand Down Expand Up @@ -4402,45 +4402,6 @@ const docTemplate = `{
"EventManual"
]
},
"errors.PipelineError": {
"type": "object",
"properties": {
"data": {},
"is_warning": {
"type": "boolean"
},
"message": {
"type": "string"
},
"type": {
"$ref": "#/definitions/errors.PipelineErrorType"
}
}
},
"errors.PipelineErrorType": {
"type": "string",
"enum": [
"linter",
"deprecation",
"compiler",
"generic",
"bad_habit"
],
"x-enum-comments": {
"PipelineErrorTypeBadHabit": "some bad-habit error",
"PipelineErrorTypeCompiler": "some error with the config semantics",
"PipelineErrorTypeDeprecation": "using some deprecated feature",
"PipelineErrorTypeGeneric": "some generic error",
"PipelineErrorTypeLinter": "some error with the config syntax"
},
"x-enum-varnames": [
"PipelineErrorTypeLinter",
"PipelineErrorTypeDeprecation",
"PipelineErrorTypeCompiler",
"PipelineErrorTypeGeneric",
"PipelineErrorTypeBadHabit"
]
},
"model.Workflow": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -4487,6 +4448,45 @@ const docTemplate = `{
"$ref": "#/definitions/StatusValue"
}
}
},
"types.PipelineError": {
"type": "object",
"properties": {
"data": {},
"is_warning": {
"type": "boolean"
},
"message": {
"type": "string"
},
"type": {
"$ref": "#/definitions/types.PipelineErrorType"
}
}
},
"types.PipelineErrorType": {
"type": "string",
"enum": [
"linter",
"deprecation",
"compiler",
"generic",
"bad_habit"
],
"x-enum-comments": {
"PipelineErrorTypeBadHabit": "some bad-habit error",
"PipelineErrorTypeCompiler": "some error with the config semantics",
"PipelineErrorTypeDeprecation": "using some deprecated feature",
"PipelineErrorTypeGeneric": "some generic error",
"PipelineErrorTypeLinter": "some error with the config syntax"
},
"x-enum-varnames": [
"PipelineErrorTypeLinter",
"PipelineErrorTypeDeprecation",
"PipelineErrorTypeCompiler",
"PipelineErrorTypeGeneric",
"PipelineErrorTypeBadHabit"
]
}
}
}`
Expand Down
8 changes: 4 additions & 4 deletions cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ var flags = append([]cli.Flag{
Usage: "Disable version check in admin web ui.",
Name: "skip-version-check",
},
&cli.StringSliceFlag{
EnvVars: []string{"WOODPECKER_ADDONS"},
Name: "addons",
Usage: "list of addon files",
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_ADDON_FORGE"},
Name: "addon-forge",
Usage: "forge addon",
},
//
// backend options for pipeline compiler
Expand Down
13 changes: 3 additions & 10 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/server"
"go.woodpecker-ci.org/woodpecker/v2/server/cache"
"go.woodpecker-ci.org/woodpecker/v2/server/forge"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/addon"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/bitbucket"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/bitbucketdatacenter"
"go.woodpecker-ci.org/woodpecker/v2/server/forge/gitea"
Expand All @@ -40,8 +41,6 @@ import (
"go.woodpecker-ci.org/woodpecker/v2/server/queue"
"go.woodpecker-ci.org/woodpecker/v2/server/store"
"go.woodpecker-ci.org/woodpecker/v2/server/store/datastore"
"go.woodpecker-ci.org/woodpecker/v2/shared/addon"
addonTypes "go.woodpecker-ci.org/woodpecker/v2/shared/addon/types"
)

func setupStore(c *cli.Context) (store.Store, error) {
Expand Down Expand Up @@ -107,15 +106,9 @@ func setupMembershipService(_ *cli.Context, r forge.Forge) cache.MembershipServi

// setupForge helper function to set up the forge from the CLI arguments.
func setupForge(c *cli.Context) (forge.Forge, error) {
addonForge, err := addon.Load[forge.Forge](c.StringSlice("addons"), addonTypes.TypeForge)
if err != nil {
return nil, err
}
if addonForge != nil {
return addonForge.Value, nil
}

switch {
case c.String("addon-forge") != "":
return addon.Load(c.String("addon-forge"))
case c.Bool("github"):
return setupGitHub(c)
case c.Bool("gitlab"):
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/10-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ kubectl apply -f $PLUGIN_TEMPLATE

```yaml title=".woodpecker.yaml"
steps:
deploy-to-k8s:
- name: deploy-to-k8s
image: laszlocloud/my-k8s-plugin
settings:
template: config/k8s/service.yaml
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/20-usage/51-plugins/20-creating-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ docker run --rm \
These should also be built for different OS/architectures.
- Use [built-in env vars](../50-environment.md#built-in-environment-variables) where possible.
- Do not use any configuration except settings (and internal env vars). This means: Don't require using [`environment`](../50-environment.md) and don't require specific secret names.
- Add a `docs.md` file, listing all your settings and plugin metadata ([example](https://codeberg.org/woodpecker-plugins/plugin-docker-buildx/src/branch/main/docs.md)).
- Add your plugin to the [plugin index](/plugins) using your `docs.md` ([the example above in the index](https://woodpecker-ci.org/plugins/Docker%20Buildx)).
- Add a `docs.md` file, listing all your settings and plugin metadata ([example](https://github.com/woodpecker-ci/plugin-git/blob/main/docs.md)).
- Add your plugin to the [plugin index](/plugins) using your `docs.md` ([the example above in the index](https://woodpecker-ci.org/plugins/Git%20Clone)).
12 changes: 5 additions & 7 deletions docs/docs/30-administration/10-server-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,6 @@ Supported variables:
- `owner`: the repo's owner
- `repo`: the repo's name

### `WOODPECKER_ADDONS`

> Default: empty

List of addon files. See [addons](./75-addons/75-overview.md).

---

### `WOODPECKER_LIMIT_MEM_SWAP`
Expand Down Expand Up @@ -559,4 +553,8 @@ See [Bitbucket configuration](./11-forges/50-bitbucket.md#configuration)

### `WOODPECKER_GITLAB_...`

See [Gitlab configuration](./11-forges/40-gitlab.md#configuration)
See [GitLab configuration](./11-forges/40-gitlab.md#configuration)

### `WOODPECKER_ADDON_FORGE`

See [addon forges](./11-forges/100-addon.md).
70 changes: 70 additions & 0 deletions docs/docs/30-administration/11-forges/100-addon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Addon forges

If the forge you're using does not comply with [Woodpecker's requirements](../../92-development/02-core-ideas.md#forge) or your setup is too specific to be added to Woodpecker's core, you can write your own forge using an addon forge.

:::warning
Addon forges are still experimental. Their implementation can change and break at any time.
:::

:::danger
You need to trust the author of the addon forge you use. It can access authentication codes and other possibly sensitive information.
:::

## Usage

To use an addon forge, download the correct addon version. Then, you can add the following to your configuration:

```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/`.

Using an addon forge always overwrites Woodpecker's internal forge configuration.

qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
### Bug reports

If you experience bugs, please check which component has the issue. If it's the addon, **do not raise an issue in the main repository**, but rather use the separate addon repositories. To check which component is responsible for the bug, look at the logs. Logs from addons are marked with a special field `addon` containing their addon file name.

## List of addon forges

If you wrote or found an addon forge, please add it here so others can find it!

_Be the first one to add your addon forge!_

## Creating addon forges

Addons use RPC to communicate to the server and are implemented using the [`go-plugin` library](https://github.com/hashicorp/go-plugin).

### Writing your code

This example will use the Go language.

Directly import Woodpecker's Go packages (`go.woodpecker-ci.org/woodpecker/woodpecker/v2`) and use the interfaces and types defined there.

In the `main` function, just call `"go.woodpecker-ci.org/woodpecker/v2/server/forge/addon".Serve` with a `"go.woodpecker-ci.org/woodpecker/v2/server/forge".Forge` as argument.
This will take care of connecting the addon forge to the server.

### Example structure

```go
package main

import (
"context"
"net/http"

"go.woodpecker-ci.org/woodpecker/v2/server/forge/addon"
forgeTypes "go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
"go.woodpecker-ci.org/woodpecker/v2/server/model"
)

func main() {
addon.Serve(config{})
}

type config struct {
}

// `config` must implement `"go.woodpecker-ci.org/woodpecker/v2/server/forge".Forge`. You must directly use Woodpecker's packages - see imports above.
```
35 changes: 17 additions & 18 deletions docs/docs/30-administration/11-forges/60-bitbucket_datacenter.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ Woodpecker comes with experimental support for Bitbucket Datacenter / Server, fo

To enable Bitbucket Server you should configure the Woodpecker container using the following environment variables:

```diff
# docker-compose.yml
version: '3'

services:
woodpecker-server:
[...]
environment:
- [...]
+ - WOODPECKER_BITBUCKET_DC=true
+ - WOODPECKER_BITBUCKET_DC_GIT_USERNAME=foo
+ - WOODPECKER_BITBUCKET_DC_GIT_PASSWORD=bar
+ - WOODPECKER_BITBUCKET_DC_CLIENT_ID=xxx
+ - WOODPECKER_BITBUCKET_DC_CLIENT_SECRET=yyy
+ - WOODPECKER_BITBUCKET_DC_URL=http://stash.mycompany.com

woodpecker-agent:
[...]
```diff title="docker-compose.yaml"
version: '3'

services:
woodpecker-server:
[...]
environment:
- [...]
+ - WOODPECKER_BITBUCKET_DC=true
+ - WOODPECKER_BITBUCKET_DC_GIT_USERNAME=foo
+ - WOODPECKER_BITBUCKET_DC_GIT_PASSWORD=bar
+ - WOODPECKER_BITBUCKET_DC_CLIENT_ID=xxx
+ - WOODPECKER_BITBUCKET_DC_CLIENT_SECRET=yyy
+ - WOODPECKER_BITBUCKET_DC_URL=http://stash.mycompany.com

woodpecker-agent:
[...]
```

## Service Account
Expand Down
Loading