Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Nomad Jobspec Plugin #1299

Merged
merged 5 commits into from
Apr 20, 2021
Merged

Nomad Jobspec Plugin #1299

merged 5 commits into from
Apr 20, 2021

Conversation

mitchellh
Copy link
Contributor

@mitchellh mitchellh commented Apr 8, 2021

Builds on #1298.

This introduces a plugin that can deploy to Nomad directly from a job specification file. This uses the mutable deployments functionality introduced in #1298. Example below:

// The waypoint.hcl file
deploy {
  use "nomad-jobspec" {
    // Templated to perhaps bring in the artifact from a previous
	// build/registry, entrypoint env vars, etc.
    jobspec = templatefile("${path.app}/app.nomad.tpl")
  }
}
// The app.nomad.tpl file
job "web" {
  datacenters = ["dc1"]
  group "app" {
    task "app" {
      driver = "docker"
      config {
        image = "${artifact.image}:${artifact.tag}"

        // For local Nomad, you prob don't need this on a real deploy
        network_mode = "host"
      }
      env {
        %{ for k,v in entrypoint.env ~}
        ${k} = "${v}"
        %{ endfor ~}

        // For URL service
        PORT = "3000"
      }
    }
  }
}

@rkrasiuk
Copy link

rkrasiuk commented Apr 9, 2021

@mitchellh thanks for adding this functionality. is there a plan to support levant down the road?

@mitchellh
Copy link
Contributor Author

@mitchellh thanks for adding this functionality. is there a plan to support levant down the road?

Yes, likely via a separate plugin. We're trying to make well-scoped plugins. But if you look at how simple this one is, you can see that these are really quick, easy things to write!

Copy link
Member

@briancain briancain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Gave this a go with the waypoint-examples/nodejs project, but copied it over to use the jobspec plugin: hashicorp/waypoint-examples#65

Worked for me bringing up a job a couple of times and destroying each time!

Copy link
Contributor

@krantzinator krantzinator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this!
I did have to specify a namespace in my job templatefile to get the release URL to work; it does not seem to be defaulting to "default" for me:

job "web" {
  datacenters = ["dc1"]
  namespace = "default"

builtin/nomad/jobspec/platform.go Outdated Show resolved Hide resolved
@krantzinator
Copy link
Contributor

Thanks for tackling this!
I did have to specify a namespace in my job templatefile to get the release URL to work; it does not seem to be defaulting to "default" for me. This is more an FYI, as it's something only I seem to be experiencing currently:

job "web" {
  datacenters = ["dc1"]
  namespace = "default"

Fixed! #1358
:shipit: x2

Copy link
Contributor

@evanphx evanphx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just that one confusion about the indenting on the example, otherwise 👍

@mitchellh mitchellh merged commit cb79673 into feature/generations Apr 20, 2021
@mitchellh mitchellh deleted the feature/nomad branch April 20, 2021 15:39
@Allan-Nava
Copy link

Need to create a new file app.nomad.tpl right ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants