Skip to content

Use dev/preview:create-preview in Werft #14174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions .werft/jobs/build/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,36 @@ async function createVM(werft: Werft, config: JobConfig) {
const cpu = config.withLargeVM ? 12 : 6;
const memory = config.withLargeVM ? 24 : 12;

// set some common vars for TF
// We pass the GCP credentials explicitly, otherwise for some reason TF doesn't pick them up
const commonVars = `GOOGLE_BACKEND_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
GOOGLE_APPLICATION_CREDENTIALS=${GCLOUD_SERVICE_ACCOUNT_PATH} \
TF_VAR_kubeconfig_path=${GLOBAL_KUBECONFIG_PATH} \
TF_VAR_preview_name=${config.previewEnvironment.destname} \
TF_VAR_vm_cpu=${cpu} \
TF_VAR_vm_memory=${memory}Gi \
TF_VAR_vm_storage_class="longhorn-gitpod-k3s-202209251218-onereplica"`
// -replace=... forces recreation of the resource
const planArgs = config.cleanSlateDeployment ? "-replace=harvester_virtualmachine.harvester" : ""

const environment = {
// We pass the GCP credentials explicitly, otherwise for some reason TF doesn't pick them up
"GOOGLE_BACKEND_CREDENTIALS": GCLOUD_SERVICE_ACCOUNT_PATH,
"GOOGLE_APPLICATION_CREDENTIALS": GCLOUD_SERVICE_ACCOUNT_PATH,
"TF_VAR_kubeconfig_path": GLOBAL_KUBECONFIG_PATH,
"TF_VAR_preview_name": config.previewEnvironment.destname,
"TF_VAR_vm_cpu": `${cpu}`,
"TF_VAR_vm_memory": `${memory}Gi`,
"TF_VAR_vm_storage_class": "longhorn-gitpod-k3s-202209251218-onereplica",
"TF_CLI_ARGS_plan": planArgs
}

const variables = Object
.entries(environment)
.filter(([_, value]) => value.length > 0)
.map(([key, value]) => `${key}="${value}"`)
.join(" ")

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

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

try {
await execStream(`${commonVars} \
./dev/preview/workflow/preview/deploy-harvester.sh`,
{slice: prepareSlices.BOOT_VM}
);
await execStream(`${variables} leeway run dev/preview:create-preview`, {slice: prepareSlices.BOOT_VM});
} catch (err) {
werft.currentPhaseSpan.setAttribute("preview.created_vm", false);
werft.fail(prepareSlices.BOOT_VM, new Error(`Failed creating VM: ${err}`))
Expand Down
20 changes: 10 additions & 10 deletions dev/preview/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ scripts:
- name: create-preview
description: Provisions a new preview environment
script: |
export TF_VAR_dev_kube_path="/home/gitpod/.kube/config"
export TF_VAR_dev_kube_context="dev"
export TF_VAR_harvester_kube_path="/home/gitpod/.kube/config"
export TF_VAR_harvester_kube_context="harvester"
export TF_VAR_preview_name="$(previewctl get-name)"
export TF_VAR_vm_cpu=6
export TF_VAR_vm_memory=12Gi
export TF_VAR_vm_storage_class="longhorn-gitpod-k3s-202209251218-onereplica"
export TF_VAR_dev_kube_path="${TF_VAR_dev_kube_path:-/home/gitpod/.kube/config}"
export TF_VAR_dev_kube_context="${TF_VAR_dev_kube_context:-dev}"
export TF_VAR_harvester_kube_path="${TF_VAR_harvester_kube_path:-/home/gitpod/.kube/config}"
export TF_VAR_harvester_kube_context="${TF_VAR_harvester_kube_context:-harvester}"
export TF_VAR_preview_name="${TF_VAR_preview_name:-$(previewctl get-name)}"
export TF_VAR_vm_cpu="${TF_VAR_vm_cpu:-6}"
export TF_VAR_vm_memory="${TF_VAR_vm_memory:-12Gi}"
export TF_VAR_vm_storage_class="${TF_VAR_vm_storage_class:-longhorn-gitpod-k3s-202209251218-onereplica}"
./workflow/preview/deploy-harvester.sh

- name: delete-preview
description: Delete an existing preview environment
script: |
export DESTROY=true
export TF_VAR_kubeconfig_path="/home/gitpod/.kube/config"
export TF_VAR_preview_name="$(previewctl get-name)"
export TF_VAR_kubeconfig_path="${TF_VAR_kubeconfig_path:-/home/gitpod/.kube/config}"
export TF_VAR_preview_name="${TF_VAR_preview_name:-$(previewctl get-name)}"
./workflow/preview/deploy-harvester.sh

- name: deploy-gitpod
Expand Down