Skip to content

Commit

Permalink
Merge branch 'master' into feature/experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
jromero authored Apr 16, 2020
2 parents 0f4fb4d + 11e3a67 commit 754ca0c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ assignees: ''

### Description
<!-- A concise description of what problem the feature solves and why solving it matters.
Ex. My shoelaces won't stay tied and I keep tripping [...] -->
Ex. My shoelaces won't stay tied and I keep tripping... -->

### Proposed solution
<!-- A clear and concise description of what you want to happen.
Expand All @@ -19,4 +19,6 @@ Ex. We could have velcro on the shoes instead of laces...-->
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

### Additional context
- [ ] This feature should be documented somewhere

<!-- Add any other context or screenshots about the feature request here. -->
4 changes: 3 additions & 1 deletion internal/build/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ func testPhase(t *testing.T, when spec.G, it spec.S) {
})

it.After(func() {
registry.StopRegistry(t)
if registry != nil {
registry.StopRegistry(t)
}
h.AssertNil(t, os.Unsetenv("DOCKER_CONFIG"))
})

Expand Down
19 changes: 18 additions & 1 deletion testhelpers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ func RunRegistry(t *testing.T) *TestRegistryConfig {
password: password,
}

// ensure registry is ready
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
for {
_, err := registryConfig.RegistryCatalog()
if err == nil {
break
}

err = ctx.Err()
if err != nil {
t.Fatal("registry not ready:", err.Error())
}

time.Sleep(500 * time.Microsecond)
}

return registryConfig
}

Expand Down Expand Up @@ -107,7 +124,7 @@ func startRegistry(t *testing.T, runRegistryName, username, password string) str
}

func generateHtpasswd(ctx context.Context, t *testing.T, username string, password string) io.Reader {
//https://docs.docker.com/registry/deploying/#restricting-access
// https://docs.docker.com/registry/deploying/#restricting-access
htpasswdCtr, err := dockerCli(t).ContainerCreate(ctx, &dockercontainer.Config{
Image: registryContainerName,
Entrypoint: []string{"htpasswd", "-Bbn", username, password},
Expand Down
25 changes: 15 additions & 10 deletions testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ func CreateImage(t *testing.T, dockerCli client.CommonAPIClient, repoName, docke
})
AssertNil(t, err)

err = checkResponse(resp)
defer resp.Body.Close()
err = checkResponse(resp.Body)
AssertNil(t, errors.Wrapf(err, "building image %s", style.Symbol(repoName)))
}

Expand All @@ -299,15 +300,15 @@ func CreateImageFromDir(t *testing.T, dockerCli client.CommonAPIClient, repoName
})
AssertNil(t, err)

err = checkResponse(resp)
defer resp.Body.Close()
err = checkResponse(resp.Body)
AssertNil(t, errors.Wrapf(err, "building image %s", style.Symbol(repoName)))
}

func checkResponse(response dockertypes.ImageBuildResponse) error {
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
func checkResponse(responseBody io.Reader) error {
body, err := ioutil.ReadAll(responseBody)
if err != nil {
return err
return errors.Wrap(err, "reading body")
}

messages := strings.Builder{}
Expand Down Expand Up @@ -361,12 +362,16 @@ func DockerRmi(dockerCli client.CommonAPIClient, repoNames ...string) error {
func PushImage(dockerCli client.CommonAPIClient, ref string, registryConfig *TestRegistryConfig) error {
rc, err := dockerCli.ImagePush(context.Background(), ref, dockertypes.ImagePushOptions{RegistryAuth: registryConfig.RegistryAuth()})
if err != nil {
return err
return errors.Wrap(err, "pushing image")
}
if _, err := io.Copy(ioutil.Discard, rc); err != nil {
return err

defer rc.Close()
err = checkResponse(rc)
if err != nil {
return errors.Wrap(err, "push response")
}
return rc.Close()

return nil
}

func HTTPGetE(url string, headers map[string]string) (string, error) {
Expand Down

0 comments on commit 754ca0c

Please sign in to comment.