Skip to content

Commit

Permalink
Add force flag for dockyard and warship
Browse files Browse the repository at this point in the history
Signed-off-by: Quanyi Ma <maquanyi@huawei.com>
  • Loading branch information
Quanyi Ma committed Oct 8, 2017
1 parent 2512b8a commit f542e66
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion dockyard/client/binary/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
)

//UploadBinaryFile upload binary file to the Dockyard service.
func UploadBinaryFile(filePath, domain, namespace, repository, tag string) error {
func UploadBinaryFile(filePath, domain, namespace, repository, tag string, force bool) error {
if f, err := os.Open(filePath); err != nil {
return err
} else {
Expand All @@ -37,6 +38,7 @@ func UploadBinaryFile(filePath, domain, namespace, repository, tag string) error
return err
} else {
req.Header.Set("Content-Type", "text/plain")
req.Header.Set("Binary-Force", strconv.FormatBool(force))

client := &http.Client{}
if resp, err := client.Do(req); err != nil {
Expand Down
12 changes: 9 additions & 3 deletions dockyard/client/cmd/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/Huawei/containerops/common"
"github.com/Huawei/containerops/dockyard/client/binary"
)

var force bool

var binaryCmd = &cobra.Command{
Use: "binary",
Short: "Upload or download binary file from repository build by Dockyard service",
Expand Down Expand Up @@ -77,6 +80,9 @@ func init() {
binaryCmd.AddCommand(uplaodCmd)
binaryCmd.AddCommand(downloadCmd)

uplaodCmd.Flags().BoolVarP(&force, "force", "f", false, "use the current version of file replace the file in the server")
viper.BindPFlag("force", uplaodCmd.Flags().Lookup("force"))

}

//uploadBinary upload binary to Dockyard service.
Expand All @@ -95,12 +101,12 @@ func uploadBinary(cmd *cobra.Command, args []string) {
repository := strings.Split(args[1], "/")[1]
tag := strings.Split(args[1], "/")[2]

if err := binary.UploadBinaryFile(args[0], domain, namespace, repository, tag); err != nil {
fmt.Println("Upload file error: ", err.Error())
if err := binary.UploadBinaryFile(args[0], domain, namespace, repository, tag, force); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

fmt.Println("Upload file sucessfully.")
fmt.Println("Upload file [", args[0], "] sucessfully.")
os.Exit(0)
}

Expand Down
2 changes: 2 additions & 0 deletions dockyard/handler/binaryv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func PostBinaryV1Handler(ctx *macaron.Context) (int, []byte) {
return http.StatusBadRequest, result
}
}
} else {

}

result, _ := json.Marshal(map[string]string{})
Expand Down
4 changes: 2 additions & 2 deletions singular/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func init() {
viper.BindPFlag("public-key", templateCmd.Flags().Lookup("public-key"))
viper.BindPFlag("output", templateCmd.Flags().Lookup("output"))
viper.BindPFlag("db", templateCmd.Flags().Lookup("db"))
viper.BindPFlag("delete", templateCmd.Flags().Lookup("del"))
viper.BindPFlag("delete", templateCmd.Flags().Lookup("delete"))

folderCmd.Flags().StringVarP(&privateKey, "private-key", "i", "", "ssh identity file")
folderCmd.Flags().StringVarP(&publicKey, "public-key", "p", "", "ssh public identity file")
Expand All @@ -84,7 +84,7 @@ func init() {
viper.BindPFlag("public-key", folderCmd.Flags().Lookup("public-key"))
viper.BindPFlag("output", folderCmd.Flags().Lookup("output"))
viper.BindPFlag("db", folderCmd.Flags().Lookup("db"))
viper.BindPFlag("delete", folderCmd.Flags().Lookup("del"))
viper.BindPFlag("delete", folderCmd.Flags().Lookup("delete"))
}

//Deploy the Cloud Native stack with a template file.
Expand Down

0 comments on commit f542e66

Please sign in to comment.