Skip to content

Commit

Permalink
pack: added TCM file packaging
Browse files Browse the repository at this point in the history
Closes #TNTP-1097
  • Loading branch information
AlexandrLitkevich committed Jan 27, 2025
1 parent 0d17f18 commit 9f99d09
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cli/cmdcontext/cmdcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ type TarantoolCli struct {
version version.Version
}

// TcmCli describes tarantool executable.
type TcmCli struct {
// Executable is a path to tcm executable.
Executable string
}

// GetVersion returns and caches the tarantool version.
func (tntCli *TarantoolCli) GetVersion() (version.Version, error) {
if tntCli.version.Str != "" {
Expand Down Expand Up @@ -104,6 +110,8 @@ type CliCtx struct {
Verbose bool
// TarantoolCli is current tarantool cli.
TarantoolCli TarantoolCli
// Tcmcli is current tcm cli.
TcmCli
// IntegrityCheck is a public key used for integrity check.
IntegrityCheck string
// IntegrityCheckPeriod is an period during which the integrity check is reproduced.
Expand Down
32 changes: 32 additions & 0 deletions cli/configure/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ func Cli(cmdCtx *cmdcontext.CmdCtx) error {
// Set default (system) tarantool binary, can be replaced by "local" or "system" later.
cmdCtx.Cli.TarantoolCli.Executable, _ = exec.LookPath("tarantool")

// Set default (system) tcm binary, can be replaced by "local" or "system" later.
cmdCtx.Cli.TcmCli.Executable, _ = exec.LookPath("tcm")

switch {
case cmdCtx.Cli.IsSystem:
return configureSystemCli(cmdCtx)
Expand Down Expand Up @@ -552,6 +555,30 @@ func detectLocalTt(cliOpts *config.CliOpts) (string, error) {
return localCli, nil
}

// detectLocalTcm searches for available Tcm executable.
func detectLocalTcm(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts) (string, error) {
localTcm, err := util.JoinAbspath(cliOpts.Env.BinDir, "tcm")
if err != nil {
return "", err
}

if _, err := os.Stat(localTcm); err == nil {
if _, err := exec.LookPath(localTcm); err != nil {
return "", fmt.Errorf(`found Tcm binary '%s' isn't executable: %s`,
localTcm, err)
}

cmdCtx.Cli.TcmCli.Executable = localTcm
} else if !os.IsNotExist(err) {
return "", fmt.Errorf("failed to get access to Tcm binary file: %s", err)
}

log.Debugf("tcm executable found: '%s'", cmdCtx.Cli.TcmCli.Executable)

return localTcm, nil
}


Check failure on line 581 in cli/configure/configure.go

View workflow job for this annotation

GitHub Actions / tests-ee (2.11.2-0-r609.linux.x86_64)

File is not properly formatted (gofmt)

Check failure on line 581 in cli/configure/configure.go

View workflow job for this annotation

GitHub Actions / tests-ee (3.2.0-0-r40.linux.x86_64)

File is not properly formatted (gofmt)

Check failure on line 581 in cli/configure/configure.go

View workflow job for this annotation

GitHub Actions / tests-ce (1.10)

File is not properly formatted (gofmt)

Check failure on line 581 in cli/configure/configure.go

View workflow job for this annotation

GitHub Actions / tests-ce (2.10)

File is not properly formatted (gofmt)

Check failure on line 581 in cli/configure/configure.go

View workflow job for this annotation

GitHub Actions / tests-ce (3.0)

File is not properly formatted (gofmt)
// configureLocalCli configures Tarantool CLI if the launch is local.
func configureLocalCli(cmdCtx *cmdcontext.CmdCtx) error {
launchDir, err := os.Getwd()
Expand Down Expand Up @@ -595,6 +622,11 @@ func configureLocalCli(cmdCtx *cmdcontext.CmdCtx) error {
return err
}

_, err = detectLocalTcm(cmdCtx, cliOpts)
if err != nil {
return err
}

var localCli string
if !cmdCtx.Cli.IsSelfExec {
localCli, err = detectLocalTt(cliOpts)
Expand Down
12 changes: 12 additions & 0 deletions cli/pack/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ func copyBinaries(bundleEnvPath string, packCtx *PackCtx, cmdCtx *cmdcontext.Cmd
if err := util.CopyFileDeep(ttExecutable, util.JoinPaths(pkgBin, "tt")); err != nil {
return fmt.Errorf("failed copying tt: %s", err)
}

// Copy tcm.
if packCtx.WithBinaries {
if cmdCtx.Cli.TcmCli.Executable == "" {
log.Warnf("Skip copying tcm binary: not found")
} else {
if err := util.CopyFileDeep(cmdCtx.Cli.TcmCli.Executable,
util.JoinPaths(pkgBin, "tcm")); err != nil {
return fmt.Errorf("failed copying tarantool: %s", err)
}
}
}
return nil
}

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions test/integration/pack/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@ def test_pack_tgz_compat_with_binaries(tt_cmd, tmp_path):

assert os.path.isfile(os.path.join(app_path, "tt"))
assert os.path.isfile(os.path.join(app_path, "tarantool"))
assert os.path.isfile(os.path.join(app_path, "tcm"))

script = ("cat > tarantool <<EOF\n"
"#!/bin/bash\n"
Expand Down Expand Up @@ -1014,6 +1015,8 @@ def test_pack_tgz_links_to_binaries(tt_cmd, tmp_path):

tt_is_link = os.path.islink(os.path.join(extract_path, "bin", "tt"))
tnt_is_link = os.path.islink(os.path.join(extract_path, "bin", "tarantool"))
tnt_is_link = os.path.islink(os.path.join(extract_path, "bin", "tcm"))

assert not tt_is_link
assert not tnt_is_link

Expand Down

0 comments on commit 9f99d09

Please sign in to comment.