1
1
import { exec } from "../../util/shell" ;
2
2
import { Werft } from "../../util/werft" ;
3
3
import { JobConfig } from "./job-config" ;
4
+ import * as https from "https" ;
4
5
5
6
interface config {
6
7
phase : string ;
@@ -71,16 +72,21 @@ export async function triggerUpgradeTests(werft: Werft, config: JobConfig, usern
71
72
export async function triggerSelfHostedPreview ( werft : Werft , config : JobConfig , username : string ) {
72
73
const replicatedChannel = config . replicatedChannel || config . repository . branch ;
73
74
const cluster = config . cluster || "k3s" ;
75
+ const subdomain = `${ replicatedChannel . replace ( "/" , "-" ) . slice ( 0 , 10 ) } -${ cluster } `
74
76
75
77
var licenseFlag : string = ""
78
+ var customerID : string = ""
79
+ var annotation : string = ""
80
+
81
+
76
82
77
83
if ( ! [ "stable" , "unstable" , "beta" ] . includes ( replicatedChannel . toLowerCase ( ) ) ) {
78
84
werft . phase ( "get-replicated-license" , `Create and download replicated license for ${ replicatedChannel } ` ) ;
79
85
80
- exec ( `replicated customer create --channel ${ replicatedChannel } --name ${ replicatedChannel } ` ,
86
+ exec ( `replicated customer create --channel ${ replicatedChannel } --name ${ config . version } ` ,
81
87
{ slice : "get-replicated-license" } )
82
88
83
- exec ( `replicated customer download-license --customer ${ replicatedChannel } > license.yaml` ,
89
+ exec ( `replicated customer download-license --customer ${ config . version } > license.yaml` ,
84
90
{ slice : "get-replicated-license" , dontCheckRc : true } )
85
91
86
92
exec ( `install -D license.yaml install/licenses/${ replicatedChannel } .yaml` ,
@@ -89,16 +95,26 @@ export async function triggerSelfHostedPreview(werft: Werft, config: JobConfig,
89
95
werft . done ( "get-replicated-license" ) ;
90
96
91
97
licenseFlag = `-s install/licenses/${ replicatedChannel } .yaml`
98
+
99
+ const ret = exec ( `replicated customer ls | grep ${ config . version } | awk '{print $1}'` ,
100
+ { slice : "get-replicated-license" , dontCheckRc : true } )
101
+
102
+ const customerIDS = ret . stdout . split ( "\n" ) . filter ( item => item ) ;
103
+ if ( customerIDS . length > 0 ) {
104
+ customerID = customerIDS [ 0 ] . trim ( )
105
+ annotation = `-a customerID=${ customerID } `
106
+ }
92
107
}
93
108
109
+ exec ( `cat install/licenses/${ replicatedChannel } .yaml` )
94
110
95
111
exec ( `git config --global user.name "${ username } "` ) ;
96
112
97
- var annotation = `-a channel=${ replicatedChannel } -a preview=true -a skipTests=true -a deps=external` ;
113
+ annotation = `${ annotation } -a channel=${ replicatedChannel } -a preview=true -a skipTests=true -a deps=external` ;
98
114
99
115
werft . phase ( "self-hosted-preview" , `Create self-hosted preview in ${ cluster } ` ) ;
100
116
101
- annotation = `${ annotation } -a cluster=${ cluster } -a updateGitHubStatus=gitpod-io/gitpod`
117
+ annotation = `${ annotation } -a cluster=${ cluster } -a updateGitHubStatus=gitpod-io/gitpod -a subdomain= ${ subdomain } `
102
118
103
119
const testFile : string = ".werft/self-hosted-installer-tests.yaml" ;
104
120
@@ -115,6 +131,44 @@ export async function triggerSelfHostedPreview(werft: Werft, config: JobConfig,
115
131
if ( ! config . mainBuild ) {
116
132
werft . fail ( "self-hosted-preview" , err ) ;
117
133
}
134
+ deleteReplicatedLicense ( werft , customerID )
118
135
exec ( "exit 0" ) ;
119
136
}
120
137
}
138
+
139
+ export async function deleteReplicatedLicense ( werft : Werft , customerID : string ) {
140
+ if ( customerID == "" ) {
141
+ console . log ( "No customerID found, skipping replicated license cleanup" )
142
+ return
143
+ }
144
+
145
+ console . log ( "trying to cleanup replicated license" )
146
+ werft . phase ( "delete-replicated-license" , "Deletes the replicated license created" )
147
+ const http = require ( 'https' ) ;
148
+
149
+ const options = {
150
+ method : 'POST' ,
151
+ hostname : 'api.replicated.com' ,
152
+ port : null ,
153
+ path : `/vendor/v3/customer/${ customerID } /archive` ,
154
+ headers : {
155
+ Authorization : process . env . REPLICATED_API_TOKEN
156
+ }
157
+ } ;
158
+
159
+ const req = http . request ( options , function ( res ) {
160
+ const chunks = [ ] ;
161
+
162
+ res . on ( 'data' , function ( chunk ) {
163
+ chunks . push ( chunk ) ;
164
+ } ) ;
165
+
166
+ res . on ( 'end' , function ( ) {
167
+ const body = Buffer . concat ( chunks ) ;
168
+ console . log ( body . toString ( ) ) ;
169
+ } ) ;
170
+ } ) ;
171
+
172
+ req . end ( ) ;
173
+ werft . done ( "delete-replicated-license" )
174
+ }
0 commit comments