-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Thomascogez/cli
Add cli integration
- Loading branch information
Showing
8 changed files
with
111 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/Thomascogez/dump-and-dumper/dumper" | ||
"github.com/Thomascogez/dump-and-dumper/helpers" | ||
upload "github.com/Thomascogez/dump-and-dumper/uploader" | ||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var dumpCmd = &cobra.Command{ | ||
Use: "dump", | ||
Short: "Execute dump against all container using required label", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cli, err := client.NewClientWithOpts(client.FromEnv) | ||
helpers.CheckError(err) | ||
|
||
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{}) | ||
helpers.CheckError(err) | ||
|
||
s3Uploader := upload.NewS3UploaderFromFlags(cmd.Flags()) | ||
dockerDumper := dumper.DockerDumper{Uploader: s3Uploader} | ||
|
||
containersToDump := dumper.FindContainersToDump(containers) | ||
|
||
fmt.Printf("[dump & dumper] - Start dumping %d container(s) ...\n", len(containersToDump)) | ||
|
||
dockerDumper.Dump(containersToDump) | ||
|
||
fmt.Printf("[dump & dumper] - Done dumping %d container(s)\n", len(containersToDump)) | ||
}, | ||
} | ||
|
||
func init() { | ||
dumpCmd.PersistentFlags().String("s3-endpoint", "", "Define endpoint of s3 bucket") | ||
dumpCmd.PersistentFlags().String("s3-region", "", "Define region of s3 bucket") | ||
dumpCmd.PersistentFlags().String("s3-bucket", "", "Define name of the destination bucket") | ||
dumpCmd.PersistentFlags().String("s3-secretKeyId", "", "Id of the secret in order to access s3 bucket") | ||
dumpCmd.PersistentFlags().String("s3-secretKey", "", "Secret key in order to access s3 bucket") | ||
|
||
rootCmd.AddCommand(dumpCmd) | ||
} |
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,23 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "dump-dumper", | ||
Short: "dump-dumper is a simple cli tool to streamline your dockerize database backup process", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Welcome to dump-dumper") | ||
}, | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} |
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,4 +1,7 @@ | ||
package main | ||
|
||
import "github.com/Thomascogez/dump-and-dumper/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
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