Skip to content
This repository was archived by the owner on Oct 29, 2023. It is now read-only.

Commit 8a80d58

Browse files
committed
Added support for directly using path to binaries
NEW FEATURES - Implemented Issue 21 "Add support for directly using path to binaries" BUGS FIXED - unpack would not act on old tarball where files were not explicitly marked as regular. TESTING - Added test for Issue 21
1 parent fb979f9 commit 8a80d58

16 files changed

+1012
-79
lines changed

Diff for: Changelog

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
1.8.0 08-Jul-2018
2+
NEW FEATURES
3+
- Implemented Issue 21 "Add support for directly using path to binaries"
4+
5+
BUGS FIXED
6+
- unpack would not act on old tarball where files were not
7+
explicitly marked as regular.
8+
- Fixed Issue 22 "dbdeployer should check whether the binaries are for the
9+
current OS"
10+
TESTING
11+
- Added test for Issue 21
12+
113
1.7.0 01-Jul-2018
214
NEW FEATURES
315
- Added option for custom history file for each sandbox

Diff for: README.md

+58-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[DBdeployer](https://github.com/datacharmer/dbdeployer) is a tool that deploys MySQL database servers easily.
44
This is a port of [MySQL-Sandbox](https://github.com/datacharmer/mysql-sandbox), originally written in Perl, and re-designed from the ground up in [Go](https://golang.org). See the [features comparison](https://github.com/datacharmer/dbdeployer/blob/master/docs/features.md) for more detail.
55

6-
Documentation updated for version 1.7.0 (30-Jun-2018 20:44 UTC)
6+
Documentation updated for version 1.8.0 (08-Jul-2018 08:03 UTC)
77

88
## Installation
99

@@ -13,7 +13,7 @@ Get the one for your O.S. from [dbdeployer releases](https://github.com/datachar
1313

1414
For example:
1515

16-
$ VERSION=1.7.0
16+
$ VERSION=1.8.0
1717
$ origin=https://github.com/datacharmer/dbdeployer/releases/download/$VERSION
1818
$ wget $origin/dbdeployer-$VERSION.linux.tar.gz
1919
$ tar -xzf dbdeployer-$VERSION.linux.tar.gz
@@ -47,7 +47,7 @@ For example:
4747
The program doesn't have any dependencies. Everything is included in the binary. Calling *dbdeployer* without arguments or with ``--help`` will show the main help screen.
4848

4949
$ dbdeployer --version
50-
dbdeployer version 1.7.0
50+
dbdeployer version 1.8.0
5151

5252

5353
$ dbdeployer -h
@@ -179,6 +179,7 @@ The easiest command is ``deploy single``, which installs a single sandbox.
179179
For example:
180180
dbdeployer deploy single 5.7 # deploys the latest release of 5.7.x
181181
dbdeployer deploy single 5.7.21 # deploys a specific release
182+
dbdeployer deploy single /path/to/5.7.21 # deploys a specific release in a given path
182183

183184
For this command to work, there must be a directory $HOME/opt/mysql/5.7.21, containing
184185
the binary files from mysql-5.7.21-$YOUR_OS-x86_64.tar.gz
@@ -233,6 +234,7 @@ The ``deploy replication`` command will install a master and two or more slaves,
233234

234235
$ dbdeployer deploy replication 5.7 # deploys highest revision for 5.7
235236
$ dbdeployer deploy replication 5.7.21 # deploys a specific revision
237+
$ dbdeployer deploy replication /path/to/5.7.21 # deploys a specific revision in a given path
236238
# (implies topology = master-slave)
237239

238240
$ dbdeployer deploy --topology=master-slave replication 5.7
@@ -293,17 +295,62 @@ You can issue the command ``dbdeployer deploy single 8.0``, and it will use 8.0.
293295

294296
## Multiple sandboxes, same version and type
295297

296-
If you want to deploy several instances of the same version and the same type (for example two single sandboxes of 8.0.4, or two group replication instances with different single-primary setting) you can specify the data directory name and the ports manually.
298+
If you want to deploy several instances of the same version and the same type (for example two single sandboxes of 8.0.4, or two replication instances with different settings) you can specify the data directory name and the ports manually.
297299

298300
$ dbdeployer deploy single 8.0.4
299301
# will deploy in msb_8_0_4 using port 8004
300302

301303
$ dbdeployer deploy single 8.0.4 --sandbox-directory=msb2_8_0_4
302304
# will deploy in msb2_8_0_4 using port 8005 (which dbdeployer detects and uses)
303305

304-
$ dbdeployer deploy replication 8.0.4 --sandbox-directory=rsandbox2_8_0_4 --base-port=18600
306+
$ dbdeployer deploy replication 8.0.4 --concurrent
307+
# will deploy replication in rsandbox_8_0_4 using default calculated ports 19009, 19010, 19011
308+
309+
$ dbdeployer deploy replication 8.0.4 \
310+
--gtid \
311+
--sandbox-directory=rsandbox2_8_0_4 \
312+
--base-port=18600 --concurrent
305313
# will deploy replication in rsandbox2_8_0_4 using ports 18601, 18602, 18603
306314

315+
## Using the direct path to the expanded tarball
316+
317+
If you have a custom organization of expanded tarballs, you may want to use the direct path to the binaries, instead of a combination of ``--sandbox-binary`` and the version name.
318+
319+
For example, let's assume your binaries are organized as follows:
320+
321+
$HOME/opt/
322+
/percona/
323+
/5.7.21
324+
/5.7.22
325+
/8.0.11
326+
/mysql/
327+
/5.7.21
328+
/5.7.22
329+
/8.0.11
330+
331+
You can deploy a single sandbox for a Percona server version 5.7.22 using any of the following approaches:
332+
333+
#1
334+
dbdeployer deploy single --sandbox-binary=$HOME/opt/percona 5.7.22
335+
336+
#2
337+
dbdeployer deploy single $HOME/opt/percona/5.7.22
338+
339+
#3
340+
dbdeployer defaults update sandbox-binary $HOME/opt/percona
341+
dbdeployer deploy single 5.7.22
342+
343+
#4
344+
export SANDBOX_BINARY=$HOME/opt/percona
345+
dbdeployer deploy single 5.7.22
346+
347+
Methods #1 and #2 are equivalent. They set the sandbox binary directory temporarily to a new one, and use it for the current deployement
348+
349+
Methods #3 and #4 will set the sandbox binary directory permanently, with the difference that #3 is set for any invocation of dbdeployer system-wide (in a different terminal window, it will use the new value,) while #4 is set only for the current session (in a different terminal window, it will still use the default.)
350+
351+
Be aware that, using this kind of organization may see conflicts during deployment. For example, after installing Percona Server 5.7.22, if you want to install MySQL 5.7.22 you will need to specify a ``--sandbox-directory`` explicitly.
352+
Instead, if you use the prefix approach defined in the "standard and non-standard basedir names," conflicts should be avoided.
353+
307354
## Ports management
308355

309356
dbdeployer will try using the default port for each sandbox whenever possible. For single sandboxes, the port will be the version number without dots: 5.7.22 will deploy on port 5722. For multiple sandboxes, the port number is defined by using a prefix number (visible in the defaults: ``dbdeployer defaults list``) + the port number + the revision number (for some topologies multiplied by 100.)
@@ -755,18 +802,18 @@ Should you need to compile your own binaries for dbdeployer, follow these steps:
755802
2. Run ``go get github.com/datacharmer/dbdeployer``. This will import all the code that is needed to build dbdeployer.
756803
3. Change directory to ``$GOPATH/src/github.com/datacharmer/dbdeployer``.
757804
4. From the folder ``./pflag``, copy the file ``string_slice.go`` to ``$GOPATH/src/github.com/spf13/pflag``.
758-
5. Run ``./build.sh {linux|OSX} 1.7.0``
759-
6. If you need the docs enabled binaries (see the section "Generating additional documentation") run ``MKDOCS=1 ./build.sh {linux|OSX} 1.7.0``
805+
5. Run ``./build.sh {linux|OSX} 1.8.0``
806+
6. If you need the docs enabled binaries (see the section "Generating additional documentation") run ``MKDOCS=1 ./build.sh {linux|OSX} 1.8.0``
760807

761808
## Generating additional documentation
762809

763810
Between this file and [the API API list](https://github.com/datacharmer/dbdeployer/blob/master/docs/API/API-1.1.md), you have all the existing documentation for dbdeployer.
764811
Should you need additional formats, though, dbdeployer is able to generate them on-the-fly. Tou will need the docs-enabled binaries: in the distribution list, you will find:
765812

766-
* dbdeployer-1.7.0-docs.linux.tar.gz
767-
* dbdeployer-1.7.0-docs.osx.tar.gz
768-
* dbdeployer-1.7.0.linux.tar.gz
769-
* dbdeployer-1.7.0.osx.tar.gz
813+
* dbdeployer-1.8.0-docs.linux.tar.gz
814+
* dbdeployer-1.8.0-docs.osx.tar.gz
815+
* dbdeployer-1.8.0.linux.tar.gz
816+
* dbdeployer-1.8.0.osx.tar.gz
770817

771818
The executables containing ``-docs`` in their name have the same capabilities of the regular ones, but in addition they can run the *hidden* command ``tree``, with alias ``docs``.
772819

Diff for: cmd/replication.go

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Use the "unpack" command to get the tarball into the right directory.
8383
Example: `
8484
$ dbdeployer deploy replication 5.7 # deploys highest revision for 5.7
8585
$ dbdeployer deploy replication 5.7.21 # deploys a specific revision
86+
$ dbdeployer deploy replication /path/to/5.7.21 # deploys a specific revision in a given path
8687
# (implies topology = master-slave)
8788
8889
$ dbdeployer deploy --topology=master-slave replication 5.7

Diff for: cmd/single.go

+35-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"fmt"
2020
"os"
2121
"path"
22-
"path/filepath"
2322
"regexp"
2423
"strings"
2524

@@ -75,11 +74,7 @@ func GetAbsolutePathFromFlag(cmd *cobra.Command, name string) string {
7574
if err != nil {
7675
common.Exit(1, fmt.Sprintf("Error getting flag value for --%s", name))
7776
}
78-
value, err = filepath.Abs(value)
79-
if err != nil {
80-
common.Exit(1, fmt.Sprintf("Error getting absolute path for %s", value))
81-
}
82-
return value
77+
return common.AbsolutePath(value)
8378
}
8479

8580
func check_if_abridged_version(version, basedir string) string {
@@ -114,6 +109,7 @@ func FillSdef(cmd *cobra.Command, args []string) sandbox.SandboxDef {
114109
basedir := GetAbsolutePathFromFlag(cmd, "sandbox-binary")
115110

116111
sd.BasedirName = args[0]
112+
version_from_option := false
117113
sd.Version, _ = flags.GetString("binary-version")
118114
if sd.Version == "" {
119115
sd.Version = args[0]
@@ -122,6 +118,34 @@ func FillSdef(cmd *cobra.Command, args []string) sandbox.SandboxDef {
122118
if old_version != sd.Version {
123119
sd.BasedirName = sd.Version
124120
}
121+
} else {
122+
version_from_option = true
123+
}
124+
125+
if common.DirExists(sd.BasedirName) {
126+
sd.BasedirName = common.RemoveTrailingSlash(sd.BasedirName)
127+
sd.BasedirName = common.AbsolutePath(sd.BasedirName)
128+
// fmt.Printf("OLD bd <%s> - v: <%s>\n",basedir, sd.Version )
129+
target := sd.BasedirName
130+
old_basedir := basedir
131+
basedir = common.DirName(sd.BasedirName)
132+
if old_basedir != defaults.Defaults().SandboxBinary {
133+
// basedir was set using either an environment variable
134+
// or a command line option
135+
if old_basedir != basedir {
136+
// The new basedir is different from the one given by command line or env
137+
common.Exit(1, "The Sandbox Binary directory was set twice,",
138+
fmt.Sprintf(" using conflicting values: '%s' and '%s' ", old_basedir, basedir))
139+
}
140+
}
141+
sd.BasedirName = common.BaseName(sd.BasedirName)
142+
if !version_from_option {
143+
sd.Version = sd.BasedirName
144+
}
145+
if !common.IsVersion(sd.Version) {
146+
common.Exit(1, fmt.Sprintf("No version detected for directory %s", target))
147+
}
148+
// fmt.Printf("NEW bd <%s> - v: <%s>\n",basedir, sd.Version )
125149
}
126150

127151
sd.Port = common.VersionToPort(sd.Version)
@@ -136,11 +160,14 @@ func FillSdef(cmd *cobra.Command, args []string) sandbox.SandboxDef {
136160
sd.Port = sd.UserPort
137161
}
138162

139-
sd.Basedir = path.Join(basedir, sd.Version)
163+
sd.Basedir = path.Join(basedir, sd.BasedirName)
140164
// sd.Basedir = path.Join(basedir, args[0])
141165
if !common.DirExists(sd.Basedir) {
142166
common.Exit(1, fmt.Sprintf("basedir '%s' not found", sd.Basedir))
143167
}
168+
169+
common.CheckTarballOperatingSystem(sd.Basedir)
170+
144171
sd.SandboxDir = GetAbsolutePathFromFlag(cmd, "sandbox-home")
145172

146173
common.CheckSandboxDir(sd.SandboxDir)
@@ -231,6 +258,7 @@ containing an unpacked tarball. The place where these directories are found is d
231258
For example:
232259
dbdeployer deploy single 5.7 # deploys the latest release of 5.7.x
233260
dbdeployer deploy single 5.7.21 # deploys a specific release
261+
dbdeployer deploy single /path/to/5.7.21 # deploys a specific release in a given path
234262
235263
For this command to work, there must be a directory $HOME/opt/mysql/5.7.21, containing
236264
the binary files from mysql-5.7.21-$YOUR_OS-x86_64.tar.gz

Diff for: common/fileutil.go

+8
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ func DirName(filename string) string {
303303
return filepath.Dir(filename)
304304
}
305305

306+
func AbsolutePath(value string) string {
307+
filename, err := filepath.Abs(value)
308+
if err != nil {
309+
Exit(1, fmt.Sprintf("Error getting absolute path for %s", value))
310+
}
311+
return filename
312+
}
313+
306314
func Mkdir(dir_name string) {
307315
err := os.Mkdir(dir_name, 0755)
308316
if err != nil {

Diff for: common/strutils.go

+5
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,8 @@ func Exit(exit_code int, messages ...string) {
215215
}
216216
os.Exit(exit_code)
217217
}
218+
219+
func RemoveTrailingSlash(s string) string {
220+
re := regexp.MustCompile(`/$`)
221+
return re.ReplaceAllString(s, "")
222+
}

Diff for: common/version.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
package common
1717

18-
var VersionDef string = "1.7.0" // 2018-06-23
18+
var VersionDef string = "1.8.0" // 2018-07-05
1919

2020
// Compatible version is the version used to mark compatible archives (templates, configuration).
2121
// It is usually major.minor.0, except when we are at version 0.x, when
2222
// every revision may bring incompatibility
23-
var CompatibleVersion string = "1.7.0" // 2018-06-23
23+
var CompatibleVersion string = "1.8.0" // 2018-07-05

0 commit comments

Comments
 (0)