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

feat: handle distroless for upgrade all packages #570

Merged
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3750a02
propogate error
ashnamehrotra Apr 5, 2024
d5a1059
do not need to set unassigned updates to nil
ashnamehrotra Apr 5, 2024
5f7e590
specify linux for OS in ExtractFileFromState and get archi
ashnamehrotra Apr 5, 2024
a8a6f57
save debugging
ashnamehrotra Apr 5, 2024
b4aa1e3
take OSVersion as pkgmgr arg
ashnamehrotra Apr 9, 2024
3c1c92e
working debian changes
ashnamehrotra Apr 9, 2024
a65c173
update vex unit tests for pkgmgr changes
ashnamehrotra Apr 9, 2024
5a037d3
saving part of debian changes
ashnamehrotra Apr 19, 2024
eefb00f
debian changes to read only outdated packages via packages.txt
ashnamehrotra Apr 23, 2024
c8031c8
cleanup
ashnamehrotra Apr 23, 2024
c0a9904
rpm changes - read from manifest2 and compare w yum info
ashnamehrotra Apr 23, 2024
843f264
cleanup
ashnamehrotra Apr 23, 2024
435fab5
handle platform OS case, more cleanup
ashnamehrotra Apr 23, 2024
aae6520
modify integration test to include distroless
ashnamehrotra Apr 23, 2024
51e2066
Merge branch 'main' of github.com:project-copacetic/copacetic into pa…
ashnamehrotra Apr 23, 2024
84e90f3
clarifications
ashnamehrotra Apr 23, 2024
4327c96
test all but custom dpkg/status.d
ashnamehrotra Apr 24, 2024
cfe7f56
rename test file
ashnamehrotra Apr 24, 2024
c6face3
run go mod tidy
ashnamehrotra Apr 24, 2024
e6cb18b
revert ignore errors test case
ashnamehrotra Apr 24, 2024
8d33292
fix description - fluent bit container does have apt
ashnamehrotra Apr 24, 2024
c89f379
fix unit test dpkg
ashnamehrotra Apr 24, 2024
3d96ff2
lint fix
ashnamehrotra Apr 24, 2024
c42224b
update golang.org/x/net to v0.23.0
ashnamehrotra Apr 24, 2024
6855c3a
downloadPath to dpkgDownloadPath const
ashnamehrotra Apr 24, 2024
ab28700
check for .md5sums file
ashnamehrotra Apr 24, 2024
611d610
patch test changes to test same set of images with ignore-errors false
ashnamehrotra Apr 24, 2024
64763ff
add kube-proxy v1.26.1 to integration test
ashnamehrotra Apr 24, 2024
8149583
libss1 to libssl1
ashnamehrotra Apr 25, 2024
e1284e3
add documentation
ashnamehrotra Apr 25, 2024
a0099f4
Merge branch 'main' of github.com:project-copacetic/copacetic into pa…
ashnamehrotra Apr 25, 2024
3cd0953
GetPackageInfo unit test
ashnamehrotra Apr 26, 2024
6038534
space formatting txt block
ashnamehrotra Apr 26, 2024
88656d4
getOsVersion unit test
ashnamehrotra Apr 26, 2024
04bd6bf
add darwin comment
ashnamehrotra Apr 26, 2024
c1081b0
update quickstart w documentation
ashnamehrotra Apr 27, 2024
8eaf7b6
Merge branch 'main' of github.com:project-copacetic/copacetic into pa…
ashnamehrotra Apr 27, 2024
3f7fa51
Merge branch 'main' of github.com:project-copacetic/copacetic into pa…
ashnamehrotra May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ toolchain go1.21.5

require (
github.com/aquasecurity/trivy v0.45.1
github.com/containerd/containerd v1.7.13
github.com/cpuguy83/dockercfg v0.3.1
github.com/cpuguy83/go-docker v0.3.0
github.com/distribution/reference v0.5.0
Expand Down Expand Up @@ -57,7 +58,6 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/console v1.0.4 // indirect
github.com/containerd/containerd v1.7.13 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/ttrpc v1.2.2 // indirect
Expand Down Expand Up @@ -152,12 +152,12 @@ require (
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.18.0 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201117144127-c1f2f97bffc9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 h1:hNQpMuAJe5CtcUqCXaWga3FHu+kQvCqcsoVaQgSV60o=
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
Expand All @@ -572,8 +572,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ=
golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o=
Expand Down Expand Up @@ -614,13 +614,13 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@
"description": "Valid dpkg/status, apt present, custom network config",
"ignoreErrors": false
},
{
"image": "docker.io/fluent/fluent-bit",
"tag": "1.8.4",
"digest": "sha256:2d80c13c2e7e06aa6a2e54a1825c6adbb3829c8a133ff617a0a61790bd61c53d",
"distro": "Google Distroless",
"description": "Custom dpkg/status.d with base64 names",
"ignoreErrors": false
},
{
"image": "docker.io/fluent/fluent-bit",
"tag": "1.8.4",
"digest": "sha256:2d80c13c2e7e06aa6a2e54a1825c6adbb3829c8a133ff617a0a61790bd61c53d",
"localName": "localimage:tag",
"distro": "Google Distroless",
"description": "Custom dpkg/status.d with base64 names, locally tagged with image name only",
"ignoreErrors": false
},
{
"image": "docker.io/openpolicyagent/opa",
"tag": "0.46.0",
"digest": "sha256:c4b11c9b86eaba41276ae682bb6875332316242010b7523efe30f365ad0c3cb8",
"distro": "Google Distroless",
"description": "Custom dpkg/status.d with text names, no apt, libssl1",
"ignoreErrors": false
},
{
"image": "quay.io/calico/cni",
"tag": "v3.15.1",
Expand All @@ -65,6 +90,14 @@
"description": "Valid rpm DB, no dnf, yum & rpm present, arm64 cross-arch",
"ignoreErrors": false
},
{
"image": "mcr.microsoft.com/cbl-mariner/distroless/base",
"tag": "2.0.20220527",
"digest": "sha256:f550c5428df17b145851ad75983aca6d613ad4b51ca7983b2a83e67d0ac91a5d",
"distro": "Mariner Distroless",
"description": "Custom rpmmanifest files, no yum/dnf/microdnf/rpm",
"ignoreErrors": false
},
{
"image": "docker.io/library/centos",
"tag": "7.6.1810",
Expand Down
4 changes: 2 additions & 2 deletions integration/fixtures/test-images.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"tag": "1.8.4",
"digest": "sha256:2d80c13c2e7e06aa6a2e54a1825c6adbb3829c8a133ff617a0a61790bd61c53d",
"distro": "Google Distroless",
"description": "Custom dpkg/status.d with base64 names, no apt",
"description": "Custom dpkg/status.d with base64 names",
"ignoreErrors": false
},
{
Expand All @@ -63,7 +63,7 @@
"digest": "sha256:2d80c13c2e7e06aa6a2e54a1825c6adbb3829c8a133ff617a0a61790bd61c53d",
"localName": "localimage:tag",
"distro": "Google Distroless",
"description": "Custom dpkg/status.d with base64 names, no apt, locally tagged with image name only",
"description": "Custom dpkg/status.d with base64 names, locally tagged with image name only",
"ignoreErrors": false
},
{
Expand Down
5 changes: 2 additions & 3 deletions integration/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ func TestPatch(t *testing.T) {
var file []byte
var err error

// test distroless and non-distroless
if reportFile {
file, err = os.ReadFile("fixtures/test-images.json")
if err != nil {
t.Error("Unable to read test-images", err)
}
} else {
// only test non-distroless
file, err = os.ReadFile("fixtures/test-images-non-distroless.json")
// test all images besides custom dpkg/status.d
file, err = os.ReadFile("fixtures/test-images-update-all.json")
if err != nil {
t.Error("Unable to read test-images", err)
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/buildkit/buildkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"

"github.com/containerd/containerd/platforms"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/client/llb/sourceresolver"
gwclient "github.com/moby/buildkit/frontend/gateway/client"
Expand Down Expand Up @@ -60,7 +61,12 @@ func InitializeBuildkitConfig(ctx context.Context, c gwclient.Client, image stri

// Extracts the bytes of the file denoted by `path` from the state `st`.
func ExtractFileFromState(ctx context.Context, c gwclient.Client, st *llb.State, path string) ([]byte, error) {
def, err := st.Marshal(ctx)
platform := platforms.Normalize(platforms.DefaultSpec())
if platform.OS != "linux" {
platform.OS = "linux"
}

def, err := st.Marshal(ctx, llb.Platform(platform))
if err != nil {
return nil, err
}
Expand Down
33 changes: 27 additions & 6 deletions pkg/patch/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/containerd/containerd/platforms"
"github.com/docker/buildx/build"
"github.com/docker/cli/cli/config"
log "github.com/sirupsen/logrus"
Expand All @@ -19,6 +20,7 @@ import (

"github.com/distribution/reference"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
gwclient "github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/session"
Expand Down Expand Up @@ -188,17 +190,21 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
return nil, err
}

osVersion, err := getOSVersion(ctx, fileBytes)
if err != nil {
ch <- err
return nil, err
}

// get package manager based on os family type
manager, err = pkgmgr.GetPackageManager(osType, config, workingFolder)
manager, err = pkgmgr.GetPackageManager(osType, osVersion, config, workingFolder)
if err != nil {
ch <- err
return nil, err
}
// do not specify updates, will update all
updates = nil
} else {
// get package manager based on os family type
manager, err = pkgmgr.GetPackageManager(updates.Metadata.OS.Type, config, workingFolder)
manager, err = pkgmgr.GetPackageManager(updates.Metadata.OS.Type, updates.Metadata.OS.Version, config, workingFolder)
if err != nil {
ch <- err
return nil, err
Expand All @@ -213,10 +219,15 @@ func patchWithContext(ctx context.Context, ch chan error, image, reportFile, pat
return nil, err
}

def, err := patchedImageState.Marshal(ctx)
platform := platforms.Normalize(platforms.DefaultSpec())
if platform.OS != "linux" {
platform.OS = "linux"
}

def, err := patchedImageState.Marshal(ctx, llb.Platform(platform))
if err != nil {
ch <- err
return nil, err
return nil, fmt.Errorf("unable to get platform from ImageState %w", err)
}

res, err := c.Solve(ctx, gwclient.SolveRequest{
Expand Down Expand Up @@ -319,6 +330,16 @@ func getOSType(ctx context.Context, osreleaseBytes []byte) (string, error) {
}
}

func getOSVersion(ctx context.Context, osreleaseBytes []byte) (string, error) {
r := bytes.NewReader(osreleaseBytes)
osData, err := osrelease.Parse(ctx, r)
if err != nil {
return "", fmt.Errorf("unable to parse os-release data %w", err)
}

return osData["VERSION_ID"], nil
}

func dockerLoad(ctx context.Context, pipeR io.Reader) error {
cmd := exec.CommandContext(ctx, "docker", "load")
cmd.Stdin = pipeR
Expand Down
Loading
Loading