@@ -2,6 +2,7 @@ package dockercompose
22
33import (
44 "fmt"
5+ "net/url"
56 "os"
67 "path/filepath"
78 "regexp"
@@ -10,7 +11,6 @@ import (
1011
1112 "github.com/nhost/be/services/mimir/model"
1213 "github.com/nhost/cli/ssl"
13- "net/url"
1414)
1515
1616const (
@@ -205,21 +205,32 @@ func trafikFiles(dotnhostfolder string) error {
205205 return nil
206206}
207207
208+ func getDockerHost () (string , error ) {
209+ socket , ok := os .LookupEnv ("DOCKER_HOST" )
210+ if ! ok {
211+ return "/var/run/docker.sock" , nil
212+ }
213+
214+ u , err := url .Parse (socket )
215+ if err != nil {
216+ return "" , fmt .Errorf ("failed to parse DOCKER_HOST: %w" , err )
217+ }
218+ if u .Scheme != "unix" {
219+ return "" , fmt .Errorf ( //nolint:err113
220+ "unsupported scheme %s in DOCKER_HOST, only unix supported" ,
221+ u .Scheme ,
222+ )
223+ }
224+ return u .Path , nil
225+ }
226+
208227func traefik (subdomain , projectName string , port uint , dotnhostfolder string ) (* Service , error ) {
209228 if err := trafikFiles (dotnhostfolder ); err != nil {
210229 return nil , fmt .Errorf ("failed to create traefik files: %w" , err )
211230 }
212- path := "/var/run/docker.sock"
213- socket , ok := os .LookupEnv ("DOCKER_HOST" )
214- if ok {
215- u , err := url .Parse (socket )
216- if err != nil {
217- return nil , fmt .Errorf ("failed to parse DOCKER_HOST: %w" , err )
218- }
219- if u .Scheme != "unix" {
220- return nil , fmt .Errorf ("unsupported scheme %s in DOCKER_HOST, only unix supported" , u .Scheme )
221- }
222- path = u .Path
231+ path , err := getDockerHost ()
232+ if err != nil {
233+ return nil , fmt .Errorf ("failed to get docker host: %w" , err )
223234 }
224235
225236 return & Service {
0 commit comments