Skip to content

Commit 30fd0a9

Browse files
mads-hartmannroboquat
authored andcommitted
Use dev/preview:create-preview in Werft
1 parent dd97e9e commit 30fd0a9

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

.werft/jobs/build/prepare.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,33 +101,36 @@ async function createVM(werft: Werft, config: JobConfig) {
101101
const cpu = config.withLargeVM ? 12 : 6;
102102
const memory = config.withLargeVM ? 24 : 12;
103103

104-
// set some common vars for TF
105-
// We pass the GCP credentials explicitly, otherwise for some reason TF doesn't pick them up
106-
const commonVars = `GOOGLE_BACKEND_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
107-
GOOGLE_APPLICATION_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
108-
TF_VAR_kubeconfig_path=${GLOBAL_KUBECONFIG_PATH} \
109-
TF_VAR_preview_name=${config.previewEnvironment.destname} \
110-
TF_VAR_vm_cpu=${cpu} \
111-
TF_VAR_vm_memory=${memory}Gi \
112-
TF_VAR_vm_storage_class="longhorn-gitpod-k3s-202209251218-onereplica"`
104+
// -replace=... forces recreation of the resource
105+
const planArgs = config.cleanSlateDeployment ? "-replace=harvester_virtualmachine.harvester" : ""
106+
107+
const environment = {
108+
// We pass the GCP credentials explicitly, otherwise for some reason TF doesn't pick them up
109+
"GOOGLE_BACKEND_CREDENTIALS": GCLOUD_SERVICE_ACCOUNT_PATH,
110+
"GOOGLE_APPLICATION_CREDENTIALS": GCLOUD_SERVICE_ACCOUNT_PATH,
111+
"TF_VAR_kubeconfig_path": GLOBAL_KUBECONFIG_PATH,
112+
"TF_VAR_preview_name": config.previewEnvironment.destname,
113+
"TF_VAR_vm_cpu": `${cpu}`,
114+
"TF_VAR_vm_memory": `${memory}Gi`,
115+
"TF_VAR_vm_storage_class": "longhorn-gitpod-k3s-202209251218-onereplica",
116+
"TF_CLI_ARGS_plan": planArgs
117+
}
118+
119+
const variables = Object
120+
.entries(environment)
121+
.filter(([_, value]) => value.length > 0)
122+
.map(([key, value]) => `${key}="${value}"`)
123+
.join(" ")
113124

114125
if (config.cleanSlateDeployment) {
115126
werft.log(prepareSlices.BOOT_VM, "Cleaning previously created VM");
116-
// -replace=... forces recreation of the resource
117-
await execStream(`${commonVars} \
118-
TF_CLI_ARGS_plan="-replace=harvester_virtualmachine.harvester" \
119-
./dev/preview/workflow/preview/deploy-harvester.sh`,
120-
{slice: prepareSlices.BOOT_VM}
121-
);
127+
await execStream(`${variables} leeway run dev/preview:create-preview`, {slice: prepareSlices.BOOT_VM});
122128
}
123129

124130
werft.log(prepareSlices.BOOT_VM, "Creating VM");
125131

126132
try {
127-
await execStream(`${commonVars} \
128-
./dev/preview/workflow/preview/deploy-harvester.sh`,
129-
{slice: prepareSlices.BOOT_VM}
130-
);
133+
await execStream(`${variables} leeway run dev/preview:create-preview`, {slice: prepareSlices.BOOT_VM});
131134
} catch (err) {
132135
werft.currentPhaseSpan.setAttribute("preview.created_vm", false);
133136
werft.fail(prepareSlices.BOOT_VM, new Error(`Failed creating VM: ${err}`))

dev/preview/BUILD.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ scripts:
1111
- name: create-preview
1212
description: Provisions a new preview environment
1313
script: |
14-
export TF_VAR_dev_kube_path="/home/gitpod/.kube/config"
15-
export TF_VAR_dev_kube_context="dev"
16-
export TF_VAR_harvester_kube_path="/home/gitpod/.kube/config"
17-
export TF_VAR_harvester_kube_context="harvester"
18-
export TF_VAR_preview_name="$(previewctl get-name)"
19-
export TF_VAR_vm_cpu=6
20-
export TF_VAR_vm_memory=12Gi
21-
export TF_VAR_vm_storage_class="longhorn-gitpod-k3s-202209251218-onereplica"
14+
export TF_VAR_dev_kube_path="${TF_VAR_dev_kube_path:-/home/gitpod/.kube/config}"
15+
export TF_VAR_dev_kube_context="${TF_VAR_dev_kube_context:-dev}"
16+
export TF_VAR_harvester_kube_path="${TF_VAR_harvester_kube_path:-/home/gitpod/.kube/config}"
17+
export TF_VAR_harvester_kube_context="${TF_VAR_harvester_kube_context:-harvester}"
18+
export TF_VAR_preview_name="${TF_VAR_preview_name:-$(previewctl get-name)}"
19+
export TF_VAR_vm_cpu="${TF_VAR_vm_cpu:-6}"
20+
export TF_VAR_vm_memory="${TF_VAR_vm_memory:-12Gi}"
21+
export TF_VAR_vm_storage_class="${TF_VAR_vm_storage_class:-longhorn-gitpod-k3s-202209251218-onereplica}"
2222
./workflow/preview/deploy-harvester.sh
2323
2424
- name: delete-preview
2525
description: Delete an existing preview environment
2626
script: |
2727
export DESTROY=true
28-
export TF_VAR_kubeconfig_path="/home/gitpod/.kube/config"
29-
export TF_VAR_preview_name="$(previewctl get-name)"
28+
export TF_VAR_kubeconfig_path="${TF_VAR_kubeconfig_path:-/home/gitpod/.kube/config}"
29+
export TF_VAR_preview_name="${TF_VAR_preview_name:-$(previewctl get-name)}"
3030
./workflow/preview/deploy-harvester.sh
3131
3232
- name: deploy-gitpod

0 commit comments

Comments
 (0)