Skip to content

Commit

Permalink
Merge branch 'master' into f-docker-progress-detection
Browse files Browse the repository at this point in the history
  • Loading branch information
nickethier committed May 3, 2018
2 parents c6729ff + 86093d1 commit bef2845
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

IMPROVEMENTS:
* client/driver: Add progress monitoring and inactivity detection to docker
image pulls [GH-4192]
image pulls [[GH-4192](https://github.com/hashicorp/nomad/issues/4192)
* command: add -short option to init command that emits a minimal
jobspec [[GH-4239](https://github.com/hashicorp/nomad/issues/4239)]

## 0.8.3 (April 27, 2018)

Expand Down
2 changes: 1 addition & 1 deletion api/allocations.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ type AllocationListStub struct {
ClientDescription string
TaskStates map[string]*TaskState
DeploymentStatus *AllocDeploymentStatus
RescheduleTracker *RescheduleTracker
FollowupEvalID string
RescheduleTracker *RescheduleTracker
CreateIndex uint64
ModifyIndex uint64
CreateTime int64
Expand Down
71 changes: 69 additions & 2 deletions command/job_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ Alias: nomad init
Creates an example job file that can be used as a starting
point to customize further.
Init Options:
-short
If the short flag is set, a minimal jobspec without comments is emitted.
`
return strings.TrimSpace(helpText)
}
Expand All @@ -37,8 +42,18 @@ func (c *JobInitCommand) Synopsis() string {
func (c *JobInitCommand) Name() string { return "job init" }

func (c *JobInitCommand) Run(args []string) int {
var short bool

flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&short, "short", false, "")

if err := flags.Parse(args); err != nil {
return 1
}

// Check for misuse
if len(args) != 0 {
if len(flags.Args()) != 0 {
c.Ui.Error("This command takes no arguments")
c.Ui.Error(commandErrorText(c))
return 1
Expand All @@ -55,8 +70,16 @@ func (c *JobInitCommand) Run(args []string) int {
return 1
}

var jobSpec []byte

if short {
jobSpec = []byte(shortJob)
} else {
jobSpec = []byte(defaultJob)
}

// Write out the example
err = ioutil.WriteFile(DefaultInitName, []byte(defaultJob), 0660)
err = ioutil.WriteFile(DefaultInitName, jobSpec, 0660)
if err != nil {
c.Ui.Error(fmt.Sprintf("Failed to write '%s': %v", DefaultInitName, err))
return 1
Expand All @@ -67,6 +90,50 @@ func (c *JobInitCommand) Run(args []string) int {
return 0
}

var shortJob = strings.TrimSpace(`
job "example" {
datacenters = ["dc1"]
group "cache" {
ephemeral_disk {
size = 300
}
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
port_map {
db = 6379
}
}
resources {
cpu = 500
memory = 256
network {
mbits = 10
port "db" {}
}
}
service {
name = "redis-cache"
tags = ["global", "cache"]
port = "db"
check {
name = "alive"
type = "tcp"
interval = "10s"
timeout = "2s"
}
}
}
}
}
`)

var defaultJob = strings.TrimSpace(`
# There can only be a single job definition per file. This job is named
# "example" so it will create a job with the ID and Name "example".
Expand Down
10 changes: 10 additions & 0 deletions command/job_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/mitchellh/cli"
"github.com/stretchr/testify/require"
)

func TestInitCommand_Implements(t *testing.T) {
Expand Down Expand Up @@ -57,6 +58,15 @@ func TestInitCommand_Run(t *testing.T) {
t.Fatalf("unexpected file content\n\n%s", string(content))
}

// Works with -short flag
os.Remove(DefaultInitName)
if code := cmd.Run([]string{"-short"}); code != 0 {
require.Zero(t, code, "unexpected exit code: %d", code)
}
content, err = ioutil.ReadFile(DefaultInitName)
require.NoError(t, err)
require.Equal(t, string(content), shortJob)

// Fails if the file exists
if code := cmd.Run([]string{}); code != 1 {
t.Fatalf("expect exit code 1, got: %d", code)
Expand Down
2 changes: 2 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5987,6 +5987,7 @@ func (a *Allocation) Stub() *AllocListStub {
TaskStates: a.TaskStates,
DeploymentStatus: a.DeploymentStatus,
FollowupEvalID: a.FollowupEvalID,
RescheduleTracker: a.RescheduleTracker,
CreateIndex: a.CreateIndex,
ModifyIndex: a.ModifyIndex,
CreateTime: a.CreateTime,
Expand All @@ -6010,6 +6011,7 @@ type AllocListStub struct {
TaskStates map[string]*TaskState
DeploymentStatus *AllocDeploymentStatus
FollowupEvalID string
RescheduleTracker *RescheduleTracker
CreateIndex uint64
ModifyIndex uint64
CreateTime int64
Expand Down
1 change: 1 addition & 0 deletions website/source/resources.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ description: |-
<li><a href="https://www.hashicorp.com/blog/auto-bootstrapping-a-nomad-cluster">Auto-bootstrapping a Nomad Cluster</a> - Nic Jackson</li>
<li><a href="https://www.hashicorp.com/blog/replacing-queues-with-nomad-dispatch">Replacing Queues with Nomad Dispatch</a> - Armon Dadgar</li>
<li><a href="https://sanderknape.com/2016/08/nomad-consul-multi-datacenter-container-orchestration/">Multi-datacenter Container Orchestration with Nomad and Consul</a> - Sander Knape</li>
<li><a href="https://www.hashicorp.com/blog/on-demand-container-storage-with-hashicorp-nomad/">On-demand Container Storage with HashiCorp Nomad</a> - Jeff Silberman, <strong>Portworx</strong></li>
</ul>

<h2>Tools for Provisioning and Experimentation</h2>
Expand Down

0 comments on commit bef2845

Please sign in to comment.