Skip to content

Commit

Permalink
Pull images before trying to run them
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Apr 8, 2023
1 parent 942f283 commit 7b37bf3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 10 additions & 2 deletions builder/build/prebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,24 @@ func (b *Build) StartAddons() (map[string]string, error) {
var err error
// dedupe addons
addons := removeDuplicateStr(b.AppJSON.GetTestAddons())
redisImage := "redis:alpine"
postgresImage := "postgres:alpine"
// use a switch statement to iterate over addons
for _, addon := range addons {
switch addon {
case "heroku-redis:in-dyno":
if err = b.containers.RunContainer("redis", b.CodebuildBuildId, &container.Config{Image: "redis:alpine"}); err != nil {
if err = b.containers.PullImage(redisImage); err != nil {
return nil, err
}
if err = b.containers.RunContainer("redis", b.CodebuildBuildId, &container.Config{Image: redisImage}); err != nil {
return nil, err
}
envOverides["REDIS_URL"] = "redis://redis:6379"
case "heroku-postgresql:in-dyno":
if err = b.containers.RunContainer("db", b.CodebuildBuildId, &container.Config{Image: "postgres:alpine"}); err != nil {
if err = b.containers.PullImage(postgresImage); err != nil {
return nil, err
}
if err = b.containers.RunContainer("db", b.CodebuildBuildId, &container.Config{Image: postgresImage}); err != nil {
return nil, err
}
envOverides["DATABASE_URL"] = "postgres://postgres:postgres@db:5432/postgres"
Expand Down
8 changes: 8 additions & 0 deletions builder/build/prebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,18 @@ func TestRemoveDuplicateStr(t *testing.T) {

func TestStartAddons(t *testing.T) {
mockedContainers := new(MockContainers)
mockedContainers.On(
"PullImage",
"redis:alpine",
).Return(nil)
mockedContainers.On(
"RunContainer",
"redis", CodebuildBuildId, &container.Config{Image: "redis:alpine"},
).Return(nil)
mockedContainers.On(
"PullImage",
"postgres:alpine",
).Return(nil)
mockedContainers.On(
"RunContainer",
"db", CodebuildBuildId, &container.Config{Image: "postgres:alpine"},
Expand Down

0 comments on commit 7b37bf3

Please sign in to comment.