@@ -32,6 +32,8 @@ import (
3232 "github.com/spf13/cobra"
3333)
3434
35+ const modeDockerInSystemService = "docker-in-system"
36+
3537func createServiceCommand (execer fakeruntime.Execer ) (c * cobra.Command ) {
3638 opt := & serviceOption {
3739 Execer : execer ,
@@ -58,18 +60,19 @@ DaoCloud: docker.m.daocloud.io/linuxsuren/api-testing`,
5860 flags := c .Flags ()
5961 flags .StringVarP (& opt .scriptPath , "script-path" , "" , "" , "The service script file path" )
6062 flags .StringVarP (& opt .mode , "mode" , "m" , "" ,
61- fmt .Sprintf ("Availeble values: %v" , service .ServiceModeOS .All ()))
63+ fmt .Sprintf ("Availeble values: %v" , append ( service .ServiceModeOS .All (), modeDockerInSystemService )))
6264 flags .StringVarP (& opt .image , "image" , "" , defaultImage , "The image of the service which as a container" )
6365 flags .StringVarP (& opt .pull , "pull" , "" , "always" , `Pull image before creating ("always"|"missing"|"never")` )
6466 flags .StringVarP (& opt .version , "version" , "" , version .GetVersion (), "The version of the service image" )
6567 flags .StringVarP (& opt .LocalStorage , "local-storage" , "" , "/var/data/atest" ,
6668 "The local storage path which will be mounted into the container" )
69+ flags .IntVarP (& opt .port , "port" , "" , 8080 , "The port of the service" )
6770 flags .StringVarP (& opt .SecretServer , "secret-server" , "" , "" , "The secret server URL" )
6871 flags .StringVarP (& opt .SkyWalking , "skywalking" , "" , "" , "Push the browser tracing data to the Apache SkyWalking URL" )
6972 return
7073}
7174
72- const defaultImage = "linuxsuren.docker.scarf.sh /linuxsuren/api-testing"
75+ const defaultImage = "ghcr.io /linuxsuren/api-testing"
7376
7477type serviceOption struct {
7578 action string
@@ -80,6 +83,7 @@ type serviceOption struct {
8083 fakeruntime.Execer
8184 mode string
8285 pull string
86+ port int
8387
8488 SecretServer string
8589 SkyWalking string
@@ -91,18 +95,41 @@ func (o *serviceOption) preRunE(c *cobra.Command, args []string) (err error) {
9195 o .stdOut = c .OutOrStdout ()
9296 o .action = args [0 ]
9397
98+ serviceCommand := "atest"
99+ serviceArgs := []string {"server" , "--extension-registry=ghcr.io" }
100+ if o .mode == modeDockerInSystemService {
101+ if o .Execer .OS () == "windows" {
102+ serviceCommand = "run"
103+ serviceArgs = []string {"atest" , "server" , "--extension-registry=ghcr.io" }
104+ o .mode = "docker"
105+ } else {
106+ serviceCommand = "docker"
107+ serviceArgs = []string {"run" , "-v=atest:/root/.config/atest" , "-v=atest-ssh:/root/.ssh" ,
108+ fmt .Sprintf ("-p=%d:8080" , o .port ), "--pull" , o .pull , fmt .Sprintf ("%s:%s" , o .image , o .version ),
109+ "atest" , "server" , "--extension-registry=ghcr.io" }
110+ o .mode = string (service .ServiceModeOS )
111+ }
112+ }
113+ if strings .Contains (o .version , "unknown" ) {
114+ o .version = ""
115+ }
116+
94117 if o .service , err = service .GetAvailableService (service .ServiceMode (o .mode ),
95118 service.ContainerOption {
96- Image : o .action ,
97- Pull : o .pull ,
98- Tag : o .version ,
99- Writer : c .OutOrStdout (),
119+ Image : o .image ,
120+ Pull : o .pull ,
121+ Tag : o .version ,
122+ Writer : c .OutOrStdout (),
123+ Volumes : map [string ]string {"atest" : "/root/.config/atest" },
124+ Ports : map [int ]int {o .port : 8080 },
125+ Restart : "always" ,
126+ Name : "atest" ,
100127 }, service.CommonService {
101128 ID : "atest" ,
102129 Name : "atest" ,
103130 Description : "API Testing Server" ,
104- Command : "atest" ,
105- Args : [] string { "server" } ,
131+ Command : serviceCommand ,
132+ Args : serviceArgs ,
106133 Execer : o .Execer ,
107134 }); err != nil {
108135 return
0 commit comments