Skip to content

Commit

Permalink
Add port to code server start.
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikXu committed Jan 27, 2023
1 parent 4858412 commit 0c8a406
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions cmd/code_server/code_server_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ package code_server
import (
"fmt"
"power-ci/utils"
"strings"

"github.com/spf13/cobra"
)

var startScript = `#!/bin/bash
func init() {
codeServerStartCmd.Flags().StringVarP(&PORT, "port", "p", "80", "Bind port")
}

var PORT string

var template = `#!/bin/bash
PASSWORD=$(uuidgen)
mkdir -p ~/.config/code-server
cat>~/.config/code-server/config.yaml<<EOF
bind-addr: 0.0.0.0:80
bind-addr: 0.0.0.0:{PORT}
auth: password
password: ${PASSWORD}
cert: false
Expand All @@ -25,7 +32,8 @@ var codeServerStartCmd = &cobra.Command{
Use: "start",
Short: "Start code server",
Run: func(cmd *cobra.Command, args []string) {
filepath := utils.WriteScript("start-code-server.sh", startScript)
script := strings.Replace(template, "{PORT}", PORT, -1)
filepath := utils.WriteScript("start-code-server.sh", script)
utils.ExecuteScript(filepath)
fmt.Println("Start success")
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Get version of power-ci",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("0.1.2")
fmt.Println("0.1.3")
},
}

0 comments on commit 0c8a406

Please sign in to comment.