2019-02-19 23:56:41 +00:00
|
|
|
// Copyright 2019 Drone IO, Inc.
|
|
|
|
//
|
|
|
|
// 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 main
|
|
|
|
|
|
|
|
import (
|
2019-09-29 20:51:56 +00:00
|
|
|
"time"
|
|
|
|
|
2019-02-19 23:56:41 +00:00
|
|
|
"github.com/drone/drone/cmd/drone-server/config"
|
|
|
|
"github.com/drone/drone/core"
|
|
|
|
"github.com/drone/drone/livelog"
|
2019-03-05 07:16:53 +00:00
|
|
|
"github.com/drone/drone/metric/sink"
|
2019-02-19 23:56:41 +00:00
|
|
|
"github.com/drone/drone/pubsub"
|
2019-10-02 06:28:57 +00:00
|
|
|
"github.com/drone/drone/service/canceler"
|
2020-06-05 02:15:30 +00:00
|
|
|
"github.com/drone/drone/service/canceler/reaper"
|
2019-02-19 23:56:41 +00:00
|
|
|
"github.com/drone/drone/service/commit"
|
2019-09-21 00:08:25 +00:00
|
|
|
contents "github.com/drone/drone/service/content"
|
2019-02-19 23:56:41 +00:00
|
|
|
"github.com/drone/drone/service/content/cache"
|
|
|
|
"github.com/drone/drone/service/hook"
|
|
|
|
"github.com/drone/drone/service/hook/parser"
|
2019-09-21 00:08:25 +00:00
|
|
|
"github.com/drone/drone/service/linker"
|
2019-02-19 23:56:41 +00:00
|
|
|
"github.com/drone/drone/service/netrc"
|
2019-09-21 00:08:25 +00:00
|
|
|
orgs "github.com/drone/drone/service/org"
|
2019-02-19 23:56:41 +00:00
|
|
|
"github.com/drone/drone/service/repo"
|
|
|
|
"github.com/drone/drone/service/status"
|
|
|
|
"github.com/drone/drone/service/syncer"
|
|
|
|
"github.com/drone/drone/service/token"
|
2020-06-08 18:32:28 +00:00
|
|
|
"github.com/drone/drone/service/transfer"
|
2019-02-19 23:56:41 +00:00
|
|
|
"github.com/drone/drone/service/user"
|
|
|
|
"github.com/drone/drone/session"
|
|
|
|
"github.com/drone/drone/trigger"
|
|
|
|
"github.com/drone/drone/trigger/cron"
|
|
|
|
"github.com/drone/drone/version"
|
|
|
|
"github.com/drone/go-scm/scm"
|
|
|
|
|
|
|
|
"github.com/google/wire"
|
|
|
|
)
|
|
|
|
|
|
|
|
// wire set for loading the services.
|
|
|
|
var serviceSet = wire.NewSet(
|
2019-10-02 06:28:57 +00:00
|
|
|
canceler.New,
|
2019-02-19 23:56:41 +00:00
|
|
|
commit.New,
|
|
|
|
cron.New,
|
|
|
|
livelog.New,
|
2019-09-21 00:08:25 +00:00
|
|
|
linker.New,
|
2019-02-19 23:56:41 +00:00
|
|
|
parser.New,
|
|
|
|
pubsub.New,
|
|
|
|
token.Renewer,
|
2020-06-08 18:32:28 +00:00
|
|
|
transfer.New,
|
2019-02-19 23:56:41 +00:00
|
|
|
trigger.New,
|
|
|
|
user.New,
|
|
|
|
|
2019-09-11 03:16:19 +00:00
|
|
|
provideRepositoryService,
|
2019-02-19 23:56:41 +00:00
|
|
|
provideContentService,
|
2019-03-05 07:16:53 +00:00
|
|
|
provideDatadog,
|
2019-02-19 23:56:41 +00:00
|
|
|
provideHookService,
|
|
|
|
provideNetrcService,
|
2019-09-29 20:51:56 +00:00
|
|
|
provideOrgService,
|
2020-06-05 02:15:30 +00:00
|
|
|
provideReaper,
|
2019-02-19 23:56:41 +00:00
|
|
|
provideSession,
|
|
|
|
provideStatusService,
|
|
|
|
provideSyncer,
|
|
|
|
provideSystem,
|
|
|
|
)
|
|
|
|
|
|
|
|
// provideContentService is a Wire provider function that
|
|
|
|
// returns a contents service wrapped with a simple LRU cache.
|
|
|
|
func provideContentService(client *scm.Client, renewer core.Renewer) core.FileService {
|
|
|
|
return cache.Contents(
|
|
|
|
contents.New(client, renewer),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// provideHookService is a Wire provider function that returns a
|
|
|
|
// hook service based on the environment configuration.
|
|
|
|
func provideHookService(client *scm.Client, renewer core.Renewer, config config.Config) core.HookService {
|
|
|
|
return hook.New(client, config.Proxy.Addr, renewer)
|
|
|
|
}
|
|
|
|
|
|
|
|
// provideNetrcService is a Wire provider function that returns
|
|
|
|
// a netrc service based on the environment configuration.
|
|
|
|
func provideNetrcService(client *scm.Client, renewer core.Renewer, config config.Config) core.NetrcService {
|
|
|
|
return netrc.New(
|
|
|
|
client,
|
|
|
|
renewer,
|
|
|
|
config.Cloning.AlwaysAuth,
|
|
|
|
config.Cloning.Username,
|
|
|
|
config.Cloning.Password,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-09-29 20:51:56 +00:00
|
|
|
// provideOrgService is a Wire provider function that
|
|
|
|
// returns an organization service wrapped with a simple cache.
|
|
|
|
func provideOrgService(client *scm.Client, renewer core.Renewer) core.OrganizationService {
|
|
|
|
return orgs.NewCache(orgs.New(client, renewer), 10, time.Minute*5)
|
|
|
|
}
|
|
|
|
|
2019-09-11 03:16:19 +00:00
|
|
|
// provideRepo is a Wire provider function that returns
|
|
|
|
// a repo based on the environment configuration
|
|
|
|
func provideRepositoryService(client *scm.Client, renewer core.Renewer, config config.Config) core.RepositoryService {
|
|
|
|
return repo.New(
|
|
|
|
client,
|
|
|
|
renewer,
|
|
|
|
config.Repository.Visibility,
|
2019-09-12 06:46:07 +00:00
|
|
|
config.Repository.Trusted,
|
2019-09-11 03:16:19 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-02-19 23:56:41 +00:00
|
|
|
// provideSession is a Wire provider function that returns a
|
|
|
|
// user session based on the environment configuration.
|
2019-06-06 20:27:38 +00:00
|
|
|
func provideSession(store core.UserStore, config config.Config) (core.Session, error) {
|
2019-02-19 23:56:41 +00:00
|
|
|
return session.New(store, session.NewConfig(
|
|
|
|
config.Session.Secret,
|
2019-04-19 19:32:35 +00:00
|
|
|
config.Session.Timeout,
|
|
|
|
config.Session.Secure),
|
2019-06-06 20:27:38 +00:00
|
|
|
), nil
|
2019-02-19 23:56:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// provideUserService is a Wire provider function that returns a
|
|
|
|
// user service based on the environment configuration.
|
|
|
|
func provideStatusService(client *scm.Client, renewer core.Renewer, config config.Config) core.StatusService {
|
|
|
|
return status.New(client, renewer, status.Config{
|
|
|
|
Base: config.Server.Addr,
|
|
|
|
Name: config.Status.Name,
|
|
|
|
Disabled: config.Status.Disabled,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// provideSyncer is a Wire provider function that returns a
|
|
|
|
// repository synchronizer.
|
|
|
|
func provideSyncer(repoz core.RepositoryService,
|
|
|
|
repos core.RepositoryStore,
|
|
|
|
users core.UserStore,
|
|
|
|
batch core.Batcher,
|
|
|
|
config config.Config) core.Syncer {
|
|
|
|
sync := syncer.New(repoz, repos, users, batch)
|
|
|
|
// the user can define a filter that limits which
|
|
|
|
// repositories can be synchronized and stored in the
|
|
|
|
// database.
|
|
|
|
if filter := config.Repository.Filter; len(filter) > 0 {
|
|
|
|
sync.SetFilter(syncer.NamespaceFilter(filter))
|
|
|
|
}
|
|
|
|
return sync
|
|
|
|
}
|
|
|
|
|
|
|
|
// provideSyncer is a Wire provider function that returns the
|
|
|
|
// system details structure.
|
|
|
|
func provideSystem(config config.Config) *core.System {
|
|
|
|
return &core.System{
|
|
|
|
Proto: config.Server.Proto,
|
|
|
|
Host: config.Server.Host,
|
|
|
|
Link: config.Server.Addr,
|
|
|
|
Version: version.Version.String(),
|
|
|
|
}
|
|
|
|
}
|
2019-03-05 07:16:53 +00:00
|
|
|
|
2020-06-05 02:15:30 +00:00
|
|
|
// provideReaper is a Wire provider function that returns the
|
|
|
|
// zombie build reaper.
|
|
|
|
func provideReaper(
|
|
|
|
repos core.RepositoryStore,
|
|
|
|
builds core.BuildStore,
|
|
|
|
stages core.StageStore,
|
|
|
|
canceler core.Canceler,
|
|
|
|
config config.Config,
|
|
|
|
) *reaper.Reaper {
|
|
|
|
return reaper.New(
|
|
|
|
repos,
|
|
|
|
builds,
|
|
|
|
stages,
|
|
|
|
canceler,
|
|
|
|
config.Cleanup.Running,
|
|
|
|
config.Cleanup.Pending,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-03-05 07:16:53 +00:00
|
|
|
// provideDatadog is a Wire provider function that returns the
|
|
|
|
// datadog sink.
|
|
|
|
func provideDatadog(
|
|
|
|
users core.UserStore,
|
|
|
|
repos core.RepositoryStore,
|
|
|
|
builds core.BuildStore,
|
|
|
|
system *core.System,
|
2019-03-13 21:47:47 +00:00
|
|
|
license *core.License,
|
2019-03-05 07:16:53 +00:00
|
|
|
config config.Config,
|
|
|
|
) *sink.Datadog {
|
|
|
|
return sink.New(
|
|
|
|
users,
|
|
|
|
repos,
|
|
|
|
builds,
|
|
|
|
*system,
|
|
|
|
sink.Config{
|
2021-01-20 21:29:40 +00:00
|
|
|
Endpoint: config.Datadog.Endpoint,
|
|
|
|
Token: config.Datadog.Token,
|
|
|
|
License: license.Kind,
|
|
|
|
Licensor: license.Licensor,
|
|
|
|
Subscription: license.Subscription,
|
|
|
|
EnableGithub: config.IsGitHub(),
|
|
|
|
EnableGithubEnt: config.IsGitHubEnterprise(),
|
|
|
|
EnableGitlab: config.IsGitLab(),
|
|
|
|
EnableBitbucket: config.IsBitbucket(),
|
|
|
|
EnableStash: config.IsStash(),
|
|
|
|
EnableGogs: config.IsGogs(),
|
|
|
|
EnableGitea: config.IsGitea(),
|
2021-12-27 00:44:19 +00:00
|
|
|
EnableGitee: config.IsGitee(),
|
2021-01-20 21:29:40 +00:00
|
|
|
EnableAgents: !config.Agent.Disabled,
|
2019-03-05 07:16:53 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|