55 "encoding/json"
66 "fmt"
77 "groundseg/config"
8+ "groundseg/dockerclient"
89 "groundseg/structs"
910 "io"
1011 "io/ioutil"
@@ -42,7 +43,7 @@ func init() {
4243 if err = killContainerUsingPort (80 ); err != nil {
4344 zap .L ().Error (fmt .Sprintf ("Couldn't stop container on port 80: %v" , err ))
4445 }
45- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
46+ cli , err := dockerclient . New ( )
4647 if err != nil {
4748 zap .L ().Error (fmt .Sprintf ("Error creating Docker client: %v" , err ))
4849 return
@@ -63,7 +64,7 @@ func init() {
6364func killContainerUsingPort (n uint16 ) error {
6465 // Initialize Docker client
6566 ctx := context .Background ()
66- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
67+ cli , err := dockerclient . New ( )
6768 if err != nil {
6869 return err
6970 }
@@ -156,7 +157,7 @@ func updateDocker() {
156157// return the container status of a slice of ships
157158func GetShipStatus (patps []string ) (map [string ]string , error ) {
158159 statuses := make (map [string ]string )
159- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
160+ cli , err := dockerclient . New ( )
160161 if err != nil {
161162 errmsg := fmt .Sprintf ("Error getting Docker info: %v" , err )
162163 zap .L ().Error (errmsg )
@@ -195,7 +196,7 @@ func GetShipStatus(patps []string) (map[string]string, error) {
195196
196197func GetContainerRunningStatus (containerName string ) (string , error ) {
197198 var status string
198- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
199+ cli , err := dockerclient . New ( )
199200 if err != nil {
200201 }
201202 defer cli .Close ()
@@ -217,7 +218,7 @@ func GetContainerRunningStatus(containerName string) (string, error) {
217218
218219// return the name of a container's network
219220func GetContainerNetwork (name string ) (string , error ) {
220- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
221+ cli , err := dockerclient . New ( )
221222 if err != nil {
222223 return "" , err
223224 }
@@ -234,7 +235,7 @@ func GetContainerNetwork(name string) (string, error) {
234235
235236// creates a volume by name
236237func CreateVolume (name string ) error {
237- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
238+ cli , err := dockerclient . New ( )
238239 if err != nil {
239240 errmsg := fmt .Errorf ("Failed to create docker client: %v : %v" , name , err )
240241 return errmsg
@@ -254,7 +255,7 @@ func CreateVolume(name string) error {
254255
255256// deletes a volume by its name
256257func DeleteVolume (name string ) error {
257- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
258+ cli , err := dockerclient . New ( )
258259 if err != nil {
259260 errmsg := fmt .Errorf ("Failed to create docker client: %v : %v" , name , err )
260261 return errmsg
@@ -272,7 +273,7 @@ func DeleteVolume(name string) error {
272273
273274// deletes a container by its name
274275func DeleteContainer (name string ) error {
275- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
276+ cli , err := dockerclient . New ( )
276277 if err != nil {
277278 errmsg := fmt .Errorf ("Failed to create docker client: %v : %v" , name , err )
278279 return errmsg
@@ -291,7 +292,7 @@ func DeleteContainer(name string) error {
291292
292293// Write a file to a specific location in a volume
293294func WriteFileToVolume (name string , file string , content string ) error {
294- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
295+ cli , err := dockerclient . New ( )
295296 if err != nil {
296297 errmsg := fmt .Errorf ("Failed to create docker client: %v : %v" , name , err )
297298 return errmsg
@@ -381,7 +382,7 @@ func StartContainer(containerName string, containerType string) (structs.Contain
381382 existingContainer , _ := FindContainer (containerName )
382383
383384 ctx := context .Background ()
384- cli , err := client . NewClientWithOpts ( client . FromEnv )
385+ cli , err := dockerclient . New ( )
385386 if err != nil {
386387 return containerState , err
387388 }
@@ -525,7 +526,7 @@ func CreateContainer(containerName string, containerType string) (structs.Contai
525526 return containerState , err
526527 }
527528 ctx := context .Background ()
528- cli , err := client . NewClientWithOpts ( client . FromEnv )
529+ cli , err := dockerclient . New ( )
529530 if err != nil {
530531 return containerState , err
531532 }
@@ -604,7 +605,7 @@ func GetLatestContainerInfo(containerType string) (map[string]string, error) {
604605// stop a container with the name
605606func StopContainerByName (containerName string ) error {
606607 ctx := context .Background ()
607- cli , err := client . NewClientWithOpts ( client . FromEnv )
608+ cli , err := dockerclient . New ( )
608609 if err != nil {
609610 return err
610611 }
@@ -633,7 +634,7 @@ func StopContainerByName(containerName string) error {
633634// pull the image if it doesn't exist locally
634635func PullImageIfNotExist (desiredImage string , imageInfo map [string ]string ) (bool , error ) {
635636 ctx := context .Background ()
636- cli , err := client . NewClientWithOpts ( client . FromEnv )
637+ cli , err := dockerclient . New ( )
637638 if err != nil {
638639 return false , err
639640 }
@@ -660,7 +661,7 @@ func PullImageIfNotExist(desiredImage string, imageInfo map[string]string) (bool
660661
661662// looks for a container with the given name and returns it, or nil if not found
662663func FindContainer (containerName string ) (* types.Container , error ) {
663- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
664+ cli , err := dockerclient . New ( )
664665 if err != nil {
665666 return nil , err
666667 }
@@ -698,7 +699,7 @@ func DockerPoller() {
698699
699700// execute command
700701func ExecDockerCommand (containerName string , cmd []string ) (string , error ) {
701- cli , err := client . NewClientWithOpts ( client . FromEnv )
702+ cli , err := dockerclient . New ( )
702703 if err != nil {
703704 return "" , err
704705 }
@@ -758,7 +759,7 @@ func GetContainerIDByName(ctx context.Context, cli *client.Client, name string)
758759// restart a running container
759760func RestartContainer (name string ) error {
760761 ctx := context .Background ()
761- cli , err := client . NewClientWithOpts ( client . FromEnv )
762+ cli , err := dockerclient . New ( )
762763 if err != nil {
763764 return fmt .Errorf ("Couldn't create client: %v" , err )
764765 }
@@ -787,7 +788,7 @@ func contains(slice []string, str string) bool {
787788}
788789
789790func volumeExists (volumeName string ) (bool , error ) {
790- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
791+ cli , err := dockerclient . New ( )
791792 if err != nil {
792793 return false , fmt .Errorf ("Failed to create client: %v" , err )
793794 }
@@ -805,7 +806,7 @@ func volumeExists(volumeName string) (bool, error) {
805806}
806807
807808func addOrGetNetwork (networkName string ) (string , error ) {
808- cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation () )
809+ cli , err := dockerclient . New ( )
809810 if err != nil {
810811 return "" , fmt .Errorf ("Failed to create client: %v" , err )
811812 }
0 commit comments