Skip to content

Commit cfbacce

Browse files
authored
fix: add grace period to allow registry to start up (#282)
Added 10s grace period + timeout on registry container wait. This makes logging in to the custom registry more reliable. Signed-off-by: ayush-panta <ayushkp@amazon.com>
1 parent b04e346 commit cfbacce

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

tests/login.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"time"
1011

1112
"github.com/onsi/ginkgo/v2"
1213
"github.com/onsi/gomega/gbytes"
@@ -42,14 +43,25 @@ func Login(o *option.Option) {
4243
htpasswdDir := filepath.Dir(ffs.CreateTempFile(filename, htpasswd))
4344
ginkgo.DeferCleanup(os.RemoveAll, htpasswdDir)
4445
port := fnet.GetFreePort()
45-
command.Run(o, "run",
46+
containerID := command.StdoutStr(o, "run",
4647
"-dp", fmt.Sprintf("%d:5000", port),
4748
"--name", "registry",
4849
"-v", fmt.Sprintf("%s:/auth", htpasswdDir),
4950
"-e", "REGISTRY_AUTH=htpasswd",
5051
"-e", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm",
5152
"-e", fmt.Sprintf("REGISTRY_AUTH_HTPASSWD_PATH=/auth/%s", filename),
5253
registryImage)
54+
// Wait for container to be running
55+
tries := 0
56+
for command.StdoutStr(o, "inspect", "-f", "{{.State.Running}}", containerID) != "true" {
57+
if tries >= 5 {
58+
ginkgo.Fail("Registry container failed to start after 5 seconds")
59+
}
60+
time.Sleep(1 * time.Second)
61+
tries++
62+
}
63+
// Wait for registry service to be ready
64+
time.Sleep(10 * time.Second)
5365
registry = fmt.Sprintf(`localhost:%d`, port)
5466
tag = fmt.Sprintf(`%s/test-login:tag`, registry)
5567
buildContext := ffs.CreateBuildContext(fmt.Sprintf(`FROM %s

tests/logout.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"time"
1011

1112
"github.com/onsi/ginkgo/v2"
1213

@@ -42,14 +43,25 @@ func Logout(o *option.Option) {
4243
htpasswdDir := filepath.Dir(ffs.CreateTempFile(filename, htpasswd))
4344
ginkgo.DeferCleanup(os.RemoveAll, htpasswdDir)
4445
port := fnet.GetFreePort()
45-
command.Run(o, "run",
46+
containerID := command.StdoutStr(o, "run",
4647
"-dp", fmt.Sprintf("%d:5000", port),
4748
"--name", "registry",
4849
"-v", fmt.Sprintf("%s:/auth", htpasswdDir),
4950
"-e", "REGISTRY_AUTH=htpasswd",
5051
"-e", "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm",
5152
"-e", fmt.Sprintf("REGISTRY_AUTH_HTPASSWD_PATH=/auth/%s", filename),
5253
registryImage)
54+
// Wait for container to be running
55+
tries := 0
56+
for command.StdoutStr(o, "inspect", "-f", "{{.State.Running}}", containerID) != "true" {
57+
if tries >= 5 {
58+
ginkgo.Fail("Registry container failed to start after 5 seconds")
59+
}
60+
time.Sleep(1 * time.Second)
61+
tries++
62+
}
63+
// Wait for registry service to be ready
64+
time.Sleep(10 * time.Second)
5365
registry = fmt.Sprintf(`localhost:%d`, port)
5466
tag = fmt.Sprintf(`%s/test-login:tag`, registry)
5567
buildContext := ffs.CreateBuildContext(fmt.Sprintf(`FROM %s

0 commit comments

Comments
 (0)