Skip to content

Commit

Permalink
Merge pull request #975 from krancour/build-clone-url
Browse files Browse the repository at this point in the history
add support for optional build-level cloneURL field
  • Loading branch information
krancour authored Aug 12, 2019
2 parents 11e4239 + c2d8043 commit a421d31
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 10 deletions.
11 changes: 10 additions & 1 deletion brigade-controller/cmd/brigade-controller/controller/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ func workerEnv(project, build *v1.Secret, config *Config) []v1.EnvVar {
serviceAccount = string(project.Data["serviceAccount"])
}

// Try to get cloneURL from the build first. This allows gateways to override
// the project-level cloneURL if the commit that should be built, for
// instance, exists only within a fork. If this isn't set at the build-level,
// fall back to the project-level default.
cloneURL := bsv.String("clone_url")
if cloneURL == "" {
cloneURL = string(project.Data["cloneURL"])
}

envs := []v1.EnvVar{
{Name: "CI", Value: "true"},
{Name: "BRIGADE_BUILD_ID", Value: build.Labels["build"]},
Expand All @@ -255,7 +264,7 @@ func workerEnv(project, build *v1.Secret, config *Config) []v1.EnvVar {
{Name: "BRIGADE_EVENT_TYPE", Value: bsv.String("event_type")},
{Name: "BRIGADE_PROJECT_ID", Value: bsv.String("project_id")},
{Name: "BRIGADE_LOG_LEVEL", Value: bsv.String("log_level")},
{Name: "BRIGADE_REMOTE_URL", Value: string(project.Data["cloneURL"])},
{Name: "BRIGADE_REMOTE_URL", Value: cloneURL},
{Name: "BRIGADE_WORKSPACE", Value: "/vcs"},
{Name: "BRIGADE_PROJECT_NAMESPACE", Value: build.Namespace},
{Name: "BRIGADE_SERVICE_ACCOUNT", Value: serviceAccount},
Expand Down
4 changes: 2 additions & 2 deletions brigade-worker/node_modules/.yarn-integrity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion brigade-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"typescript": "^3.2.2"
},
"dependencies": {
"@brigadecore/brigadier": "^0.6.1",
"@brigadecore/brigadier": "^0.8.0",
"@kubernetes/client-node": "^0.10.1",
"byline": "^5.0.0",
"child-process-promise": "^2.2.1",
Expand Down
4 changes: 4 additions & 0 deletions brigade-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* - `BRIGADE_EVENT_PROVIDER`: The name of the event provider, such as `github` or `dockerhub`
* - `BRIGADE_PROJECT_ID`: The project ID. This is used to load the Project
* object from configuration.
* - `BRIGADE_REMOTE_URL`: The URL from which to obtain source code to be built.
* This is optional. If left unset by the controller, the worker will fall
* back to a project-level URL.
* - `BRIGADE_COMMIT_ID`: The VCS commit ID (e.g. the Git commit)
* - `BRIGADE_COMMIT_REF`: The VCS full reference, defaults to
* `refs/heads/master`
Expand Down Expand Up @@ -107,6 +110,7 @@ let e: events.BrigadeEvent = {
workerID: process.env.BRIGADE_BUILD_NAME || `unknown-${defaultULID}`,
type: process.env.BRIGADE_EVENT_TYPE || "ping",
provider: process.env.BRIGADE_EVENT_PROVIDER || "unknown",
cloneURL: process.env.BRIGADE_REMOTE_URL,
revision: {
commit: process.env.BRIGADE_COMMIT_ID,
ref: process.env.BRIGADE_COMMIT_REF
Expand Down
11 changes: 10 additions & 1 deletion brigade-worker/src/k8s.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,15 @@ function sidecarSpec(
imageTag = "brigadecore/git-sidecar:latest";
}

// Try to get cloneURL from the event first. This allows gateways to override
// the project-level cloneURL if the commit that should be built, for
// instance, exists only within a fork. If this isn't set at the event-level,
// fall back to the project-level default.
let cloneURL = e.cloneURL;
if (cloneURL == "") {
cloneURL = project.repo.cloneURL
}

let spec = new kubernetes.V1Container();
(spec.name = "vcs-sidecar"),
(spec.env = [
Expand All @@ -849,7 +858,7 @@ function sidecarSpec(
envVar("BRIGADE_EVENT_PROVIDER", e.provider),
envVar("BRIGADE_EVENT_TYPE", e.type),
envVar("BRIGADE_PROJECT_ID", project.id),
envVar("BRIGADE_REMOTE_URL", project.repo.cloneURL),
envVar("BRIGADE_REMOTE_URL", cloneURL),
envVar("BRIGADE_WORKSPACE", local),
envVar("BRIGADE_PROJECT_NAMESPACE", project.kubernetes.namespace),
envVar("BRIGADE_SUBMODULES", initGitSubmodules.toString()),
Expand Down
8 changes: 4 additions & 4 deletions brigade-worker/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@brigadecore/brigadier@^0.6.1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@brigadecore/brigadier/-/brigadier-0.6.1.tgz#deb4174de9314c5997521a1b3e2a7c6bcfeddc68"
integrity sha512-95U96JnRhobKZUMJtTVtT0+EWQ8zgJw7MAFYdzd0K4ajkGZAahJdXGbFrey4R3JZbcJZhwCh3Ny+pLP7EjLgCQ==
"@brigadecore/brigadier@^0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@brigadecore/brigadier/-/brigadier-0.8.0.tgz#8ef41ff5ee13a18a8fbe7c8621fa39d21bc7e266"
integrity sha512-lZWDpuVAwrcYFpbNlAjwjsEGom2KEAxg3xAR+BZT9h7Syd8Nu2KIVBKs8sfKgEl1Fhy4DWhg+m2QZMa4sXjwxg==
dependencies:
"@kubernetes/client-node" "^0.10.1"
child-process-promise "^2.2.1"
Expand Down
4 changes: 4 additions & 0 deletions pkg/brigade/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type Build struct {
Type string `json:"type"`
// Provider is the name of the service that caused the event (github, vsts, cron, ...)
Provider string `json:"provider"`
// CloneURL is the URL at which the repository can be cloned.
// This is optional at the build-level. If set, it overrides the same setting
// at the projet-level.
CloneURL string `json:"clone_url"`
// Revision describes a vcs revision.
Revision *Revision `json:"revision"`
// Payload is the raw data as received by the webhook.
Expand Down
2 changes: 2 additions & 0 deletions pkg/storage/kube/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (s *store) CreateBuild(build *brigade.Build) error {
StringData: map[string]string{
"build_id": buildName,
"build_name": buildName,
"clone_url": build.CloneURL,
"commit_id": build.Revision.Commit,
"commit_ref": build.Revision.Ref,
"event_provider": build.Provider,
Expand Down Expand Up @@ -203,6 +204,7 @@ func NewBuildFromSecret(secret v1.Secret) *brigade.Build {
ProjectID: lbs["project"],
Type: sv.String("event_type"),
Provider: sv.String("event_provider"),
CloneURL: sv.String("clone_url"),
Revision: &brigade.Revision{
Commit: sv.String("commit_id"),
Ref: sv.String("commit_ref"),
Expand Down

0 comments on commit a421d31

Please sign in to comment.