mirror of https://github.com/harness/drone.git
add build link to envs while running pipelines (#773)
parent
f6c2826cd2
commit
d219d79395
|
@ -19,6 +19,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/harness/gitness/app/url"
|
||||
"github.com/harness/gitness/livelog"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
|
@ -28,16 +29,22 @@ import (
|
|||
)
|
||||
|
||||
type embedded struct {
|
||||
config *types.Config
|
||||
manager ExecutionManager
|
||||
config *types.Config
|
||||
urlProvider url.Provider
|
||||
manager ExecutionManager
|
||||
}
|
||||
|
||||
var _ client.Client = (*embedded)(nil)
|
||||
|
||||
func NewEmbeddedClient(manager ExecutionManager, config *types.Config) client.Client {
|
||||
func NewEmbeddedClient(
|
||||
manager ExecutionManager,
|
||||
urlProvider url.Provider,
|
||||
config *types.Config,
|
||||
) client.Client {
|
||||
return &embedded{
|
||||
config: config,
|
||||
manager: manager,
|
||||
config: config,
|
||||
urlProvider: urlProvider,
|
||||
manager: manager,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,8 +109,8 @@ func (e *embedded) Detail(ctx context.Context, stage *drone.Stage) (*client.Cont
|
|||
Config: ConvertToDroneFile(details.Config),
|
||||
Netrc: ConvertToDroneNetrc(details.Netrc),
|
||||
System: &drone.System{
|
||||
Proto: e.config.Server.HTTP.Proto,
|
||||
Host: "host.docker.internal",
|
||||
Proto: e.urlProvider.GetAPIProto(),
|
||||
Host: e.urlProvider.GetAPIHostname(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -209,18 +209,19 @@ func ConvertToDroneBuild(execution *types.Execution) *drone.Build {
|
|||
|
||||
func ConvertToDroneRepo(repo *types.Repository) *drone.Repo {
|
||||
return &drone.Repo{
|
||||
ID: repo.ID,
|
||||
Trusted: true, // as builds are running on user machines, the repo is marked trusted.
|
||||
UID: repo.UID,
|
||||
UserID: repo.CreatedBy,
|
||||
Name: repo.UID,
|
||||
HTTPURL: repo.GitURL,
|
||||
Link: repo.GitURL,
|
||||
Private: !repo.IsPublic,
|
||||
Created: repo.Created,
|
||||
Updated: repo.Updated,
|
||||
Version: repo.Version,
|
||||
Branch: repo.DefaultBranch,
|
||||
ID: repo.ID,
|
||||
Trusted: true, // as builds are running on user machines, the repo is marked trusted.
|
||||
UID: repo.UID,
|
||||
UserID: repo.CreatedBy,
|
||||
Namespace: repo.Path,
|
||||
Name: repo.UID,
|
||||
HTTPURL: repo.GitURL,
|
||||
Link: repo.GitURL,
|
||||
Private: !repo.IsPublic,
|
||||
Created: repo.Created,
|
||||
Updated: repo.Updated,
|
||||
Version: repo.Version,
|
||||
Branch: repo.DefaultBranch,
|
||||
// TODO: We can get this from configuration once we start populating it.
|
||||
// If this is not set drone runner cancels the build.
|
||||
Timeout: int64((10 * time.Hour).Seconds()),
|
||||
|
|
|
@ -56,6 +56,10 @@ func ProvideExecutionManager(
|
|||
|
||||
// ProvideExecutionClient provides a client implementation to interact with the execution manager.
|
||||
// We use an embedded client here.
|
||||
func ProvideExecutionClient(manager ExecutionManager, config *types.Config) client.Client {
|
||||
return NewEmbeddedClient(manager, config)
|
||||
func ProvideExecutionClient(
|
||||
manager ExecutionManager,
|
||||
urlProvider url.Provider,
|
||||
config *types.Config,
|
||||
) client.Client {
|
||||
return NewEmbeddedClient(manager, urlProvider, config)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright 2023 Harness, 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 triggerer
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/app/url"
|
||||
"github.com/harness/gitness/types"
|
||||
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
// combine is a helper function that combines one or more maps of
|
||||
// environment variables into a single map.
|
||||
func combine(env ...map[string]string) map[string]string {
|
||||
c := map[string]string{}
|
||||
for _, e := range env {
|
||||
maps.Copy(c, e)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
func Envs(
|
||||
repo *types.Repository,
|
||||
pipeline *types.Pipeline,
|
||||
urlProvider url.Provider,
|
||||
) map[string]string {
|
||||
return map[string]string{
|
||||
"DRONE_BUILD_LINK": urlProvider.GenerateUIBuildURL(repo.Path, pipeline.UID, pipeline.Seq),
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/harness/gitness/app/pipeline/scheduler"
|
||||
"github.com/harness/gitness/app/pipeline/triggerer/dag"
|
||||
"github.com/harness/gitness/app/store"
|
||||
"github.com/harness/gitness/app/url"
|
||||
"github.com/harness/gitness/store/database/dbtx"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
|
@ -82,6 +83,7 @@ type triggerer struct {
|
|||
tx dbtx.Transactor
|
||||
pipelineStore store.PipelineStore
|
||||
fileService file.Service
|
||||
urlProvider url.Provider
|
||||
scheduler scheduler.Scheduler
|
||||
repoStore store.RepoStore
|
||||
}
|
||||
|
@ -93,6 +95,7 @@ func New(
|
|||
pipelineStore store.PipelineStore,
|
||||
tx dbtx.Transactor,
|
||||
repoStore store.RepoStore,
|
||||
urlProvider url.Provider,
|
||||
scheduler scheduler.Scheduler,
|
||||
fileService file.Service,
|
||||
) Triggerer {
|
||||
|
@ -101,6 +104,7 @@ func New(
|
|||
checkStore: checkStore,
|
||||
stageStore: stageStore,
|
||||
scheduler: scheduler,
|
||||
urlProvider: urlProvider,
|
||||
tx: tx,
|
||||
pipelineStore: pipelineStore,
|
||||
fileService: fileService,
|
||||
|
@ -316,6 +320,7 @@ func (t *triggerer) Trigger(
|
|||
// TODO: this can be made better. We are setting this later since otherwise any parsing failure
|
||||
// would lead to an incremented pipeline sequence number.
|
||||
execution.Number = pipeline.Seq
|
||||
execution.Params = combine(execution.Params, Envs(repo, pipeline, t.urlProvider))
|
||||
|
||||
err = t.createExecutionWithStages(ctx, execution, stages)
|
||||
if err != nil {
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/harness/gitness/app/pipeline/file"
|
||||
"github.com/harness/gitness/app/pipeline/scheduler"
|
||||
"github.com/harness/gitness/app/store"
|
||||
"github.com/harness/gitness/app/url"
|
||||
"github.com/harness/gitness/store/database/dbtx"
|
||||
|
||||
"github.com/google/wire"
|
||||
|
@ -38,7 +39,8 @@ func ProvideTriggerer(
|
|||
fileService file.Service,
|
||||
scheduler scheduler.Scheduler,
|
||||
repoStore store.RepoStore,
|
||||
urlProvider url.Provider,
|
||||
) Triggerer {
|
||||
return New(executionStore, checkStore, stageStore, pipelineStore,
|
||||
tx, repoStore, scheduler, fileService)
|
||||
tx, repoStore, urlProvider, scheduler, fileService)
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -59,8 +60,14 @@ type Provider interface {
|
|||
// GetAPIHostname returns the host for the api endpoint.
|
||||
GetAPIHostname() string
|
||||
|
||||
// GenerateUIBuildURL returns the endpoint to use for viewing build executions.
|
||||
GenerateUIBuildURL(repoPath, pipelineUID string, seqNumber int64) string
|
||||
|
||||
// GetGITHostname returns the host for the git endpoint.
|
||||
GetGITHostname() string
|
||||
|
||||
// GetAPIProto returns the proto for the API hostname
|
||||
GetAPIProto() string
|
||||
}
|
||||
|
||||
// Provider provides the URLs of the gitness system.
|
||||
|
@ -154,6 +161,11 @@ func (p *provider) GenerateGITCloneURL(repoPath string) string {
|
|||
return p.gitURL.JoinPath(repoPath).String()
|
||||
}
|
||||
|
||||
func (p *provider) GenerateUIBuildURL(repoPath, pipelineUID string, seqNumber int64) string {
|
||||
return p.uiURL.JoinPath(repoPath, "pipelines",
|
||||
pipelineUID, "execution", strconv.Itoa(int(seqNumber))).String()
|
||||
}
|
||||
|
||||
func (p *provider) GenerateUIRepoURL(repoPath string) string {
|
||||
return p.uiURL.JoinPath(repoPath).String()
|
||||
}
|
||||
|
@ -173,3 +185,7 @@ func (p *provider) GetAPIHostname() string {
|
|||
func (p *provider) GetGITHostname() string {
|
||||
return p.gitURL.Hostname()
|
||||
}
|
||||
|
||||
func (p *provider) GetAPIProto() string {
|
||||
return p.apiURL.Scheme
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
cancelerCanceler := canceler.ProvideCanceler(executionStore, streamer, repoStore, schedulerScheduler, stageStore, stepStore)
|
||||
commitService := commit.ProvideService(gitrpcInterface)
|
||||
fileService := file.ProvideService(gitrpcInterface)
|
||||
triggererTriggerer := triggerer.ProvideTriggerer(executionStore, checkStore, stageStore, transactor, pipelineStore, fileService, schedulerScheduler, repoStore)
|
||||
triggererTriggerer := triggerer.ProvideTriggerer(executionStore, checkStore, stageStore, transactor, pipelineStore, fileService, schedulerScheduler, repoStore, provider)
|
||||
executionController := execution.ProvideController(transactor, authorizer, executionStore, checkStore, cancelerCanceler, commitService, triggererTriggerer, repoStore, stageStore, pipelineStore)
|
||||
logStore := logs.ProvideLogStore(db, config)
|
||||
logStream := livelog.ProvideLogStream()
|
||||
|
@ -249,7 +249,7 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||
routerRouter := router.ProvideRouter(apiHandler, gitHandler, webHandler, provider)
|
||||
serverServer := server2.ProvideServer(config, routerRouter)
|
||||
executionManager := manager.ProvideExecutionManager(config, executionStore, pipelineStore, provider, streamer, fileService, logStore, logStream, checkStore, repoStore, schedulerScheduler, secretStore, stageStore, stepStore, principalStore)
|
||||
client := manager.ProvideExecutionClient(executionManager, config)
|
||||
client := manager.ProvideExecutionClient(executionManager, provider, config)
|
||||
pluginManager := plugin2.ProvidePluginManager(config, pluginStore)
|
||||
runtimeRunner, err := runner.ProvideExecutionRunner(config, client, pluginManager)
|
||||
if err != nil {
|
||||
|
|
4
go.mod
4
go.mod
|
@ -13,7 +13,7 @@ require (
|
|||
github.com/bmatcuk/doublestar/v4 v4.6.0
|
||||
github.com/coreos/go-semver v0.3.0
|
||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
|
||||
github.com/drone-runners/drone-runner-docker v1.8.4-0.20231017141518-b8f2abebce54
|
||||
github.com/drone-runners/drone-runner-docker v1.8.4-0.20231106161015-8c0240291f1d
|
||||
github.com/drone/drone-go v1.7.1
|
||||
github.com/drone/drone-yaml v1.2.3
|
||||
github.com/drone/funcmap v0.0.0-20190918184546-d4ef6e88376d
|
||||
|
@ -71,6 +71,7 @@ require (
|
|||
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||
cloud.google.com/go/iam v1.1.0 // indirect
|
||||
dario.cat/mergo v1.0.0 // indirect
|
||||
github.com/99designs/basicauth-go v0.0.0-20160802081356-2a93ba0f464d // indirect
|
||||
github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e // indirect
|
||||
github.com/antonmedv/expr v1.15.2 // indirect
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
|
@ -85,6 +86,7 @@ require (
|
|||
github.com/docker/go-connections v0.4.0 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/drone/envsubst v1.0.3 // indirect
|
||||
github.com/drone/signal v1.0.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -17,6 +17,7 @@ code.gitea.io/gitea v1.17.2/go.mod h1:sovminOoSsc8IC2T29rX9+MmaboHTu8QDEvJjaSqIX
|
|||
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
|
||||
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
|
||||
docker.io/go-docker v1.0.0/go.mod h1:7tiAn5a0LFmjbPDbyTPOaTTOuG1ZRNXdPA6RvKY+fpY=
|
||||
github.com/99designs/basicauth-go v0.0.0-20160802081356-2a93ba0f464d h1:j6oB/WPCigdOkxtuPl1VSIiLpy7Mdsu6phQffbF19Ng=
|
||||
github.com/99designs/basicauth-go v0.0.0-20160802081356-2a93ba0f464d/go.mod h1:3cARGAK9CfW3HoxCy1a0G4TKrdiKke8ftOMEOHyySYs=
|
||||
github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e h1:rl2Aq4ZODqTDkeSqQBy+fzpZPamacO1Srp8zq7jf2Sc=
|
||||
github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e/go.mod h1:Xa6lInWHNQnuWoF0YPSsx+INFA9qk7/7pTjwb3PInkY=
|
||||
|
@ -149,6 +150,8 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
|
|||
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
github.com/drone-runners/drone-runner-docker v1.8.4-0.20231017141518-b8f2abebce54 h1:x/cUhafXzMsCA8OfUn1NyMSbzbDfqAP5zuT+D5tErD0=
|
||||
github.com/drone-runners/drone-runner-docker v1.8.4-0.20231017141518-b8f2abebce54/go.mod h1:iXTCJv+tESfI/ggWZwinI2ZAzHTGS+Ic5A9gcUElTns=
|
||||
github.com/drone-runners/drone-runner-docker v1.8.4-0.20231106161015-8c0240291f1d h1:ZJNxTUJzYxRkMzikX3eMbPrUxKGRVC9fNptTykwEN6c=
|
||||
github.com/drone-runners/drone-runner-docker v1.8.4-0.20231106161015-8c0240291f1d/go.mod h1:iXTCJv+tESfI/ggWZwinI2ZAzHTGS+Ic5A9gcUElTns=
|
||||
github.com/drone/drone-go v1.7.1 h1:ZX+3Rs8YHUSUQ5mkuMLmm1zr1ttiiE2YGNxF3AnyDKw=
|
||||
github.com/drone/drone-go v1.7.1/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg=
|
||||
github.com/drone/drone-runtime v1.0.7-0.20190729202838-87c84080f4a1/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs=
|
||||
|
@ -167,6 +170,7 @@ github.com/drone/go-scm v1.31.2 h1:6hZxf0aETV17830fMCPrgcA4y8j/8Gdfy0xEdInUeqQ=
|
|||
github.com/drone/go-scm v1.31.2/go.mod h1:DFIJJjhMj0TSXPz+0ni4nyZ9gtTtC40Vh/TGRugtyWw=
|
||||
github.com/drone/runner-go v1.12.0 h1:zUjDj9ylsJ4n4Mvy4znddq/Z4EBzcUXzTltpzokKtgs=
|
||||
github.com/drone/runner-go v1.12.0/go.mod h1:vu4pPPYDoeN6vdYQAY01GGGsAIW4aLganJNaa8Fx8zE=
|
||||
github.com/drone/signal v1.0.0 h1:NrnM2M/4yAuU/tXs6RP1a1ZfxnaHwYkd0kJurA1p6uI=
|
||||
github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc=
|
||||
github.com/drone/spec v0.0.0-20230919004456-7455b8913ff5 h1:NgAseJNQpJE3XtgJUPu4x7x5fcBjqZ3oKHDJfwBYdWk=
|
||||
github.com/drone/spec v0.0.0-20230919004456-7455b8913ff5/go.mod h1:KyQZA9qwuscbbM7yTrtZg25Wammoc5GKwaRem8kDA5k=
|
||||
|
|
Loading…
Reference in New Issue