Compare commits
10 Commits
master
...
oscar-next
Author | SHA1 | Date | |
---|---|---|---|
885098809b | |||
82906eb832 | |||
dcf30657c1 | |||
3c28c8cdd9 | |||
f7b2fcb5bd | |||
dfbd70b326 | |||
96cb2cc8a4 | |||
2839a68c6a | |||
c9e3696ffd | |||
4940258365 |
13
go/main.go
13
go/main.go
@ -4,6 +4,7 @@ import (
|
||||
"log"
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -15,12 +16,20 @@ func main() {
|
||||
config.Summarize()
|
||||
|
||||
// Init tasks
|
||||
taskItems := []tasks.Tasker{
|
||||
taskItems := []common.Tasker{
|
||||
tasks.NewListRepositoryMenuTask(config),
|
||||
tasks.NewListOperationMenuTask(config),
|
||||
tasks.NewGenerateJwtTokenTask(config),
|
||||
tasks.NewTestEnvironmentTask(),
|
||||
tasks.NewCurlLookupTask(),
|
||||
tasks.NewCodeSecurityScanTask(),
|
||||
tasks.NewInstallDockerTask(),
|
||||
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)
|
||||
}
|
||||
|
33
go/operations/edgestack/menu.go
Normal file
33
go/operations/edgestack/menu.go
Normal file
@ -0,0 +1,33 @@
|
||||
package edgestack
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
type OperationMenuSubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewOperationMenuSubTask(cfg *configs.Config) *OperationMenuSubTask {
|
||||
return &OperationMenuSubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *OperationMenuSubTask) Execute() error {
|
||||
subTaskItems := []common.Tasker{
|
||||
NewTagOfficialImageSubTask(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 *OperationMenuSubTask) String() string {
|
||||
return "edgestack"
|
||||
}
|
40
go/operations/edgestack/tag_official_image.go
Normal file
40
go/operations/edgestack/tag_official_image.go
Normal file
@ -0,0 +1,40 @@
|
||||
package edgestack
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type TagOfficialImageSubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewTagOfficialImageSubTask(cfg *configs.Config) *TagOfficialImageSubTask {
|
||||
return &TagOfficialImageSubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *TagOfficialImageSubTask) Execute() error {
|
||||
utils.SuccessPrint(`
|
||||
docker pull nginx:latest
|
||||
docker image tag nginx:latest ghcr.io/oscarzhou-portainer/nginx:1
|
||||
docker push ghcr.io/oscarzhou-portainer/nginx:1
|
||||
-----------------
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
nginx-container:
|
||||
image: ghcr.io/oscarzhou-portainer/nginx:1
|
||||
container_name: "nginx-from-ghcr"
|
||||
ports:
|
||||
- "${PORT:-81}:80"
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *TagOfficialImageSubTask) String() string {
|
||||
return "Create Image for Private Registry"
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package repositories
|
||||
|
||||
type Actioner interface {
|
||||
Execute() error
|
||||
}
|
33
go/repositories/agent/build_docker_image.go
Normal file
33
go/repositories/agent/build_docker_image.go
Normal file
@ -0,0 +1,33 @@
|
||||
package agent
|
||||
|
||||
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(`
|
||||
./dev.sh compile
|
||||
./dev.sh build
|
||||
----
|
||||
./dev.sh compile
|
||||
docker build -t "portainerci/agent:oscar-alpine" -f build/linux/alpine.Dockerfile .
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *BuildDockerImageSubTask) String() string {
|
||||
return "Build Docker Image"
|
||||
}
|
31
go/repositories/agent/menu.go
Normal file
31
go/repositories/agent/menu.go
Normal file
@ -0,0 +1,31 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
type MenuSubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewMenuSubTask(cfg *configs.Config) *MenuSubTask {
|
||||
return &MenuSubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *MenuSubTask) Execute() error {
|
||||
subTaskItems := []common.Tasker{
|
||||
NewBuildDockerImageSubTask(task.Config),
|
||||
NewPushImageSubTask(task.Config),
|
||||
}
|
||||
|
||||
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *MenuSubTask) String() string {
|
||||
return "agent"
|
||||
}
|
32
go/repositories/agent/push_image.go
Normal file
32
go/repositories/agent/push_image.go
Normal file
@ -0,0 +1,32 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type PushImageSubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewPushImageSubTask(cfg *configs.Config) *PushImageSubTask {
|
||||
return &PushImageSubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *PushImageSubTask) Execute() error {
|
||||
utils.SuccessPrint(`
|
||||
export CR_PAT=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
|
||||
echo $CR_PAT | docker login ghcr.io -u oscarzhou-portainer --password-stdin
|
||||
docker image tag portainerci/agent:develop-78af729 ghcr.io/oscarzhou-portainer/agent:develop-78af729
|
||||
docker push ghcr.io/oscarzhou-portainer/agent:develop-78af729docker
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *PushImageSubTask) String() string {
|
||||
return "Push Docker Image"
|
||||
}
|
@ -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`)
|
||||
}
|
31
go/repositories/portainer-ee/build_docker_image.go
Normal file
31
go/repositories/portainer-ee/build_docker_image.go
Normal file
@ -0,0 +1,31 @@
|
||||
package portaineree
|
||||
|
||||
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(`
|
||||
yarn build
|
||||
docker build -t "portainerci/portainer-ee:4803" -f build/linux/Dockerfile .
|
||||
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v "/var/run/docker.sock:/var/run/docker.sock" -v ${env:HOME}/volume/portainer-ee-data-2:/data --add-host=host.docker.internal:host-gateway portainerci/portainer:ee-4803
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *BuildDockerImageSubTask) String() string {
|
||||
return "Build Docker Image"
|
||||
}
|
32
go/repositories/portainer-ee/menu.go
Normal file
32
go/repositories/portainer-ee/menu.go
Normal file
@ -0,0 +1,32 @@
|
||||
package portaineree
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
type MenuSubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewMenuSubTask(cfg *configs.Config) *MenuSubTask {
|
||||
return &MenuSubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *MenuSubTask) Execute() error {
|
||||
subTaskItems := []common.Tasker{
|
||||
NewBuildDockerImageSubTask(task.Config),
|
||||
NewSwarmDeploySubTask(task.Config),
|
||||
NewStandaloneDeploySubTask(task.Config),
|
||||
}
|
||||
|
||||
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *MenuSubTask) String() string {
|
||||
return "portainer-ee"
|
||||
}
|
32
go/repositories/portainer-ee/standalone_deploy.go
Normal file
32
go/repositories/portainer-ee/standalone_deploy.go
Normal file
@ -0,0 +1,32 @@
|
||||
package portaineree
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type StandaloneDeploySubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewStandaloneDeploySubTask(cfg *configs.Config) *StandaloneDeploySubTask {
|
||||
return &StandaloneDeploySubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *StandaloneDeploySubTask) Execute() error {
|
||||
utils.SuccessPrint(`
|
||||
yarn build
|
||||
docker build -t "portainerci/portainer-ee:oscar-test" -f build/linux/linux.Dockerfile .
|
||||
docker image tag portainerci/portainer-ee:oscar-test portainerci/portainer-ee:latest
|
||||
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v "/var/run/docker.sock:/var/run/docker.sock" -v /home/oscar/volume/portainer-ee-data-1:/data --add-host=host.docker.internal:host-gateway portainerci/portainer-ee:oscar-test
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *StandaloneDeploySubTask) String() string {
|
||||
return "Deploy Portainer in Docker Standalone"
|
||||
}
|
67
go/repositories/portainer-ee/swarm_deploy.go
Normal file
67
go/repositories/portainer-ee/swarm_deploy.go
Normal file
@ -0,0 +1,67 @@
|
||||
package portaineree
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type SwarmDeploySubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewSwarmDeploySubTask(cfg *configs.Config) *SwarmDeploySubTask {
|
||||
return &SwarmDeploySubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *SwarmDeploySubTask) Execute() error {
|
||||
utils.SuccessPrint(`
|
||||
version: '3.2'
|
||||
|
||||
services:
|
||||
agent:
|
||||
image: portainer/agent:latest
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /var/lib/docker/volumes:/var/lib/docker/volumes
|
||||
networks:
|
||||
- agent_network
|
||||
deploy:
|
||||
mode: global
|
||||
placement:
|
||||
constraints: [node.platform.os == linux]
|
||||
|
||||
portainer:
|
||||
image: portainerci/portainer-ee:4803
|
||||
command: -H tcp://tasks.agent:9001 --tlsskipverify --log-level ERROR
|
||||
ports:
|
||||
- "9443:9443"
|
||||
- "9000:9000"
|
||||
- "8000:8000"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- /home/oscar/volume/portainer-ee-data-1:/data
|
||||
networks:
|
||||
- agent_network
|
||||
deploy:
|
||||
mode: replicated
|
||||
replicas: 1
|
||||
placement:
|
||||
constraints: [node.role == manager]
|
||||
|
||||
networks:
|
||||
agent_network:
|
||||
driver: overlay
|
||||
attachable: true
|
||||
--------------------------
|
||||
docker stack deploy -c docker-compose.yaml portainer
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *SwarmDeploySubTask) String() string {
|
||||
return "Deploy Portainer in Swarm"
|
||||
}
|
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"
|
||||
}
|
30
go/repositories/unpacker/menu.go
Normal file
30
go/repositories/unpacker/menu.go
Normal file
@ -0,0 +1,30 @@
|
||||
package unpacker
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
type MenuSubTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewMenuSubTask(cfg *configs.Config) *MenuSubTask {
|
||||
return &MenuSubTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *MenuSubTask) Execute() error {
|
||||
subTaskItems := []common.Tasker{
|
||||
NewBuildDockerImageSubTask(task.Config),
|
||||
}
|
||||
|
||||
common.ListCommandMenu(subTaskItems, "Which management commands do you want to choose:", false, task.ParentTasks)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *MenuSubTask) String() string {
|
||||
return "unpacker"
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type CodeSecurityScanTask struct {
|
||||
ParentTasks []common.Tasker
|
||||
}
|
||||
|
||||
func NewCodeSecurityScanTask() *CodeSecurityScanTask {
|
||||
@ -30,6 +32,10 @@ func (task *CodeSecurityScanTask) Execute() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *CodeSecurityScanTask) SetParentTaskers(tasks []common.Tasker) {
|
||||
task.ParentTasks = tasks
|
||||
}
|
||||
|
||||
func (task *CodeSecurityScanTask) String() string {
|
||||
return "Code Security Scan"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package tasks
|
||||
package common
|
||||
|
||||
import "errors"
|
||||
|
||||
@ -13,6 +13,9 @@ func (task *ExitTask) Execute() error {
|
||||
return errors.New("exit")
|
||||
}
|
||||
|
||||
func (task *ExitTask) SetParentTaskers(tasks []Tasker) {
|
||||
}
|
||||
|
||||
func (task *ExitTask) String() string {
|
||||
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 (
|
||||
"fmt"
|
||||
@ -10,11 +10,17 @@ import (
|
||||
type Tasker interface {
|
||||
Execute() error
|
||||
String() string
|
||||
SetParentTaskers(tasks []Tasker)
|
||||
}
|
||||
|
||||
// ListCommandMenu iterates task items to display them // on the screen as the menu options
|
||||
func ListCommandMenu(taskItems []Tasker, menuDesp string) error {
|
||||
taskItems = append(taskItems, NewExitTask())
|
||||
func ListCommandMenu(taskItems []Tasker, menuDesp string, rootMenu bool, parentTaskItems []Tasker) error {
|
||||
if rootMenu {
|
||||
taskItems = append(taskItems, NewExitTask())
|
||||
} else {
|
||||
taskItems = append(taskItems, NewReturnTask(parentTaskItems))
|
||||
}
|
||||
|
||||
for {
|
||||
printMainMenu := func() {
|
||||
taskNames := []string{}
|
||||
@ -33,7 +39,6 @@ func ListCommandMenu(taskItems []Tasker, menuDesp string) error {
|
||||
}
|
||||
|
||||
option := utils.SelectMenuItem(printMainMenu)
|
||||
|
||||
index, err := strconv.Atoi(option)
|
||||
if err != nil {
|
||||
utils.ErrorPrint("please type the option number\n")
|
@ -2,10 +2,12 @@ package tasks
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type CurlLookupTask struct {
|
||||
ParentTasks []common.Tasker
|
||||
}
|
||||
|
||||
func NewCurlLookupTask() *CurlLookupTask {
|
||||
@ -43,6 +45,10 @@ func (task *CurlLookupTask) Execute() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *CurlLookupTask) SetParentTaskers(tasks []common.Tasker) {
|
||||
task.ParentTasks = tasks
|
||||
}
|
||||
|
||||
func (task *CurlLookupTask) String() string {
|
||||
return "Lookup Curl Commands"
|
||||
}
|
||||
|
56
go/tasks/install_docker.go
Normal file
56
go/tasks/install_docker.go
Normal file
@ -0,0 +1,56 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type InstallDockerTask struct {
|
||||
ParentTasks []common.Tasker
|
||||
}
|
||||
|
||||
func NewInstallDockerTask() *InstallDockerTask {
|
||||
return &InstallDockerTask{}
|
||||
}
|
||||
|
||||
func (task *InstallDockerTask) Execute() error {
|
||||
|
||||
utils.SuccessPrint(`
|
||||
sudo apt-get update
|
||||
sudo apt-get install \
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg \
|
||||
lsb-release
|
||||
sudo mkdir -p /etc/apt/keyrings
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
||||
echo \
|
||||
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
|
||||
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
|
||||
sudo apt-get update
|
||||
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
|
||||
|
||||
-------------------
|
||||
sudo apt install docker.io
|
||||
|
||||
-------------------
|
||||
sudo groupadd docker
|
||||
sudo usermod -aG docker $USER
|
||||
|
||||
multipass list
|
||||
multipass shell <instance name>
|
||||
sudo passwd ubuntu
|
||||
|
||||
newgrp docker
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *InstallDockerTask) SetParentTaskers(tasks []common.Tasker) {
|
||||
task.ParentTasks = tasks
|
||||
}
|
||||
|
||||
func (task *InstallDockerTask) String() string {
|
||||
return "Install Docker Binary"
|
||||
}
|
@ -7,10 +7,11 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
type GenerateJwtTokenTask struct {
|
||||
Config *configs.Config
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
type GenerateJwtTokenResponse struct {
|
||||
@ -19,7 +20,7 @@ type GenerateJwtTokenResponse struct {
|
||||
|
||||
func NewGenerateJwtTokenTask(cfg *configs.Config) *GenerateJwtTokenTask {
|
||||
return &GenerateJwtTokenTask{
|
||||
Config: cfg,
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,26 +2,32 @@ package tasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/tasks/subtasks"
|
||||
)
|
||||
|
||||
type ListDevToolCommandTask struct {
|
||||
Config *configs.Config
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewListDevToolCommandTask(cfg *configs.Config) *ListDevToolCommandTask {
|
||||
return &ListDevToolCommandTask{
|
||||
Config: cfg,
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *ListDevToolCommandTask) Execute() error {
|
||||
subTaskItems := []Tasker{
|
||||
subTaskItems := []common.Tasker{
|
||||
subtasks.NewListVolumeSubTask(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
|
||||
}
|
||||
|
35
go/tasks/list_ops_menus.go
Normal file
35
go/tasks/list_ops_menus.go
Normal file
@ -0,0 +1,35 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/operations/edgestack"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
type ListOperationMenuTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewListOperationMenuTask(cfg *configs.Config) *ListOperationMenuTask {
|
||||
return &ListOperationMenuTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *ListOperationMenuTask) Execute() error {
|
||||
subTaskItems := []common.Tasker{
|
||||
edgestack.NewOperationMenuSubTask(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 *ListOperationMenuTask) String() string {
|
||||
return "Choose Operations"
|
||||
}
|
39
go/tasks/list_repo_menus.go
Normal file
39
go/tasks/list_repo_menus.go
Normal file
@ -0,0 +1,39 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/repositories/agent"
|
||||
portaineree "ocl/portainer-devtool/repositories/portainer-ee"
|
||||
"ocl/portainer-devtool/repositories/unpacker"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
)
|
||||
|
||||
type ListRepositoryMenuTask struct {
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewListRepositoryMenuTask(cfg *configs.Config) *ListRepositoryMenuTask {
|
||||
return &ListRepositoryMenuTask{
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
func (task *ListRepositoryMenuTask) Execute() error {
|
||||
subTaskItems := []common.Tasker{
|
||||
portaineree.NewMenuSubTask(task.Config),
|
||||
agent.NewMenuSubTask(task.Config),
|
||||
unpacker.NewMenuSubTask(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 *ListRepositoryMenuTask) String() string {
|
||||
return "Choose Repositories"
|
||||
}
|
@ -2,17 +2,18 @@ package subtasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ListRepositorySubTask struct {
|
||||
Config *configs.Config
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewListRepositorySubTask(cfg *configs.Config) *ListRepositorySubTask {
|
||||
return &ListRepositorySubTask{
|
||||
Config: cfg,
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,18 +4,19 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"ocl/portainer-devtool/configs"
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ListVolumeSubTask struct {
|
||||
Config *configs.Config
|
||||
common.GeneralTask
|
||||
}
|
||||
|
||||
func NewListVolumeSubTask(cfg *configs.Config) *ListVolumeSubTask {
|
||||
return &ListVolumeSubTask{
|
||||
Config: cfg,
|
||||
GeneralTask: *common.NewGeneralTask(cfg),
|
||||
}
|
||||
}
|
||||
|
||||
|
30
go/tasks/test-env.go
Normal file
30
go/tasks/test-env.go
Normal file
@ -0,0 +1,30 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"ocl/portainer-devtool/tasks/common"
|
||||
"ocl/portainer-devtool/utils"
|
||||
)
|
||||
|
||||
type TestEnvironmentTask struct {
|
||||
ParentTasks []common.Tasker
|
||||
}
|
||||
|
||||
func NewTestEnvironmentTask() *TestEnvironmentTask {
|
||||
return &TestEnvironmentTask{}
|
||||
}
|
||||
|
||||
func (task *TestEnvironmentTask) Execute() error {
|
||||
utils.SuccessPrint(`
|
||||
https://github.com/portainer/platform/actions
|
||||
`)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (task *TestEnvironmentTask) SetParentTaskers(tasks []common.Tasker) {
|
||||
task.ParentTasks = tasks
|
||||
}
|
||||
|
||||
func (task *TestEnvironmentTask) String() string {
|
||||
return "Create Testing Environment(VPN)"
|
||||
}
|
Loading…
Reference in New Issue
Block a user