-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
CLI should accept JSON job specs #1749
Comments
I guess its the same issue as #1163 I don't get why JSON would be 2nd level citizen on CLI HCL is terrible to write out programmatically from e.g. PHP (no lib to serialize an array to HCL), where JSON (or even YAML) are very easy to work with
but doesn't mention the |
Hi @jippi I think I see the confusion here. The JobSpec and the Job File are different things. The result of the A JSON job file would need to map to the HCL. The mapping between HCL and JSON is not always 1-1, but here is an example to help you out: job "jenkins" {
datacenters = ["dc1"]
group "jenkins" {
ephemeral_disk {
size = 300
}
task "jenkins" {
driver = "docker"
config {
image = "jenkins:alpine"
port_map {
ui = 8080
agent = 50000
}
}
resources {
cpu = 500
memory = 256
network {
mbits = 10
port "ui" {}
port "agent" {}
}
}
}
}
} {
"job": {
"jenkins": {
"datacenters": ["us-east-1"],
"group": [
{
"jenkins": {
"ephemeral_disk": {
"size": "300",
},
"task": [
{
"jenkins": {
"driver": "docker",
"config": {
"image": "jenkins:alpine",
"port_map": {
"ui": "8080",
"agent": "50000"
}
},
"resources": {
"cpu": "500",
"memory": "256",
"network": {
"mbits": "10",
"port": [
{ "ui": {} },
{ "agent": {} }
]
}
}
}
}
]
}
}
]
}
}
} To re-iterate, there are two kinds of JSON:
The @dadgar do you think it would be a good idea to add the JSON schema to the nomad docs somewhere? |
JSON version already exists: https://www.nomadproject.io/docs/jobspec/json.html |
Going to update the issue to represent the fact that the CLI should detect if the job is JSON and submit it. |
@dadgar I think there are two issues here - there are people who generate HCL-compliant JSON (which the HCL parser will happily parse), and there's the JSON spec. For example, the jobfile I posted above does work because it's parsed as JSON-HCL. |
I think must people want |
I don't disagree with that, but I think people also want |
@sethvargo Yeah I think we are on the same page! That is what I am saying I want to support |
@dadgar @sethvargo thanks for the clarification For me the confusion started with me assuming Also HCL page There don't seem to be any JSON JobFile examples in the docs atm then? |
Yeah, so this whole JSON <> HCL thing is a bit confusing. =)
This leads you to believe you simply can convert a job spec written in HCL into JSON and it will work. Obviously this is not really the case... I'm (trying to) autogenerating job (JSON) and have found that the HCL documentation can't really be followed. https://www.nomadproject.io/docs/http/json-jobs.html (The example job will not parse due to the task requesting a DiskMB allocation, something that is not allowed since version 0.5.0.) The job @sethvargo posted above will not parse, if you add consul service and check to it.
For a JSON job containing service with checks to parse one must use |
@rickardrosen It is both a product and documentation bug unfortunately! Would you mind creating a PR to remedy the docs and make it parse as that is an easy win right now. Parsing JSON is a little bigger of a task |
I think that HCL is way nicer, and would personally be happy to be able to submit hcl jobs via api. |
I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues. |
Nomad version
v0.4.1
Operating system and Environment details
Issue
invalid key: Job
when submitting JSON jobsTrying
nomad run -output <job.nomad>
on an existing HCL job, converting it to JSON, fail with the same errorReproduction steps
raw.json
nomad run raw.json
Nomad Server logs (if appropriate)
Job file (if appropriate)
The example JSON from the documentation.
Any other JSON job i've tried to submit fail on the same error :)
The text was updated successfully, but these errors were encountered: