teleport/dronegen/os_repos.go
Jakub Nyckowski 32673f7eca
Build version checker - multiple fixes (#30580)
* Build version checker - multiple fixes

In several files, the command 'go run' has been updated to 'CC=gcc go run'. This ensures that gcc is used when compiling the Go code, to provide better cross platform support. Prior to this change, the Go compiler was making platform specific builds.

This was a significant issue with the 'kube operator' goal where the built binary could not operate across different platforms.

The change has been applied consistently throughout the codebase in 'Makefile', 'container_image_triggers.go', 'version.mk', 'os_repos.go', and 'build.assets/Makefile' files. Compliance with this new standard should be maintained going forward for any new compilation requests.

* Update .drone.yml

* Replace CC=gcc environment variable with CGO_ENABLED=0

The CC=gcc environment variable was replaced with CGO_ENABLED=0 as CGO is not needed.

* Update .drone.yml
2023-08-16 23:26:41 +00:00

116 lines
3.9 KiB
Go

// 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"
"time"
)
type osPackageDeployment struct {
versionChannel string
packageNameFilter string
packageToTest string
displayName string
}
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",
},
// Rolling release pipelines
{
versionChannel: "rolling",
packageNameFilter: `$($DRONE_REPO_PRIVATE && echo "*ent*" || echo "")`,
packageToTest: "teleport-ent",
displayName: "Teleport",
},
}
return buildPromoteOsPackagePipelines(packageDeployments)
}
func buildPromoteOsPackagePipelines(packageDeployments []osPackageDeployment) pipeline {
releaseEnvironmentFilePath := "/go/vars/release-environment.txt"
clonePath := "/go/src/github.com/gravitational/teleport"
ghaBuild := ghaBuildType{
trigger: triggerPromote,
pipelineName: "publish-os-package-repos",
checkoutPath: clonePath,
workflows: buildWorkflows(releaseEnvironmentFilePath, packageDeployments),
enableParallelWorkflowRuns: true,
}
setupSteps := []step{
{
Name: "Determine if release should go to development or production",
Image: fmt.Sprintf("golang:%s-alpine", GoVersion),
Commands: []string{
fmt.Sprintf("cd %q", path.Join(clonePath, "build.assets", "tooling")),
fmt.Sprintf("mkdir -pv %q", path.Dir(releaseEnvironmentFilePath)),
fmt.Sprintf(`(CGO_ENABLED=0 go run ./cmd/check -tag ${DRONE_TAG} -check prerelease && echo "promote" || echo "build") > %q`, releaseEnvironmentFilePath),
},
},
}
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,
seriesRunFilter: fmt.Sprintf(".*%s.*", repoType),
inputs: inputs,
})
}
}
return workflows
}