-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate jenkins to use imagetest_harness_k3s for tests (#2499)
Signed-off-by: Jamon <[email protected]>
- Loading branch information
1 parent
6f55394
commit f63f2fa
Showing
5 changed files
with
167 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// default values - these get overridden when the resource is called | ||
variable "values" { | ||
type = any | ||
default = { | ||
namespace = "jenkins" | ||
fullnameOverride = "jenkins" | ||
nameOverride = "jenkins" | ||
create_namespace = true | ||
|
||
controller = { | ||
javaOpts = "" | ||
jenkinsOpts = "" | ||
admin = { | ||
createSecret = false | ||
} | ||
installPlugins = false | ||
sidecars = { | ||
configAutoReload = { | ||
enabled = false | ||
} | ||
} | ||
image = { | ||
registry = "cgr.dev" | ||
repository = "chainguard/jenkins" | ||
tag = "latest" | ||
} | ||
} | ||
} | ||
} | ||
|
||
module "helm" { | ||
source = "../../../../tflib/imagetest/helm" | ||
|
||
namespace = "jenkins" | ||
chart = "jenkins" | ||
repo = "https://charts.jenkins.io" | ||
|
||
values = var.values | ||
} | ||
|
||
output "install_cmd" { | ||
value = module.helm.install_cmd | ||
} | ||
|
||
output "release_name" { | ||
value = module.helm.release_name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/sh | ||
|
||
# set -euo pipefail | ||
|
||
apk add curl openjdk-21-jre-base | ||
|
||
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk/ | ||
|
||
kubectl port-forward -n jenkins svc/jenkins 8080:8080& | ||
sleep 5 # wait for port-forward to settle | ||
curl -s -O "http://localhost:8080/jnlpJars/jenkins-cli.jar" | ||
mv jenkins-cli.jar /tmp/ | ||
|
||
# define a job | ||
cat /tests/hello-world.xml | \ | ||
$JAVA_HOME/bin/java \ | ||
-jar /tmp/jenkins-cli.jar \ | ||
-s http://127.0.0.1:8080 \ | ||
create-job "Hello world" | ||
|
||
sleep 5 # wait for port-forward to settle | ||
|
||
# run the job | ||
$JAVA_HOME/bin/java \ | ||
-jar /tmp/jenkins-cli.jar \ | ||
-s http://127.0.0.1:8080 build "Hello world" | ||
|
||
sleep 5 # wait for port-forward to settle | ||
|
||
# check job success | ||
STATUS=`$JAVA_HOME/bin/java \ | ||
-jar /tmp/jenkins-cli.jar \ | ||
-s http://127.0.0.1:8080 console "Hello world" |grep 'Finished: SUCCESS'` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<project> | ||
<description/> | ||
<keepDependencies>false</keepDependencies> | ||
<properties/> | ||
<scm class="hudson.scm.NullSCM"/> | ||
<canRoam>true</canRoam> | ||
<disabled>false</disabled> | ||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> | ||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> | ||
<triggers/> | ||
<concurrentBuild>false</concurrentBuild> | ||
<builders> | ||
<hudson.tasks.Shell> | ||
<command>echo "Hello world!"</command> | ||
<configuredLocalRules/> | ||
</hudson.tasks.Shell> | ||
</builders> | ||
<publishers/> | ||
<buildWrappers/> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,78 @@ | ||
terraform { | ||
required_providers { | ||
oci = { source = "chainguard-dev/oci" } | ||
oci = { source = "chainguard-dev/oci" } | ||
imagetest = { source = "chainguard-dev/imagetest" } | ||
} | ||
} | ||
|
||
locals { | ||
namespace = "jenkins" | ||
} | ||
|
||
variable "digest" { | ||
description = "The image digest to run tests over." | ||
} | ||
|
||
data "oci_exec_test" "version" { | ||
digest = var.digest | ||
script = "docker run --rm $IMAGE_NAME --version" | ||
data "oci_string" "ref" { input = var.digest } | ||
|
||
data "imagetest_inventory" "this" {} | ||
|
||
resource "imagetest_harness_k3s" "this" { | ||
name = "jenkins" | ||
inventory = data.imagetest_inventory.this | ||
|
||
sandbox = { | ||
mounts = [ | ||
{ | ||
source = path.module | ||
destination = "/tests" | ||
} | ||
] | ||
} | ||
} | ||
|
||
data "oci_exec_test" "run-tests" { | ||
digest = var.digest | ||
script = "${path.module}/run-tests.sh" | ||
module "helm_controller" { | ||
source = "./controller" | ||
values = { | ||
namespace = local.namespace | ||
fullnameOverride = local.namespace | ||
nameOverride = local.namespace | ||
create_namespace = true | ||
|
||
controller = { | ||
javaOpts = "" | ||
jenkinsOpts = "" | ||
installPlugins = false | ||
admin = { | ||
createSecret = false | ||
} | ||
sidecars = { | ||
configAutoReload = { | ||
enabled = false | ||
} | ||
} | ||
image = { | ||
registry = data.oci_string.ref.registry | ||
repository = data.oci_string.ref.repo | ||
tag = data.oci_string.ref.pseudo_tag | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "imagetest_feature" "this" { | ||
harness = imagetest_harness_k3s.this | ||
name = "jenkins" | ||
description = "Test jenkins functionality" | ||
|
||
steps = [ | ||
{ | ||
name = "Install controller", | ||
cmd = module.helm_controller.install_cmd | ||
}, | ||
{ | ||
name = "Test running a job", | ||
cmd = "/tests/hello-world.sh" | ||
}, | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.