Skip to content

Commit

Permalink
Merge pull request #1723 from buildpacks/jkutner/x-text
Browse files Browse the repository at this point in the history
Upgrade golang.org/x/text in tools
  • Loading branch information
jkutner authored Apr 14, 2023
2 parents 2e1320b + fb5d074 commit afff088
Show file tree
Hide file tree
Showing 18 changed files with 486 additions and 799 deletions.
3 changes: 0 additions & 3 deletions golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ linters:
enable:
- bodyclose
- exportloopref
- deadcode
- dogsled
- gocritic
- goimports
Expand All @@ -18,12 +17,10 @@ linters:
- revive
- rowserrcheck
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unused
- varcheck
- whitespace

linters-settings:
Expand Down
2 changes: 1 addition & 1 deletion internal/build/container_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ drwxr-xr-x 2 123 456 (.*) some-vol
})
}

func createContainer(ctx context.Context, imageName, containerDir, osType string, cmd ...string) (dcontainer.ContainerCreateCreatedBody, error) {
func createContainer(ctx context.Context, imageName, containerDir, osType string, cmd ...string) (dcontainer.CreateResponse, error) {
isolationType := dcontainer.IsolationDefault
if osType == "windows" {
isolationType = dcontainer.IsolationProcess
Expand Down
4 changes: 2 additions & 2 deletions internal/build/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
type DockerClient interface {
ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
VolumeRemove(ctx context.Context, volumeID string, force bool) error
ContainerWait(ctx context.Context, container string, condition containertypes.WaitCondition) (<-chan containertypes.ContainerWaitOKBody, <-chan error)
ContainerWait(ctx context.Context, container string, condition containertypes.WaitCondition) (<-chan containertypes.WaitResponse, <-chan error)
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error
ContainerCreate(ctx context.Context, config *containertypes.Config, hostConfig *containertypes.HostConfig, networkingConfig *networktypes.NetworkingConfig, platform *specs.Platform, containerName string) (containertypes.ContainerCreateCreatedBody, error)
ContainerCreate(ctx context.Context, config *containertypes.Config, hostConfig *containertypes.HostConfig, networkingConfig *networktypes.NetworkingConfig, platform *specs.Platform, containerName string) (containertypes.CreateResponse, error)
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error
Expand Down
2 changes: 1 addition & 1 deletion internal/build/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Phase struct {
handler container.Handler
ctrConf *dcontainer.Config
hostConf *dcontainer.HostConfig
ctr dcontainer.ContainerCreateCreatedBody
ctr dcontainer.CreateResponse
uid, gid int
appPath string
containerOps []ContainerOperation
Expand Down
2 changes: 1 addition & 1 deletion internal/build/phase_config_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {

when("building with interactive mode", func() {
it("returns a phase config provider with interactive args", func() {
handler := func(bodyChan <-chan container.ContainerWaitOKBody, errChan <-chan error, reader io.Reader) error {
handler := func(bodyChan <-chan container.WaitResponse, errChan <-chan error, reader io.Reader) error {
return errors.New("i was called")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/build/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func testPhase(t *testing.T, when spec.G, it spec.S) {

it("runs the phase with provided handlers", func() {
var actual string
var handler container.Handler = func(bodyChan <-chan dcontainer.ContainerWaitOKBody, errChan <-chan error, reader io.Reader) error {
var handler container.Handler = func(bodyChan <-chan dcontainer.WaitResponse, errChan <-chan error, reader io.Reader) error {
data, _ := io.ReadAll(reader)
actual = string(data)
return nil
Expand Down
5 changes: 1 addition & 4 deletions internal/builder/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ func (i *Inspector) Inspect(name string, daemon bool, orderDetectionDepth int) (
return Info{}, fmt.Errorf("reading image metadata: %w", err)
}

stackID, err := labelManager.StackID()
if err != nil {
// TODO log warn
}
stackID, _ := labelManager.StackID() // ignore error because stack is optional

mixins, err := labelManager.Mixins()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cache/volume_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func testCache(t *testing.T, when spec.G, it spec.S) {

when("there is a cache volume", func() {
it.Before(func() {
dockerClient.VolumeCreate(context.TODO(), volume.VolumeCreateBody{
dockerClient.VolumeCreate(context.TODO(), volume.CreateOptions{
Name: volumeName,
})
})
Expand Down
7 changes: 3 additions & 4 deletions internal/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import (
"io"

"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
dcontainer "github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/stdcopy"
"github.com/pkg/errors"
)

type Handler func(bodyChan <-chan dcontainer.ContainerWaitOKBody, errChan <-chan error, reader io.Reader) error
type Handler func(bodyChan <-chan dcontainer.WaitResponse, errChan <-chan error, reader io.Reader) error

type DockerClient interface {
ContainerWait(ctx context.Context, container string, condition dcontainer.WaitCondition) (<-chan containertypes.ContainerWaitOKBody, <-chan error)
ContainerWait(ctx context.Context, container string, condition dcontainer.WaitCondition) (<-chan dcontainer.WaitResponse, <-chan error)
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error
}
Expand All @@ -41,7 +40,7 @@ func RunWithHandler(ctx context.Context, docker DockerClient, ctrID string, hand
}

func DefaultHandler(out, errOut io.Writer) Handler {
return func(bodyChan <-chan dcontainer.ContainerWaitOKBody, errChan <-chan error, reader io.Reader) error {
return func(bodyChan <-chan dcontainer.WaitResponse, errChan <-chan error, reader io.Reader) error {
copyErr := make(chan error)
go func() {
_, err := stdcopy.StdCopy(out, errOut, reader)
Expand Down
2 changes: 1 addition & 1 deletion internal/termui/termui.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (s *Termui) handle() {
}

func (s *Termui) Handler() container.Handler {
return func(bodyChan <-chan dcontainer.ContainerWaitOKBody, errChan <-chan error, reader io.Reader) error {
return func(bodyChan <-chan dcontainer.WaitResponse, errChan <-chan error, reader io.Reader) error {
var (
copyErr = make(chan error)
r, w = io.Pipe()
Expand Down
12 changes: 6 additions & 6 deletions internal/termui/termui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func testTermui(t *testing.T, when spec.G, it spec.S) {
it("performs the lifecycle", func() {
var (
fakeBuild = make(chan bool, 1)
fakeBodyChan = make(chan dcontainer.ContainerWaitOKBody, 1)
fakeBodyChan = make(chan dcontainer.WaitResponse, 1)
fakeApp = fakes.NewApp()
r, w = io.Pipe()
fakeDockerStdWriter = fakes.NewDockerStdWriter(w)
Expand Down Expand Up @@ -69,7 +69,7 @@ func testTermui(t *testing.T, when spec.G, it spec.S) {
)

defer func() {
fakeBodyChan <- dcontainer.ContainerWaitOKBody{StatusCode: 0}
fakeBodyChan <- dcontainer.WaitResponse{StatusCode: 0}
fakeBuild <- true
w.Close()
fakeApp.StopRunning()
Expand Down Expand Up @@ -142,7 +142,7 @@ func testTermui(t *testing.T, when spec.G, it spec.S) {
h.AssertFalse(t, bpChildren2[0].GetChildren()[0].GetReference().(*tar.Header).FileInfo().IsDir())

// finish build
fakeBodyChan <- dcontainer.ContainerWaitOKBody{StatusCode: 0}
fakeBodyChan <- dcontainer.WaitResponse{StatusCode: 0}
w.Close()
time.Sleep(500 * time.Millisecond)
fakeBuild <- true
Expand All @@ -154,7 +154,7 @@ func testTermui(t *testing.T, when spec.G, it spec.S) {
it("performs the lifecycle (when the builder is untrusted)", func() {
var (
fakeBuild = make(chan bool, 1)
fakeBodyChan = make(chan dcontainer.ContainerWaitOKBody, 1)
fakeBodyChan = make(chan dcontainer.WaitResponse, 1)
fakeApp = fakes.NewApp()
r, w = io.Pipe()
fakeDockerStdWriter = fakes.NewDockerStdWriter(w)
Expand Down Expand Up @@ -185,7 +185,7 @@ func testTermui(t *testing.T, when spec.G, it spec.S) {
)

defer func() {
fakeBodyChan <- dcontainer.ContainerWaitOKBody{StatusCode: 0}
fakeBodyChan <- dcontainer.WaitResponse{StatusCode: 0}
fakeBuild <- true
w.Close()
fakeApp.StopRunning()
Expand Down Expand Up @@ -226,7 +226,7 @@ func testTermui(t *testing.T, when spec.G, it spec.S) {
}, eventuallyInterval, eventuallyDuration)

// finish build
fakeBodyChan <- dcontainer.ContainerWaitOKBody{StatusCode: 1}
fakeBodyChan <- dcontainer.WaitResponse{StatusCode: 1}
w.Close()
time.Sleep(500 * time.Millisecond)
fakeBuild <- true
Expand Down
3 changes: 1 addition & 2 deletions pkg/buildpack/buildpack_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package buildpack_test

import (
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -554,7 +553,7 @@ func (e *errorBlob) Open() (io.ReadCloser, error) {
e.count += 1
return e.realBlob.Open()
}
return nil, errors.New(fmt.Sprintf("error from errBlob (reached limit of %d)", e.limit))
return nil, fmt.Errorf("error from errBlob (reached limit of %d)", e.limit)
}

type readerBlob struct {
Expand Down
11 changes: 4 additions & 7 deletions pkg/client/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,18 +548,18 @@ func extractSupportedLifecycleApis(labels map[string]string) ([]string, error) {
// io.buildpacks.lifecycle.apis":"{\"buildpack\":{\"deprecated\":[],\"supported\":[\"0.2\",\"0.3\",\"0.4\",\"0.5\",\"0.6\",\"0.7\",\"0.8\",\"0.9\"]},\"platform\":{\"deprecated\":[],\"supported\":[\"0.3\",\"0.4\",\"0.5\",\"0.6\",\"0.7\",\"0.8\",\"0.9\",\"0.10\"]}}\",\"io.buildpacks.lifecycle.version\":\"0.15.3\"}")

// This struct is defined in lifecycle-repository/tools/image/main.go#Descriptor -- we could consider moving it from the main package to an importable location.
var bpPlatformApi struct {
var bpPlatformAPI struct {
Platform struct {
Deprecated []string
Supported []string
}
}
if len(labels["io.buildpacks.lifecycle.apis"]) > 0 {
err := json.Unmarshal([]byte(labels["io.buildpacks.lifecycle.apis"]), &bpPlatformApi)
err := json.Unmarshal([]byte(labels["io.buildpacks.lifecycle.apis"]), &bpPlatformAPI)
if err != nil {
return nil, err
}
return append(bpPlatformApi.Platform.Deprecated, bpPlatformApi.Platform.Supported...), nil
return append(bpPlatformAPI.Platform.Deprecated, bpPlatformAPI.Platform.Supported...), nil
}
return []string{}, nil
}
Expand Down Expand Up @@ -1069,10 +1069,7 @@ func prependBuildpackToOrder(order dist.Order, bpInfo dist.ModuleInfo) (newOrder
ModuleInfo: bpInfo,
Optional: false,
}}
for _, g := range newEntry.Group {
newGroup = append(newGroup, g)
}
newEntry.Group = newGroup
newEntry.Group = append(newGroup, newEntry.Group...)
newOrder = append(newOrder, newEntry)
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/client/create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/Masterminds/semver"
"github.com/buildpacks/imgutil"
"github.com/pkg/errors"
"golang.org/x/text/cases"
"golang.org/x/text/language"

pubbldr "github.com/buildpacks/pack/builder"
"github.com/buildpacks/pack/internal/builder"
Expand Down Expand Up @@ -268,7 +270,7 @@ func (c *Client) addConfig(ctx context.Context, kind string, config pubbldr.Modu
if deprecatedAPI.Equal(bpDesc.API()) {
c.logger.Warnf(
"%s %s is using deprecated Buildpacks API version %s",
strings.Title(kind),
cases.Title(language.AmericanEnglish).String(kind),
style.Symbol(bpDesc.Info().FullName()),
style.Symbol(bpDesc.API().String()),
)
Expand All @@ -278,11 +280,11 @@ func (c *Client) addConfig(ctx context.Context, kind string, config pubbldr.Modu

// Fixes 1453
sort.Slice(depBPs, func(i, j int) bool {
compareId := strings.Compare(depBPs[i].Descriptor().Info().ID, depBPs[j].Descriptor().Info().ID)
if compareId == 0 {
compareID := strings.Compare(depBPs[i].Descriptor().Info().ID, depBPs[j].Descriptor().Info().ID)
if compareID == 0 {
return strings.Compare(depBPs[i].Descriptor().Info().Version, depBPs[j].Descriptor().Info().Version) <= 0
}
return compareId < 0
return compareID < 0
})

for _, module := range append([]buildpack.BuildModule{mainBP}, depBPs...) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type DockerClient interface {
ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error)
Info(ctx context.Context) (types.Info, error)
VolumeRemove(ctx context.Context, volumeID string, force bool) error
ContainerCreate(ctx context.Context, config *containertypes.Config, hostConfig *containertypes.HostConfig, networkingConfig *networktypes.NetworkingConfig, platform *specs.Platform, containerName string) (containertypes.ContainerCreateCreatedBody, error)
ContainerCreate(ctx context.Context, config *containertypes.Config, hostConfig *containertypes.HostConfig, networkingConfig *networktypes.NetworkingConfig, platform *specs.Platform, containerName string) (containertypes.CreateResponse, error)
CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
ContainerInspect(ctx context.Context, container string) (types.ContainerJSON, error)
ContainerRemove(ctx context.Context, container string, options types.ContainerRemoveOptions) error
CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
ContainerWait(ctx context.Context, container string, condition containertypes.WaitCondition) (<-chan containertypes.ContainerWaitOKBody, <-chan error)
ContainerWait(ctx context.Context, container string, condition containertypes.WaitCondition) (<-chan containertypes.WaitResponse, <-chan error)
ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error)
ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error
}
Loading

0 comments on commit afff088

Please sign in to comment.