diff --git a/doc/dependency_decisions.yml b/doc/dependency_decisions.yml index 35678fcc866..aa56e661768 100644 --- a/doc/dependency_decisions.yml +++ b/doc/dependency_decisions.yml @@ -325,6 +325,12 @@ :when: 2020-08-12 08:03:13.360476000 Z - - :permit - CC-BY-4.0 - - :who: + - :who: :why: Used by caniuse-lite :when: 2020-09-23 12:14:34.205000000 Z +- - :ignore + - "./enterprise/dev/ci/images" + - :who: + :why: Internal module + :versions: [] + :when: 2020-11-29 06:02:35.623296000 Z diff --git a/enterprise/dev/ci/ci/helpers.go b/enterprise/dev/ci/ci/helpers.go index 441bfe956b1..f6cc961bccb 100644 --- a/enterprise/dev/ci/ci/helpers.go +++ b/enterprise/dev/ci/ci/helpers.go @@ -9,6 +9,7 @@ import ( "time" "github.com/hashicorp/go-multierror" + "github.com/sourcegraph/sourcegraph/enterprise/dev/ci/images" "github.com/sourcegraph/sourcegraph/internal/lazyregexp" ) @@ -166,3 +167,12 @@ func (c Config) isGoOnly() bool { func (c Config) shouldRunE2EandQA() bool { return c.releaseBranch || c.taggedRelease || c.isBextReleaseBranch || c.patch || c.branch == "main" } + +// candidateImageTag provides the tag for a candidate image built for this Buildkite run. +// +// Note that the availability of this image depends on whether a candidate gets built, +// as determined in `addDockerImages()`. +func (c Config) candidateImageTag() string { + buildNumber := os.Getenv("BUILDKITE_BUILD_NUMBER") + return images.CandidateImageTag(c.commit, buildNumber) +} diff --git a/enterprise/dev/ci/ci/pipeline-steps.go b/enterprise/dev/ci/ci/pipeline-steps.go index 89e052eac79..fa4aab6036a 100644 --- a/enterprise/dev/ci/ci/pipeline-steps.go +++ b/enterprise/dev/ci/ci/pipeline-steps.go @@ -6,6 +6,7 @@ import ( "path/filepath" "strings" + "github.com/sourcegraph/sourcegraph/enterprise/dev/ci/images" bk "github.com/sourcegraph/sourcegraph/internal/buildkite" ) @@ -256,13 +257,13 @@ func triggerE2EandQA(c Config, commonEnv map[string]string) func(*bk.Pipeline) { // Set variables that indicate the tag for 'us.gcr.io/sourcegraph-dev' images built // from this CI run's commit, and credentials to access them. - env["CANDIDATE_VERSION"] = candidateImageTag(c) + env["CANDIDATE_VERSION"] = c.candidateImageTag() env["VAGRANT_SERVICE_ACCOUNT"] = "buildkite@sourcegraph-ci.iam.gserviceaccount.com" // Test upgrades from mininum upgradeable Sourcegraph version env["MINIMUM_UPGRADEABLE_VERSION"] = "3.20.0" - env["DOCKER_CLUSTER_IMAGES_TXT"] = clusterDockerImages(SourcegraphDockerImages) + env["DOCKER_CLUSTER_IMAGES_TXT"] = clusterDockerImages(images.SourcegraphDockerImages) return func(pipeline *bk.Pipeline) { if !c.shouldRunE2EandQA() { @@ -322,25 +323,25 @@ func addDockerImages(c Config, final bool) func(*bk.Pipeline) { switch { // build all images for tagged releases case c.taggedRelease: - for _, dockerImage := range SourcegraphDockerImages { + for _, dockerImage := range images.SourcegraphDockerImages { addDockerImage(c, dockerImage, false)(pipeline) } // replicates `main` build but does not deploy `insiders` images case c.isMasterDryRun: - for _, dockerImage := range SourcegraphDockerImages { + for _, dockerImage := range images.SourcegraphDockerImages { addDockerImage(c, dockerImage, false)(pipeline) } // deploy `insiders` images for `main` case c.branch == "main": - for _, dockerImage := range SourcegraphDockerImages { + for _, dockerImage := range images.SourcegraphDockerImages { addDockerImage(c, dockerImage, true)(pipeline) } // ensure candidate images are available for testing case c.shouldRunE2EandQA(): - for _, dockerImage := range SourcegraphDockerImages { + for _, dockerImage := range images.SourcegraphDockerImages { addDockerImage(c, dockerImage, false)(pipeline) } @@ -386,8 +387,8 @@ func addCandidateDockerImage(c Config, app string) func(*bk.Pipeline) { cmds = append(cmds, bk.Cmd(cmdDir+"/build.sh")) } - devImage := fmt.Sprintf("%s/%s", SourcegraphDockerDevRegistry, image) - devTag := candidateImageTag(c) + devImage := fmt.Sprintf("%s/%s", images.SourcegraphDockerDevRegistry, image) + devTag := c.candidateImageTag() cmds = append(cmds, // Retag the local image for dev registry bk.Cmd(fmt.Sprintf("docker tag %s %s:%s", localImage, devImage, devTag)), @@ -404,8 +405,8 @@ func addCandidateDockerImage(c Config, app string) func(*bk.Pipeline) { func addFinalDockerImage(c Config, app string, insiders bool) func(*bk.Pipeline) { return func(pipeline *bk.Pipeline) { image := strings.ReplaceAll(app, "/", "-") - devImage := fmt.Sprintf("%s/%s", SourcegraphDockerDevRegistry, image) - publishImage := fmt.Sprintf("%s/%s", SourcegraphDockerPublishRegistry, image) + devImage := fmt.Sprintf("%s/%s", images.SourcegraphDockerDevRegistry, image) + publishImage := fmt.Sprintf("%s/%s", images.SourcegraphDockerPublishRegistry, image) var images []string for _, image := range []string{publishImage, devImage} { @@ -422,7 +423,7 @@ func addFinalDockerImage(c Config, app string, insiders bool) func(*bk.Pipeline) } } - candidateImage := fmt.Sprintf("%s:%s", devImage, candidateImageTag(c)) + candidateImage := fmt.Sprintf("%s:%s", devImage, c.candidateImageTag()) cmd := fmt.Sprintf("./dev/ci/docker-publish.sh %s %s", candidateImage, strings.Join(images, " ")) pipeline.AddStep(fmt.Sprintf(":docker: :white_check_mark: %s", app), bk.Cmd(cmd)) diff --git a/enterprise/dev/ci/images/go.mod b/enterprise/dev/ci/images/go.mod new file mode 100644 index 00000000000..7f2756d1400 --- /dev/null +++ b/enterprise/dev/ci/images/go.mod @@ -0,0 +1,3 @@ +module github.com/sourcegraph/sourcegraph/enterprise/dev/ci/images + +go 1.14 diff --git a/enterprise/dev/ci/ci/images.go b/enterprise/dev/ci/images/images.go similarity index 78% rename from enterprise/dev/ci/ci/images.go rename to enterprise/dev/ci/images/images.go index e241be03bff..cbee92b16f1 100644 --- a/enterprise/dev/ci/ci/images.go +++ b/enterprise/dev/ci/images/images.go @@ -1,8 +1,13 @@ -package ci +/* +Package images describes the publishing scheme for Sourcegraph images. + +It is published as a standalone module to enable tooling in other repositories to more +easily use these definitions. +*/ +package images import ( "fmt" - "os" ) const ( @@ -52,11 +57,10 @@ var SourcegraphDockerImages = []string{ "minio", } -// candidateImageTag provides the tag for a candidate image built for this Buildkite run. +// CandidateImageTag provides the tag for a candidate image built for this Buildkite run. // // Note that the availability of this image depends on whether a candidate gets built, // as determined in `addDockerImages()`. -func candidateImageTag(c Config) string { - buildNumber := os.Getenv("BUILDKITE_BUILD_NUMBER") - return fmt.Sprintf("%s_%s_candidate", c.commit, buildNumber) +func CandidateImageTag(commit, buildNumber string) string { + return fmt.Sprintf("%s_%s_candidate", commit, buildNumber) } diff --git a/go.mod b/go.mod index 940396ddeb2..bd3ec4060e8 100644 --- a/go.mod +++ b/go.mod @@ -160,6 +160,7 @@ require ( github.com/sourcegraph/go-lsp v0.0.0-20200429204803-219e11d77f5d github.com/sourcegraph/gosyntect v0.0.0-20200429204402-842ed26129d0 github.com/sourcegraph/jsonx v0.0.0-20200629203448-1a936bd500cf + github.com/sourcegraph/sourcegraph/enterprise/dev/ci/images v0.0.0-00010101000000-000000000000 github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/src-d/enry/v2 v2.1.0 @@ -230,3 +231,5 @@ replace github.com/golang/lint => golang.org/x/lint v0.0.0-20191125180803-fdd1cd // See: https://github.com/ghodss/yaml/pull/65 replace github.com/ghodss/yaml => github.com/sourcegraph/yaml v1.0.1-0.20200714132230-56936252f152 + +replace github.com/sourcegraph/sourcegraph/enterprise/dev/ci/images => ./enterprise/dev/ci/images