Skip to content

Commit 9d648cc

Browse files
Merge pull request #59 from shipyard-run/nomad_job
Nomad job
2 parents 4ddf3be + 481c754 commit 9d648cc

33 files changed

+1270
-177
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ jobs:
1010
- name: Check out code into the Go module directory
1111
uses: actions/checkout@v2
1212

13+
- name: Setup Go version
14+
uses: actions/setup-go@v2-beta
15+
with:
16+
go-version: '1.13.9' # The Go version to download (if necessary) and use.
17+
1318
- name: Get dependencies
1419
run: |
20+
go version
1521
go get -v -t ./...
1622
1723
- name: Unit Test
@@ -32,9 +38,15 @@ jobs:
3238
runs-on: ubuntu-latest
3339

3440
steps:
35-
- uses: actions/checkout@v2
36-
- name: Build and install
37-
run: make install_local
41+
- uses: actions/checkout@v2
42+
43+
- name: Setup Go version
44+
uses: actions/setup-go@v2-beta
45+
with:
46+
go-version: '1.13.9' # The Go version to download (if necessary) and use.
47+
48+
- name: Build and install
49+
run: make install_local
3850

39-
- name: Run tests
40-
run: make test_functional
51+
- name: Run tests
52+
run: make test_functional

.github/workflows/release.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: goreleaser
22

33
on:
4-
pull_request:
54
push:
65
tags:
76
- 'v*'

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## version 0.0.4
4+
5+
### Container
6+
Allow HTTP health checks to be added to containers
7+
8+
39
## version 0.0.2
410

511
## Docs

cmd/push.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"golang.org/x/xerrors"
1414
)
1515

16-
func newPushCmd(ct clients.ContainerTasks, kc clients.Kubernetes, ht clients.HTTP, log hclog.Logger) *cobra.Command {
16+
func newPushCmd(ct clients.ContainerTasks, kc clients.Kubernetes, ht clients.HTTP, nc clients.Nomad, l hclog.Logger) *cobra.Command {
1717
return &cobra.Command{
1818
Use: "push [image] [cluster]",
1919
Short: "Push a local Docker image to a cluster",
@@ -50,9 +50,9 @@ func newPushCmd(ct clients.ContainerTasks, kc clients.Kubernetes, ht clients.HTT
5050

5151
switch p.Info().Type {
5252
case config.TypeK8sCluster:
53-
return pushK8sCluster(image, p.(*config.K8sCluster), ct, kc, ht, log)
53+
return pushK8sCluster(image, p.(*config.K8sCluster), ct, kc, ht, l)
5454
case config.TypeNomadCluster:
55-
return pushNomadCluster(image, p.(*config.NomadCluster), ct, ht, log)
55+
return pushNomadCluster(image, p.(*config.NomadCluster), ct, nc, l)
5656
}
5757

5858
return nil
@@ -80,7 +80,7 @@ func pushK8sCluster(image string, c *config.K8sCluster, ct clients.ContainerTask
8080
return nil
8181
}
8282

83-
func pushNomadCluster(image string, c *config.NomadCluster, ct clients.ContainerTasks, ht clients.HTTP, log hclog.Logger) error {
83+
func pushNomadCluster(image string, c *config.NomadCluster, ct clients.ContainerTasks, ht clients.Nomad, log hclog.Logger) error {
8484
cl := providers.NewNomadCluster(c, ct, ht, log)
8585

8686
// get the id of the cluster

cmd/push_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ func setupPush(state string) (*cobra.Command, *mocks.MockContainerTasks, func())
2020

2121
mk := &mocks.MockKubernetes{}
2222
mh := &mocks.MockHTTP{}
23+
mn := &mocks.MockNomad{}
2324

24-
return newPushCmd(mt, mk, mh, hclog.NewNullLogger()), mt, setupState(state)
25+
return newPushCmd(mt, mk, mh, mn, hclog.NewNullLogger()), mt, setupState(state)
2526
}
2627

2728
func TestPushInvalidArgsReturnsError(t *testing.T) {

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func init() {
6060
//rootCmd.AddCommand(toolsCmd)
6161
//rootCmd.AddCommand(upgradeCmd)
6262
rootCmd.AddCommand(uninstallCmd)
63-
rootCmd.AddCommand(newPushCmd(engineClients.ContainerTasks, engineClients.Kubernetes, engineClients.HTTP, logger))
63+
rootCmd.AddCommand(newPushCmd(engineClients.ContainerTasks, engineClients.Kubernetes, engineClients.HTTP, engineClients.Nomad, logger))
6464
}
6565

6666
func configure() {

functional_tests/features/single_container.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Feature: Docker Container
22
In order to test Docker containers
33
I should apply a blueprint
44

5-
Scenario: Single Container
5+
Scenario: Single Container from Local Blueprint
66
Given I apply the config "./test_fixtures/single_container"
77
Then there should be 1 network called "onprem"
88
And there should be 1 container running called "consul.container.shipyard"

functional_tests/features/single_k3s_cluster.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ Feature: Kubernetes Cluster
77
Given I apply the config "./test_fixtures/single_k3s_cluster"
88
Then there should be 1 network called "cloud"
99
And there should be 1 container running called "server.k3s.k8s_cluster.shipyard"
10+
And there should be 1 container running called "consul-http.ingress.shipyard"
1011
And a call to "http://localhost:18500/v1/agent/members" should result in status 200

functional_tests/main_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import (
1313
"testing"
1414
"time"
1515

16+
"os/exec"
17+
1618
"github.com/DATA-DOG/godog"
1719
"github.com/DATA-DOG/godog/colors"
1820
"github.com/docker/docker/api/types"
1921
"github.com/docker/docker/api/types/filters"
2022
"github.com/hashicorp/go-hclog"
2123
"github.com/shipyard-run/shipyard/pkg/shipyard"
22-
"k8s.io/utils/exec"
2324
)
2425

2526
var currentClients *shipyard.Clients
@@ -73,8 +74,10 @@ func FeatureContext(s *godog.Suite) {
7374
})
7475

7576
s.AfterScenario(func(interface{}, error) {
76-
ex := exec.New()
77-
cmd := ex.Command("yard-dev", []string{"destroy"}...)
77+
fmt.Println("")
78+
cmd := exec.Command("yard-dev", []string{"destroy"}...)
79+
cmd.Stdout = os.Stdout
80+
cmd.Stderr = os.Stderr
7881
cmd.Run()
7982
})
8083
}
@@ -88,9 +91,19 @@ func iRunApply(config string) error {
8891
}
8992

9093
// run the shipyard executable
91-
ex := exec.New()
92-
cmd := ex.Command("yard-dev", []string{"run", config}...)
93-
return cmd.Run()
94+
cmd := exec.Command("yard-dev", []string{"run", "--no-browser", config}...)
95+
cmd.Stdout = os.Stdout
96+
cmd.Stderr = os.Stderr
97+
98+
runErr := cmd.Run()
99+
100+
if runErr != nil {
101+
if exitError, ok := runErr.(*exec.ExitError); ok {
102+
return fmt.Errorf("Shipyard command exited with status code %d", exitError.ExitCode())
103+
}
104+
}
105+
106+
return nil
94107
}
95108

96109
func thereShouldBeContainerRunningCalled(arg1 int, arg2 string) error {
@@ -147,7 +160,7 @@ func thereShouldBe1NetworkCalled(arg1 string) error {
147160
func aCallToShouldResultInStatus(arg1 string, arg2 int) error {
148161
// try 100 times
149162
var err error
150-
for i := 0; i < 100; i++ {
163+
for i := 0; i < 200; i++ {
151164
var resp *http.Response
152165
resp, err = http.Get(arg1)
153166

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
job "example_2" {
2+
datacenters = ["dc1"]
3+
type = "service"
4+
5+
update {
6+
max_parallel = 1
7+
min_healthy_time = "10s"
8+
healthy_deadline = "3m"
9+
progress_deadline = "10m"
10+
auto_revert = false
11+
canary = 0
12+
}
13+
14+
migrate {
15+
max_parallel = 1
16+
health_check = "checks"
17+
min_healthy_time = "10s"
18+
healthy_deadline = "5m"
19+
}
20+
21+
group "cache" {
22+
count = 1
23+
24+
restart {
25+
# The number of attempts to run the job within the specified interval.
26+
attempts = 2
27+
interval = "30m"
28+
delay = "15s"
29+
mode = "fail"
30+
}
31+
32+
ephemeral_disk {
33+
size = 200
34+
}
35+
36+
task "redis" {
37+
# The "driver" parameter specifies the task driver that should be used to
38+
# run the task.
39+
driver = "docker"
40+
41+
config {
42+
image = "redis:3.2"
43+
44+
port_map {
45+
db = 6380
46+
}
47+
}
48+
49+
resources {
50+
cpu = 500 # 500 MHz
51+
memory = 256 # 256MB
52+
53+
network {
54+
mbits = 10
55+
port "db" {}
56+
}
57+
}
58+
59+
service {
60+
name = "redis-cache"
61+
tags = ["global", "cache"]
62+
port = "db"
63+
64+
check {
65+
name = "alive"
66+
type = "tcp"
67+
interval = "10s"
68+
timeout = "2s"
69+
}
70+
}
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)