-
Notifications
You must be signed in to change notification settings - Fork 12
/
rpm.go
101 lines (84 loc) · 2.2 KB
/
rpm.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
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
package pack
import (
"fmt"
"os"
"path/filepath"
"github.com/apex/log"
"github.com/otiai10/copy"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/config"
"github.com/tarantool/tt/cli/util"
)
// rpmPacker is a structure that implements Packer interface
// with specific rpm packing behavior.
type rpmPacker struct {
}
// Run packs a bundle into rpm package.
func (packer *rpmPacker) Run(cmdCtx *cmdcontext.CmdCtx, packCtx *PackCtx,
opts *config.CliOpts) error {
var err error
if err := util.CheckRequiredBinaries("cpio"); err != nil {
return err
}
// Create a package directory, where it will be built.
packageDir, err := os.MkdirTemp("", "")
if err != nil {
return err
}
defer func() {
err := os.RemoveAll(packageDir)
if err != nil {
log.Warnf("Failed to remove a temporary directory %s: %s",
packageDir, err.Error())
}
}()
log.Debugf("A root for package is located in: %s", packageDir)
// Prepare a bundle.
bundlePath, err := prepareBundle(cmdCtx, packCtx, opts, true)
if err != nil {
return err
}
defer func() {
err := os.RemoveAll(bundlePath)
if err != nil {
log.Warnf("Failed to remove a temporary directory %s: %s",
bundlePath, err.Error())
}
}()
bundleName, err := getPackageName(packCtx, opts, "", false)
if err != nil {
return err
}
if err := copy.Copy(bundlePath, filepath.Join(packageDir, "usr", "share", "tarantool",
bundleName)); err != nil {
return err
}
rpmSuffix, err := getRPMSuffix()
if err != nil {
return err
}
resPackagePath, err := getPackageName(packCtx, opts, rpmSuffix, true)
if err != nil {
return err
}
envSystemPath := filepath.Join("/", defaultEnvPrefix, bundleName)
err = initSystemdDir(packCtx, opts, packageDir, envSystemPath)
if err != nil {
return err
}
err = packRpm(cmdCtx, packCtx, opts, packageDir, resPackagePath)
if err != nil {
return fmt.Errorf("failed to create RPM package: %s", err)
}
log.Infof("Created result RPM package: %s", resPackagePath)
return nil
}
// getRPMSuffix returns suffix for an RPM package.
func getRPMSuffix() (string, error) {
arch, err := util.GetArch()
if err != nil {
return "", err
}
debSuffix := "-1" + "." + arch + ".rpm"
return debSuffix, nil
}