-
Notifications
You must be signed in to change notification settings - Fork 387
/
docker_earthly_cmds.go
64 lines (56 loc) · 1.55 KB
/
docker_earthly_cmds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package subcmd
import (
"fmt"
"os"
"github.com/earthly/earthly/docker2earthly"
"github.com/urfave/cli/v2"
)
type Doc2Earth struct {
cli CLI
earthfilePath string
earthfileFinalImage string
}
func NewDoc2Earth(cli CLI) *Doc2Earth {
return &Doc2Earth{
cli: cli,
}
}
func (a *Doc2Earth) Cmds() []*cli.Command {
return []*cli.Command{
{
Name: "docker2earthly",
Usage: "Convert a Dockerfile into Earthfile",
Description: "Converts an existing dockerfile into an Earthfile.",
Hidden: true, // Experimental.
Action: a.action,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "dockerfile",
Usage: "Path to dockerfile input, or - for stdin",
Value: "Dockerfile",
Destination: &a.cli.Flags().DockerfilePath,
},
&cli.StringFlag{
Name: "earthfile",
Usage: "Path to Earthfile output, or - for stdout",
Value: "Earthfile",
Destination: &a.earthfilePath,
},
&cli.StringFlag{
Name: "tag",
Usage: "Name and tag for the built image; formatted as 'name:tag'",
Destination: &a.earthfileFinalImage,
},
},
},
}
}
func (a *Doc2Earth) action(cliCtx *cli.Context) error {
a.cli.SetCommandName("docker2earthly")
err := docker2earthly.Docker2Earthly(a.cli.Flags().DockerfilePath, a.earthfilePath, a.earthfileFinalImage)
if err != nil {
return err
}
fmt.Fprintf(os.Stderr, "An Earthfile has been generated; to run it use: earthly +build; then run with docker run -ti %s\n", a.earthfileFinalImage)
return nil
}