-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_docker.go
76 lines (67 loc) · 2.03 KB
/
generate_docker.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
65
66
67
68
69
70
71
72
73
74
75
76
package dmg
import (
"fmt"
"path"
"path/filepath"
"github.com/cardinalby/xgo-pack/pkg/docker"
"github.com/cardinalby/xgo-pack/pkg/pipeline/buildctx"
)
// image that doesn't support creating "Applications" symlink
const originalCreateDmgDockerImage = "sporsh/create-dmg"
func Generate(
ctx buildctx.Context,
srcBundle string,
outDmgPath string,
appName string,
addApplicationsSymlink bool,
) error {
dockerImageName := originalCreateDmgDockerImage
if addApplicationsSymlink {
createDmgDockerImage, err := ctx.Artifacts.Get(ctx, buildctx.KindMacosCreateDmgDockerImage)
if err != nil {
return fmt.Errorf("error getting local create-dmg docker image: %w", err)
}
dockerImageName = createDmgDockerImage.GetPath()
}
return dockerCreateDmg(ctx, dockerImageName, srcBundle, outDmgPath, appName, addApplicationsSymlink)
}
func dockerCreateDmg(
ctx buildctx.Context,
imgName string,
srcBundlePath string,
outDmgPath string,
appName string,
addApplicationsSymlink bool,
) error {
internalSrcPath := "/src"
internalSrcBundlePath := path.Join(internalSrcPath, appName+".app")
internalDstDir := "/out"
var env map[string]string
if addApplicationsSymlink {
env = map[string]string{
"APPLICATIONS_SYMLINK": "1",
}
}
srcBundlePathAbs, err := filepath.Abs(srcBundlePath)
if err != nil {
return fmt.Errorf("error getting absolute path for src bundle '%s': %w", srcBundlePath, err)
}
outDmgPathDir := filepath.Dir(outDmgPath)
outDmgDirPathAbs, err := filepath.Abs(outDmgPathDir)
if err != nil {
return fmt.Errorf("error getting absolute path for out dmg dir '%s': %w", outDmgPathDir, err)
}
stdout, err := docker.RunOnceRes(ctx, imgName, docker.RunOptions{
Volumes: map[string]string{
srcBundlePathAbs: internalSrcBundlePath,
outDmgDirPathAbs: internalDstDir,
},
Env: env,
Args: []string{appName, internalSrcPath, path.Join(internalDstDir, filepath.Base(outDmgPath))},
})
if err != nil {
return fmt.Errorf("error running create-dmg docker container: %w. %s", err, stdout)
}
ctx.Logger.Printf(stdout)
return nil
}