forked from rzane/docker2exe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
103 lines (94 loc) · 2.2 KB
/
Copy pathmain.go
File metadata and controls
103 lines (94 loc) · 2.2 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"fmt"
"os"
"os/user"
"path"
"github.com/rzane/docker2exe/cmd"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "docker2exe",
Usage: "create an executable from a docker image",
Action: generate,
Flags: []cli.Flag{
&cli.StringFlag{
Required: true,
Name: "name",
Usage: "name of your executable",
},
&cli.StringFlag{
Required: true,
Name: "image",
Usage: "name of your docker image",
},
&cli.BoolFlag{
Name: "embed",
Usage: "embed a docker image in the binary",
},
&cli.StringFlag{
Name: "workdir",
Aliases: []string{"w"},
Usage: "mount the user's current directory in the image",
},
&cli.StringSliceFlag{
Name: "env",
Aliases: []string{"e"},
Usage: "whitelist environment variables",
},
&cli.StringSliceFlag{
Name: "volume",
Aliases: []string{"v"},
Usage: "bind mount a volume",
},
&cli.StringFlag{
Name: "output",
Usage: "directory to output",
},
&cli.StringSliceFlag{
Name: "target",
Aliases: []string{"t"},
Usage: "platforms and architectures to target",
},
&cli.StringFlag{
Name: "ports",
Usage: "ports to use",
},
&cli.StringFlag{
Name: "module",
Usage: "name of generated golang module",
},
},
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func generate(c *cli.Context) error {
generator := cmd.Generator{
Output: c.String("output"),
Name: c.String("name"),
Targets: c.StringSlice("target"),
Module: c.String("module"),
Image: c.String("image"),
Embed: c.Bool("embed"),
Workdir: c.String("workdir"),
Env: c.StringSlice("env"),
Ports: c.String("ports"),
Volumes: c.StringSlice("volume"),
}
if generator.Output == "" {
cwd, _ := os.Getwd()
generator.Output = path.Join(cwd, "dist")
}
if generator.Module == "" {
user, _ := user.Current()
generator.Module = fmt.Sprintf("github.com/%s/%s", user.Username, generator.Name)
}
if len(generator.Targets) == 0 {
generator.Targets = []string{"darwin/amd64", "darwin/arm64", "linux/amd64", "windows/amd64"}
}
return generator.Run()
}