Skip to content

Commit 67c42e9

Browse files
fix(start): make storage seeding respect db.seed.enabled with --no-seed override
1 parent 66e0f72 commit 67c42e9

File tree

2 files changed

+103
-11
lines changed

2 files changed

+103
-11
lines changed

internal/start/start.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ func run(ctx context.Context, fsys afero.Fs, excludedContainers []string, dbConf
249249
utils.Config.Storage.ImageTransformation.Enabled && !isContainerExcluded(utils.Config.Storage.ImgProxyImage, excluded)
250250
isS3ProtocolEnabled := utils.Config.Storage.S3Protocol != nil && utils.Config.Storage.S3Protocol.Enabled
251251
fmt.Fprintln(os.Stderr, "Starting containers...")
252-
if skipSeed {
253-
fmt.Fprintln(os.Stderr, "Skipping storage seeding (--no-seed enabled)")
254-
}
255252
workdir, err := os.Getwd()
256253
if err != nil {
257254
return errors.Errorf("failed to get working directory: %w", err)
@@ -1280,19 +1277,23 @@ EOF
12801277
}
12811278

12821279
fmt.Fprintln(os.Stderr, "Waiting for health checks...")
1280+
12831281
if utils.NoBackupVolume && slices.Contains(started, utils.StorageId) {
12841282
if err := start.WaitForHealthyService(ctx, serviceTimeout, utils.StorageId); err != nil {
12851283
return err
12861284
}
1287-
// Disable prompts when seeding
1288-
if skipSeed {
1289-
fmt.Fprintln(os.Stderr, "Skipping storage seeding (--no-seed enabled)")
1290-
} else {
1291-
// Disable prompts when seeding
1292-
if err := buckets.Run(ctx, "", false, fsys); err != nil {
1293-
return err
1285+
1286+
// Follow db.seed.enabled by default, allow --no-seed as override
1287+
if skipSeed {
1288+
fmt.Fprintln(os.Stderr, "Skipping storage seeding (--no-seed enabled)")
1289+
} else if !utils.Config.Db.Seed.Enabled {
1290+
fmt.Fprintln(os.Stderr, "Skipping storage seeding (db.seed.enabled = false)")
1291+
} else {
1292+
if err := buckets.Run(ctx, "", false, fsys); err != nil {
1293+
return err
1294+
}
12941295
}
1295-
}
1296+
12961297
}
12971298
return start.WaitForHealthyService(ctx, serviceTimeout, started...)
12981299
}

internal/start/start_test.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,97 @@ func TestDatabaseStart(t *testing.T) {
253253
assert.NoError(t, err)
254254
assert.Empty(t, apitest.ListUnmatchedRequests())
255255
})
256+
257+
t.Run("skips storage seeding when db.seed.enabled is false", func(t *testing.T) {
258+
utils.Config.Analytics.Enabled = false
259+
utils.Config.Api.Enabled = false
260+
utils.Config.Auth.Enabled = false
261+
utils.Config.Realtime.Enabled = false
262+
utils.Config.Studio.Enabled = false
263+
utils.Config.EdgeRuntime.Enabled = false
264+
utils.Config.Inbucket.Enabled = false
265+
utils.Config.Db.Pooler.Enabled = false
266+
267+
fsys := afero.NewMemMapFs()
268+
269+
// Restore global state
270+
origSeed := utils.Config.Db.Seed.Enabled
271+
t.Cleanup(func() {
272+
utils.Config.Db.Seed.Enabled = origSeed
273+
})
274+
utils.Config.Db.Seed.Enabled = false
275+
276+
require.NoError(t, apitest.MockDocker(utils.Docker))
277+
defer gock.OffAll()
278+
279+
gock.New(utils.Docker.DaemonHost()).
280+
Head("/_ping").
281+
Reply(http.StatusOK)
282+
283+
gock.New(utils.Docker.DaemonHost()).
284+
Post("/v" + utils.Docker.ClientVersion() + "/networks/create").
285+
Reply(http.StatusCreated).
286+
JSON(network.CreateResponse{})
287+
288+
// 🔑 REQUIRED: cache all images
289+
for _, img := range config.Images.Services() {
290+
service := utils.GetRegistryImageUrl(img)
291+
gock.New(utils.Docker.DaemonHost()).
292+
Get("/v" + utils.Docker.ClientVersion() + "/images/" + service + "/json").
293+
Reply(http.StatusOK).
294+
JSON(image.InspectResponse{})
295+
}
296+
297+
// ALSO mock postgres image (DB is not part of Services())
298+
dbImage := utils.GetRegistryImageUrl(utils.Config.Db.Image)
299+
gock.New(utils.Docker.DaemonHost()).
300+
Get("/v" + utils.Docker.ClientVersion() + "/images/" + dbImage + "/json").
301+
Reply(http.StatusOK).
302+
JSON(image.InspectResponse{})
303+
304+
utils.DbId = "test-postgres"
305+
utils.Config.Db.Port = 54322
306+
utils.Config.Db.MajorVersion = 15
307+
308+
gock.New(utils.Docker.DaemonHost()).
309+
Get("/v" + utils.Docker.ClientVersion() + "/volumes/" + utils.DbId).
310+
Reply(http.StatusOK).
311+
JSON(volume.Volume{})
312+
313+
apitest.MockDockerStart(
314+
utils.Docker,
315+
utils.GetRegistryImageUrl(utils.Config.Db.Image),
316+
utils.DbId,
317+
)
318+
319+
gock.New(utils.Docker.DaemonHost()).
320+
Get("/v" + utils.Docker.ClientVersion() + "/containers/" + utils.DbId + "/json").
321+
Reply(http.StatusOK).
322+
JSON(container.InspectResponse{
323+
ContainerJSONBase: &container.ContainerJSONBase{
324+
State: &container.State{
325+
Running: true,
326+
Health: &container.Health{Status: types.Healthy},
327+
},
328+
},
329+
})
330+
exclude := []string{
331+
utils.ShortContainerImageName(utils.Config.Api.KongImage),
332+
utils.ShortContainerImageName(utils.Config.Storage.Image),
333+
}
334+
335+
err := run(
336+
context.Background(),
337+
fsys,
338+
exclude,
339+
pgconn.Config{Host: utils.DbId},
340+
false,
341+
)
342+
343+
assert.NoError(t, err)
344+
assert.Empty(t, apitest.ListUnmatchedRequests())
345+
})
346+
256347
}
257348

258349
func TestFormatMapForEnvConfig(t *testing.T) {

0 commit comments

Comments
 (0)