Skip to content

Commit a51c618

Browse files
committed
chore(workflow): compatible with the latest dryccfile format
1 parent b0bd707 commit a51c618

29 files changed

Lines changed: 108 additions & 134 deletions

cmd/builds.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (d *DryccCmd) BuildsInfo(appID string, version int) error {
5656
}
5757

5858
// BuildsCreate creates a build for an app.
59-
func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile, dryccfile, confirm string) error {
59+
func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile, dryccpath, confirm string) error {
6060
s, appID, err := load(d.ConfigFile, appID)
6161

6262
if err != nil {
@@ -76,13 +76,8 @@ func (d *DryccCmd) BuildsCreate(appID, image, stack, procfile, dryccfile, confir
7676
}
7777

7878
dryccfileMap := make(map[string]interface{})
79-
if _, err := os.Stat(dryccfile); err == nil {
80-
contents, err := os.ReadFile(dryccfile)
81-
if err != nil {
82-
return err
83-
}
84-
85-
if dryccfileMap, err = parseDryccfile(contents); err != nil {
79+
if info, err := os.Stat(dryccpath); err == nil && info.IsDir() {
80+
if dryccfileMap, err = drycc.ParseDryccfile(dryccpath); err != nil {
8681
return err
8782
}
8883
}
@@ -110,11 +105,6 @@ func parseProcfile(procfile []byte) (map[string]string, error) {
110105
return procfileMap, yaml.Unmarshal(procfile, &procfileMap)
111106
}
112107

113-
func parseDryccfile(dryccfile []byte) (map[string]interface{}, error) {
114-
dryccfileMap := make(map[string]interface{})
115-
return dryccfileMap, yaml.Unmarshal(dryccfile, &dryccfileMap)
116-
}
117-
118108
func buildConfirmAction(c *drycc.Client, appID string, procfileMap map[string]string,
119109
dryccfileMap map[string]interface{}, confirm string) error {
120110

@@ -123,7 +113,7 @@ func buildConfirmAction(c *drycc.Client, appID string, procfileMap map[string]st
123113
if ((len(build.Procfile) != 0 && len(procfileMap) == 0) || (len(build.Dryccfile) != 0 && len(dryccfileMap) == 0)) && (confirm == "" || confirm != "yes") {
124114
// hint
125115
fmt.Printf(` ! WARNING: Potentially Build Create Action
126-
! The Procfile or drycc.yaml is empty, not last time
116+
! The Procfile or drycc file is empty, not last time
127117
! To proceed, type "yes" !
128118
129119
> `)

cmd/builds_test.go

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"net/http"
77
"os"
8+
"path/filepath"
89
"testing"
910

1011
"github.com/drycc/controller-sdk-go/api"
@@ -146,10 +147,19 @@ warp: ./warp 8`
146147
"warp": "./warp 8",
147148
},
148149
Dryccfile: map[string]interface{}{
149-
"deploy": map[string]interface{}{
150-
"web": map[string]interface{}{
151-
"command": []string{"bash", "-c"},
152-
"args": []string{"bundle exec puma -C config/puma.rb"},
150+
"pipeline": map[string]interface{}{
151+
"web.yaml": map[string]interface{}{
152+
"kind": "pipeline",
153+
"ptype": "web",
154+
"deploy": map[string]interface{}{
155+
"command": []string{
156+
"bash",
157+
"-c",
158+
},
159+
"args": []string{
160+
"bundle exec puma -C config/puma.rb",
161+
},
162+
},
153163
},
154164
},
155165
},
@@ -166,18 +176,22 @@ warp: ./warp 8
166176
`), os.ModePerm)
167177
assert.NoError(t, err)
168178

169-
err = os.WriteFile("drycc.yaml", []byte(`
179+
dryccpath := ".drycc"
180+
os.MkdirAll(dryccpath, 0700)
181+
defer os.RemoveAll(dryccpath)
182+
err = os.WriteFile(filepath.Join(dryccpath, "web.yaml"), []byte(`
183+
kind: pipeline
184+
ptype: web
170185
deploy:
171-
web:
172-
command:
173-
- bash
174-
- -c
175-
args:
176-
- bundle exec puma -C config/puma.rb
186+
command:
187+
- bash
188+
- -c
189+
args:
190+
- bundle exec puma -C config/puma.rb
177191
`), os.ModePerm)
178192
assert.NoError(t, err)
179193

180-
err = cmdr.BuildsCreate("franklin", "nx/326:latest", "container", "Procfile", "drycc.yaml", "yes")
194+
err = cmdr.BuildsCreate("franklin", "nx/326:latest", "container", "Procfile", dryccpath, "yes")
181195
assert.NoError(t, err)
182196
assert.Equal(t, testutil.StripProgress(b.String()), "Creating build... done\n", "output")
183197

cmd/config.go

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,7 @@ func (d *DryccCmd) ConfigPull(appID, ptype, group, fileName string, interactive
189189
}
190190

191191
if interactive {
192-
contents, err := os.ReadFile(fileName)
193-
if err != nil {
194-
return err
195-
}
196-
localConfigVars := strings.Split(string(contents), "\n")
197-
configMap, err := parseEnv(localConfigVars[:len(localConfigVars)-1])
192+
configMap, err := drycc.ParseEnv(fileName)
198193
if err != nil {
199194
return err
200195
}
@@ -356,27 +351,6 @@ func parseConfig(ptype, group string, configVars []string) ([]api.ConfigValue, e
356351
return configMap, nil
357352
}
358353

359-
func parseEnv(configVars []string) (map[string]interface{}, error) {
360-
configMap := make(map[string]interface{})
361-
362-
regex := regexp.MustCompile(`^([A-z0-9_\-\.]+)=([\s\S]*)$`)
363-
for _, config := range configVars {
364-
// Skip config that starts with an comment
365-
if config[0] == '#' {
366-
continue
367-
}
368-
369-
if regex.MatchString(config) {
370-
captures := regex.FindStringSubmatch(config)
371-
configMap[captures[1]] = captures[2]
372-
} else {
373-
return nil, fmt.Errorf("'%s' does not match the pattern 'key=var', ex: MODE=test", config)
374-
}
375-
}
376-
377-
return configMap, nil
378-
}
379-
380354
func formatEnv(configVars map[string]interface{}) string {
381355
var formattedConfig string
382356

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ go 1.23
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-20241210030451-bd35b03af548
8+
github.com/drycc/controller-sdk-go v0.0.0-20250114084605-55b2a28ae6ee
99
github.com/drycc/pkg v0.0.0-20241028091700-8caca001c932
1010
github.com/minio/selfupdate v0.6.0
1111
github.com/olekukonko/tablewriter v0.0.5
1212
github.com/schollz/progressbar/v3 v3.17.0
13-
github.com/stretchr/testify v1.9.0
13+
github.com/stretchr/testify v1.10.0
1414
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c
1515
golang.org/x/net v0.33.0
1616
gopkg.in/yaml.v3 v3.0.1

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
99
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1010
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
1111
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
12-
github.com/drycc/controller-sdk-go v0.0.0-20241210030451-bd35b03af548 h1:eU8e0vViXNIltGCRlIWcNMZ2YCrAkfDtYXaa/wdJI4Q=
13-
github.com/drycc/controller-sdk-go v0.0.0-20241210030451-bd35b03af548/go.mod h1:F9ViuoVcZ/OG1WnfZBYH6j4v6mb5B+RW9FLaCopADoo=
12+
github.com/drycc/controller-sdk-go v0.0.0-20250114084605-55b2a28ae6ee h1:A8uiBnRTW4mY5zKnwku25Rf1YHAAexTAfyMSPiF3uX8=
13+
github.com/drycc/controller-sdk-go v0.0.0-20250114084605-55b2a28ae6ee/go.mod h1:lGJpGtKDE7WUVJhkxOgWQfd4GEulJ/NlcJycVZIzs5g=
1414
github.com/drycc/pkg v0.0.0-20241028091700-8caca001c932 h1:tUfkfjmFmlm9n0dYp1NoHcFK6+APD/wHZ2We6CKXDSI=
1515
github.com/drycc/pkg v0.0.0-20241028091700-8caca001c932/go.mod h1:upGcZF/RCEqidGjSnWHh/txRC1I4GPsRGvF8/+bDfwU=
1616
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -39,8 +39,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
3939
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
4040
github.com/schollz/progressbar/v3 v3.17.0 h1:Fv+vG6O6jnJwdjCelvfyYO7sF2jaUGQVmdH4CxcZdsQ=
4141
github.com/schollz/progressbar/v3 v3.17.0/go.mod h1:5H4fLgifX+KeQCsEJnZTOepgZLe1jFF1lpPXb68IJTA=
42-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
43-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
42+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
43+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
4444
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4545
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
4646
golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=

parser/apps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Options:
7373
--no-remote
7474
do not create a 'drycc' git remote.
7575
-r --remote REMOTE
76-
name of remote to create. [default: drycc]
76+
name of remote to create. [default: drycc].
7777
`
7878

7979
args, err := docopt.ParseArgs(usage, argv, "")
@@ -97,7 +97,7 @@ Usage: drycc apps:list [options]
9797
9898
Options:
9999
-l --limit=<num>
100-
the maximum number of results to display, defaults to config setting
100+
the maximum number of results to display, defaults to config setting.
101101
`
102102

103103
args, err := docopt.ParseArgs(usage, argv, "")
@@ -204,7 +204,7 @@ Usage: drycc apps:run [--mount=<volume>:<path>...] [options] [--] <command>...
204204
205205
Arguments:
206206
<volume>
207-
the volume name
207+
the volume name.
208208
<path>
209209
the filesystem path.
210210
<command>

parser/auth.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Options:
5151
-p --password=<password>
5252
provide a password for the account.
5353
--ssl-verify=true
54-
enables/disables SSL certificate verification for API requests
54+
enables/disables SSL certificate verification for API requests.
5555
`
5656

5757
args, err := docopt.ParseArgs(usage, argv, "")
@@ -76,8 +76,6 @@ func authLogout(argv []string, cmdr cmd.Commander) error {
7676
Logs out from a controller and clears the user session.
7777
7878
Usage: drycc auth:logout
79-
80-
Options:
8179
`
8280

8381
if _, err := docopt.ParseArgs(usage, argv, ""); err != nil {

parser/autoscale.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ Arguments:
6969
<ptype>
7070
the process type to add to the application's autoscale settings.
7171
--min=<min>
72-
minimum replicas to keep around
72+
minimum replicas to keep around.
7373
--max=<max>
74-
max replicas to scale up to
74+
max replicas to scale up to.
7575
--cpu-percent=<cpu-percent>
76-
target CPU utilization
76+
target CPU utilization.
7777
7878
Options:
7979
-a --app=<app>

parser/builds.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func Builds(argv []string, cmdr cmd.Commander) error {
1010
usage := `
1111
Valid commands for builds:
1212
13-
builds:info Print information about a specific build.
13+
builds:info Print information about a specific build
1414
builds:create imports an image and deploys as a new release
1515
1616
Use 'drycc help [command]' to learn more.
@@ -86,8 +86,8 @@ Options:
8686
The stack name for the application, defaults to container.
8787
-p --procfile=<procfile>
8888
A YAML file used to supply a Procfile to the application.
89-
-d --dryccfile=<dryccfile>
90-
A YAML file used to supply a drycc.yaml to the application.
89+
-d --dryccpath=<dryccpath>
90+
Drycc config path to the application, default is '.drycc'.
9191
--confirm=yes
9292
To proceed, type "yes".
9393
`
@@ -100,13 +100,11 @@ Options:
100100

101101
app := safeGetString(args, "--app")
102102
image := safeGetString(args, "<image>")
103-
stack := safeGetString(args, "--stack")
104103
confirm := safeGetString(args, "--confirm")
105-
if stack == "" {
106-
stack = "container"
107-
}
104+
105+
stack := safeGetValue(args, "--stack", "container")
108106
procfile := safeGetValue(args, "--procfile", "Procfile")
109-
dryccfile := safeGetValue(args, "--dryccfile", "drycc.yaml")
107+
dryccpath := safeGetValue(args, "--dryccpath", ".")
110108

111-
return cmdr.BuildsCreate(app, image, stack, procfile, dryccfile, confirm)
109+
return cmdr.BuildsCreate(app, image, stack, procfile, dryccpath, confirm)
112110
}

parser/certs.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Options:
107107

108108
func certRemove(argv []string, cmdr cmd.Commander) error {
109109
usage := `
110-
removes a certificate/key pair from the application.
110+
Remove a certificate/key pair from the application.
111111
112112
Usage: drycc certs:remove <name> [options]
113113
@@ -131,13 +131,13 @@ Options:
131131

132132
func certInfo(argv []string, cmdr cmd.Commander) error {
133133
usage := `
134-
fetch more detailed information about a certificate
134+
Fetch more detailed information about a certificate.
135135
136136
Usage: drycc certs:info <name> [options]
137137
138138
Arguments:
139139
<name>
140-
the name of the cert to get information from
140+
the name of the cert to get information from.
141141
142142
Options:
143143
-a --app=<app>
@@ -155,15 +155,15 @@ Options:
155155

156156
func certAttach(argv []string, cmdr cmd.Commander) error {
157157
usage := `
158-
attach a certificate to a domain.
158+
Attach a certificate to a domain.
159159
160160
Usage: drycc certs:attach <name> <domain> [options]
161161
162162
Arguments:
163163
<name>
164-
name of the certificate to attach domain to
164+
name of the certificate to attach domain to.
165165
<domain>
166-
common name of the domain to attach to (needs to already be in the system)
166+
common name of the domain to attach to (needs to already be in the system).
167167
168168
Options:
169169
-a --app=<app>
@@ -182,7 +182,7 @@ Options:
182182

183183
func certDetach(argv []string, cmdr cmd.Commander) error {
184184
usage := `
185-
detach a certificate from a domain.
185+
Detach a certificate from a domain.
186186
187187
Usage: drycc certs:detach <name> <domain> [options]
188188

0 commit comments

Comments
 (0)