MCPcopy
hub / github.com/determined-ai/determined / TestRunContainerWithService

Function TestRunContainerWithService

agent/pkg/docker/docker_api_test.go:197–292  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

195const testServiceImage = "nginx:latest"
196
197func TestRunContainerWithService(t *testing.T) {
198 ctx, cancel := context.WithCancel(context.Background())
199 defer cancel()
200 agentID := uuid.NewString()
201 containerID := uuid.NewString()
202
203 t.Log("building client")
204 rawCl, err := dclient.NewClientWithOpts(dclient.WithAPIVersionNegotiation(), dclient.FromEnv)
205 require.NoError(t, err)
206 defer func() {
207 if cErr := rawCl.Close(); cErr != nil {
208 t.Logf("closing docker client: %s", cErr)
209 }
210 }()
211 cl := docker.NewClient(rawCl)
212
213 t.Log("pull test image")
214 evs := make(chan docker.Event, 1024)
215 pub := events.ChannelPublisher(evs)
216 if err = cl.PullImage(ctx, docker.PullImage{Name: testServiceImage}, pub); err != nil {
217 t.Errorf("pulling image: %s", err.Error())
218 return
219 }
220 close(evs)
221 _, _, err = rawCl.ImageInspectWithRaw(ctx, testImage)
222 require.NoError(t, err)
223
224 t.Log("creating simple container")
225 evs = make(chan docker.Event, 64)
226 pub = events.ChannelPublisher(evs)
227 dockerID, err := cl.CreateContainer(ctx, cproto.NewID(), cproto.RunSpec{
228 ContainerConfig: container.Config{
229 Image: testServiceImage,
230 Labels: map[string]string{
231 docker.AgentLabel: agentID,
232 docker.ContainerIDLabel: containerID,
233 },
234 },
235 }, pub)
236 require.NoError(t, err)
237
238 t.Log("running simple container")
239 c, err := cl.RunContainer(ctx, ctx, dockerID, pub)
240 require.NoError(t, err)
241
242 close(evs)
243 defer func() {
244 if rErr := rawCl.ContainerRemove(
245 ctx,
246 c.ContainerInfo.ID,
247 container.RemoveOptions{Force: true},
248 ); rErr != nil {
249 t.Errorf("failed to cleanup container %s: %s", c.ContainerInfo.ID, rErr)
250 }
251 }()
252
253 t.Log("ensure it is listed when searching docker for our containers")
254 containers, err := cl.ListRunningContainers(ctx, docker.LabelFilter(docker.AgentLabel, agentID))

Callers

nothing calls this directly

Calls 15

PullImageMethod · 0.95
CreateContainerMethod · 0.95
RunContainerMethod · 0.95
ListRunningContainersMethod · 0.95
ReattachContainerMethod · 0.95
SignalContainerMethod · 0.95
NewClientFunction · 0.92
ChannelPublisherFunction · 0.92
NewIDFunction · 0.92
LabelFilterFunction · 0.92
IDTypeAlias · 0.92
cancelFunction · 0.85

Tested by

no test coverage detected