Skip to content

install: added support install TCM #1159

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

Open
wants to merge 6 commits 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
allow find WAL files inside nested subdirectories.
- `tt search tcm` - the command performs a search for tarantool cluster
manager (TCM) in the customer zone or local `distfiles` directory.
- `tt install tcm` - the command performs an install for tarantool cluster
manager (TCM) from the customer zone or local `distfiles` directory.
- `tt tcm status`: added command to check TCM runtime status (modes: `watchdog` or `interactive`).
- `tt tcm stop`: add command for graceful termination of TCM processes (modes: `watchdog` or `interactive`).

Expand Down Expand Up @@ -766,4 +768,4 @@ Additionally, several fixes were implemented to improve stability.
- Module ``tt create``, to create an application from a template.
- Module ``tt build``, to build an application.
- Module ``tt install``, to install tarantool/tt.
- Module ``tt remove``, to remove tarantool/tt.
- Module ``tt remove``, to remove tarantool/tt.
23 changes: 10 additions & 13 deletions cli/binary/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,27 @@ func printVersion(versionString string) {
}

// ParseBinaries seeks through fileList returning array of found versions of program.
func ParseBinaries(fileList []fs.DirEntry, programName string,
func ParseBinaries(fileList []fs.DirEntry, program search.ProgramType,
binDir string) ([]version.Version, error) {
var binaryVersions []version.Version

symlinkName := programName
if programName == search.ProgramEe || programName == search.ProgramDev {
symlinkName = search.ProgramCe
}
symlinkName := program.Exec()

binActive := ""
programPath := filepath.Join(binDir, symlinkName)
if fileInfo, err := os.Lstat(programPath); err == nil {
if programName == search.ProgramDev &&
if program == search.ProgramDev &&
fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink {
binActive, isTarantoolBinary, err := install.IsTarantoolDev(programPath, binDir)
if err != nil {
return binaryVersions, err
}
if isTarantoolBinary {
binaryVersions = append(binaryVersions,
version.Version{Str: programName + " -> " + binActive + " [active]"})
version.Version{Str: program.String() + " -> " + binActive + " [active]"})
}
return binaryVersions, nil
} else if programName == search.ProgramCe && fileInfo.Mode()&os.ModeSymlink == 0 {
} else if program == search.ProgramCe && fileInfo.Mode()&os.ModeSymlink == 0 {
tntCli := cmdcontext.TarantoolCli{Executable: programPath}
binaryVersion, err := tntCli.GetVersion()
if err != nil {
Expand All @@ -71,7 +68,7 @@ func ParseBinaries(fileList []fs.DirEntry, programName string,
}
}

versionPrefix := programName + version.FsSeparator
versionPrefix := program.String() + version.FsSeparator
var err error
for _, f := range fileList {
if strings.HasPrefix(f.Name(), versionPrefix) {
Expand Down Expand Up @@ -111,22 +108,22 @@ func ListBinaries(cmdCtx *cmdcontext.CmdCtx, cliOpts *config.CliOpts) (err error
return fmt.Errorf("error reading directory %q: %s", binDir, err)
}

programs := [...]string{
programs := [...]search.ProgramType{
search.ProgramTt,
search.ProgramCe,
search.ProgramDev,
search.ProgramEe,
}
fmt.Println("List of installed binaries:")
for _, programName := range programs {
binaryVersions, err := ParseBinaries(binDirFilesList, programName, binDir)
for _, program := range programs {
binaryVersions, err := ParseBinaries(binDirFilesList, program, binDir)
if err != nil {
return err
}

if len(binaryVersions) > 0 {
sort.Stable(sort.Reverse(version.VersionSlice(binaryVersions)))
log.Infof(programName + ":")
log.Infof(program.String() + ":")
for _, binVersion := range binaryVersions {
printVersion(binVersion.Str)
}
Expand Down
13 changes: 7 additions & 6 deletions cli/binary/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
"github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tarantool/tt/cli/search"
"github.com/tarantool/tt/cli/version"
)

func TestParseBinaries(t *testing.T) {
fileList, err := os.ReadDir("./testdata/bin")
require.NoError(t, err)
versions, err := ParseBinaries(fileList, "tarantool", "./testdata/bin")
versions, err := ParseBinaries(fileList, search.ProgramCe, "./testdata/bin")
require.NoError(t, err)
sort.Stable(sort.Reverse(version.VersionSlice(versions)))
expectedSortedVersions := []string{"master", "2.10.5", "2.8.6 [active]", "1.10.0", "0000000"}
Expand All @@ -33,7 +34,7 @@ func TestParseBinariesTarantoolDev(t *testing.T) {
testDir := fmt.Sprintf("./testdata/tarantool_dev/%s", dir)
fileList, err := os.ReadDir(testDir)
assert.NoError(t, err)
versions, err := ParseBinaries(fileList, "tarantool-dev", testDir)
versions, err := ParseBinaries(fileList, search.ProgramDev, testDir)
assert.NoError(t, err)
require.Equal(t, 1, len(versions))
version := versions[0].Str
Expand All @@ -49,15 +50,15 @@ func TestParseBinariesNoSymlink(t *testing.T) {

fileList, err := os.ReadDir(tmpDir)
require.NoError(t, err)
versions, err := ParseBinaries(fileList, "tarantool", tmpDir)
versions, err := ParseBinaries(fileList, search.ProgramCe, tmpDir)
require.NoError(t, err)
sort.Stable(sort.Reverse(version.VersionSlice(versions)))
expectedSortedVersions := []string{"3.1.0-entrypoint-83-gcb0264c3c [active]", "2.10.1"}
require.Equal(t, len(expectedSortedVersions), len(versions))
for i := 0; i < len(expectedSortedVersions); i++ {
assert.Equal(t, expectedSortedVersions[i], versions[i].Str)
}
versions, err = ParseBinaries(fileList, "tarantool-ee", tmpDir)
versions, err = ParseBinaries(fileList, search.ProgramEe, tmpDir)
require.NoError(t, err)
sort.Stable(sort.Reverse(version.VersionSlice(versions)))
expectedSortedVersions = []string{"2.11.1"}
Expand All @@ -68,7 +69,7 @@ func TestParseBinariesNoSymlink(t *testing.T) {

// Tarantool exists, but not executable.
require.NoError(t, os.Chmod(filepath.Join(tmpDir, "tarantool"), 0440))
versions, err = ParseBinaries(fileList, "tarantool-ee", tmpDir)
versions, err = ParseBinaries(fileList, search.ProgramEe, tmpDir)
require.NoError(t, err)
sort.Stable(sort.Reverse(version.VersionSlice(versions)))
expectedSortedVersions = []string{"2.11.1"}
Expand All @@ -78,6 +79,6 @@ func TestParseBinariesNoSymlink(t *testing.T) {
}

require.NoError(t, os.Chmod(filepath.Join(tmpDir, "tarantool"), 0440))
_, err = ParseBinaries(fileList, "tarantool", tmpDir)
_, err = ParseBinaries(fileList, search.ProgramCe, tmpDir)
require.ErrorContains(t, err, "failed to get tarantool version")
}
32 changes: 16 additions & 16 deletions cli/binary/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type SwitchCtx struct {
BinDir string
// IncDir is a directory witch stores include files.
IncDir string
// ProgramName is a program name to switch to.
ProgramName string
// ProgramType is a program name to switch to.
ProgramType search.ProgramType
// Version of the program to switch to.
Version string
}
Expand All @@ -39,32 +39,32 @@ func cleanString(str string) string {
}

// ChooseProgram shows a menu in terminal to choose program for switch.
func ChooseProgram(supportedPrograms []string) (string, error) {
func ChooseProgram(supportedPrograms []string) (search.ProgramType, error) {
programSelect := promptui.Select{
Label: "Select program",
Items: supportedPrograms,
HideSelected: true,
}
_, program, err := programSelect.Run()

return program, err
return search.NewProgramType(program), err
}

// ChooseVersion shows a menu in terminal to choose version of program to switch to.
func ChooseVersion(binDir string, programName string) (string, error) {
func ChooseVersion(binDir string, program search.ProgramType) (string, error) {
binDirFilesList, err := os.ReadDir(binDir)

if len(binDirFilesList) == 0 || errors.Is(err, fs.ErrNotExist) {
return "", fmt.Errorf("there are no binaries installed in this environment of 'tt'")
} else if err != nil {
return "", fmt.Errorf("error reading directory %q: %s", binDir, err)
}
versions, err := ParseBinaries(binDirFilesList, programName, binDir)
versions, err := ParseBinaries(binDirFilesList, program, binDir)
if err != nil {
return "", err
}
if len(versions) == 0 {
return "", fmt.Errorf("there are no %s installed in this environment of 'tt'", programName)
return "", fmt.Errorf("there are no %s installed in this environment of 'tt'", program)
}
var versionStr []string
for _, version := range versions {
Expand All @@ -90,13 +90,13 @@ func ChooseVersion(binDir string, programName string) (string, error) {

// switchTt switches 'tt' program.
func switchTt(switchCtx SwitchCtx) error {
log.Infof("Switching to %s %s.", switchCtx.ProgramName, switchCtx.Version)
log.Infof("Switching to %s %s.", switchCtx.ProgramType, switchCtx.Version)

ttVersion := switchCtx.Version
if !strings.HasPrefix(switchCtx.Version, "v") {
ttVersion = "v" + ttVersion
}
versionStr := search.ProgramTt + version.FsSeparator + ttVersion
versionStr := search.ProgramTt.String() + version.FsSeparator + ttVersion

if util.IsRegularFile(filepath.Join(switchCtx.BinDir, versionStr)) {
err := util.CreateSymlink(versionStr, filepath.Join(switchCtx.BinDir, "tt"), true)
Expand All @@ -106,19 +106,19 @@ func switchTt(switchCtx SwitchCtx) error {
log.Infof("Done")
} else {
return fmt.Errorf("%s %s is not installed in current environment",
switchCtx.ProgramName, switchCtx.Version)
switchCtx.ProgramType, switchCtx.Version)
}
return nil
}

// switchTarantool switches 'tarantool' program.
func switchTarantool(switchCtx SwitchCtx, enterprise bool) error {
log.Infof("Switching to %s %s.", switchCtx.ProgramName, switchCtx.Version)
log.Infof("Switching to %s %s.", switchCtx.ProgramType, switchCtx.Version)
var versionStr string
if enterprise {
versionStr = search.ProgramEe + version.FsSeparator + switchCtx.Version
versionStr = search.ProgramEe.String() + version.FsSeparator + switchCtx.Version
} else {
versionStr = search.ProgramCe + version.FsSeparator + switchCtx.Version
versionStr = search.ProgramCe.String() + version.FsSeparator + switchCtx.Version
}
if util.IsRegularFile(filepath.Join(switchCtx.BinDir, versionStr)) &&
util.IsDir(filepath.Join(switchCtx.IncDir, "include", versionStr)) {
Expand All @@ -135,7 +135,7 @@ func switchTarantool(switchCtx SwitchCtx, enterprise bool) error {
log.Infof("Done")
} else {
return fmt.Errorf("%s %s is not installed in current environment",
switchCtx.ProgramName, switchCtx.Version)
switchCtx.ProgramType, switchCtx.Version)
}
return nil
}
Expand All @@ -144,15 +144,15 @@ func switchTarantool(switchCtx SwitchCtx, enterprise bool) error {
func Switch(switchCtx SwitchCtx) error {
var err error

switch switchCtx.ProgramName {
switch switchCtx.ProgramType {
case search.ProgramTt:
err = switchTt(switchCtx)
case search.ProgramCe:
err = switchTarantool(switchCtx, false)
case search.ProgramEe:
err = switchTarantool(switchCtx, true)
default:
return fmt.Errorf("unknown application: %s", switchCtx.ProgramName)
return fmt.Errorf("unknown application: %s", switchCtx.ProgramType)
}

return err
Expand Down
9 changes: 5 additions & 4 deletions cli/binary/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/fatih/color"
"github.com/otiai10/copy"
"github.com/stretchr/testify/assert"
"github.com/tarantool/tt/cli/search"
"github.com/tarantool/tt/cli/util"
)

Expand All @@ -30,7 +31,7 @@ func TestSwitchTarantool(t *testing.T) {
var testCtx SwitchCtx
testCtx.IncDir = filepath.Join(tempDir, "include")
testCtx.BinDir = filepath.Join(tempDir, "bin")
testCtx.ProgramName = "tarantool"
testCtx.ProgramType = search.NewProgramType("tarantool")
testCtx.Version = "2.10.3"
err = Switch(testCtx)
assert.Nil(t, err)
Expand All @@ -48,17 +49,17 @@ func TestSwitchUnknownProgram(t *testing.T) {
var testCtx SwitchCtx
testCtx.IncDir = filepath.Join(".", "include")
testCtx.BinDir = filepath.Join(".", "bin")
testCtx.ProgramName = "tarantool-foo"
testCtx.ProgramType = search.NewProgramType("tarantool-foo")
testCtx.Version = "2.10.3"
err := Switch(testCtx)
assert.Equal(t, err.Error(), "unknown application: tarantool-foo")
assert.Equal(t, err.Error(), "unknown application: unknown(0)")
}

func TestSwitchNotInstalledVersion(t *testing.T) {
var testCtx SwitchCtx
testCtx.IncDir = filepath.Join(".", "include")
testCtx.BinDir = filepath.Join(".", "bin")
testCtx.ProgramName = "tarantool"
testCtx.ProgramType = search.NewProgramType("tarantool")
testCtx.Version = "2.10.3"
err := Switch(testCtx)
assert.Equal(t, err.Error(), "tarantool 2.10.3 is not installed in current environment")
Expand Down
18 changes: 9 additions & 9 deletions cli/cmd/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import (
)

var binariesSupportedPrograms = []string{
search.ProgramCe,
search.ProgramEe,
search.ProgramTt,
search.ProgramCe.String(),
search.ProgramEe.String(),
search.ProgramTt.String(),
}

// NewBinariesCmd creates binaries command.
func NewBinariesCmd() *cobra.Command {
var binariesCmd = &cobra.Command{
binariesCmd := &cobra.Command{
Use: "binaries",
}

var switchCmd = &cobra.Command{
switchCmd := &cobra.Command{
Use: "switch [program] [version]",
Short: "Switch to installed binary",
Example: `
Expand All @@ -44,7 +44,7 @@ You will need to choose version using arrow keys in your console.
Run: RunModuleFunc(internalSwitchModule),
Args: cobra.MatchAll(cobra.MaximumNArgs(2), binariesSwitchValidateArgs),
}
var listCmd = &cobra.Command{
listCmd := &cobra.Command{
Use: "list",
Short: "Show a list of installed binaries and their versions.",
Run: RunModuleFunc(internalListModule),
Expand Down Expand Up @@ -73,9 +73,9 @@ func internalSwitchModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
var err error

if len(args) > 0 {
switchCtx.ProgramName = args[0]
switchCtx.ProgramType = search.NewProgramType(args[0])
} else {
switchCtx.ProgramName, err = binary.ChooseProgram(binariesSupportedPrograms)
switchCtx.ProgramType, err = binary.ChooseProgram(binariesSupportedPrograms)
if err != nil {
return err
}
Expand All @@ -84,7 +84,7 @@ func internalSwitchModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
if len(args) > 1 {
switchCtx.Version = args[1]
} else {
switchCtx.Version, err = binary.ChooseVersion(cliOpts.Env.BinDir, switchCtx.ProgramName)
switchCtx.Version, err = binary.ChooseVersion(cliOpts.Env.BinDir, switchCtx.ProgramType)
if err != nil {
return err
}
Expand Down
Loading
Loading