@@ -4,7 +4,7 @@ import * as path from 'path';
44import { exec , ExecOptions } from './util/shell' ;
55import { Werft } from './util/werft' ;
66import { waitForDeploymentToSucceed , wipeAndRecreateNamespace , setKubectlContextNamespace , deleteNonNamespaceObjects , findFreeHostPorts , createNamespace , helmInstallName } from './util/kubectl' ;
7- import { newIssueCertficate , installCertficate , IssueCertificateParams , InstallCertificateParams } from './util/certs' ;
7+ import { issueCertficate , installCertficate , IssueCertificateParams , InstallCertificateParams } from './util/certs' ;
88import { reportBuildFailureInSlack } from './util/slack' ;
99import * as semver from 'semver' ;
1010import * as util from 'util' ;
@@ -77,6 +77,7 @@ const installerSlices = {
7777 INSTALLER_POST_PROCESSING : "installer post processing" ,
7878 APPLY_INSTALL_MANIFESTS : "installer apply" ,
7979 DEPLOYMENT_WAITING : "monitor server deployment" ,
80+ DNS_ADD_RECORD : "add dns record"
8081}
8182
8283const vmSlices = {
@@ -303,6 +304,8 @@ export async function build(context, version) {
303304 withVM,
304305 } ;
305306
307+ exec ( `kubectl --namespace keys get secret host-key -o yaml > /workspace/host-key.yaml` )
308+
306309 if ( withVM ) {
307310 werft . phase ( phases . VM , "Start VM" ) ;
308311
@@ -431,6 +434,7 @@ export async function deployToDevWithInstaller(deploymentConfig: DeploymentConfi
431434 // in a VM, the secrets have alreay been copied
432435 // If using core-dev, we want to execute further kubectl operations only in the created namespace
433436 setKubectlContextNamespace ( namespace , metaEnv ( { slice : installerSlices . SET_CONTEXT } ) ) ;
437+ werft . done ( installerSlices . SET_CONTEXT )
434438 try {
435439 werft . log ( installerSlices . ISSUE_CERTIFICATES , "organizing a certificate for the preview environment..." ) ;
436440
@@ -535,7 +539,7 @@ export async function deployToDevWithInstaller(deploymentConfig: DeploymentConfi
535539
536540 werft . log ( "SSH gateway hostkey" , "copy host-key from secret" )
537541 try {
538- exec ( `kubectl --namespace keys get secret host-key -o yaml \
542+ exec ( `cat /workspace/ host-key. yaml \
539543 | yq w - metadata.namespace ${ namespace } \
540544 | yq d - metadata.uid \
541545 | yq d - metadata.resourceVersion \
@@ -610,6 +614,8 @@ export async function deployToDevWithInstaller(deploymentConfig: DeploymentConfi
610614 werft . fail ( installerSlices . DEPLOYMENT_WAITING , err ) ;
611615 }
612616
617+ await addDNSRecord ( deploymentConfig . namespace , deploymentConfig . domain , ! withVM )
618+
613619 // TODO: Fix sweeper, it does not appear to be doing clean-up
614620 werft . log ( 'sweeper' , 'installing Sweeper' ) ;
615621 const sweeperVersion = deploymentConfig . sweeperImage . split ( ":" ) [ 1 ] ;
@@ -695,7 +701,7 @@ export async function deployToDevWithHelm(deploymentConfig: DeploymentConfig, wo
695701 await issueMetaCerts ( namespace , domain ) ;
696702 await installMetaCertificates ( namespace ) ;
697703 werft . done ( 'certificate' ) ;
698-
704+ await addDNSRecord ( deploymentConfig . namespace , deploymentConfig . domain , false )
699705 werft . done ( 'prep' ) ;
700706 } catch ( err ) {
701707 werft . fail ( 'prep' , err ) ;
@@ -893,10 +899,50 @@ export async function deployToDevWithHelm(deploymentConfig: DeploymentConfig, wo
893899 }
894900}
895901
902+ async function addDNSRecord ( namespace : string , domain : string , isLoadbalancer : boolean ) {
903+ let wsProxyLBIP = null
904+ if ( isLoadbalancer === true ) {
905+ werft . log ( installerSlices . DNS_ADD_RECORD , "Getting ws-proxy loadbalancer IP" ) ;
906+ for ( let i = 0 ; i < 60 ; i ++ ) {
907+ try {
908+ let lb = exec ( `kubectl -n ${ namespace } get service ws-proxy -o=jsonpath='{.status.loadBalancer.ingress[0].ip}'` , { silent : true } )
909+ if ( lb . length > 4 ) {
910+ wsProxyLBIP = lb
911+ break
912+ }
913+ await sleep ( 1000 )
914+ } catch ( err ) {
915+ await sleep ( 1000 )
916+ }
917+ }
918+ if ( wsProxyLBIP == null ) {
919+ werft . fail ( installerSlices . DNS_ADD_RECORD , new Error ( "Can't get ws-proxy loadbalancer IP" ) ) ;
920+ }
921+ werft . log ( installerSlices . DNS_ADD_RECORD , "Get ws-proxy loadbalancer IP: " + wsProxyLBIP ) ;
922+ } else {
923+ wsProxyLBIP = getCoreDevIngressIP ( )
924+ }
925+
926+ var cmd = `set -x \
927+ && cd /workspace/.werft/dns \
928+ && rm -rf .terraform* \
929+ && export GOOGLE_APPLICATION_CREDENTIALS="${ GCLOUD_SERVICE_ACCOUNT_PATH } " \
930+ && terraform init -backend-config='prefix=${ namespace } ' -migrate-state -upgrade \
931+ && terraform apply -auto-approve \
932+ -var 'dns_zone_domain=gitpod-dev.com' \
933+ -var 'domain=${ domain } ' \
934+ -var 'ingress_ip=${ getCoreDevIngressIP ( ) } ' \
935+ -var 'ws_proxy_ip=${ wsProxyLBIP } '` ;
936+
937+ werft . log ( installerSlices . DNS_ADD_RECORD , "Terraform command for create dns record: " + cmd )
938+ exec ( cmd , { ...metaEnv ( ) , slice : installerSlices . DNS_ADD_RECORD } ) ;
939+ werft . done ( installerSlices . DNS_ADD_RECORD ) ;
940+ }
941+
896942export async function issueMetaCerts ( namespace : string , domain : string ) {
897943 let additionalSubdomains : string [ ] = [ "" , "*." , "*.ws-dev." ]
898944 var metaClusterCertParams = new IssueCertificateParams ( ) ;
899- metaClusterCertParams . pathToTerraform = "/workspace/.werft/certs " ;
945+ metaClusterCertParams . pathToTemplate = "/workspace/.werft/util/templates " ;
900946 metaClusterCertParams . gcpSaPath = GCLOUD_SERVICE_ACCOUNT_PATH ;
901947 metaClusterCertParams . namespace = namespace ;
902948 metaClusterCertParams . certNamespace = "certs" ;
@@ -905,7 +951,7 @@ export async function issueMetaCerts(namespace: string, domain: string) {
905951 metaClusterCertParams . ip = getCoreDevIngressIP ( ) ;
906952 metaClusterCertParams . bucketPrefixTail = ""
907953 metaClusterCertParams . additionalSubdomains = additionalSubdomains
908- await newIssueCertficate ( werft , metaClusterCertParams , metaEnv ( ) ) ;
954+ await issueCertficate ( werft , metaClusterCertParams , metaEnv ( ) ) ;
909955}
910956
911957async function installMetaCertificates ( namespace : string ) {
0 commit comments