(t *testing.T, ctx context.Context, registryURL, name, hookScript string)
| 1115 | } |
| 1116 | |
| 1117 | func buildHookImage(t *testing.T, ctx context.Context, registryURL, name, hookScript string) string { |
| 1118 | t.Helper() |
| 1119 | c, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) |
| 1120 | require.NoError(t, err) |
| 1121 | defer c.Close() |
| 1122 | |
| 1123 | dockerfile := `FROM ghcr.io/basecamp/once-campfire:main |
| 1124 | COPY post-restore /hooks/post-restore |
| 1125 | ` |
| 1126 | |
| 1127 | var buf bytes.Buffer |
| 1128 | tw := tar.NewWriter(&buf) |
| 1129 | addTarEntry := func(name string, data []byte) { |
| 1130 | require.NoError(t, tw.WriteHeader(&tar.Header{Name: name, Size: int64(len(data)), Mode: 0644})) |
| 1131 | _, err := tw.Write(data) |
| 1132 | require.NoError(t, err) |
| 1133 | } |
| 1134 | addTarEntry("Dockerfile", []byte(dockerfile)) |
| 1135 | |
| 1136 | require.NoError(t, tw.WriteHeader(&tar.Header{Name: "post-restore", Size: int64(len(hookScript)), Mode: 0755})) |
| 1137 | _, err = tw.Write([]byte(hookScript)) |
| 1138 | require.NoError(t, err) |
| 1139 | require.NoError(t, tw.Close()) |
| 1140 | |
| 1141 | fullTag := registryURL + "/" + name + ":latest" |
| 1142 | |
| 1143 | buildResp, err := c.ImageBuild(ctx, &buf, build.ImageBuildOptions{ |
| 1144 | Tags: []string{fullTag}, |
| 1145 | Dockerfile: "Dockerfile", |
| 1146 | Remove: true, |
| 1147 | }) |
| 1148 | require.NoError(t, err) |
| 1149 | io.Copy(io.Discard, buildResp.Body) |
| 1150 | buildResp.Body.Close() |
| 1151 | |
| 1152 | pushResp, err := c.ImagePush(ctx, fullTag, image.PushOptions{RegistryAuth: "e30="}) // base64 "{}" |
| 1153 | require.NoError(t, err) |
| 1154 | io.Copy(io.Discard, pushResp) |
| 1155 | pushResp.Close() |
| 1156 | |
| 1157 | return fullTag |
| 1158 | } |
| 1159 | |
| 1160 | func buildTestBackup(t *testing.T, imageName string) []byte { |
| 1161 | t.Helper() |
no test coverage detected
searching dependent graphs…