Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions v1/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ var (
podFlag string
podNamespace string // pre parsed pod namespace
podName string // pre parsed pod name

mvnCmd string //custom maven command
)

const (
Expand All @@ -71,16 +73,19 @@ We advice you to use this in local dev phase.
Scenario 0: Build bundle at current workspace and deploy it to a local running ark container with default port:
arkctl deploy

Scenario 1: Build bundle at given path and deploy it to local running ark container with given port:
Scenario 1: Build the bundle using a custom Maven command to compile the project in the current workspace and deploy it to a locally running Ark container on the default port.:
arkctl deploy --mvnCmd ${mvnCmd}

Scenario 2: Build bundle at given path and deploy it to local running ark container with given port:
arkctl deploy --port ${your ark container portFlag} ${path/to/your/project}

Scenario 2: Deploy a local pre-built bundle to local running ark container:
Scenario 3: Deploy a local pre-built bundle to local running ark container:
arkctl deploy ${path/to/your/pre/built/bundle.jar}

Scenario 3: Build and deploy a bundle at current dir to a remote running ark container in k8s cluster with default port:
Scenario 4: Build and deploy a bundle at current dir to a remote running ark container in k8s cluster with default port:
arkctl deploy --pod ${namespace}/${name}

Scenario 4: Build an maven multi module project and deploy a sub module to a running ark container:
Scenario 5: Build an maven multi module project and deploy a sub module to a running ark container:
arkctl deploy --sub ${path/to/your/sub/module}
`,
Args: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -113,11 +118,13 @@ func execMavenBuild(ctx *contextutil.Context) bool {
style.InfoPrefix("Stage").Println("BuildBundle")
style.InfoPrefix("BuildDirectory").Println(defaultArg)

compileCmd, compileArg := parseMavenCommand(mvnCmd)

mvn := cmdutil.BuildCommandWithWorkDir(
ctx,
defaultArg,
"mvn",
"clean", "package", "-Dmaven.test.skip=true")
compileCmd,
compileArg...)
style.InfoPrefix("Command").Println(mvn.String())

if err := mvn.Exec(); err != nil {
Expand Down Expand Up @@ -151,6 +158,19 @@ func execMavenBuild(ctx *contextutil.Context) bool {
return true
}

func parseMavenCommand(mvnCmd string) (string, []string) {
compileCmd := "mvn"
compileArg := []string{"clean", "package", "-Dmaven.test.skip=true"}
if mvnCmd != "" {
args := strings.Fields(mvnCmd)
if len(args) > 0 {
compileCmd = args[0]
compileArg = args[1:]
}
}
return compileCmd, compileArg
}

func execParseBizModel(ctx *contextutil.Context) bool {
style.InfoPrefix("Stage").Println("ParseBizModel")
bundlePath := osutil.GetLocalFileProtocol() + defaultArg
Expand Down Expand Up @@ -450,6 +470,11 @@ func init() {
DeployCommand.Flags().StringVar(&podFlag, "pod", "", `
If Provided, arkctl will try to deploy the bundle to the ark container running in given pod.
`)

DeployCommand.Flags().StringVar(&mvnCmd, "mvnCmd", "", `
If Provided, arkctl will try to deploy the mvnCmd to compile maven project.
`)

DeployCommand.Flags().StringVar(&subBundlePath, "sub", "", `
If Provided, arkctl will try to build the project at current dir and deploy the bundle at subBundlePath.
`)
Expand Down
71 changes: 71 additions & 0 deletions v1/cmd/deploy/deploy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package deploy

import (
"reflect"
"testing"
)

func TestParseMavenCommand(t *testing.T) {
tests := []struct {
name string
mvnCmd string
wantCmd string
wantArgs []string
}{
{
name: "empty command",
mvnCmd: "",
wantCmd: "mvn",
wantArgs: []string{"clean", "package", "-Dmaven.test.skip=true"},
},
{
name: "custom command without args",
mvnCmd: "mvnw",
wantCmd: "mvnw",
wantArgs: []string{},
},
{
name: "custom command with args",
mvnCmd: "mvn clean install",
wantCmd: "mvn",
wantArgs: []string{"clean", "install"},
},
{
name: "complex command with args",
mvnCmd: "mvnw clean package -DskipTests",
wantCmd: "mvnw",
wantArgs: []string{"clean", "package", "-DskipTests"},
},
{
name: "command with multiple spaces",
mvnCmd: "mvn clean package",
wantCmd: "mvn",
wantArgs: []string{"clean", "package"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotCmd, gotArgs := parseMavenCommand(tt.mvnCmd)
if gotCmd != tt.wantCmd {
t.Errorf("parseMavenCommand() gotCmd = %v, want %v", gotCmd, tt.wantCmd)
}
if !reflect.DeepEqual(gotArgs, tt.wantArgs) {
t.Errorf("parseMavenCommand() gotArgs = %v, want %v", gotArgs, tt.wantArgs)
}
})
}
}