Skip to content

Commit 9005fa5

Browse files
committed
feat(pipeline): add dryccfile support
1 parent d4ee259 commit 9005fa5

10 files changed

Lines changed: 84 additions & 31 deletions

File tree

cmd/builds.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,40 @@ func (d *DryccCmd) BuildsList(appID string, results int) error {
4343
}
4444

4545
// BuildsCreate creates a build for an app.
46-
func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile string) error {
46+
func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile string, dryccfile string) error {
4747
s, appID, err := load(d.ConfigFile, appID)
4848

4949
if err != nil {
5050
return err
5151
}
5252

5353
procfileMap := make(map[string]string)
54+
if _, err := os.Stat(procfile); err == nil {
55+
contents, err := os.ReadFile(procfile)
56+
if err != nil {
57+
return err
58+
}
5459

55-
if procfile != "" {
56-
if procfileMap, err = parseProcfile([]byte(procfile)); err != nil {
60+
if procfileMap, err = parseProcfile(contents); err != nil {
5761
return err
5862
}
59-
} else if _, err := os.Stat("Procfile"); err == nil {
60-
contents, err := os.ReadFile("Procfile")
63+
}
64+
65+
dryccfileMap := make(map[string]interface{})
66+
if _, err := os.Stat(dryccfile); err == nil {
67+
contents, err := os.ReadFile(dryccfile)
6168
if err != nil {
6269
return err
6370
}
6471

65-
if procfileMap, err = parseProcfile(contents); err != nil {
72+
if dryccfileMap, err = parseDryccfile(contents); err != nil {
6673
return err
6774
}
6875
}
6976

7077
d.Print("Creating build... ")
7178
quit := progress(d.WOut)
72-
_, err = builds.New(s.Client, appID, image, stack, procfileMap)
79+
_, err = builds.New(s.Client, appID, image, stack, procfileMap, dryccfileMap)
7380
quit <- true
7481
<-quit
7582
if d.checkAPICompatibility(s.Client, err) != nil {
@@ -85,3 +92,8 @@ func parseProcfile(procfile []byte) (map[string]string, error) {
8592
procfileMap := make(map[string]string)
8693
return procfileMap, yaml.Unmarshal(procfile, &procfileMap)
8794
}
95+
96+
func parseDryccfile(dryccfile []byte) (map[string]interface{}, error) {
97+
dryccfileMap := make(map[string]interface{})
98+
return dryccfileMap, yaml.Unmarshal(dryccfile, &dryccfileMap)
99+
}

cmd/builds_test.go

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestBuildsCreate(t *testing.T) {
143143
fmt.Fprintf(w, "{}")
144144
})
145145

146-
err = cmdr.BuildsCreate("enterprise", "ncc/1701:A", "container", "")
146+
err = cmdr.BuildsCreate("enterprise", "ncc/1701:A", "container", "", "")
147147
assert.NoError(t, err)
148148
assert.Equal(t, testutil.StripProgress(b.String()), "Creating build... done\n", "output")
149149

@@ -163,9 +163,22 @@ func TestBuildsCreate(t *testing.T) {
163163
})
164164
b.Reset()
165165

166-
err = cmdr.BuildsCreate("bradbury", "nx/72307:latest", "container", `web: ./drive
167-
warp: ./warp 8
168-
`)
166+
tmpDir, err := os.MkdirTemp("", "tmpdir")
167+
if err != nil {
168+
t.Fatalf("error creating temp directory (%s)", err)
169+
}
170+
data := `web: ./drive
171+
warp: ./warp 8`
172+
if err := os.WriteFile(tmpDir+"/Procfile", []byte(data), 0644); err != nil {
173+
t.Fatalf("error creating %s/Procfile (%s)", tmpDir, err)
174+
}
175+
defer func() {
176+
if err := os.RemoveAll(tmpDir); err != nil {
177+
t.Fatalf("failed to remove Procfile from %s (%s)", tmpDir, err)
178+
}
179+
}()
180+
181+
err = cmdr.BuildsCreate("bradbury", "nx/72307:latest", "container", tmpDir+"/Procfile", "")
169182
assert.NoError(t, err)
170183
assert.Equal(t, testutil.StripProgress(b.String()), "Creating build... done\n", "output")
171184

@@ -178,6 +191,14 @@ warp: ./warp 8
178191
"web": "./drive",
179192
"warp": "./warp 8",
180193
},
194+
Dryccfile: map[string]interface{}{
195+
"deploy": map[string]interface{}{
196+
"web": map[string]interface{}{
197+
"command": []string{"bash", "-c"},
198+
"args": []string{"bundle exec puma -C config/puma.rb"},
199+
},
200+
},
201+
},
181202
}, r)
182203

183204
w.WriteHeader(http.StatusCreated)
@@ -190,7 +211,18 @@ warp: ./warp 8
190211
`), os.ModePerm)
191212
assert.NoError(t, err)
192213

193-
err = cmdr.BuildsCreate("franklin", "nx/326:latest", "container", "")
214+
err = os.WriteFile("drycc.yaml", []byte(`
215+
deploy:
216+
web:
217+
command:
218+
- bash
219+
- -c
220+
args:
221+
- bundle exec puma -C config/puma.rb
222+
`), os.ModePerm)
223+
assert.NoError(t, err)
224+
225+
err = cmdr.BuildsCreate("franklin", "nx/326:latest", "container", "Procfile", "drycc.yaml")
194226
assert.NoError(t, err)
195227
assert.Equal(t, testutil.StripProgress(b.String()), "Creating build... done\n", "output")
196228

cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Commander interface {
2424
Logout() error
2525
Whoami(bool) error
2626
BuildsList(string, int) error
27-
BuildsCreate(string, string, string, string) error
27+
BuildsCreate(string, string, string, string, string) error
2828
CanaryInfo(string) error
2929
CanaryCreate(string, []string) error
3030
CanaryRemove(string, []string) error

cmd/releases.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ func (d *DryccCmd) ReleasesList(appID string, results int) error {
2525
if count == 0 {
2626
d.Println(fmt.Sprintf("No releases found in %s app.", appID))
2727
} else {
28-
table := d.getDefaultFormatTable([]string{"UUID", "OWNER", "VERSION", "CREATED", "SUMMARY"})
28+
table := d.getDefaultFormatTable([]string{"UUID", "OWNER", "STATE", "VERSION", "CREATED", "SUMMARY"})
2929
for _, r := range releases {
3030
summary := r.Summary
3131
if len(summary) > 64 {
3232
summary = fmt.Sprintf("%s[...]", summary[:64])
3333
}
34-
table.Append([]string{r.UUID, r.Owner, fmt.Sprintf("v%d", r.Version), r.Created, summary})
34+
table.Append([]string{r.UUID, r.Owner, r.State, fmt.Sprintf("v%d", r.Version), r.Created, summary})
3535
}
3636
table.Render()
3737
}
@@ -53,6 +53,7 @@ func (d *DryccCmd) ReleasesInfo(appID string, version int) error {
5353
table := d.getDefaultFormatTable([]string{})
5454
table.Append([]string{"App:", r.App})
5555
table.Append([]string{"UUID:", r.UUID})
56+
table.Append([]string{"State:", r.State})
5657
table.Append([]string{"Owner:", r.Owner})
5758
table.Append([]string{"Build:", r.Build})
5859
table.Append([]string{"Config:", r.Config})

cmd/releases_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestReleasesList(t *testing.T) {
3232
{
3333
"uuid": "c4aed81c-d1ca-4ff1-ab89-d2151264e1a3",
3434
"app": "numenor",
35+
"state": "succeed",
3536
"owner": "nazgul",
3637
"created": "2016-08-22T17:40:16Z",
3738
"updated": "2016-08-22T17:40:16Z",
@@ -42,6 +43,7 @@ func TestReleasesList(t *testing.T) {
4243
},
4344
{
4445
"app": "numenor",
46+
"state": "succeed",
4547
"build": null,
4648
"config": "95bd6dea-1685-4f78-a03d-fd7270b058d1",
4749
"created": "2014-01-01T00:00:00UTC",
@@ -57,9 +59,9 @@ func TestReleasesList(t *testing.T) {
5759

5860
err = cmdr.ReleasesList("numenor", -1)
5961
assert.NoError(t, err)
60-
assert.Equal(t, b.String(), `UUID OWNER VERSION CREATED SUMMARY
61-
c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 nazgul v2 2016-08-22T17:40:16Z khamul added ANGMAR
62-
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 nazgul v1 2014-01-01T00:00:00UTC nazgul created initial release
62+
assert.Equal(t, b.String(), `UUID OWNER STATE VERSION CREATED SUMMARY
63+
c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 nazgul succeed v2 2016-08-22T17:40:16Z khamul added ANGMAR
64+
de1bf5b5-4a72-4f94-a10c-d2a3741cdf75 nazgul succeed v1 2014-01-01T00:00:00UTC nazgul created initial release
6365
`, "output")
6466
}
6567

@@ -83,6 +85,7 @@ func TestReleasesListLimit(t *testing.T) {
8385
{
8486
"uuid": "c4aed81c-d1ca-4ff1-ab89-d2151264e1a3",
8587
"app": "numenor",
88+
"state": "succeed",
8689
"owner": "nazgul",
8790
"created": "2016-08-22T17:40:16Z",
8891
"updated": "2016-08-22T17:40:16Z",
@@ -97,8 +100,8 @@ func TestReleasesListLimit(t *testing.T) {
97100

98101
err = cmdr.ReleasesList("numenor", 1)
99102
assert.NoError(t, err)
100-
assert.Equal(t, b.String(), `UUID OWNER VERSION CREATED SUMMARY
101-
c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 nazgul v2 2016-08-22T17:40:16Z khamul added ANGMAR
103+
assert.Equal(t, b.String(), `UUID OWNER STATE VERSION CREATED SUMMARY
104+
c4aed81c-d1ca-4ff1-ab89-d2151264e1a3 nazgul succeed v2 2016-08-22T17:40:16Z khamul added ANGMAR
102105
`, "output")
103106
}
104107

@@ -117,6 +120,7 @@ func TestReleasesInfo(t *testing.T) {
117120
fmt.Fprintf(w, `{
118121
"uuid": "c4aed81c-d1ca-4ff1-ab89-d2151264e1a3",
119122
"app": "numenor",
123+
"state": "succeed",
120124
"owner": "nazgul",
121125
"created": "2016-08-22T17:40:16Z",
122126
"updated": "2016-08-22T17:40:16Z",
@@ -131,6 +135,7 @@ func TestReleasesInfo(t *testing.T) {
131135
assert.NoError(t, err)
132136
assert.Equal(t, b.String(), `App: numenor
133137
UUID: c4aed81c-d1ca-4ff1-ab89-d2151264e1a3
138+
State: succeed
134139
Owner: nazgul
135140
Build:
136141
Config: 3bb816b1-4fde-4b06-8afe-acd12f58a266

cmd/resources_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func TestResourceDelete(t *testing.T) {
207207
err = cmdr.ResourceDelete("example-go", "mysql", "mysql")
208208
assert.NoError(t, err)
209209

210-
assert.Equal(t, testutil.StripProgress(b.String()), "Deleting mysql from example-go... done\n", "output")
210+
assert.Equal(t, testutil.StripProgress(b.String()), "Destroying mysql...\ndone\n", "output")
211211
}
212212

213213
func TestResourcePut(t *testing.T) {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22
55
require (
66
github.com/containerd/console v1.0.4
77
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
8-
github.com/drycc/controller-sdk-go v0.0.0-20240322070846-b558c520d745
8+
github.com/drycc/controller-sdk-go v0.0.0-20240403162730-10676f2b328d
99
github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f
1010
github.com/olekukonko/tablewriter v0.0.5
1111
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
55
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
66
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
7-
github.com/drycc/controller-sdk-go v0.0.0-20240322070846-b558c520d745 h1:eXYotkPeGfc7gmjle7v2ytiNGQzoV63BHHaWZh0SNGU=
8-
github.com/drycc/controller-sdk-go v0.0.0-20240322070846-b558c520d745/go.mod h1:RJ0QxVNWhximzfd08+FkZfKzrX7gOp2gsgXfpqVPJZQ=
7+
github.com/drycc/controller-sdk-go v0.0.0-20240403162730-10676f2b328d h1:qffye+xHsNTpn9/kD0YY/fkov6IBJTJIVXWxoXtXCrw=
8+
github.com/drycc/controller-sdk-go v0.0.0-20240403162730-10676f2b328d/go.mod h1:RJ0QxVNWhximzfd08+FkZfKzrX7gOp2gsgXfpqVPJZQ=
99
github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f h1:kgjvUQJeAszDoU1Vo4vTTE92KI8Av3JPb6Qn890niXg=
1010
github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f/go.mod h1:n+QxGif6ha9CEoxVnlipxb9IdmerybcUSzTEDFkvjiA=
1111
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=

parser/builds.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ Options:
6767
func buildsCreate(argv []string, cmdr cmd.Commander) error {
6868
usage := `
6969
Creates a new build of an application. Imports an <image> and deploys it to Drycc
70-
as a new release. If a Procfile is present in the current directory, it will be used
71-
as the default process types for this application.
70+
as a new release. If a Procfile or drycc.yaml is present in the current directory,
71+
it will be used as the default for this application.
7272
7373
Usage: drycc builds:create <image> [options]
7474
7575
Arguments:
7676
<image>
77-
A fully-qualified container image, either from Drycc Registry (e.g. registry.drycc.cc/drycc/example-go:latest)
77+
A default fully-qualified container image, either from Drycc Registry (e.g. registry.drycc.cc/drycc/example-go:latest)
7878
or from an in-house registry (e.g. myregistry.example.com:5000/example-go:latest).
7979
This image must include the tag.
8080
@@ -84,7 +84,9 @@ Options:
8484
-s --stack=<stack>
8585
The stack name for the application, defaults to container.
8686
-p --procfile=<procfile>
87-
A YAML string used to supply a Procfile to the application.
87+
A YAML file used to supply a Procfile to the application.
88+
-d --dryccfile=<dryccfile>
89+
A YAML file used to supply a drycc.yaml to the application.
8890
`
8991

9092
args, err := docopt.ParseArgs(usage, argv, "")
@@ -99,7 +101,8 @@ Options:
99101
if stack == "" {
100102
stack = "container"
101103
}
102-
procfile := safeGetString(args, "--procfile")
104+
procfile := safeGetValue(args, "--procfile", "Procfile")
105+
dryccfile := safeGetValue(args, "--dryccfile", "drycc.yaml")
103106

104-
return cmdr.BuildsCreate(app, image, stack, procfile)
107+
return cmdr.BuildsCreate(app, image, stack, procfile, dryccfile)
105108
}

parser/builds_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (d FakeDryccCmd) BuildsList(string, int) error {
1313
return errors.New("builds:list")
1414
}
1515

16-
func (d FakeDryccCmd) BuildsCreate(string, string, string, string) error {
16+
func (d FakeDryccCmd) BuildsCreate(string, string, string, string, string) error {
1717
return errors.New("builds:create")
1818
}
1919

0 commit comments

Comments
 (0)