forked from aws-deadline/deadline-cloud-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
84 lines (71 loc) · 2.38 KB
/
Copy pathtemplate.yaml
File metadata and controls
84 lines (71 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
specificationVersion: 'jobtemplate-2023-09'
name: Job sample with a new command in the PATH
description: |
A job template can define Open Job Description environments that create new command
scripts and add them to the PATH environment variable for all steps of the job to use.
jobEnvironments:
- name: RandomSleepCommand
description: Adds a command 'random-sleep' to the environment.
script:
actions:
onEnter:
command: bash
args:
- "{{Env.File.Enter}}"
embeddedFiles:
- name: Enter
type: TEXT
data: |
#!/bin/env bash
set -euo pipefail
# Make a bin directory inside the session's working directory for providing new commands
mkdir -p '{{Session.WorkingDirectory}}/bin'
# If this bin directory is not already in the PATH, then add it
if ! [[ ":$PATH:" == *':{{Session.WorkingDirectory}}/bin:'* ]]; then
export "PATH={{Session.WorkingDirectory}}/bin:$PATH"
# This message to Open Job Description exports the new PATH value to the environment
echo "openjd_env: PATH=$PATH"
fi
# Copy the SleepScript embedded file into the bin directory
cp '{{Env.File.SleepScript}}' '{{Session.WorkingDirectory}}/bin/random-sleep'
chmod u+x '{{Session.WorkingDirectory}}/bin/random-sleep'
- name: SleepScript
type: TEXT
runnable: true
data: |
#!/bin/env python
"""
Usage: random-sleep MIN MAX
Sleeps for a random number of seconds, between the MIN and MAX values.
"""
import argparse
import random
import time
random.seed()
parser = argparse.ArgumentParser(prog='random-sleep')
parser.add_argument('min', type=float)
parser.add_argument('max', type=float)
args = parser.parse_args()
duration = random.uniform(args.min, args.max)
print(f"Sleeping for duration {duration:.2f}")
time.sleep(duration)
steps:
- name: EnvWithCommand
script:
actions:
onRun:
command: bash
args:
- '{{Task.File.Run}}'
embeddedFiles:
- name: Run
type: TEXT
data: |
set -xeuo pipefail
# Run the script installed into PATH by the job environment
random-sleep 12.5 27.5
hostRequirements:
attributes:
- name: attr.worker.os.family
anyOf:
- linux