From 8da47b8eaefb797e247a6a0fe0d6e2dddfb9332f Mon Sep 17 00:00:00 2001 From: Public copy <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:45:35 +0000 Subject: [PATCH] automated commit Signed-off-by: Public copy <41898282+github-actions[bot]@users.noreply.github.com> --- .terraform.lock.hcl | 16 ++-- tflib/imagetest/playwright/main.tf | 115 +++++++++++++++++++++++++++++ tflib/publisher/providers.tf | 2 +- 3 files changed, 124 insertions(+), 9 deletions(-) create mode 100644 tflib/imagetest/playwright/main.tf diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 7bc120ffa..685036803 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -16,15 +16,15 @@ provider "registry.terraform.io/chainguard-dev/apko" { } provider "registry.terraform.io/chainguard-dev/chainguard" { - version = "0.1.21" - constraints = ">= 0.1.21" + version = "0.1.22" + constraints = ">= 0.1.22" hashes = [ - "h1:J4cMRXW6GdTr8HtIxhjU2ha9gqstgxLFA+QKW3qGWQ8=", - "h1:oMoFiZPmQzrNtxR2U3yyyZENcc840Sp8m6Jg+NOK4sM=", - "zh:1cf32ea4f028dc7d652553bc63aca6b5ee4aef8745d50bbb1b6c0031b0b9db66", - "zh:27749d80c1b87f6b53225ca990055097ccad4161364e06338e5817f600c4e514", - "zh:a1d4b4cf83c5e98bfab0b0b17f76e6aee08ec4472dacfdad44cfe4fc5a3e8d4b", - "zh:dda6d575ca6650b307b8e52a4036cc629eabf75c5b6105c0eb956ccf5b6e8e72", + "h1:AF4YBcioqhEFq/Vwv3lh4PF9/Xo/xxMrFmXZpuDzrqQ=", + "h1:iY3FlyD0p3g3mSOzRcByFd4bmweBRVoJJlioPXHLRY0=", + "zh:143b83290a3bdf5a9aff357228b88e0a54ba40e6bacb7f46cc53cb01c1a8fb90", + "zh:81e84abf8e7f6946b027ab140ee3f938d0ac824eee8916c0646cb85eb4863242", + "zh:8b7a15e1584af880aeb47df6155fa964578f10fd12daba7be29f5de080a9b7e5", + "zh:cb8d74ea9ce7c4f1fe308453185447d10c7bb8a085ce8e49b12d25c453a6b182", "zh:f809ab383cca0a5f83072981c64208cbd7fa67e986a86ee02dd2c82333221e32", ] } diff --git a/tflib/imagetest/playwright/main.tf b/tflib/imagetest/playwright/main.tf new file mode 100644 index 000000000..1229fa1d0 --- /dev/null +++ b/tflib/imagetest/playwright/main.tf @@ -0,0 +1,115 @@ +terraform { + required_providers { + random = { source = "hashicorp/random" } + } +} + +resource "random_string" "suffix" { + length = 4 + special = false + upper = false +} + +variable "tests" { + description = "A map of test files to run." + type = map(string) + + default = {} +} + +variable "playwright_image" { + description = "The Playwright Docker image to use" + type = string + default = "mcr.microsoft.com/playwright" +} + +variable "playwright_version" { + description = "The :tag@digest component of the image. Used to discover the npm version to install." + type = string + default = "v1.49.0-noble@sha256:0fc07c73230cb7c376a528d7ffc83c4bdcdcd3fc7efbe54a2eed72b1ec118377" +} + +locals { + pw_version_tag = split("@", var.playwright_version)[0] + pw_tag = trimprefix(local.pw_version_tag, "v") + pw_version = trimsuffix(local.pw_tag, "-noble") + + name = "pw-tests-${random_string.suffix.result}" + + job_spec = <<-EOJOB +apiVersion: batch/v1 +kind: Job +metadata: + name: ${local.name} +spec: + template: + spec: + containers: + - name: playwright + image: "${var.playwright_image}:${var.playwright_version}" + command: ["/bin/sh", "-c"] + args: + - | + # Copy all files from ConfigMap into a working directory + mkdir -p /playwright/tests + cp /config/tests/* /playwright/tests/ + cd /playwright + + npm install @playwright/test@${local.pw_version} + + # Run tests using the npm script + npx playwright test + env: + - name: CI + value: "true" + volumeMounts: + - name: tests-config + mountPath: /config/tests + readOnly: true + - name: playwright-tests-dir + mountPath: /playwright + restartPolicy: Never + volumes: + - name: tests-config + configMap: + name: ${local.name} + - name: playwright-tests-dir + emptyDir: {} + EOJOB +} + +output "run_cmd" { + value = <<-EOrun +set -o errexit -o nounset -o errtrace -o pipefail -x + +apk add kubectl + +mkdir -p /tmp/${local.name} + +%{for test, contents in var.tests~} +cat < /tmp/${local.name}/${test} +${contents} +EOF +%{endfor~} + +mkdir -p /tmp/${local.name}/k8s + +kubectl create configmap ${local.name} \ + %{for test, contents in var.tests~} + --from-file=/tmp/${local.name}/${test} \ + %{endfor~} + --dry-run=client -o yaml > /tmp/${local.name}/k8s/configmap.yaml + +cat < /tmp/${local.name}/k8s/job.yaml +${templatestring(local.job_spec, {})} +EOF + +echo "Applying Kubernetes resources..." +kubectl apply -f /tmp/${local.name}/k8s/ + +echo "Waiting for Playwright tests to complete..." +kubectl wait --for=condition=complete job/${local.name} --timeout=600s + +echo "Tests completed successfully!" + EOrun +} diff --git a/tflib/publisher/providers.tf b/tflib/publisher/providers.tf index a7b1eeefe..17c24b29c 100644 --- a/tflib/publisher/providers.tf +++ b/tflib/publisher/providers.tf @@ -14,7 +14,7 @@ terraform { } chainguard = { source = "chainguard-dev/chainguard" - version = ">= 0.1.21" + version = ">= 0.1.22" } imagetest = { source = "chainguard-dev/imagetest"