forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.go
113 lines (103 loc) · 4.15 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Teleport
* Copyright (C) 2023 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"fmt"
"strconv"
"time"
)
func pushCheckoutCommandsWithPath(b buildType, checkoutPath string) []string {
var commands []string
commands = append(commands, cloneRepoCommands(checkoutPath, "${DRONE_COMMIT_SHA}")...)
commands = append(commands,
`mkdir -m 0700 /root/.ssh && echo "$GITHUB_PRIVATE_KEY" > /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa`,
`ssh-keyscan -H github.com > /root/.ssh/known_hosts 2>/dev/null && chmod 600 /root/.ssh/known_hosts`,
`git submodule update --init e`,
`mkdir -pv /go/cache`,
`rm -f /root/.ssh/id_rsa`,
)
if b.fips {
commands = append(commands, `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`)
}
return commands
}
// pushPipelines builds all applicable push pipeline combinations
func pushPipelines() []pipeline {
var ps []pipeline
ps = append(ps, ghaLinuxPushPipeline(buildType{os: "linux", arch: "amd64", fips: false, buildConnect: true}))
ps = append(ps, ghaLinuxPushPipeline(buildType{os: "linux", arch: "amd64", fips: true}))
ps = append(ps, ghaLinuxPushPipeline(buildType{os: "linux", arch: "386", fips: false}))
ps = append(ps, ghaLinuxPushPipeline(buildType{os: "linux", arch: "arm64", fips: false}))
ps = append(ps, ghaLinuxPushPipeline(buildType{os: "linux", arch: "arm", fips: false}))
ps = append(ps, ghaWindowsPushPipeline())
return ps
}
// ghaLinuxPushPipeline generates a push pipeline for a given combination of
// os/arch/FIPS that calls a GitHub Actions workflow to perform the build on
// a Linux buildbox. This dispatches to the release-linux.yaml workflow in
// the teleport.e repo, which is a little more generic than the
// release-linux-arm64.yml workflow used for the arm64 build. The two will
// be unified shortly.
func ghaLinuxPushPipeline(b buildType) pipeline {
if b.os == "" {
panic("b.os must be set")
}
if b.arch == "" {
panic("b.arch must be set")
}
pipelineName := fmt.Sprintf("push-build-%s-%s", b.os, b.arch)
if b.fips {
pipelineName += "-fips"
}
wf := ghaWorkflow{
name: "release-linux.yaml",
timeout: 150 * time.Minute,
slackOnError: true,
srcRefVar: "DRONE_COMMIT",
ref: "${DRONE_BRANCH}",
shouldTagWorkflow: true,
inputs: map[string]string{
"release-target": releaseMakefileTarget(b),
"build-connect": strconv.FormatBool(b.buildConnect),
},
}
bt := ghaBuildType{
buildType: buildType{os: b.os, arch: b.arch},
trigger: triggerPush,
pipelineName: pipelineName,
workflows: []ghaWorkflow{wf},
}
return ghaBuildPipeline(bt)
}
func sendErrorToSlackStep() step {
return step{
Name: "Send Slack notification",
Image: "plugins/slack:1.4.1",
Settings: map[string]value{
"webhook": {fromSecret: "SLACK_WEBHOOK_DEV_TELEPORT"},
"template": {
raw: "*✘ Failed:* `{{ build.event }}` / `${DRONE_STAGE_NAME}` / <{{ build.link }}|Build: #{{ build.number }}>\n" +
"Author: <https://github.com/{{ build.author }}|{{ build.author }}> " +
"Repo: <https://github.com/{{ repo.owner }}/{{ repo.name }}/|{{ repo.owner }}/{{ repo.name }}> " +
"Branch: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commits/{{ build.branch }}|{{ build.branch }}> " +
"Commit: <https://github.com/{{ repo.owner }}/{{ repo.name }}/commit/{{ build.commit }}|{{ truncate build.commit 8 }}>",
},
},
When: &condition{Status: []string{"failure"}},
}
}