This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Code reformatting and minor refactoring - Fixed syntax error in code for tree.go - Added coding sample minimal-sandbox2.go
- Loading branch information
1 parent
000ef9f
commit 282b20a
Showing
11 changed files
with
275 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,68 @@ | ||
// This is a sample source file that shows how | ||
// to create a MySQL sandbox using dbdeployer code | ||
// from another Go program. | ||
package main | ||
|
||
import ( | ||
"os" | ||
"github.com/datacharmer/dbdeployer/sandbox" | ||
"github.com/datacharmer/dbdeployer/common" | ||
"github.com/datacharmer/dbdeployer/defaults" | ||
"github.com/datacharmer/dbdeployer/sandbox" | ||
"os" | ||
) | ||
|
||
func main() { | ||
// Searches for expanded sandboxes in $HOME/opt/mysql | ||
sandbox_binary := os.Getenv("HOME") + "/opt/mysql" | ||
|
||
// For this to work, we need to have | ||
// a MySQL tarball expanded in $HOME/opt/mysql/5.7.22 | ||
version := "5.7.22" | ||
|
||
// Creates sandboxes in $HOME/sandboxes | ||
sandbox_home := os.Getenv("HOME") + "/sandboxes" | ||
sandbox_binary := os.Getenv("HOME") + "/opt/mysql" | ||
|
||
// MySQL will look for binaries in $HOME/opt/mysql/5.7.22 | ||
basedir := sandbox_binary + "/" + version | ||
|
||
// The unique port for this sandbox | ||
port := 5722 | ||
|
||
// Username and password for this sandbox | ||
user := "msandbox" | ||
password := "psandbox" | ||
password := "msandbox" | ||
|
||
if !common.DirExists(sandbox_home) { | ||
common.Mkdir(sandbox_home) | ||
} | ||
|
||
var sdef = sandbox.SandboxDef{ | ||
Version: version, | ||
Basedir: basedir, | ||
SandboxDir: sandbox_home, | ||
DirName: "msb_5_7_22", | ||
LoadGrants:true, | ||
InstalledPorts:[]int{1186, 3306, 33060}, | ||
Port: port, | ||
DbUser: user, | ||
DbPassword: password, | ||
RplUser: "r" + user, | ||
RplPassword: "r" + password, | ||
RemoteAccess:"127.%", | ||
BindAddress:"127.0.0.1", | ||
// Minimum data to be filled for a simple sandbox. | ||
// See sandbox/sandbox.go for the full description | ||
// of this data structure | ||
var sdef = sandbox.SandboxDef{ | ||
Version: version, | ||
Basedir: basedir, | ||
SandboxDir: sandbox_home, | ||
DirName: "msb_5_7_22", | ||
LoadGrants: true, | ||
InstalledPorts: []int{1186, 3306, 33060}, | ||
Port: port, | ||
DbUser: user, | ||
DbPassword: password, | ||
RplUser: "r" + user, | ||
RplPassword: "r" + password, | ||
RemoteAccess: "127.%", | ||
BindAddress: "127.0.0.1", | ||
} | ||
|
||
// Calls the sandbox creation | ||
sandbox.CreateSingleSandbox(sdef) | ||
|
||
// Invokes the sandbox self-testing script | ||
common.Run_cmd(sandbox_home + "/msb_5_7_22/test_sb") | ||
|
||
// Removes the sandbox from disk | ||
sandbox.RemoveSandbox(sandbox_home, "msb_5_7_22", false) | ||
defaults.DeleteFromCatalog(sandbox_home+"/msb_5_7_22") | ||
|
||
// Removes the sandbox from dbdeployer catalog | ||
defaults.DeleteFromCatalog(sandbox_home + "/msb_5_7_22") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// This is a sample source file that shows how | ||
// to create two MySQL sandboxes using dbdeployer code | ||
// from another Go program. | ||
package main | ||
|
||
import ( | ||
"github.com/datacharmer/dbdeployer/common" | ||
"github.com/datacharmer/dbdeployer/defaults" | ||
"github.com/datacharmer/dbdeployer/sandbox" | ||
"os" | ||
) | ||
|
||
func main() { | ||
// Searches for expanded sandboxes in $HOME/opt/mysql | ||
sandbox_binary := os.Getenv("HOME") + "/opt/mysql" | ||
|
||
// Creates sandboxes in $HOME/sandboxes | ||
sandbox_home := os.Getenv("HOME") + "/sandboxes" | ||
|
||
// For this to work, we need to have | ||
// a MySQL tarball expanded in $HOME/opt/mysql/5.7.22 | ||
version1 := "5.7.22" | ||
version2 := "5.6.25" | ||
|
||
sandbox_name1 := "msb_5_7_22" | ||
sandbox_name2 := "msb_5_6_25" | ||
|
||
// The unique ports for these sandboxes | ||
port1 := 5722 | ||
port2 := 5625 | ||
|
||
// MySQL will look for binaries in $HOME/opt/mysql/5.7.22 | ||
basedir1 := sandbox_binary + "/" + version1 // This is what dbdeployer expects | ||
// i.e. a name containing the full version | ||
|
||
// MySQL will look for binaries in $HOME/opt/mysql/my-5.6 | ||
basedir2 := sandbox_binary + "/my-5.6" // This is a deviation from dbdeployer | ||
// paradigm, using a non-standard name | ||
// for the base directory | ||
|
||
// Username and password for this sandbox | ||
user := "msandbox" | ||
password := "msandbox" | ||
|
||
// Creates the base target directory if it doesn't exist | ||
if !common.DirExists(sandbox_home) { | ||
common.Mkdir(sandbox_home) | ||
} | ||
|
||
// Minimum data to be filled for a simple sandbox. | ||
// See sandbox/sandbox.go for the full description | ||
// of this data structure | ||
var sdef = sandbox.SandboxDef{ | ||
Version: version1, | ||
Basedir: basedir1, | ||
SandboxDir: sandbox_home, | ||
DirName: sandbox_name1, | ||
LoadGrants: true, | ||
// This is the list of ports to ignore | ||
// when checking if the designated port is | ||
// used or not. | ||
// Try changing the Port item to 3306. | ||
// You will see that the sandbox will install using 3307 | ||
InstalledPorts: []int{1186, 3306, 33060}, | ||
Port: port1, | ||
DbUser: user, | ||
DbPassword: password, | ||
RplUser: "r" + user, | ||
RplPassword: "r" + password, | ||
RemoteAccess: "127.%", | ||
BindAddress: "127.0.0.1", | ||
} | ||
|
||
// Calls the sandbox creation | ||
sandbox.CreateSingleSandbox(sdef) | ||
|
||
sdef.Version = version2 | ||
sdef.Basedir = basedir2 | ||
sdef.DirName = sandbox_name2 | ||
sdef.Port = port2 | ||
|
||
// Calls the sandbox creation for the second sandbox | ||
sandbox.CreateSingleSandbox(sdef) | ||
|
||
// Invokes the sandbox self-testing script | ||
common.Run_cmd(sandbox_home + "/" + sandbox_name1 + "/test_sb") | ||
common.Run_cmd(sandbox_home + "/" + sandbox_name2 + "/test_sb") | ||
|
||
// Removes the sandbox from disk | ||
sandbox.RemoveSandbox(sandbox_home, sandbox_name1, false) | ||
sandbox.RemoveSandbox(sandbox_home, sandbox_name2, false) | ||
|
||
// Removes the sandbox from dbdeployer catalog | ||
defaults.DeleteFromCatalog(sandbox_home + "/" + sandbox_name1) | ||
defaults.DeleteFromCatalog(sandbox_home + "/" + sandbox_name2) | ||
} |
Oops, something went wrong.