2022-10-18 01:24:12 +00:00
|
|
|
// Copyright 2022 Woodpecker Authors
|
2018-02-19 22:24:10 +00:00
|
|
|
// Copyright 2018 Drone.IO Inc.
|
2018-03-10 19:09:14 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// 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
|
2018-03-10 19:09:14 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-10 19:09:14 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// 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.
|
|
|
|
|
2017-06-29 22:51:22 +00:00
|
|
|
package main
|
2017-05-03 21:25:33 +00:00
|
|
|
|
|
|
|
import (
|
2021-11-25 16:15:36 +00:00
|
|
|
"context"
|
2022-06-01 18:06:27 +00:00
|
|
|
"crypto"
|
|
|
|
"crypto/ed25519"
|
|
|
|
"crypto/rand"
|
|
|
|
"encoding/hex"
|
2022-10-17 23:48:04 +00:00
|
|
|
"errors"
|
2017-06-28 17:21:22 +00:00
|
|
|
"fmt"
|
2021-12-11 12:15:04 +00:00
|
|
|
"net/url"
|
2021-10-28 19:02:43 +00:00
|
|
|
"os"
|
2021-12-11 12:15:04 +00:00
|
|
|
"strings"
|
2017-09-20 19:29:57 +00:00
|
|
|
"time"
|
2017-06-28 17:21:22 +00:00
|
|
|
|
2021-10-12 07:25:13 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
|
|
"github.com/rs/zerolog/log"
|
2021-10-27 19:03:14 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2021-10-12 07:25:13 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
|
2023-11-07 07:04:33 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/server"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/cache"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/forge"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/forge/bitbucket"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/forge/gitea"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/forge/github"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/forge/gitlab"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/model"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/plugins/environments"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/plugins/registry"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/plugins/secrets"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/queue"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/store"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/store/datastore"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/server/store/types"
|
2017-05-03 21:25:33 +00:00
|
|
|
)
|
|
|
|
|
2021-10-19 09:44:49 +00:00
|
|
|
func setupStore(c *cli.Context) (store.Store, error) {
|
2023-08-21 07:29:45 +00:00
|
|
|
// TODO: find a better way than global var to pass down to allow long migrations
|
|
|
|
server.Config.Server.Migrations.AllowLong = c.Bool("migrations-allow-long")
|
2021-10-30 12:53:24 +00:00
|
|
|
datasource := c.String("datasource")
|
|
|
|
driver := c.String("driver")
|
2023-07-14 23:15:13 +00:00
|
|
|
xorm := store.XORM{
|
|
|
|
Log: c.Bool("log-xorm"),
|
|
|
|
ShowSQL: c.Bool("log-xorm-sql"),
|
|
|
|
}
|
2021-10-30 12:53:24 +00:00
|
|
|
|
2021-11-13 19:18:06 +00:00
|
|
|
if driver == "sqlite3" {
|
|
|
|
if datastore.SupportedDriver("sqlite3") {
|
|
|
|
log.Debug().Msgf("server has sqlite3 support")
|
|
|
|
} else {
|
2022-10-18 01:24:12 +00:00
|
|
|
log.Debug().Msgf("server was built without sqlite3 support!")
|
2021-11-13 19:18:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !datastore.SupportedDriver(driver) {
|
|
|
|
log.Fatal().Msgf("database driver '%s' not supported", driver)
|
|
|
|
}
|
|
|
|
|
|
|
|
if driver == "sqlite3" {
|
2023-07-28 11:31:25 +00:00
|
|
|
if err := checkSqliteFileExist(datasource); err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("check sqlite file")
|
2021-10-30 12:53:24 +00:00
|
|
|
}
|
2021-10-28 19:02:43 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 19:18:06 +00:00
|
|
|
opts := &store.Opts{
|
2021-10-30 12:53:24 +00:00
|
|
|
Driver: driver,
|
|
|
|
Config: datasource,
|
2023-07-14 23:15:13 +00:00
|
|
|
XORM: xorm,
|
2021-10-19 09:44:49 +00:00
|
|
|
}
|
2021-11-13 19:18:06 +00:00
|
|
|
log.Trace().Msgf("setup datastore: %#v", *opts)
|
|
|
|
store, err := datastore.NewEngine(opts)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("could not open datastore")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := store.Migrate(); err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("could not migrate datastore")
|
|
|
|
}
|
|
|
|
|
|
|
|
return store, nil
|
2017-05-03 21:25:33 +00:00
|
|
|
}
|
|
|
|
|
2023-07-28 11:31:25 +00:00
|
|
|
func checkSqliteFileExist(path string) error {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
if err != nil && os.IsNotExist(err) {
|
|
|
|
log.Warn().Msgf("no sqlite3 file found, will create one at '%s'", path)
|
|
|
|
return nil
|
2021-10-30 12:53:24 +00:00
|
|
|
}
|
2023-07-28 11:31:25 +00:00
|
|
|
return err
|
2021-10-28 19:02:43 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 00:02:08 +00:00
|
|
|
func setupQueue(c *cli.Context, s store.Store) queue.Queue {
|
2021-12-11 12:15:04 +00:00
|
|
|
return queue.WithTaskStore(queue.New(c.Context), s)
|
2017-05-04 00:02:08 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 19:59:07 +00:00
|
|
|
func setupSecretService(c *cli.Context, s model.SecretStore) model.SecretService {
|
2021-12-11 12:15:04 +00:00
|
|
|
return secrets.New(c.Context, s)
|
2017-05-07 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setupRegistryService(c *cli.Context, s store.Store) model.RegistryService {
|
2020-05-19 12:44:16 +00:00
|
|
|
if c.String("docker-config") != "" {
|
|
|
|
return registry.Combined(
|
|
|
|
registry.New(s),
|
|
|
|
registry.Filesystem(c.String("docker-config")),
|
|
|
|
)
|
|
|
|
}
|
2021-12-01 13:22:06 +00:00
|
|
|
return registry.New(s)
|
2017-05-07 16:47:06 +00:00
|
|
|
}
|
|
|
|
|
2023-03-18 19:35:27 +00:00
|
|
|
func setupEnvironService(c *cli.Context, _ store.Store) model.EnvironService {
|
2022-02-23 07:59:52 +00:00
|
|
|
return environments.Parse(c.StringSlice("environment"))
|
2017-06-29 22:51:22 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
func setupMembershipService(_ *cli.Context, r forge.Forge) cache.MembershipService {
|
2022-07-25 01:09:35 +00:00
|
|
|
return cache.NewMembershipService(r)
|
|
|
|
}
|
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
// setupForge helper function to setup the forge from the CLI arguments.
|
|
|
|
func setupForge(c *cli.Context) (forge.Forge, error) {
|
2017-06-28 17:21:22 +00:00
|
|
|
switch {
|
|
|
|
case c.Bool("github"):
|
2022-11-09 07:12:17 +00:00
|
|
|
return setupGitHub(c)
|
2017-06-28 17:21:22 +00:00
|
|
|
case c.Bool("gitlab"):
|
Fix spelling: gitlab (#1411)
This is most of the GitLab changes that I dropped from #1405.
As before, I'm happy to adjust things...
<details><summary>Problematic Changes</summary>
Fwiw, this is the part that causes the tests to break (I don't
understand why, but I'm leaving this change out):
```patch
commit 703cbe3ed398bf32535120ead733b80aa145c8db
Author: Josh Soref <2119212+jsoref@users.noreply.github.com>
Date: Tue Nov 8 17:09:06 2022 -0500
event?! -- this seems broken
diff --git a/server/forge/gitlab/testdata/hooks.go b/server/forge/gitlab/testdata/hooks.go
index 7d39306..e394afc 100644
--- a/server/forge/gitlab/testdata/hooks.go
+++ b/server/forge/gitlab/testdata/hooks.go
@@ -27,7 +27,7 @@ var (
ServiceHookHeaders = http.Header{
"Content-Type": []string{"application/json"},
"User-Agent": []string{"GitLab/14.3.0"},
- "X-Gitlab-Event": []string{"Service Hook"},
+ "X-GitLab-Event": []string{"Service Hook"},
}
)
diff --git a/shared/token/token.go b/shared/token/token.go
index 3f15537..191e5ee 100644
--- a/shared/token/token.go
+++ b/shared/token/token.go
@@ -64,7 +64,7 @@ func ParseRequest(r *http.Request, fn SecretFunc) (*Token, error) {
return parse(bearer, fn)
}
- token = r.Header.Get("X-Gitlab-Token")
+ token = r.Header.Get("X-GitLab-Token")
if len(token) != 0 {
return parse(token, fn)
}
```
</details>
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
2022-11-09 16:16:17 +00:00
|
|
|
return setupGitLab(c)
|
2017-06-28 17:21:22 +00:00
|
|
|
case c.Bool("bitbucket"):
|
|
|
|
return setupBitbucket(c)
|
|
|
|
case c.Bool("gitea"):
|
|
|
|
return setupGitea(c)
|
|
|
|
default:
|
|
|
|
return nil, fmt.Errorf("version control system not configured")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-14 08:34:05 +00:00
|
|
|
// setupBitbucket helper function to setup the Bitbucket forge from the CLI arguments.
|
2022-11-04 23:35:06 +00:00
|
|
|
func setupBitbucket(c *cli.Context) (forge.Forge, error) {
|
2021-10-19 09:44:49 +00:00
|
|
|
opts := &bitbucket.Opts{
|
|
|
|
Client: c.String("bitbucket-client"),
|
|
|
|
Secret: c.String("bitbucket-secret"),
|
|
|
|
}
|
2022-11-04 23:35:06 +00:00
|
|
|
log.Trace().Msgf("Forge (bitbucket) opts: %#v", opts)
|
2021-10-19 09:44:49 +00:00
|
|
|
return bitbucket.New(opts)
|
2017-06-28 17:21:22 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 08:34:05 +00:00
|
|
|
// setupGitea helper function to setup the Gitea forge from the CLI arguments.
|
2022-11-04 23:35:06 +00:00
|
|
|
func setupGitea(c *cli.Context) (forge.Forge, error) {
|
2021-12-11 12:15:04 +00:00
|
|
|
server, err := url.Parse(c.String("gitea-server"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
Clean up config environment variables for server and agent (#218)
The goal here is to make consistent use of configuration environment variables prefixed `WOODPECKER_`. Where several variants existed, this PR aims to remove all but one option, leaving the most explicit.
This PR only changes server and agent code, but not documentation, in order to keep the PR digestible. Once we have consensus that this is correct, I'll change docs accordingly.
User (rather: admin) facing changes in this PR:
- In general, support for all server and agent config environment variables (env vars) starting with `DRONE_` is removed. The according `WOODPECKER_*` variables must be used instead.
- The env var `WOODPECKER_HOST` replaces `DRONE_HOST`, and `DRONE_SERVER_HOST`.
- The env var `WOODPECKER_AGENT_SECRET` is used to configure the shared secret which agents use to authenticate against the server. It replaces `WOODPECKER_SECRET`, `DRONE_SECRET`, `WOODPECKER_PASSWORD`, `DRONE_PASSWORD`, and `DRONE_AGENT_SECRET`.
- The env var `WOODPECKER_DATABASE_DRIVER` replaces `DRONE_DATABASE_DRIVER` and `DATABASE_DRIVER`.
- The env var `WOODPECKER_DATABASE_DATASOURCE` replaces `DRONE_DATABASE_DATASOURCE` and `DATABASE_CONFIG`.
2021-09-28 13:43:44 +00:00
|
|
|
opts := gitea.Opts{
|
2022-01-31 14:38:00 +00:00
|
|
|
URL: strings.TrimRight(server.String(), "/"),
|
|
|
|
Client: c.String("gitea-client"),
|
|
|
|
Secret: c.String("gitea-secret"),
|
|
|
|
SkipVerify: c.Bool("gitea-skip-verify"),
|
Clean up config environment variables for server and agent (#218)
The goal here is to make consistent use of configuration environment variables prefixed `WOODPECKER_`. Where several variants existed, this PR aims to remove all but one option, leaving the most explicit.
This PR only changes server and agent code, but not documentation, in order to keep the PR digestible. Once we have consensus that this is correct, I'll change docs accordingly.
User (rather: admin) facing changes in this PR:
- In general, support for all server and agent config environment variables (env vars) starting with `DRONE_` is removed. The according `WOODPECKER_*` variables must be used instead.
- The env var `WOODPECKER_HOST` replaces `DRONE_HOST`, and `DRONE_SERVER_HOST`.
- The env var `WOODPECKER_AGENT_SECRET` is used to configure the shared secret which agents use to authenticate against the server. It replaces `WOODPECKER_SECRET`, `DRONE_SECRET`, `WOODPECKER_PASSWORD`, `DRONE_PASSWORD`, and `DRONE_AGENT_SECRET`.
- The env var `WOODPECKER_DATABASE_DRIVER` replaces `DRONE_DATABASE_DRIVER` and `DATABASE_DRIVER`.
- The env var `WOODPECKER_DATABASE_DATASOURCE` replaces `DRONE_DATABASE_DATASOURCE` and `DATABASE_CONFIG`.
2021-09-28 13:43:44 +00:00
|
|
|
}
|
|
|
|
if len(opts.URL) == 0 {
|
2021-10-12 07:25:13 +00:00
|
|
|
log.Fatal().Msg("WOODPECKER_GITEA_URL must be set")
|
Clean up config environment variables for server and agent (#218)
The goal here is to make consistent use of configuration environment variables prefixed `WOODPECKER_`. Where several variants existed, this PR aims to remove all but one option, leaving the most explicit.
This PR only changes server and agent code, but not documentation, in order to keep the PR digestible. Once we have consensus that this is correct, I'll change docs accordingly.
User (rather: admin) facing changes in this PR:
- In general, support for all server and agent config environment variables (env vars) starting with `DRONE_` is removed. The according `WOODPECKER_*` variables must be used instead.
- The env var `WOODPECKER_HOST` replaces `DRONE_HOST`, and `DRONE_SERVER_HOST`.
- The env var `WOODPECKER_AGENT_SECRET` is used to configure the shared secret which agents use to authenticate against the server. It replaces `WOODPECKER_SECRET`, `DRONE_SECRET`, `WOODPECKER_PASSWORD`, `DRONE_PASSWORD`, and `DRONE_AGENT_SECRET`.
- The env var `WOODPECKER_DATABASE_DRIVER` replaces `DRONE_DATABASE_DRIVER` and `DATABASE_DRIVER`.
- The env var `WOODPECKER_DATABASE_DATASOURCE` replaces `DRONE_DATABASE_DATASOURCE` and `DATABASE_CONFIG`.
2021-09-28 13:43:44 +00:00
|
|
|
}
|
2022-11-04 23:35:06 +00:00
|
|
|
log.Trace().Msgf("Forge (gitea) opts: %#v", opts)
|
Clean up config environment variables for server and agent (#218)
The goal here is to make consistent use of configuration environment variables prefixed `WOODPECKER_`. Where several variants existed, this PR aims to remove all but one option, leaving the most explicit.
This PR only changes server and agent code, but not documentation, in order to keep the PR digestible. Once we have consensus that this is correct, I'll change docs accordingly.
User (rather: admin) facing changes in this PR:
- In general, support for all server and agent config environment variables (env vars) starting with `DRONE_` is removed. The according `WOODPECKER_*` variables must be used instead.
- The env var `WOODPECKER_HOST` replaces `DRONE_HOST`, and `DRONE_SERVER_HOST`.
- The env var `WOODPECKER_AGENT_SECRET` is used to configure the shared secret which agents use to authenticate against the server. It replaces `WOODPECKER_SECRET`, `DRONE_SECRET`, `WOODPECKER_PASSWORD`, `DRONE_PASSWORD`, and `DRONE_AGENT_SECRET`.
- The env var `WOODPECKER_DATABASE_DRIVER` replaces `DRONE_DATABASE_DRIVER` and `DATABASE_DRIVER`.
- The env var `WOODPECKER_DATABASE_DATASOURCE` replaces `DRONE_DATABASE_DATASOURCE` and `DATABASE_CONFIG`.
2021-09-28 13:43:44 +00:00
|
|
|
return gitea.New(opts)
|
2017-06-28 17:21:22 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 08:34:05 +00:00
|
|
|
// setupGitLab helper function to setup the GitLab forge from the CLI arguments.
|
Fix spelling: gitlab (#1411)
This is most of the GitLab changes that I dropped from #1405.
As before, I'm happy to adjust things...
<details><summary>Problematic Changes</summary>
Fwiw, this is the part that causes the tests to break (I don't
understand why, but I'm leaving this change out):
```patch
commit 703cbe3ed398bf32535120ead733b80aa145c8db
Author: Josh Soref <2119212+jsoref@users.noreply.github.com>
Date: Tue Nov 8 17:09:06 2022 -0500
event?! -- this seems broken
diff --git a/server/forge/gitlab/testdata/hooks.go b/server/forge/gitlab/testdata/hooks.go
index 7d39306..e394afc 100644
--- a/server/forge/gitlab/testdata/hooks.go
+++ b/server/forge/gitlab/testdata/hooks.go
@@ -27,7 +27,7 @@ var (
ServiceHookHeaders = http.Header{
"Content-Type": []string{"application/json"},
"User-Agent": []string{"GitLab/14.3.0"},
- "X-Gitlab-Event": []string{"Service Hook"},
+ "X-GitLab-Event": []string{"Service Hook"},
}
)
diff --git a/shared/token/token.go b/shared/token/token.go
index 3f15537..191e5ee 100644
--- a/shared/token/token.go
+++ b/shared/token/token.go
@@ -64,7 +64,7 @@ func ParseRequest(r *http.Request, fn SecretFunc) (*Token, error) {
return parse(bearer, fn)
}
- token = r.Header.Get("X-Gitlab-Token")
+ token = r.Header.Get("X-GitLab-Token")
if len(token) != 0 {
return parse(token, fn)
}
```
</details>
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
2022-11-09 16:16:17 +00:00
|
|
|
func setupGitLab(c *cli.Context) (forge.Forge, error) {
|
2017-06-28 17:21:22 +00:00
|
|
|
return gitlab.New(gitlab.Opts{
|
2021-10-03 12:42:47 +00:00
|
|
|
URL: c.String("gitlab-server"),
|
|
|
|
ClientID: c.String("gitlab-client"),
|
|
|
|
ClientSecret: c.String("gitlab-secret"),
|
|
|
|
SkipVerify: c.Bool("gitlab-skip-verify"),
|
2017-06-28 17:21:22 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-05-14 08:34:05 +00:00
|
|
|
// setupGitHub helper function to setup the GitHub forge from the CLI arguments.
|
2022-11-09 07:12:17 +00:00
|
|
|
func setupGitHub(c *cli.Context) (forge.Forge, error) {
|
2021-10-19 09:44:49 +00:00
|
|
|
opts := github.Opts{
|
2022-01-31 14:38:00 +00:00
|
|
|
URL: c.String("github-server"),
|
|
|
|
Client: c.String("github-client"),
|
|
|
|
Secret: c.String("github-secret"),
|
|
|
|
SkipVerify: c.Bool("github-skip-verify"),
|
|
|
|
MergeRef: c.Bool("github-merge-ref"),
|
2021-10-19 09:44:49 +00:00
|
|
|
}
|
2022-11-04 23:35:06 +00:00
|
|
|
log.Trace().Msgf("Forge (github) opts: %#v", opts)
|
2021-10-19 09:44:49 +00:00
|
|
|
return github.New(opts)
|
2017-06-28 17:21:22 +00:00
|
|
|
}
|
2017-06-29 22:51:22 +00:00
|
|
|
|
2021-12-01 13:22:06 +00:00
|
|
|
func setupMetrics(g *errgroup.Group, _store store.Store) {
|
2022-10-28 15:38:53 +00:00
|
|
|
pendingSteps := promauto.NewGauge(prometheus.GaugeOpts{
|
2021-10-13 06:34:57 +00:00
|
|
|
Namespace: "woodpecker",
|
2022-10-28 15:38:53 +00:00
|
|
|
Name: "pending_steps",
|
|
|
|
Help: "Total number of pending pipeline steps.",
|
2019-05-30 09:11:14 +00:00
|
|
|
})
|
2022-10-28 15:38:53 +00:00
|
|
|
waitingSteps := promauto.NewGauge(prometheus.GaugeOpts{
|
2021-10-13 06:34:57 +00:00
|
|
|
Namespace: "woodpecker",
|
2022-10-28 15:38:53 +00:00
|
|
|
Name: "waiting_steps",
|
2022-10-18 01:24:12 +00:00
|
|
|
Help: "Total number of pipeline waiting on deps.",
|
2019-07-10 08:00:38 +00:00
|
|
|
})
|
2022-10-28 15:38:53 +00:00
|
|
|
runningSteps := promauto.NewGauge(prometheus.GaugeOpts{
|
2021-10-13 06:34:57 +00:00
|
|
|
Namespace: "woodpecker",
|
2022-10-28 15:38:53 +00:00
|
|
|
Name: "running_steps",
|
|
|
|
Help: "Total number of running pipeline steps.",
|
2019-05-30 09:11:14 +00:00
|
|
|
})
|
|
|
|
workers := promauto.NewGauge(prometheus.GaugeOpts{
|
2021-10-13 06:34:57 +00:00
|
|
|
Namespace: "woodpecker",
|
2019-05-30 09:11:14 +00:00
|
|
|
Name: "worker_count",
|
|
|
|
Help: "Total number of workers.",
|
|
|
|
})
|
2022-10-18 01:24:12 +00:00
|
|
|
pipelines := promauto.NewGauge(prometheus.GaugeOpts{
|
2021-10-13 06:34:57 +00:00
|
|
|
Namespace: "woodpecker",
|
2022-10-18 01:24:12 +00:00
|
|
|
Name: "pipeline_total_count",
|
|
|
|
Help: "Total number of pipelines.",
|
2019-05-30 09:11:14 +00:00
|
|
|
})
|
|
|
|
users := promauto.NewGauge(prometheus.GaugeOpts{
|
2021-10-13 06:34:57 +00:00
|
|
|
Namespace: "woodpecker",
|
2019-05-30 09:11:14 +00:00
|
|
|
Name: "user_count",
|
|
|
|
Help: "Total number of users.",
|
|
|
|
})
|
|
|
|
repos := promauto.NewGauge(prometheus.GaugeOpts{
|
2021-10-13 06:34:57 +00:00
|
|
|
Namespace: "woodpecker",
|
2019-05-30 09:11:14 +00:00
|
|
|
Name: "repo_count",
|
|
|
|
Help: "Total number of repos.",
|
|
|
|
})
|
|
|
|
|
|
|
|
g.Go(func() error {
|
|
|
|
for {
|
2021-11-25 16:15:36 +00:00
|
|
|
stats := server.Config.Services.Queue.Info(context.TODO())
|
2022-10-28 15:38:53 +00:00
|
|
|
pendingSteps.Set(float64(stats.Stats.Pending))
|
|
|
|
waitingSteps.Set(float64(stats.Stats.WaitingOnDeps))
|
|
|
|
runningSteps.Set(float64(stats.Stats.Running))
|
2019-05-30 09:11:14 +00:00
|
|
|
workers.Set(float64(stats.Stats.Workers))
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
g.Go(func() error {
|
|
|
|
for {
|
2021-12-01 13:22:06 +00:00
|
|
|
repoCount, _ := _store.GetRepoCount()
|
|
|
|
userCount, _ := _store.GetUserCount()
|
2022-10-18 01:24:12 +00:00
|
|
|
pipelineCount, _ := _store.GetPipelineCount()
|
|
|
|
pipelines.Set(float64(pipelineCount))
|
2019-05-30 09:11:14 +00:00
|
|
|
users.Set(float64(userCount))
|
|
|
|
repos.Set(float64(repoCount))
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-06-01 18:06:27 +00:00
|
|
|
|
2023-05-14 08:34:05 +00:00
|
|
|
// setupSignatureKeys generate or load key pair to sign webhooks requests (i.e. used for extensions)
|
2022-06-01 18:06:27 +00:00
|
|
|
func setupSignatureKeys(_store store.Store) (crypto.PrivateKey, crypto.PublicKey) {
|
|
|
|
privKeyID := "signature-private-key"
|
|
|
|
|
|
|
|
privKey, err := _store.ServerConfigGet(privKeyID)
|
2022-10-17 23:48:04 +00:00
|
|
|
if errors.Is(err, types.RecordNotExist) {
|
2022-06-01 18:06:27 +00:00
|
|
|
_, privKey, err := ed25519.GenerateKey(rand.Reader)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msgf("Failed to generate private key")
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
err = _store.ServerConfigSet(privKeyID, hex.EncodeToString(privKey))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msgf("Failed to generate private key")
|
|
|
|
return nil, nil
|
|
|
|
}
|
2022-09-03 18:41:23 +00:00
|
|
|
log.Debug().Msg("Created private key")
|
2022-06-01 18:06:27 +00:00
|
|
|
return privKey, privKey.Public()
|
|
|
|
} else if err != nil {
|
|
|
|
log.Fatal().Err(err).Msgf("Failed to load private key")
|
|
|
|
return nil, nil
|
|
|
|
}
|
2023-10-23 06:45:34 +00:00
|
|
|
privKeyStr, err := hex.DecodeString(privKey)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Msgf("Failed to decode private key")
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
privateKey := ed25519.PrivateKey(privKeyStr)
|
|
|
|
return privateKey, privateKey.Public()
|
2022-06-01 18:06:27 +00:00
|
|
|
}
|