Compare commits
5 Commits
f4f3164978
...
dfbd70b326
Author | SHA1 | Date | |
---|---|---|---|
dfbd70b326 | |||
96cb2cc8a4 | |||
2839a68c6a | |||
c9e3696ffd | |||
4940258365 |
10
go/main.go
10
go/main.go
@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"ocl/portainer-devtool/configs"
|
"ocl/portainer-devtool/configs"
|
||||||
"ocl/portainer-devtool/tasks"
|
"ocl/portainer-devtool/tasks"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -15,12 +16,17 @@ func main() {
|
|||||||
config.Summarize()
|
config.Summarize()
|
||||||
|
|
||||||
// Init tasks
|
// Init tasks
|
||||||
taskItems := []tasks.Tasker{
|
taskItems := []common.Tasker{
|
||||||
|
tasks.NewListRepositoriesTask(config),
|
||||||
tasks.NewGenerateJwtTokenTask(config),
|
tasks.NewGenerateJwtTokenTask(config),
|
||||||
tasks.NewCurlLookupTask(),
|
tasks.NewCurlLookupTask(),
|
||||||
tasks.NewCodeSecurityScanTask(),
|
tasks.NewCodeSecurityScanTask(),
|
||||||
tasks.NewListDevToolCommandTask(config),
|
tasks.NewListDevToolCommandTask(config),
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.ListCommandMenu(taskItems, "Which repository of action do you want operate:")
|
for _, taskItem := range taskItems {
|
||||||
|
taskItem.SetParentTaskers(taskItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
common.ListCommandMenu(taskItems, "Which repository of action do you want to operate:", true, nil)
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package repositories
|
|
||||||
|
|
||||||
type Actioner interface {
|
|
||||||
Execute() error
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
package repositories
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"ocl/portainer-devtool/commands"
|
|
||||||
"ocl/portainer-devtool/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
ACTION_EE_BUILD_ALL int = iota + 1
|
|
||||||
ACTION_EE_RUN_FRONTEND
|
|
||||||
ACTION_EE_RUN_BACKEND
|
|
||||||
ACTION_EE_VALIDATE_ALL
|
|
||||||
ACTION_EE_VALIDATE_FRONTEND
|
|
||||||
ACTION_EE_VALIDATE_BACKEND
|
|
||||||
ACTION_EE_RUN_UNIT_TEST_ALL
|
|
||||||
ACTION_EE_RUN_UNIT_TEST_FRONTEND
|
|
||||||
ACTION_EE_RUN_UNIT_TEST_BACKEND
|
|
||||||
)
|
|
||||||
|
|
||||||
type PortainerEE struct {
|
|
||||||
WorkDir string
|
|
||||||
FrontendDir string
|
|
||||||
BackendDir string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewPortainerEERepository() *PortainerEE {
|
|
||||||
repo := &PortainerEE{
|
|
||||||
WorkDir: "/home/oscarzhou/source/github.com/portainer/portainer-ee",
|
|
||||||
}
|
|
||||||
|
|
||||||
utils.HighlightPrint("Your portainer EE repository work directory is ")
|
|
||||||
fmt.Println(repo.WorkDir)
|
|
||||||
|
|
||||||
return repo
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *PortainerEE) Execute() error {
|
|
||||||
err := commands.ListBranches(repo.WorkDir)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if !utils.PromptContinue() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
option := utils.PromptMenu(repo.listSubMenu)
|
|
||||||
switch option {
|
|
||||||
case ACTION_EE_BUILD_ALL:
|
|
||||||
|
|
||||||
case ACTION_EE_RUN_FRONTEND:
|
|
||||||
commands.RunPortainerClient(repo.WorkDir)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (repo *PortainerEE) listSubMenu() {
|
|
||||||
utils.MenuPrint("Do you want?", `
|
|
||||||
1. Build both front-end and backend
|
|
||||||
2. Run front-end only
|
|
||||||
3. Run backend only
|
|
||||||
4. Validate both fornt-end and backend before commit
|
|
||||||
5. Validate front-end only before commit
|
|
||||||
6. Validate backend only before commit
|
|
||||||
7. Run unit tests for both front-end and backend
|
|
||||||
8. Run unit tests for front-end only
|
|
||||||
9. Run unit tests for backend only`)
|
|
||||||
}
|
|
30
go/repositories/unpacker/build_docker_image.go
Normal file
30
go/repositories/unpacker/build_docker_image.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package unpacker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ocl/portainer-devtool/configs"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
|
"ocl/portainer-devtool/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
type BuildDockerImageSubTask struct {
|
||||||
|
common.GeneralTask
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBuildDockerImageSubTask(cfg *configs.Config) *BuildDockerImageSubTask {
|
||||||
|
return &BuildDockerImageSubTask{
|
||||||
|
GeneralTask: *common.NewGeneralTask(cfg),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *BuildDockerImageSubTask) Execute() error {
|
||||||
|
utils.SuccessPrint(`
|
||||||
|
docker image tag docker.io/portainer/compose-unpacker:latest oscarzhou/compose-unpacker:28
|
||||||
|
docker image push oscarzhou/compose-unpacker:28
|
||||||
|
`)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *BuildDockerImageSubTask) String() string {
|
||||||
|
return "Build Docker Image"
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
package tasks
|
package tasks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
"ocl/portainer-devtool/utils"
|
"ocl/portainer-devtool/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CodeSecurityScanTask struct {
|
type CodeSecurityScanTask struct {
|
||||||
|
ParentTasks []common.Tasker
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCodeSecurityScanTask() *CodeSecurityScanTask {
|
func NewCodeSecurityScanTask() *CodeSecurityScanTask {
|
||||||
@ -30,6 +32,10 @@ func (task *CodeSecurityScanTask) Execute() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (task *CodeSecurityScanTask) SetParentTaskers(tasks []common.Tasker) {
|
||||||
|
task.ParentTasks = tasks
|
||||||
|
}
|
||||||
|
|
||||||
func (task *CodeSecurityScanTask) String() string {
|
func (task *CodeSecurityScanTask) String() string {
|
||||||
return "Code Security Scan"
|
return "Code Security Scan"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package tasks
|
package common
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
@ -13,6 +13,9 @@ func (task *ExitTask) Execute() error {
|
|||||||
return errors.New("exit")
|
return errors.New("exit")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (task *ExitTask) SetParentTaskers(tasks []Tasker) {
|
||||||
|
}
|
||||||
|
|
||||||
func (task *ExitTask) String() string {
|
func (task *ExitTask) String() string {
|
||||||
return "Exit"
|
return "Exit"
|
||||||
}
|
}
|
28
go/tasks/common/general_task.go
Normal file
28
go/tasks/common/general_task.go
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ocl/portainer-devtool/configs"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GeneralTask struct {
|
||||||
|
Config *configs.Config
|
||||||
|
ParentTasks []Tasker
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGeneralTask(cfg *configs.Config) *GeneralTask {
|
||||||
|
return &GeneralTask{
|
||||||
|
Config: cfg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *GeneralTask) Execute() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *GeneralTask) SetParentTaskers(tasks []Tasker) {
|
||||||
|
task.ParentTasks = tasks
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *GeneralTask) String() string {
|
||||||
|
return ""
|
||||||
|
}
|
22
go/tasks/common/return.go
Normal file
22
go/tasks/common/return.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
type ReturnTask struct {
|
||||||
|
ParentTasks []Tasker
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewReturnTask(tasks []Tasker) *ReturnTask {
|
||||||
|
return &ReturnTask{
|
||||||
|
ParentTasks: tasks,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *ReturnTask) Execute() error {
|
||||||
|
return ListCommandMenu(task.ParentTasks, "", false, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *ReturnTask) SetParentTaskers(tasks []Tasker) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *ReturnTask) String() string {
|
||||||
|
return "Go Back"
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package tasks
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -10,11 +10,17 @@ import (
|
|||||||
type Tasker interface {
|
type Tasker interface {
|
||||||
Execute() error
|
Execute() error
|
||||||
String() string
|
String() string
|
||||||
|
SetParentTaskers(tasks []Tasker)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListCommandMenu iterates task items to display them // on the screen as the menu options
|
// ListCommandMenu iterates task items to display them // on the screen as the menu options
|
||||||
func ListCommandMenu(taskItems []Tasker, menuDesp string) error {
|
func ListCommandMenu(taskItems []Tasker, menuDesp string, rootMenu bool, parentTaskItems []Tasker) error {
|
||||||
taskItems = append(taskItems, NewExitTask())
|
if rootMenu {
|
||||||
|
taskItems = append(taskItems, NewExitTask())
|
||||||
|
} else {
|
||||||
|
taskItems = append(taskItems, NewReturnTask(parentTaskItems))
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
printMainMenu := func() {
|
printMainMenu := func() {
|
||||||
taskNames := []string{}
|
taskNames := []string{}
|
||||||
@ -33,7 +39,6 @@ func ListCommandMenu(taskItems []Tasker, menuDesp string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
option := utils.SelectMenuItem(printMainMenu)
|
option := utils.SelectMenuItem(printMainMenu)
|
||||||
|
|
||||||
index, err := strconv.Atoi(option)
|
index, err := strconv.Atoi(option)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.ErrorPrint("please type the option number\n")
|
utils.ErrorPrint("please type the option number\n")
|
@ -2,10 +2,12 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
"ocl/portainer-devtool/utils"
|
"ocl/portainer-devtool/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CurlLookupTask struct {
|
type CurlLookupTask struct {
|
||||||
|
ParentTasks []common.Tasker
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCurlLookupTask() *CurlLookupTask {
|
func NewCurlLookupTask() *CurlLookupTask {
|
||||||
@ -43,6 +45,10 @@ func (task *CurlLookupTask) Execute() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (task *CurlLookupTask) SetParentTaskers(tasks []common.Tasker) {
|
||||||
|
task.ParentTasks = tasks
|
||||||
|
}
|
||||||
|
|
||||||
func (task *CurlLookupTask) String() string {
|
func (task *CurlLookupTask) String() string {
|
||||||
return "Lookup Curl Commands"
|
return "Lookup Curl Commands"
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,11 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"ocl/portainer-devtool/configs"
|
"ocl/portainer-devtool/configs"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GenerateJwtTokenTask struct {
|
type GenerateJwtTokenTask struct {
|
||||||
Config *configs.Config
|
common.GeneralTask
|
||||||
}
|
}
|
||||||
|
|
||||||
type GenerateJwtTokenResponse struct {
|
type GenerateJwtTokenResponse struct {
|
||||||
@ -19,7 +20,7 @@ type GenerateJwtTokenResponse struct {
|
|||||||
|
|
||||||
func NewGenerateJwtTokenTask(cfg *configs.Config) *GenerateJwtTokenTask {
|
func NewGenerateJwtTokenTask(cfg *configs.Config) *GenerateJwtTokenTask {
|
||||||
return &GenerateJwtTokenTask{
|
return &GenerateJwtTokenTask{
|
||||||
Config: cfg,
|
GeneralTask: *common.NewGeneralTask(cfg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,26 +2,32 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"ocl/portainer-devtool/configs"
|
"ocl/portainer-devtool/configs"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
"ocl/portainer-devtool/tasks/subtasks"
|
"ocl/portainer-devtool/tasks/subtasks"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListDevToolCommandTask struct {
|
type ListDevToolCommandTask struct {
|
||||||
Config *configs.Config
|
common.GeneralTask
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListDevToolCommandTask(cfg *configs.Config) *ListDevToolCommandTask {
|
func NewListDevToolCommandTask(cfg *configs.Config) *ListDevToolCommandTask {
|
||||||
return &ListDevToolCommandTask{
|
return &ListDevToolCommandTask{
|
||||||
Config: cfg,
|
GeneralTask: *common.NewGeneralTask(cfg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (task *ListDevToolCommandTask) Execute() error {
|
func (task *ListDevToolCommandTask) Execute() error {
|
||||||
subTaskItems := []Tasker{
|
subTaskItems := []common.Tasker{
|
||||||
subtasks.NewListVolumeSubTask(task.Config),
|
subtasks.NewListVolumeSubTask(task.Config),
|
||||||
subtasks.NewListRepositorySubTask(task.Config),
|
subtasks.NewListRepositorySubTask(task.Config),
|
||||||
}
|
}
|
||||||
|
|
||||||
ListCommandMenu(subTaskItems, "Which management commands do you want to choose:")
|
for _, taskItem := range subTaskItems {
|
||||||
|
taskItem.SetParentTaskers(subTaskItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListCommandMenu(subTaskItems, "Which management commands do you want to choose:")
|
||||||
|
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
36
go/tasks/list_repo_actions.go
Normal file
36
go/tasks/list_repo_actions.go
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ocl/portainer-devtool/configs"
|
||||||
|
"ocl/portainer-devtool/repositories/unpacker"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListRepoActionsSubTask struct {
|
||||||
|
Config *configs.Config
|
||||||
|
ParentTasks []common.Tasker
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewListRepoActionsSubTask(cfg *configs.Config) *ListRepoActionsSubTask {
|
||||||
|
return &ListRepoActionsSubTask{
|
||||||
|
Config: cfg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *ListRepoActionsSubTask) Execute() error {
|
||||||
|
subTaskItems := []common.Tasker{
|
||||||
|
unpacker.NewBuildDockerImageSubTask(task.Config),
|
||||||
|
}
|
||||||
|
|
||||||
|
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *ListRepoActionsSubTask) SetParentTaskers(tasks []common.Tasker) {
|
||||||
|
task.ParentTasks = tasks
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *ListRepoActionsSubTask) String() string {
|
||||||
|
return "Choose Repository Commands"
|
||||||
|
}
|
34
go/tasks/list_repos.go
Normal file
34
go/tasks/list_repos.go
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package tasks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"ocl/portainer-devtool/configs"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ListRepositoriesTask struct {
|
||||||
|
common.GeneralTask
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewListRepositoriesTask(cfg *configs.Config) *ListRepositoriesTask {
|
||||||
|
return &ListRepositoriesTask{
|
||||||
|
GeneralTask: *common.NewGeneralTask(cfg),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *ListRepositoriesTask) Execute() error {
|
||||||
|
subTaskItems := []common.Tasker{
|
||||||
|
NewListRepoActionsSubTask(task.Config),
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, taskItem := range subTaskItems {
|
||||||
|
taskItem.SetParentTaskers(subTaskItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *ListRepositoriesTask) String() string {
|
||||||
|
return "List All Repositories"
|
||||||
|
}
|
@ -2,17 +2,18 @@ package subtasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"ocl/portainer-devtool/configs"
|
"ocl/portainer-devtool/configs"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
"ocl/portainer-devtool/utils"
|
"ocl/portainer-devtool/utils"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListRepositorySubTask struct {
|
type ListRepositorySubTask struct {
|
||||||
Config *configs.Config
|
common.GeneralTask
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListRepositorySubTask(cfg *configs.Config) *ListRepositorySubTask {
|
func NewListRepositorySubTask(cfg *configs.Config) *ListRepositorySubTask {
|
||||||
return &ListRepositorySubTask{
|
return &ListRepositorySubTask{
|
||||||
Config: cfg,
|
GeneralTask: *common.NewGeneralTask(cfg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,18 +4,19 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"ocl/portainer-devtool/configs"
|
"ocl/portainer-devtool/configs"
|
||||||
|
"ocl/portainer-devtool/tasks/common"
|
||||||
"ocl/portainer-devtool/utils"
|
"ocl/portainer-devtool/utils"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ListVolumeSubTask struct {
|
type ListVolumeSubTask struct {
|
||||||
Config *configs.Config
|
common.GeneralTask
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewListVolumeSubTask(cfg *configs.Config) *ListVolumeSubTask {
|
func NewListVolumeSubTask(cfg *configs.Config) *ListVolumeSubTask {
|
||||||
return &ListVolumeSubTask{
|
return &ListVolumeSubTask{
|
||||||
Config: cfg,
|
GeneralTask: *common.NewGeneralTask(cfg),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user