Skip to content

Commit

Permalink
feat : host argument add pull command
Browse files Browse the repository at this point in the history
  • Loading branch information
seipan committed May 10, 2024
1 parent 5b8d157 commit f150d4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
7 changes: 6 additions & 1 deletion cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ var pullCmd = &cobra.Command{
if err != nil {
return err
}
host, err := cmd.Flags().GetString("host")
if err != nil {
return err
}

port, err := api.ReceiveTarGzFromServer(id)
port, err := api.ReceiveTarGzFromServer(host, id)
if err != nil {
return err
}
Expand All @@ -48,6 +52,7 @@ var pullCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(pullCmd)
pullCmd.Flags().StringP("id", "i", "", "ketos docker image id")
pushCmd.Flags().StringP("host", "h", "", "URL of the server to use")

// Here you will define your flags and configuration settings.

Expand Down
2 changes: 1 addition & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func init() {
pushCmd.Flags().StringP("directory", "d", "", "Directory path to create docker image")
pushCmd.Flags().StringP("language", "l", "", "Language type to create docker image")
pushCmd.Flags().StringP("filename", "f", "", "Dockerfile name to create docker image")
pushCmd.Flags().StringP("host", "f", "", "URL of the server to use")
pushCmd.Flags().StringP("host", "h", "", "URL of the server to use")
pushCmd.Flags().BoolP("dockerfile", "D", false, "Dockerfile or buildpacks")
pushCmd.Flags().StringSliceP("publish", "p", []string{}, "Publish a container's port(s) to the host")
pushCmd.Flags().StringSliceP("env", "e", []string{}, "Set environment variable(s)")
Expand Down
17 changes: 10 additions & 7 deletions internal/api/receive_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
)

type Response struct {
Port string `json:"port"`
ID string `json:"id"`
Port string `json:"port"`
ID string `json:"id"`
}

func GetServerInfo(id string) (string,error) {
func GetServerInfo(id string) (string, error) {
fullURL := fmt.Sprintf("%s/info/%s", BackendURL, id)
response, err := http.Get(fullURL)
if err != nil {
Expand All @@ -33,19 +33,22 @@ func GetServerInfo(id string) (string,error) {
if err != nil {
return "", err
}
fmt.Printf("%s/info/%s\n", FrontURL, id)
fmt.Printf("%s/info/%s\n", FrontURL, id)
return resp.Port, nil
}

func ReceiveTarGzFromServer(id string) (string, error) {
fullURL := fmt.Sprintf("%s/%s", BackendURL, id)
func ReceiveTarGzFromServer(host string, id string) (string, error) {
if host == "" {
host = BackendURL
}
fullURL := fmt.Sprintf("%s/%s", host, id)
response, err := http.Get(fullURL)
if err != nil {
return "", err
}
defer response.Body.Close()

infoURL := fmt.Sprintf("%s/info/%s", BackendURL, id)
infoURL := fmt.Sprintf("%s/info/%s", host, id)
infoResponse, err := http.Get(infoURL)
if err != nil {
return "", err
Expand Down

0 comments on commit f150d4d

Please sign in to comment.