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 Feb 3, 2025
1 parent f13b13e commit 10af852
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- `tt pack `: added TCM file packaging.

### Changed

### Fixed
Expand Down
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 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
31 changes: 31 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,29 @@ 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 %q 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: %q", cmdCtx.Cli.TcmCli.Executable)

return localTcm, nil
}

// 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 +621,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 tcm: %s", err)
}
}
}
return nil
}

Expand Down
Empty file.
4 changes: 4 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,8 +1015,11 @@ 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"))
tcm_is_link = os.path.islink(os.path.join(extract_path, "bin", "tcm"))

assert not tt_is_link
assert not tnt_is_link
assert not tcm_is_link

shutil.rmtree(extract_path)
os.remove(package_file)
Expand Down

0 comments on commit 10af852

Please sign in to comment.