Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(agent): use new docker types, go upgrade #963

Merged
merged 10 commits into from
Apr 19, 2024
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (

require (
github.com/docker/distribution v2.8.2+incompatible
github.com/docker/docker v24.0.9+incompatible
github.com/docker/docker v26.0.1+incompatible
github.com/docker/go-connections v0.4.0
github.com/google/go-containerregistry v0.15.1
golang.org/x/sync v0.1.0
Expand All @@ -34,14 +34,22 @@ require (
require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/cli v23.0.5+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/vbatts/tar-split v0.11.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
)

require (
Expand Down
19 changes: 19 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v23.0.5+incompatible h1:ufWmAOuD3Vmr7JP2G5K3cyuNC4YZWiAsuDEvFVVDafE=
github.com/docker/cli v23.0.5+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8=
github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v24.0.9+incompatible h1:HPGzNmwfLZWdxHqK9/II92pyi1EpYKsAqcl4G0Of9v0=
github.com/docker/docker v24.0.9+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker v26.0.1+incompatible h1:t39Hm6lpXuXtgkF0dm1t9a5HkbUfdGy6XbWexmGr+hA=
github.com/docker/docker v26.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A=
github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
Expand All @@ -66,11 +70,16 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk=
github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
Expand Down Expand Up @@ -167,6 +176,8 @@ github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp9
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 h1:HfkjXDfhgVaN5rmueG8cL8KKeFNecRCXFhaJ2qZ5SKA=
github.com/moby/term v0.0.0-20221205130635-1aeaba878587/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down Expand Up @@ -232,6 +243,14 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1 h1:sxoY9kG1s1WpSYNyzm24rlwH4lnRYFXUVVBmKMBfRgw=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1/go.mod h1:9NiG9I2aHTKkcxqCILhjtyNA1QEiCjdBACv4IvrFQ+c=
go.opentelemetry.io/otel v1.10.0 h1:Y7DTJMR6zs1xkS/upamJYk0SxxN4C9AqRd77jmZnyY4=
go.opentelemetry.io/otel v1.10.0/go.mod h1:NbvWjCthWHKBEUMpf0/v8ZRZlni86PpGFEMA9pnQSnQ=
go.opentelemetry.io/otel/metric v0.31.0 h1:6SiklT+gfWAwWUR0meEMxQBtihpiEs4c+vL9spDTqUs=
go.opentelemetry.io/otel/metric v0.31.0/go.mod h1:ohmwj9KTSIeBnDBm/ZwH2PSZxZzoOaG2xZeekTRzL5A=
go.opentelemetry.io/otel/trace v1.10.0 h1:npQMbR8o7mum8uF95yFbOEJffhs1sbCOfDh8zAJiH5E=
go.opentelemetry.io/otel/trace v1.10.0/go.mod h1:Sij3YYczqAdz+EhmGhE6TpTxUO5/F/AzrK+kxfGqySM=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down
10 changes: 3 additions & 7 deletions golang/api/v1/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ type ContainerConfig struct {

// dagent only
// docker log config https://docs.docker.com/config/containers/logging/configure/
LogConfig *container.LogConfig `json:"logConfig"`
RestartPolicy builder.RestartPolicyName `json:"restartPolicy"`
LogConfig *container.LogConfig `json:"logConfig"`
RestartPolicy container.RestartPolicyMode `json:"restartPolicy"`
// bridge(container, default) host, none or network name
NetworkMode string `json:"networkMode"`
// extra networks
Expand Down Expand Up @@ -430,10 +430,6 @@ func (jsonConfig *Base64JSONBytes) UnmarshalJSON(b []byte) error {
}

cleaned := util.RemoveJSONComment(decoded)
if err != nil {
return err
}

*jsonConfig = Base64JSONBytes(cleaned)

return err
Expand Down Expand Up @@ -471,6 +467,6 @@ func SetDeploymentDefaults(
}

if deployImageRequest.ContainerConfig.RestartPolicy == "" {
deployImageRequest.ContainerConfig.RestartPolicy = builder.RestartUnlessStoppedRestartPolicy
deployImageRequest.ContainerConfig.RestartPolicy = container.RestartPolicyUnlessStopped
}
}
2 changes: 1 addition & 1 deletion golang/internal/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ func executeVersionDeployRequest(
dog.SetRequestID(imageReq.RequestID)

var versionData *v1.VersionData
if len(req.VersionName) > 0 {
if req.VersionName != "" {
versionData = &v1.VersionData{Version: req.VersionName, ReleaseNotes: req.ReleaseNotes}
}

Expand Down
11 changes: 6 additions & 5 deletions golang/internal/helper/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/rs/zerolog/log"

Expand Down Expand Up @@ -57,7 +58,7 @@ func deleteContainerByIDAndState(ctx context.Context, dog *dogger.DeploymentLogg
dog.WriteContainerState(common.ContainerState_WAITING, state, dogger.Info, "Removing container: "+helper.FirstN(id, VisibleIDLimit))
}

if err = cli.ContainerRemove(ctx, id, types.ContainerRemoveOptions{}); err != nil {
if err = cli.ContainerRemove(ctx, id, container.RemoveOptions{}); err != nil {
return fmt.Errorf("could not remove container (%s): %s", helper.FirstN(id, VisibleIDLimit), err.Error())
}

Expand Down Expand Up @@ -108,7 +109,7 @@ func GetAllContainers(ctx context.Context) ([]types.Container, error) {
log.Fatal().Err(err).Send()
}

containers, err := cli.ContainerList(ctx, types.ContainerListOptions{All: true})
containers, err := cli.ContainerList(ctx, container.ListOptions{All: true})
if err != nil {
return []types.Container{}, err
}
Expand Down Expand Up @@ -173,7 +174,7 @@ func DeleteImage(ctx context.Context, imageID string) error {
log.Fatal().Err(err).Send()
}

_, err = cli.ImageRemove(ctx, imageID, types.ImageRemoveOptions{})
_, err = cli.ImageRemove(ctx, imageID, image.RemoveOptions{})
return err
}

Expand All @@ -189,8 +190,8 @@ func checkOneContainer(containers []types.Container) (*types.Container, error) {
}
}

func containerListOptionsfilter(filtertype, filter string) types.ContainerListOptions {
return types.ContainerListOptions{
func containerListOptionsfilter(filtertype, filter string) container.ListOptions {
return container.ListOptions{
All: true,
Filters: filters.NewArgs(
filters.KeyValuePair{
Expand Down
6 changes: 3 additions & 3 deletions golang/internal/helper/docker/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (testSuite *DockerContainerHelperTestSuite) SetupSuite() {
preparedContainer := containerbuilder.NewDockerBuilder(context.Background()).
WithImage(nginxImage).
WithName(fmt.Sprintf("%s-%s", testSuite.prefix, testSuite.containerNames[i])).
WithRestartPolicy(containerbuilder.NoRestartPolicy)
WithRestartPolicy(container.RestartPolicyDisabled)
testSuite.testContainers = append(testSuite.testContainers, preparedContainer)
}
}
Expand All @@ -79,7 +79,7 @@ func (testSuite *DockerContainerHelperTestSuite) SetupTest() {
// this function executes after each test case
func (testSuite *DockerContainerHelperTestSuite) TearDownTest() {
containers, err := testSuite.dockerClient.ContainerList(testSuite.ctx,
types.ContainerListOptions{
container.ListOptions{
All: true,
Filters: filters.NewArgs(
filters.KeyValuePair{
Expand All @@ -97,7 +97,7 @@ func (testSuite *DockerContainerHelperTestSuite) TearDownTest() {
if err != nil {
log.Warn().Err(err).Send()
}
err = testSuite.dockerClient.ContainerRemove(testSuite.ctx, containers[i].ID, types.ContainerRemoveOptions{})
err = testSuite.dockerClient.ContainerRemove(testSuite.ctx, containers[i].ID, container.RemoveOptions{})
if err != nil {
log.Warn().Err(err).Send()
}
Expand Down
26 changes: 12 additions & 14 deletions golang/internal/helper/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/dyrector-io/dyrectorio/protobuf/go/agent"

"github.com/docker/distribution/reference"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
Expand Down Expand Up @@ -66,23 +66,21 @@ func GetRegistryURL(reg *string, registryAuth *RegistryAuth) string {
return registryAuth.URL
} else if reg != nil {
return *reg
} else {
return ""
}
return ""
}

func GetRegistryURLProto(reg *string, registryAuth *agent.RegistryAuth) string {
if registryAuth != nil {
return registryAuth.Url
} else if reg != nil {
return *reg
} else {
return ""
}
return ""
}

func GetImageByReference(ctx context.Context, cli client.APIClient, ref string) (*types.ImageSummary, error) {
images, err := cli.ImageList(ctx, types.ImageListOptions{
func GetImageByReference(ctx context.Context, cli client.APIClient, ref string) (*image.Summary, error) {
images, err := cli.ImageList(ctx, image.ListOptions{
Filters: filters.NewArgs(filters.KeyValuePair{Key: "reference", Value: ref}),
})
if err != nil {
Expand All @@ -105,7 +103,7 @@ func Exists(
logger io.StringWriter, expandedImageName, encodedAuth string,
) (*ExistResult, error) {
exists := ExistResult{}
images, err := cli.ImageList(ctx, types.ImageListOptions{
images, err := cli.ImageList(ctx, image.ListOptions{
Filters: filters.NewArgs(filters.KeyValuePair{Key: "reference", Value: expandedImageName}),
})
if err != nil {
Expand Down Expand Up @@ -163,7 +161,7 @@ func Pull(ctx context.Context, cli client.APIClient, logger io.StringWriter, exp
}
}

reader, err := cli.ImagePull(ctx, expandedImageName, types.ImagePullOptions{RegistryAuth: authCreds})
reader, err := cli.ImagePull(ctx, expandedImageName, image.PullOptions{RegistryAuth: authCreds})
if err != nil {
return err
}
Expand Down Expand Up @@ -248,7 +246,7 @@ func shouldUseLocalImage(ctx context.Context, cli client.APIClient,
}

func pullImage(ctx context.Context, cli client.APIClient, imageName, encodedAuth string) (io.ReadCloser, error) {
options := types.ImagePullOptions{
options := image.PullOptions{
RegistryAuth: encodedAuth,
}

Expand Down Expand Up @@ -349,8 +347,8 @@ func checkRemote(ctx context.Context, check remoteCheck) (err error) {
return errDigestsMatching
}

func ParseReference(image string) (reference.Reference, error) {
return reference.ParseAnyReference(strings.ToLower(image))
func ParseReference(img string) (reference.Reference, error) {
return reference.ParseAnyReference(strings.ToLower(img))
}

func ExpandImageName(imageWithTag string) (string, error) {
Expand All @@ -371,8 +369,8 @@ func ExpandImageName(imageWithTag string) (string, error) {
return named.String(), nil
}

func ExpandImageNameWithTag(image, tag string) (string, error) {
ref, err := ParseReference(image)
func ExpandImageNameWithTag(img, tag string) (string, error) {
ref, err := ParseReference(img)
if err != nil {
return "", err
}
Expand Down
8 changes: 1 addition & 7 deletions golang/internal/mapper/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func mapDagentConfig(dagent *agent.DagentContainerConfig, containerConfig *v1.Co
}

if dagent.RestartPolicy != nil {
containerConfig.RestartPolicy = mapRestartPolicy(dagent.RestartPolicy.String())
containerConfig.RestartPolicy = container.RestartPolicyMode(dagent.RestartPolicy.String())
}

if dagent.LogConfig != nil {
Expand Down Expand Up @@ -229,12 +229,6 @@ func mapCraneConfig(crane *agent.CraneContainerConfig, containerConfig *v1.Conta
}
}

func mapRestartPolicy(policy string) builder.RestartPolicyName {
lower := strings.ToLower(policy)

return builder.RestartPolicyName(strings.Replace(lower, "_", "-", -1))
}

func mapContainerState(state common.ContainerState) v1.ContainerState {
switch state {
case common.ContainerState_CONTAINER_STATE_UNSPECIFIED:
Expand Down
Loading
Loading