MCPcopy
hub / github.com/basecamp/once / buildAndPushImage

Function buildAndPushImage

integration/docker_test.go:1257–1285  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, tag, version string)

Source from the content-addressed store, hash-verified

1255}
1256
1257func buildAndPushImage(t *testing.T, ctx context.Context, tag, version string) {
1258 t.Helper()
1259 c, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
1260 require.NoError(t, err)
1261 defer c.Close()
1262
1263 dockerfile := fmt.Sprintf("FROM ghcr.io/basecamp/once-campfire:main\nLABEL version=%s\n", version)
1264
1265 var buf bytes.Buffer
1266 tw := tar.NewWriter(&buf)
1267 require.NoError(t, tw.WriteHeader(&tar.Header{Name: "Dockerfile", Size: int64(len(dockerfile)), Mode: 0644}))
1268 _, err = tw.Write([]byte(dockerfile))
1269 require.NoError(t, err)
1270 require.NoError(t, tw.Close())
1271
1272 buildResp, err := c.ImageBuild(ctx, &buf, build.ImageBuildOptions{
1273 Tags: []string{tag},
1274 Dockerfile: "Dockerfile",
1275 Remove: true,
1276 })
1277 require.NoError(t, err)
1278 io.Copy(io.Discard, buildResp.Body)
1279 buildResp.Body.Close()
1280
1281 pushResp, err := c.ImagePush(ctx, tag, image.PushOptions{RegistryAuth: "e30="})
1282 require.NoError(t, err)
1283 io.Copy(io.Discard, pushResp)
1284 pushResp.Close()
1285}

Callers 1

Calls 3

WriteHeaderMethod · 0.80
CloseMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…