2022-08-02 21:32:59 +00:00
|
|
|
// Copyright 2021 Gravitational, 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 (
|
|
|
|
"fmt"
|
|
|
|
"path"
|
2023-04-14 19:42:53 +00:00
|
|
|
"time"
|
2022-08-02 21:32:59 +00:00
|
|
|
)
|
|
|
|
|
2023-04-18 23:12:38 +00:00
|
|
|
type osPackageDeployment struct {
|
|
|
|
versionChannel string
|
|
|
|
packageNameFilter string
|
|
|
|
packageToTest string
|
|
|
|
displayName string
|
2022-08-02 21:32:59 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 23:12:38 +00:00
|
|
|
func promoteBuildOsRepoPipeline() pipeline {
|
|
|
|
packageDeployments := []osPackageDeployment{
|
|
|
|
// Normal release pipelines
|
|
|
|
{
|
|
|
|
versionChannel: "${DRONE_TAG}",
|
|
|
|
packageNameFilter: `$($DRONE_REPO_PRIVATE && echo "*ent*" || echo "")`,
|
|
|
|
packageToTest: "teleport-ent",
|
|
|
|
displayName: "Teleport",
|
|
|
|
},
|
|
|
|
// teleport-ent-updater to stable/cloud only pipelines
|
|
|
|
{
|
|
|
|
versionChannel: "cloud",
|
|
|
|
packageNameFilter: `teleport-ent-updater*`,
|
|
|
|
displayName: "teleport-ent-updater",
|
|
|
|
},
|
2023-08-08 04:52:03 +00:00
|
|
|
// Rolling release pipelines
|
|
|
|
{
|
|
|
|
versionChannel: "rolling",
|
|
|
|
packageNameFilter: `$($DRONE_REPO_PRIVATE && echo "*ent*" || echo "")`,
|
|
|
|
packageToTest: "teleport-ent",
|
|
|
|
displayName: "Teleport",
|
|
|
|
},
|
2022-08-02 21:32:59 +00:00
|
|
|
}
|
2023-04-18 23:12:38 +00:00
|
|
|
|
|
|
|
return buildPromoteOsPackagePipelines(packageDeployments)
|
2022-08-02 21:32:59 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 23:12:38 +00:00
|
|
|
func buildPromoteOsPackagePipelines(packageDeployments []osPackageDeployment) pipeline {
|
2023-04-14 19:42:53 +00:00
|
|
|
releaseEnvironmentFilePath := "/go/vars/release-environment.txt"
|
|
|
|
clonePath := "/go/src/github.com/gravitational/teleport"
|
|
|
|
|
2023-04-18 23:12:38 +00:00
|
|
|
ghaBuild := ghaBuildType{
|
2023-08-08 04:52:03 +00:00
|
|
|
trigger: triggerPromote,
|
|
|
|
pipelineName: "publish-os-package-repos",
|
|
|
|
checkoutPath: clonePath,
|
|
|
|
workflows: buildWorkflows(releaseEnvironmentFilePath, packageDeployments),
|
|
|
|
enableParallelWorkflowRuns: true,
|
2023-04-16 20:32:20 +00:00
|
|
|
}
|
2023-04-18 23:12:38 +00:00
|
|
|
setupSteps := []step{
|
2022-08-02 21:32:59 +00:00
|
|
|
{
|
2023-04-14 19:42:53 +00:00
|
|
|
Name: "Determine if release should go to development or production",
|
|
|
|
Image: fmt.Sprintf("golang:%s-alpine", GoVersion),
|
2022-08-02 21:32:59 +00:00
|
|
|
Commands: []string{
|
2023-04-14 19:42:53 +00:00
|
|
|
fmt.Sprintf("cd %q", path.Join(clonePath, "build.assets", "tooling")),
|
2023-04-15 15:10:01 +00:00
|
|
|
fmt.Sprintf("mkdir -pv %q", path.Dir(releaseEnvironmentFilePath)),
|
2023-08-16 23:26:41 +00:00
|
|
|
fmt.Sprintf(`(CGO_ENABLED=0 go run ./cmd/check -tag ${DRONE_TAG} -check prerelease && echo "promote" || echo "build") > %q`, releaseEnvironmentFilePath),
|
2022-08-02 21:32:59 +00:00
|
|
|
},
|
|
|
|
},
|
2022-10-21 06:23:21 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 23:12:38 +00:00
|
|
|
return ghaMultiBuildPipeline(setupSteps, ghaBuild)
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildWorkflows(releaseEnvironmentFilePath string, packageDeployments []osPackageDeployment) []ghaWorkflow {
|
|
|
|
repoTypes := []string{"apt", "yum"}
|
|
|
|
workflows := make([]ghaWorkflow, 0, len(repoTypes)*len(packageDeployments))
|
|
|
|
for _, packageDeployment := range packageDeployments {
|
|
|
|
for _, repoType := range repoTypes {
|
|
|
|
inputs := map[string]string{
|
|
|
|
"repo-type": repoType,
|
|
|
|
"environment": fmt.Sprintf("$(cat %q)", releaseEnvironmentFilePath),
|
|
|
|
"artifact-tag": "${DRONE_TAG}",
|
|
|
|
"release-channel": "stable",
|
|
|
|
"version-channel": packageDeployment.versionChannel,
|
|
|
|
"package-name-filter": packageDeployment.packageNameFilter,
|
|
|
|
}
|
|
|
|
|
|
|
|
if packageDeployment.packageToTest != "" {
|
|
|
|
inputs["package-to-test"] = packageDeployment.packageToTest
|
|
|
|
}
|
|
|
|
|
|
|
|
workflows = append(workflows, ghaWorkflow{
|
|
|
|
stepName: fmt.Sprintf("Publish %s to stable/%s %s repo", packageDeployment.displayName, packageDeployment.versionChannel, repoType),
|
|
|
|
name: "deploy-packages.yaml",
|
|
|
|
ref: "refs/heads/master",
|
|
|
|
timeout: 12 * time.Hour, // DR takes a long time
|
|
|
|
shouldTagWorkflow: true,
|
|
|
|
seriesRun: true,
|
2023-08-08 04:52:03 +00:00
|
|
|
seriesRunFilter: fmt.Sprintf(".*%s.*", repoType),
|
2023-04-18 23:12:38 +00:00
|
|
|
inputs: inputs,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return workflows
|
2022-08-02 21:32:59 +00:00
|
|
|
}
|