-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
470 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,22 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(genCmd) | ||
} | ||
|
||
var genCmd = &cobra.Command{ | ||
Use: "gen", | ||
Short: "Generates all the needed artifacts for the docker-based modern (data) platform", | ||
Long: `Generates all the needed artifacts for the docker-based modern (data) platform. | ||
The stack configuration can either be passed as a local file (using the --config-filename option or using the default name 'config.yml') | ||
or as an URL | ||
referencing a file on the Internet (using the --config-url option).`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Platys v 1.0") | ||
}, | ||
} |
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,36 @@ | ||
package cmd | ||
|
||
import ( | ||
|
||
"github.com/spf13/cobra" | ||
|
||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(listServicesCmd) | ||
} | ||
|
||
var listServicesCmd = &cobra.Command{ | ||
Use: "list_services", | ||
Short: "List the services", | ||
Long: `List the services contained in the given version of the platy`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
pullConfig() | ||
|
||
/* tar_config = pull_config(Stack, Version) | ||
// extract the config file from the tar in to the current folder | ||
tar_file = tarfile.open(tar_config) | ||
tar_file.extractall(path=tempfile.gettempdir()) | ||
tar_file.close() | ||
yaml = ruamel.yaml.YAML() | ||
with open(rf'{tempfile.gettempdir()}/config.yml') as file: | ||
config_yml = yaml.load(file) | ||
for c in config_yml: | ||
service = re.search("([A-Z0-9_-]+)_enable", str(c)) // if variable follows regex it's considered a service and will be printed | ||
if service is not None: | ||
print(service.group(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
package cmd | ||
|
||
import ( | ||
"archive/tar" | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"github.com/docker/docker/api/types" | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/docker/docker/client" | ||
"github.com/docker/docker/pkg/stdcopy" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
"io" | ||
"os" | ||
) | ||
|
||
var Stack string | ||
var Version string | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "platys", | ||
Short: "Platys platform generator", | ||
Long: `Platys modern data platform generator | ||
Complete documentation is available at https://github.com/TrivadisPF/platys`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Do Stuff Here | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.PersistentFlags().StringVarP(&Stack, "stack", "s", "trivadis/platys-modern-data-platform", "stack version to employ") | ||
rootCmd.PersistentFlags().StringVarP(&Version, "stack-version", "w", "latest", "version of the stack to employ") | ||
} | ||
|
||
func er(msg interface{}) { | ||
fmt.Println("Error:", msg) | ||
os.Exit(1) | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func pullConfig(){ | ||
// init and start docker container | ||
/*client = Docker.from_env() | ||
dp_container = client.containers.run(image = fmt.Sprintf("%s:%s", Stack, ), detach = True, auto_remove = True) | ||
// copy default config file (with default values to the current folder | ||
tar_config = tempfile.gettempdir() + '/config.tar' | ||
f = open(tar_config, 'wb') | ||
bits, stats = dp_container.get_archive('/opt/mdps-gen/vars/config.yml') | ||
for chunk in bits: | ||
f.write(chunk) | ||
f.close()*/ | ||
|
||
//return tar_config | ||
|
||
|
||
ctx := context.Background() | ||
|
||
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
reader, err := cli.ImagePull(ctx, Stack, types.ImagePullOptions{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
io.Copy(os.Stdout, reader) | ||
|
||
resp, err := cli.ContainerCreate(ctx, &container.Config{ | ||
Image: Stack, | ||
|
||
Tty: true, | ||
|
||
}, nil, nil, "platys") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := cli.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil { | ||
panic(err) | ||
} | ||
|
||
|
||
statusCh, errCh := cli.ContainerWait(ctx, resp.ID, container.WaitConditionNotRunning) | ||
select { | ||
case err := <-errCh: | ||
if err != nil { | ||
panic(err) | ||
} | ||
case <-statusCh: | ||
} | ||
|
||
out, err := cli.ContainerLogs(ctx, resp.ID, types.ContainerLogsOptions{ShowStdout: true}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
|
||
reader, _, err = cli.CopyFromContainer(ctx, resp.ID,"/opt/mdps-gen/vars/config.yml") | ||
if err != nil{ | ||
log.Println(err.Error()) | ||
} | ||
tr := tar.NewReader(reader) | ||
|
||
for { | ||
// hdr gives you the header of the tar file | ||
hdr, err := tr.Next() | ||
if err == io.EOF { | ||
// end of tar archive | ||
break | ||
} | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
buf := new(bytes.Buffer) | ||
buf.ReadFrom(tr) | ||
|
||
// You can use this wholeContent to create new file | ||
wholeContent := buf.String() | ||
|
||
fmt.Println("Whole of the string of ", hdr.Name ," is ",wholeContent) | ||
|
||
} | ||
|
||
stdcopy.StdCopy(os.Stdout, os.Stderr, out) | ||
cli.ContainerRemove(ctx, resp.ID,types.ContainerRemoveOptions{ | ||
RemoveVolumes: true, | ||
RemoveLinks: true, | ||
Force: true, | ||
}) | ||
} | ||
|
||
|
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,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
} | ||
|
||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Print the version number of platys", | ||
Long: `Print the version number of platys`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("Platys v 1.0") | ||
}, | ||
} |
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,6 @@ | ||
#### Installing docker dependency | ||
|
||
provide this exact version | ||
``` | ||
go get github.com/docker/docker@v19.03.9 | ||
``` |
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,14 @@ | ||
module trivadis.com/platys | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/containerd/containerd v1.3.4 // indirect | ||
github.com/docker/distribution v2.7.1+incompatible // indirect | ||
github.com/docker/docker v17.12.0-ce-rc1.0.20200514230353-811a247d06e8+incompatible | ||
github.com/docker/go-connections v0.4.0 // indirect | ||
github.com/docker/go-units v0.4.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.0.1 // indirect | ||
github.com/spf13/cobra v1.0.0 | ||
) |
Oops, something went wrong.