Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pack: added TCM file packaging #1092

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Comment on lines +270 to +271
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add test cases into Test_prepareBundle in the common_test.go.

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.
3 changes: 3 additions & 0 deletions test/integration/pack/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,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

patapenka-alexey marked this conversation as resolved.
Show resolved Hide resolved
shutil.rmtree(extract_path)
os.remove(package_file)
Expand Down