Release pipeline improvements (#10707)

This commit is contained in:
Justinas Stankevičius
2022-04-06 16:35:45 +03:00
committed by GitHub
parent 8b00134036
commit b24b561560
5 changed files with 659 additions and 263 deletions
+544 -244
View File
File diff suppressed because it is too large Load Diff
+76
View File
@@ -19,6 +19,7 @@ import (
"fmt"
"log"
"os/exec"
"strings"
)
var (
@@ -86,6 +87,81 @@ type buildType struct {
windowsUnsigned bool
}
// Description provides a human-facing description of the artifact, e.g.:
// Windows 64-bit (tsh client only)
// Linux ARMv7 (32-bit)
// MacOS Intel .pkg installer
func (b *buildType) Description(packageType string, extraQualifications ...string) string {
var result string
var os string
var arch string
var darwinArch string
var bitness int
var qualifications []string
switch b.os {
case "linux":
os = "Linux"
case "darwin":
os = "MacOS"
case "windows":
os = "Windows"
default:
panic(fmt.Sprintf("unhandled OS: %s", b.os))
}
switch b.arch {
case "arm64":
arch = "ARM64/ARMv8"
darwinArch = "Apple Silicon"
bitness = 64
case "amd64":
darwinArch = "Intel"
bitness = 64
case "arm":
arch = "ARMv7"
fallthrough
case "386":
bitness = 32
default:
panic(fmt.Sprintf("unhandled arch: %s", b.arch))
}
if b.centos7 {
qualifications = append(qualifications, "RHEL/CentOS 7.x compatible")
}
if b.fips {
qualifications = append(qualifications, "FedRAMP/FIPS")
}
qualifications = append(qualifications, extraQualifications...)
result = os
if b.os == "darwin" {
result += fmt.Sprintf(" %s", darwinArch)
} else {
// arch is implicit for Windows/Linux i386/amd64
if arch == "" {
result += fmt.Sprintf(" %d-bit", bitness)
} else {
result += fmt.Sprintf(" %s (%d-bit)", arch, bitness)
}
}
if packageType != "" {
result += fmt.Sprintf(" %s", packageType)
}
if len(qualifications) > 0 {
result += fmt.Sprintf(" (%s)", strings.Join(qualifications, ", "))
}
return result
}
// dockerService generates a docker:dind service
// It includes the Docker socket volume by default, plus any extra volumes passed in
func dockerService(v ...volumeRef) service {
+1 -1
View File
@@ -136,7 +136,7 @@ func darwinTagPipeline() pipeline {
},
{
Name: "Register artifacts",
Commands: tagCreateReleaseAssetCommands(b),
Commands: tagCreateReleaseAssetCommands(b, "", nil),
Failure: "ignore",
Environment: map[string]value{
"WORKSPACE_DIR": {raw: p.Workspace.Path},
+4 -4
View File
@@ -20,7 +20,7 @@ import (
"strings"
)
func darwinPkgPipeline(name, makeTarget string, pkgGlobs []string) pipeline {
func darwinPkgPipeline(name, makeTarget string, pkgGlobs []string, extraQualifications []string) pipeline {
b := buildType{
arch: "amd64",
os: "darwin",
@@ -88,7 +88,7 @@ func darwinPkgPipeline(name, makeTarget string, pkgGlobs []string) pipeline {
},
{
Name: "Register artifacts",
Commands: tagCreateReleaseAssetCommands(b),
Commands: tagCreateReleaseAssetCommands(b, ".pkg installer", extraQualifications),
Failure: "ignore",
Environment: map[string]value{
"WORKSPACE_DIR": {raw: p.Workspace.Path},
@@ -103,11 +103,11 @@ func darwinPkgPipeline(name, makeTarget string, pkgGlobs []string) pipeline {
}
func darwinTeleportPkgPipeline() pipeline {
return darwinPkgPipeline("build-darwin-amd64-pkg", "pkg", []string{"build/teleport*.pkg", "e/build/teleport-ent*.pkg"})
return darwinPkgPipeline("build-darwin-amd64-pkg", "pkg", []string{"build/teleport*.pkg", "e/build/teleport-ent*.pkg"}, nil)
}
func darwinTshPkgPipeline() pipeline {
return darwinPkgPipeline("build-darwin-amd64-pkg-tsh", "pkg-tsh", []string{"build/tsh*.pkg"})
return darwinPkgPipeline("build-darwin-amd64-pkg-tsh", "pkg-tsh", []string{"build/tsh*.pkg"}, []string{"tsh client only"})
}
func darwinTagDownloadArtifactCommands() []string {
+34 -14
View File
@@ -45,7 +45,12 @@ func tagCheckoutCommands(fips bool) []string {
// create necessary directories
`mkdir -p /go/cache /go/artifacts`,
// set version
`if [[ "${DRONE_TAG}" != "" ]]; then echo "${DRONE_TAG##v}" > /go/.version.txt; else egrep ^VERSION Makefile | cut -d= -f2 > /go/.version.txt; fi; cat /go/.version.txt`,
`VERSION=$(egrep ^VERSION Makefile | cut -d= -f2)
if [ "$$VERSION" != "${DRONE_TAG##v}" ]; then
echo "Mismatch between Makefile version: $$VERSION and git tag: $DRONE_TAG"
exit 1
fi
echo "$$VERSION" > /go/.version.txt`,
}
return commands
}
@@ -227,6 +232,11 @@ func tagPipeline(b buildType) pipeline {
tagEnvironment["WINDOWS_SIGNING_CERT"] = value{fromSecret: "WINDOWS_SIGNING_CERT"}
}
var extraQualifications []string
if b.os == "windows" {
extraQualifications = []string{"tsh client only"}
}
p := newKubePipeline(pipelineName)
p.Environment = map[string]value{
"BUILDBOX_VERSION": buildboxVersion,
@@ -269,8 +279,8 @@ func tagPipeline(b buildType) pipeline {
{
Name: "Register artifacts",
Image: "docker",
Commands: tagCreateReleaseAssetCommands(b, "", extraQualifications),
Failure: "ignore",
Commands: tagCreateReleaseAssetCommands(b),
Environment: map[string]value{
"RELEASES_CERT": value{fromSecret: "RELEASES_CERT_STAGING"},
"RELEASES_KEY": value{fromSecret: "RELEASES_KEY_STAGING"},
@@ -322,7 +332,7 @@ func tagCopyPackageArtifactCommands(b buildType, packageType string) []string {
}
// createReleaseAssetCommands generates a set of commands to create release & asset in release management service
func tagCreateReleaseAssetCommands(b buildType) []string {
func tagCreateReleaseAssetCommands(b buildType, packageType string, extraQualifications []string) []string {
commands := []string{
`WORKSPACE_DIR=$${WORKSPACE_DIR:-/}`,
`VERSION=$(cat "$WORKSPACE_DIR/go/.version.txt")`,
@@ -333,22 +343,32 @@ func tagCreateReleaseAssetCommands(b buildType) []string {
`CREDENTIALS="--cert $WORKSPACE_DIR/releases.crt --key $WORKSPACE_DIR/releases.key"`,
`which curl || apk add --no-cache curl`,
fmt.Sprintf(`cd "$WORKSPACE_DIR/go/artifacts"
for file in $(find . -type f ! -iname '*.sha256'); do
for file in $(find . -type f ! -iname '*.sha256' ! -iname '*-unsigned.zip*'); do
# Skip files that are not results of this build
# (e.g. tarballs from which OS packages are made)
[ -f "$file.sha256" ] || continue
product="$(basename "$file" | sed -E 's/(-|_)v?[0-9].*$//')" # extract part before -vX.Y.Z
shasum="$(cat "$file.sha256" | cut -d ' ' -f 1)"
status_code=$(curl $CREDENTIALS -o "$WORKSPACE_DIR/curl_out.txt" -w "%%{http_code}" -F "product=$product" -F "version=$VERSION" -F notesMd="# Teleport $VERSION" -F status=draft "$RELEASES_HOST/releases")
if [ $status_code -ne 200 ] && [ $status_code -ne 409 ]; then
echo "curl HTTP status: $status_code"
cat $WORKSPACE_DIR/curl_out.txt
exit 1
name="$(basename "$file" | sed -E 's/(-|_)v?[0-9].*$//')" # extract part before -vX.Y.Z
if [ "$name" = "tsh" ]; then
products="teleport teleport-ent";
else
products="$name"
fi
curl $CREDENTIALS --fail -o /dev/null -F description="TODO" -F os="%s" -F arch="%s" -F "file=@$file" -F "sha256=$shasum" -F "releaseId=$product@$VERSION" "$RELEASES_HOST/assets";
shasum="$(cat "$file.sha256" | cut -d ' ' -f 1)"
curl $CREDENTIALS --fail -o /dev/null -F description="%[1]s" -F os="%[2]s" -F arch="%[3]s" -F "file=@$file" -F "sha256=$shasum" "$RELEASES_HOST/assets";
for product in $products; do
status_code=$(curl $CREDENTIALS -o "$WORKSPACE_DIR/curl_out.txt" -w "%%{http_code}" -F "product=$product" -F "version=$VERSION" -F notesMd="# Teleport $VERSION" -F status=draft "$RELEASES_HOST/releases")
if [ $status_code -ne 200 ] && [ $status_code -ne 409 ]; then
echo "curl HTTP status: $status_code"
cat $WORKSPACE_DIR/curl_out.txt
exit 1
fi
curl $CREDENTIALS --fail -o /dev/null -X PUT "$RELEASES_HOST/releases/$product@$VERSION/assets/$(basename $file)"
done
done`,
b.os, b.arch /* TODO: fips */),
b.Description(packageType, extraQualifications...), b.os, b.arch),
}
return commands
}
@@ -478,7 +498,7 @@ func tagPackagePipeline(packageType string, b buildType) pipeline {
{
Name: "Register artifacts",
Image: "docker",
Commands: tagCreateReleaseAssetCommands(b),
Commands: tagCreateReleaseAssetCommands(b, strings.ToUpper(packageType), nil),
Failure: "ignore",
Environment: map[string]value{
"RELEASES_CERT": value{fromSecret: "RELEASES_CERT_STAGING"},