init performs the one time setup and sets up the cluster.
()
| 100 | |
| 101 | // init performs the one time setup and sets up the cluster. |
| 102 | func (c *LocalCluster) init() error { |
| 103 | var err error |
| 104 | c.dcli, err = docker.NewClientWithOpts(docker.FromEnv, docker.WithAPIVersionNegotiation()) |
| 105 | if err != nil { |
| 106 | return errors.Wrap(err, "error setting up docker client") |
| 107 | } |
| 108 | ctx, cancel := context.WithTimeout(context.Background(), requestTimeout) |
| 109 | defer cancel() |
| 110 | if _, err := c.dcli.Ping(ctx); err != nil { |
| 111 | return errors.Wrap(err, "unable to talk to docker daemon") |
| 112 | } |
| 113 | |
| 114 | if err := c.createNetwork(); err != nil { |
| 115 | return err |
| 116 | } |
| 117 | c.tempBinDir, err = os.MkdirTemp("", c.conf.prefix) |
| 118 | if err != nil { |
| 119 | return errors.Wrap(err, "error while creating tempBinDir") |
| 120 | } |
| 121 | // WidenTempDirPerms is a public hook in dgraphtest/hooks.go; the |
| 122 | // default is no-op. Downstream consumers running dgraph as a |
| 123 | // non-root user inside compose-test containers override it to |
| 124 | // widen perms on host-side temp dirs bind-mounted into containers, |
| 125 | // so the in-container uid can read and write those paths. |
| 126 | if err := WidenTempDirPerms(c.tempBinDir); err != nil { |
| 127 | return err |
| 128 | } |
| 129 | log.Printf("[INFO] tempBinDir: %v", c.tempBinDir) |
| 130 | c.tempSecretsDir, err = os.MkdirTemp("", c.conf.prefix) |
| 131 | if err != nil { |
| 132 | return errors.Wrap(err, "error while creating tempSecretsDir") |
| 133 | } |
| 134 | // Same hook, applied to the secrets temp dir. |
| 135 | if err := WidenTempDirPerms(c.tempSecretsDir); err != nil { |
| 136 | return err |
| 137 | } |
| 138 | log.Printf("[INFO] tempSecretsDir: %v", c.tempSecretsDir) |
| 139 | |
| 140 | if err := os.Mkdir(binariesPath, os.ModePerm); err != nil && !os.IsExist(err) { |
| 141 | return errors.Wrap(err, "error while making binariesPath") |
| 142 | } |
| 143 | |
| 144 | if err := os.Mkdir(datasetFilesPath, os.ModePerm); err != nil && !os.IsExist(err) { |
| 145 | return errors.Wrap(err, "error while making datafiles path") |
| 146 | } |
| 147 | |
| 148 | for _, vol := range c.conf.volumes { |
| 149 | if err := c.createVolume(vol); err != nil { |
| 150 | return err |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | c.zeros = c.zeros[:0] |
| 155 | for i := range c.conf.numZeros { |
| 156 | zo := &zero{id: i} |
| 157 | zo.containerName = fmt.Sprintf(zeroNameFmt, c.conf.prefix, zo.id) |
| 158 | zo.aliasName = fmt.Sprintf(zeroAliasNameFmt, zo.id) |
| 159 | c.zeros = append(c.zeros, zo) |
no test coverage detected