From 2f446a9fc68b6304e5b35d5acc73ed2295dd6004 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Wed, 22 Nov 2023 17:08:40 -0500 Subject: [PATCH 1/4] An example job with a few interesting actions --- ui/app/utils/default-job-templates.js | 14 +++ ui/app/utils/default_jobs/actions.js | 130 ++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) create mode 100644 ui/app/utils/default_jobs/actions.js diff --git a/ui/app/utils/default-job-templates.js b/ui/app/utils/default-job-templates.js index 1d89de7cc57..3cfec453edb 100644 --- a/ui/app/utils/default-job-templates.js +++ b/ui/app/utils/default-job-templates.js @@ -7,6 +7,7 @@ import helloWorld from './default_jobs/hello-world'; import parameterized from './default_jobs/parameterized'; import serviceDiscovery from './default_jobs/service-discovery'; import variables from './default_jobs/variables'; +import actions from './default_jobs/actions'; export default [ { @@ -22,6 +23,19 @@ export default [ }, ], }, + { + id: 'nomad/job-templates/default/actions', + keyValues: [ + { + key: 'template', + value: actions, + }, + { + key: 'description', + value: 'A raw exec job that shows off Nomad Actions', + }, + ], + }, { id: 'nomad/job-templates/default/parameterized-job', keyValues: [ diff --git a/ui/app/utils/default_jobs/actions.js b/ui/app/utils/default_jobs/actions.js new file mode 100644 index 00000000000..89987beb1fe --- /dev/null +++ b/ui/app/utils/default_jobs/actions.js @@ -0,0 +1,130 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: BUSL-1.1 + */ + +export default `job "job-with-actions" { + # Specifies the datacenter where this job should be run + # This can be omitted and it will default to ["*"] + datacenters = ["*"] + + # Run the job only on Linux or MacOS. + constraint { + attribute = "\${attr.kernel.name}" + operator = "set_contains_any" + value = "darwin,linux" + } + + group "my_group" { + # Specifies the number of instances of this group that should be running. + # Use this to scale or parallelize your job. + count = 3 + + task "sleepy" { + driver = "raw_exec" + + # The "command" stanza specifies the command to run. + # This command will run a .sh file generated from the template stanza below, + # which will sleep for 2 seconds and repeat until the job is stopped. + config { + command = "\${NOMAD_TASK_DIR}/sleepy.sh" + } + + resources { + memory = 16 + cpu = 16 + } + + template { + data = < 1){ + split($1, versionInfo, /[()]/); + version=versionInfo[1]; + gsub(" ", "", version); + releaseDate=versionInfo[2]; + urlVersion=version; gsub("\\\\.", "", urlVersion); + urlDate=releaseDate; gsub(" ", "-", urlDate); gsub(",", "", urlDate); + for(i=1; i<=NF; i++){ + if($i ~ /^[A-Z ]+:$/){ + gsub(":", "", $i); + section=$i; + itemCount[section]=0; + } + if(section && $i ~ /^\\*/){ + itemCount[section]++; + } + } + printf "Version: %s\\nRelease Date: %s\\n", version, releaseDate; + for (s in itemCount) { + printf "%d %s, ", itemCount[s], s; + } + printf "\\nLink: https://github.com/hashicorp/nomad/blob/main/CHANGELOG.md#%s-%s\\n\\n", urlVersion, tolower(urlDate); + delete itemCount; + count++; + } + }' + EOT + ] + } + + } + } +} +`; From fe5f82e8912736e643461581e98c7ef953b2f658 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Mon, 27 Nov 2023 00:26:12 -0500 Subject: [PATCH 2/4] A pretty different example job --- ui/app/utils/default-job-templates.js | 3 +- ui/app/utils/default_jobs/actions.js | 189 +++++++++++++------------- 2 files changed, 97 insertions(+), 95 deletions(-) diff --git a/ui/app/utils/default-job-templates.js b/ui/app/utils/default-job-templates.js index 3cfec453edb..02d18ab97c6 100644 --- a/ui/app/utils/default-job-templates.js +++ b/ui/app/utils/default-job-templates.js @@ -32,7 +32,8 @@ export default [ }, { key: 'description', - value: 'A raw exec job that shows off Nomad Actions', + value: + 'Nomad Actions let job authors describe commands that can be run in one click from the UI or one command from the CLI. This example job shows how to use them to simulate development on a Redis instance.', }, ], }, diff --git a/ui/app/utils/default_jobs/actions.js b/ui/app/utils/default_jobs/actions.js index 89987beb1fe..766b017affb 100644 --- a/ui/app/utils/default_jobs/actions.js +++ b/ui/app/utils/default_jobs/actions.js @@ -3,128 +3,129 @@ * SPDX-License-Identifier: BUSL-1.1 */ -export default `job "job-with-actions" { - # Specifies the datacenter where this job should be run - # This can be omitted and it will default to ["*"] +export default `job "redis-actions" { datacenters = ["*"] - # Run the job only on Linux or MacOS. - constraint { - attribute = "\${attr.kernel.name}" - operator = "set_contains_any" - value = "darwin,linux" - } - - group "my_group" { - # Specifies the number of instances of this group that should be running. - # Use this to scale or parallelize your job. - count = 3 + group "cache" { + count = 1 + network { + port "db" {} + } - task "sleepy" { - driver = "raw_exec" + task "redis" { + driver = "docker" - # The "command" stanza specifies the command to run. - # This command will run a .sh file generated from the template stanza below, - # which will sleep for 2 seconds and repeat until the job is stopped. config { - command = "\${NOMAD_TASK_DIR}/sleepy.sh" + image = "redis:3.2" + ports = ["db"] + command = "/bin/sh" + args = ["-c", "redis-server --port \${NOMAD_PORT_db} & /local/db_log.sh"] } resources { - memory = 16 - cpu = 16 + cpu = 500 + memory = 256 + } + + service { + name = "redis-service" + port = "db" + provider = "nomad" + + check { + name = "alive" + type = "tcp" + port = "db" + interval = "10s" + timeout = "2s" + } } template { - data = < 1){ - split($1, versionInfo, /[()]/); - version=versionInfo[1]; - gsub(" ", "", version); - releaseDate=versionInfo[2]; - urlVersion=version; gsub("\\\\.", "", urlVersion); - urlDate=releaseDate; gsub(" ", "-", urlDate); gsub(",", "", urlDate); - for(i=1; i<=NF; i++){ - if($i ~ /^[A-Z ]+:$/){ - gsub(":", "", $i); - section=$i; - itemCount[section]=0; - } - if(section && $i ~ /^\\*/){ - itemCount[section]++; - } - } - printf "Version: %s\\nRelease Date: %s\\n", version, releaseDate; - for (s in itemCount) { - printf "%d %s, ", itemCount[s], s; - } - printf "\\nLink: https://github.com/hashicorp/nomad/blob/main/CHANGELOG.md#%s-%s\\n\\n", urlVersion, tolower(urlDate); - delete itemCount; - count++; - } - }' - EOT + args = ["-c", < Date: Mon, 27 Nov 2023 09:40:53 -0500 Subject: [PATCH 3/4] Tests updated with const'd number of default templates --- ui/tests/acceptance/job-run-test.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/ui/tests/acceptance/job-run-test.js b/ui/tests/acceptance/job-run-test.js index 97d021c12e7..09391a36f16 100644 --- a/ui/tests/acceptance/job-run-test.js +++ b/ui/tests/acceptance/job-run-test.js @@ -29,6 +29,8 @@ const newJobName = 'new-job'; const newJobTaskGroupName = 'redis'; const newJobNamespace = 'default'; +const NUMBER_OF_DEFAULT_TEMPLATES = 5; + let managementToken, clientToken; const jsonJob = (overrides) => { @@ -245,7 +247,10 @@ module('Acceptance | job run', function (hooks) { // Assert assert .dom('[data-test-template-card]') - .exists({ count: 4 }, 'A list of default job templates is rendered.'); + .exists( + { count: NUMBER_OF_DEFAULT_TEMPLATES }, + 'A list of default job templates is rendered.' + ); await click('[data-test-create-new-button]'); assert.equal(currentRouteName(), 'jobs.run.templates.new'); @@ -331,7 +336,10 @@ module('Acceptance | job run', function (hooks) { // Assert assert .dom('[data-test-template-card]') - .exists({ count: 4 }, 'A list of default job templates is rendered.'); + .exists( + { count: NUMBER_OF_DEFAULT_TEMPLATES }, + 'A list of default job templates is rendered.' + ); await click('[data-test-create-new-button]'); assert.equal(currentRouteName(), 'jobs.run.templates.new'); @@ -380,7 +388,10 @@ module('Acceptance | job run', function (hooks) { // Assert assert .dom('[data-test-template-card]') - .exists({ count: 4 }, 'A list of default job templates is rendered.'); + .exists( + { count: NUMBER_OF_DEFAULT_TEMPLATES }, + 'A list of default job templates is rendered.' + ); await click('[data-test-create-new-button]'); assert.equal(currentRouteName(), 'jobs.run.templates.new'); @@ -576,7 +587,6 @@ module('Acceptance | job run', function (hooks) { test('default templates', async function (assert) { assert.expect(4); - const NUMBER_OF_DEFAULT_TEMPLATES = 4; await visit('/jobs/run/templates'); From d84df43d8a396f4deac04732f9fbfe573cc84bf8 Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Mon, 4 Dec 2023 10:44:06 -0500 Subject: [PATCH 4/4] Removed default jobspec params and formatted --- .changelog/19153.txt | 3 ++ ui/app/utils/default_jobs/actions.js | 46 ++++++++++++---------------- 2 files changed, 23 insertions(+), 26 deletions(-) create mode 100644 .changelog/19153.txt diff --git a/.changelog/19153.txt b/.changelog/19153.txt new file mode 100644 index 00000000000..6c9da374e1c --- /dev/null +++ b/.changelog/19153.txt @@ -0,0 +1,3 @@ +```release-note:improvement +ui: Added a new example template with Task Actions +``` diff --git a/ui/app/utils/default_jobs/actions.js b/ui/app/utils/default_jobs/actions.js index 766b017affb..cd65feab831 100644 --- a/ui/app/utils/default_jobs/actions.js +++ b/ui/app/utils/default_jobs/actions.js @@ -4,10 +4,8 @@ */ export default `job "redis-actions" { - datacenters = ["*"] group "cache" { - count = 1 network { port "db" {} } @@ -16,20 +14,32 @@ export default `job "redis-actions" { driver = "docker" config { - image = "redis:3.2" - ports = ["db"] + image = "redis:7" + ports = ["db"] command = "/bin/sh" - args = ["-c", "redis-server --port \${NOMAD_PORT_db} & /local/db_log.sh"] + args = ["-c", "redis-server --port \${NOMAD_PORT_db} & /local/db_log.sh"] + } + + template { + data = <