Skip to content

Commit d1c7f1d

Browse files
committed
alpha: use docker pull directly, add schema for storage and database
1 parent 539d636 commit d1c7f1d

File tree

4 files changed

+153
-74
lines changed

4 files changed

+153
-74
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ require (
3434
)
3535

3636
require (
37-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
3837
github.com/Masterminds/goutils v1.1.1 // indirect
3938
github.com/Microsoft/go-winio v0.5.2 // indirect
4039
github.com/andybalholm/brotli v1.0.4 // indirect
@@ -72,7 +71,6 @@ require (
7271
github.com/mitchellh/mapstructure v1.4.3 // indirect
7372
github.com/mitchellh/reflectwalk v1.0.2 // indirect
7473
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
75-
github.com/morikuni/aec v1.0.0 // indirect
7674
github.com/nwaples/rardecode v1.1.2 // indirect
7775
github.com/opencontainers/go-digest v1.0.0 // indirect
7876
github.com/opencontainers/image-spec v1.0.2 // indirect

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
336336
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
337337
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
338338
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
339-
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
340339
github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
341340
github.com/creasty/defaults v1.5.2 h1:/VfB6uxpyp6h0fr7SPp7n8WJBoV8jfxQXPCnkVSjyls=
342341
github.com/creasty/defaults v1.5.2/go.mod h1:FPZ+Y0WNrbqOVw+c6av63eyHUAl6pMHZwqLPvXUZGfY=

pkg/actions/deploy_build.go

Lines changed: 12 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package actions
33
import (
44
"bufio"
55
"context"
6-
"encoding/json"
76
"fmt"
87
"os/exec"
98
"path/filepath"
@@ -14,7 +13,6 @@ import (
1413
"github.com/ansel1/merry/v2"
1514
dockertypes "github.com/docker/docker/api/types"
1615
dockerclient "github.com/docker/docker/client"
17-
"github.com/docker/docker/pkg/jsonmessage"
1816
"github.com/outblocks/outblocks-cli/internal/util"
1917
"github.com/outblocks/outblocks-cli/pkg/config"
2018
apiv1 "github.com/outblocks/outblocks-plugin-go/gen/api/v1"
@@ -81,50 +79,7 @@ func (d *Deploy) printAppOutput(app config.App, msg string, isErr bool) {
8179
}
8280
}
8381

84-
func (d *Deploy) printAppJSONMessage(app config.App, jm *jsonmessage.JSONMessage) error {
85-
if jm.Error != nil {
86-
if jm.Error.Code == 401 {
87-
return fmt.Errorf("authentication is required")
88-
}
89-
90-
return jm.Error
91-
}
92-
93-
prefix := fmt.Sprintf("APP:%s:%s:", app.Type(), app.Name())
94-
95-
if jm.Progress != nil && jm.Progress.Current < jm.Progress.Total { // disable progressbar in non-terminal
96-
return nil
97-
}
98-
99-
msg := ""
100-
101-
if jm.TimeNano != 0 {
102-
msg += fmt.Sprintf("%s ", time.Unix(0, jm.TimeNano).Format(jsonmessage.RFC3339NanoFixed))
103-
} else if jm.Time != 0 {
104-
msg += fmt.Sprintf("%s ", time.Unix(0, jm.Time).Format(jsonmessage.RFC3339NanoFixed))
105-
}
106-
107-
if jm.ID != "" {
108-
msg += fmt.Sprintf("%s: ", jm.ID)
109-
}
110-
111-
if jm.From != "" {
112-
msg += fmt.Sprintf("(from %s)", jm.From)
113-
}
114-
115-
switch {
116-
case jm.Stream != "":
117-
msg += jm.Stream
118-
default:
119-
msg += jm.Status
120-
}
121-
122-
d.log.Printf("%s %s\n", pterm.FgGreen.Sprint(prefix), msg)
123-
124-
return nil
125-
}
126-
127-
func (d *Deploy) runAppBuildCommand(ctx context.Context, cmd *command.Cmd, app config.App) error {
82+
func (d *Deploy) runAppCommand(ctx context.Context, cmd *command.Cmd, app config.App) error {
12883
// Process stdout/stderr.
12984
var wg sync.WaitGroup
13085

@@ -186,7 +141,7 @@ func (d *Deploy) buildStaticApp(ctx context.Context, app *config.StaticApp, eval
186141
return merry.Errorf("error preparing build command for %s app: %s: %w", app.Type(), app.Name(), err)
187142
}
188143

189-
return d.runAppBuildCommand(ctx, cmd, app)
144+
return d.runAppCommand(ctx, cmd, app)
190145
}
191146

192147
func (d *Deploy) buildServiceApp(ctx context.Context, app *config.ServiceApp, eval *util.VarEvaluator) error {
@@ -237,7 +192,7 @@ func (d *Deploy) buildServiceApp(ctx context.Context, app *config.ServiceApp, ev
237192

238193
d.printAppOutput(app, fmt.Sprintf("Building image '%s'...", app.AppBuild.LocalDockerImage), false)
239194

240-
err = d.runAppBuildCommand(ctx, cmd, app)
195+
err = d.runAppCommand(ctx, cmd, app)
241196
if err != nil {
242197
return err
243198
}
@@ -289,34 +244,20 @@ func (d *Deploy) prepareApps(ctx context.Context) error {
289244
prepare = append(prepare, &appPrepare{
290245
app: app,
291246
prepare: func() error {
292-
d.printAppOutput(app, fmt.Sprintf("Pulling image '%s'...", a.AppBuild.LocalDockerImage), false)
293-
294-
reader, err := cli.ImagePull(ctx, a.AppBuild.LocalDockerImage, dockertypes.ImagePullOptions{})
247+
cmd, err := command.New(
248+
exec.Command("docker", "pull", a.AppBuild.LocalDockerImage),
249+
)
295250
if err != nil {
296-
d.printAppOutput(app, fmt.Sprintf("error pulling custom image %s", err), true)
297-
298-
return nil
251+
return merry.Errorf("error preparing pull command for %s app: %s: %w", app.Type(), app.Name(), err)
299252
}
300253

301-
var jm jsonmessage.JSONMessage
302-
303-
scanner := bufio.NewScanner(reader)
304-
305-
for scanner.Scan() {
306-
err = json.Unmarshal(scanner.Bytes(), &jm)
307-
if err != nil {
308-
return err
309-
}
310-
311-
err = d.printAppJSONMessage(app, &jm)
312-
if err != nil {
313-
return err
314-
}
315-
}
254+
d.printAppOutput(app, fmt.Sprintf("Pulling image '%s'...", a.AppBuild.LocalDockerImage), false)
316255

317-
err = reader.Close()
256+
err = d.runAppCommand(ctx, cmd, app)
318257
if err != nil {
319-
return err
258+
d.printAppOutput(app, fmt.Sprintf("error pulling custom image: %s", err), true)
259+
260+
return nil
320261
}
321262

322263
insp, _, err := cli.ImageInspectWithRaw(ctx, a.AppBuild.LocalDockerImage)

schema/schema-project.json

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,151 @@
137137
},
138138
"required": [
139139
"type"
140+
],
141+
"allOf": [
142+
{
143+
"if": {
144+
"properties": {
145+
"type": {
146+
"const": "storage"
147+
}
148+
}
149+
},
150+
"then": {
151+
"properties": {
152+
"versioning": {
153+
"description": "Enables versioning for objects.",
154+
"type": "boolean"
155+
},
156+
"location": {
157+
"description": "Specify location for storage, refer to cloud provider docs for possible options.",
158+
"type": "string"
159+
},
160+
"public": {
161+
"description": "Makes whole storage public so that all objects can be accessed.",
162+
"type": "boolean"
163+
},
164+
"max_versions": {
165+
"description": "Maximum amount of versions to keep.",
166+
"type": "integer"
167+
},
168+
"delete_in_days": {
169+
"description": "Delete new objects after X days.",
170+
"type": "integer"
171+
},
172+
"expire_versions_in_days": {
173+
"description": "Expire archived versions after X days.",
174+
"type": "integer"
175+
},
176+
"cors": {
177+
"description": "CORS settings.",
178+
"type": "array",
179+
"items": {
180+
"$ref": "#/definitions/DependencyStorageCORS"
181+
}
182+
}
183+
}
184+
}
185+
},
186+
{
187+
"if": {
188+
"anyOf": [
189+
{
190+
"properties": {
191+
"type": {
192+
"const": "mysql"
193+
}
194+
}
195+
},
196+
{
197+
"properties": {
198+
"type": {
199+
"const": "postgresql"
200+
}
201+
}
202+
}
203+
]
204+
},
205+
"then": {
206+
"properties": {
207+
"version": {
208+
"description": "Specify version of database, refer to cloud provider docs for possible options.",
209+
"type": "string"
210+
},
211+
"high_availability": {
212+
"description": "Makes database highly available meaning it will have a read replica available in case of master failure.",
213+
"type": "boolean"
214+
},
215+
"tier": {
216+
"description": "Specify tier of database, refer to cloud provider docs for possible options.",
217+
"type": "string"
218+
},
219+
"flags": {
220+
"description": "Database flags, refer to cloud provider docs for possible options.",
221+
"type": "object",
222+
"additionalProperties": {
223+
"type": "string"
224+
}
225+
},
226+
"users": {
227+
"description": "Database users.",
228+
"type": "object",
229+
"additionalProperties": {
230+
"$ref": "#/definitions/DependencyDatabaseUser"
231+
}
232+
}
233+
}
234+
}
235+
}
140236
]
141237
}
142238
}
143239
},
240+
"DependencyDatabaseUser": {
241+
"title": "Database user",
242+
"type": "object",
243+
"properties": {
244+
"password": {
245+
"description": "Explicitly set password, defaults to a randomly generated string.",
246+
"type": "string"
247+
},
248+
"hostname": {
249+
"description": "Hostname that user is allowed to connect from. Not all databases may support it.",
250+
"type": "string"
251+
}
252+
}
253+
},
254+
"DependencyStorageCORS": {
255+
"title": "Storage CORS",
256+
"type": "object",
257+
"properties": {
258+
"origins": {
259+
"description": "The list of Origins eligible to receive CORS response headers. Note: \"*\" is permitted in the list of origins, and means \"any Origin\".",
260+
"type": "array",
261+
"items": {
262+
"type": "string"
263+
}
264+
},
265+
"methods": {
266+
"description": "The list of HTTP methods on which to include CORS response headers, (GET, OPTIONS, POST, etc) Note: \"*\" is permitted in the list of methods, and means \"any method\".",
267+
"type": "array",
268+
"items": {
269+
"type": "string"
270+
}
271+
},
272+
"response_headers": {
273+
"description": "The list of HTTP headers other than the simple response headers to give permission for the user-agent to share across domains.",
274+
"type": "array",
275+
"items": {
276+
"type": "string"
277+
}
278+
},
279+
"max_age_in_seconds": {
280+
"description": "The value in seconds to return in the Access-Control-Max-Age header used in preflight responses.",
281+
"type": "integer"
282+
}
283+
}
284+
},
144285
"DependencyRun": {
145286
"title": "Run",
146287
"type": "object",

0 commit comments

Comments
 (0)