diff --git a/docker-compose.yml b/docker-compose.yml index 17722ff6..260d5661 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,7 +51,7 @@ services: # https://go-vela.github.io/docs/administration/server/ server: container_name: server - image: target/vela-server:latest + image: ${VELA_SERVER_IMAGE:-target/vela-server:latest} networks: - vela environment: diff --git a/executor/linux/build_test.go b/executor/linux/build_test.go index 59140560..35f07d99 100644 --- a/executor/linux/build_test.go +++ b/executor/linux/build_test.go @@ -1920,9 +1920,7 @@ func TestLinux_DestroyBuild(t *testing.T) { if logEntry.Level == logrus.ErrorLevel { // Ignore error from not mocking something in the VelaClient if strings.HasPrefix(logEntry.Message, "unable to upload") || - (strings.HasPrefix(logEntry.Message, "unable to destroy") && - strings.Contains(logEntry.Message, "No such container") && - strings.HasSuffix(logEntry.Message, "_notfound")) { + strings.HasSuffix(logEntry.Message, "not found") { // unable to upload final step state: Step 0 does not exist // unable to upload service snapshot: Service 0 does not exist // unable to destroy secret: Error: No such container: secret_github_octocat_1_notfound diff --git a/go.mod b/go.mod index c50d81c9..0e560cd7 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/Masterminds/semver/v3 v3.4.0 github.com/containerd/errdefs v1.0.0 github.com/distribution/reference v0.6.0 - github.com/docker/docker v28.5.1+incompatible github.com/docker/go-units v0.5.0 github.com/gin-gonic/gin v1.11.0 github.com/go-vela/sdk-go v0.27.1 @@ -14,7 +13,8 @@ require ( github.com/golang-jwt/jwt/v5 v5.3.0 github.com/google/go-cmp v0.7.0 github.com/joho/godotenv v1.5.1 - github.com/opencontainers/image-spec v1.1.1 + github.com/moby/moby/api v1.52.0 + github.com/moby/moby/client v0.1.0 github.com/prometheus/client_golang v1.23.2 github.com/sirupsen/logrus v1.9.3 github.com/urfave/cli/v3 v3.5.0 @@ -33,7 +33,6 @@ require ( github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect github.com/cenkalti/backoff/v5 v5.0.2 // indirect - github.com/containerd/containerd/v2 v2.1.3 // indirect github.com/containerd/errdefs/pkg v0.3.0 // indirect github.com/expr-lang/expr v1.17.6 // indirect github.com/fxamacker/cbor/v2 v2.9.0 // indirect @@ -54,7 +53,7 @@ require ( github.com/lib/pq v1.10.9 // indirect github.com/mattn/go-sqlite3 v1.14.28 // indirect github.com/microcosm-cc/bluemonday v1.0.27 // indirect - github.com/moby/sys/atomicwriter v0.1.0 // indirect + github.com/opencontainers/image-spec v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qpack v0.5.1 // indirect github.com/quic-go/quic-go v0.54.0 // indirect @@ -96,12 +95,11 @@ require ( github.com/bytedance/sonic/loader v0.3.0 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudwego/base64x v0.1.6 // indirect - github.com/containerd/log v0.1.0 // indirect github.com/coreos/go-semver v0.3.1 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect - github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-connections v0.6.0 // indirect github.com/drone/envsubst v1.0.3 // indirect github.com/emicklei/go-restful/v3 v3.12.2 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect @@ -140,10 +138,8 @@ require ( github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect - github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect - github.com/morikuni/aec v1.0.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect diff --git a/go.sum b/go.sum index 05873cb6..8da7d657 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= -github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= -github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb h1:ZVN4Iat3runWOFLaBCDVU5a9X/XikSRBosye++6gojw= github.com/Bose/minisentinel v0.0.0-20200130220412-917c5a9223bb/go.mod h1:WsAABbY4HQBgd3mGuG4KMNTbHJCPvx9IVBHzysbknss= github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= @@ -46,18 +44,13 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= -github.com/containerd/containerd/v2 v2.1.3 h1:eMD2SLcIQPdMlnlNF6fatlrlRLAeDaiGPGwmRKLZKNs= -github.com/containerd/containerd/v2 v2.1.3/go.mod h1:8C5QV9djwsYDNhxfTCFjWtTBZrqjditQ4/ghHSYjnHM= github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M= github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE= github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk= -github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= -github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4= github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -68,10 +61,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= 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/docker v28.5.1+incompatible h1:Bm8DchhSD2J6PsFzxC35TZo4TLGR2PdW/E69rU45NhM= -github.com/docker/docker v28.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= -github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= -github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94= +github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g= @@ -136,8 +127,6 @@ github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6 github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo= github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= @@ -239,20 +228,16 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= 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/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw= -github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs= -github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU= -github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko= -github.com/moby/term v0.0.0-20201216013528-df9cb8a40635 h1:rzf0wL0CHVc8CEsgyygG0Mn9CNCCPZqOPaz8RiiHYQk= -github.com/moby/term v0.0.0-20201216013528-df9cb8a40635/go.mod h1:FBS0z0QWA44HXygs7VXDUOGoN/1TV3RuWkLO04am3wc= +github.com/moby/moby/api v1.52.0 h1:00BtlJY4MXkkt84WhUZPRqt5TvPbgig2FZvTbe3igYg= +github.com/moby/moby/api v1.52.0/go.mod h1:8mb+ReTlisw4pS6BRzCMts5M49W5M7bKt1cJy/YbAqc= +github.com/moby/moby/client v0.1.0 h1:nt+hn6O9cyJQqq5UWnFGqsZRTS/JirUqzPjEl0Bdc/8= +github.com/moby/moby/client v0.1.0/go.mod h1:O+/tw5d4a1Ha/ZA/tPxIZJapJRUS6LNZ1wiVRxYHyUE= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8= github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= -github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM= @@ -265,7 +250,6 @@ github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJw github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -296,7 +280,6 @@ github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA= github.com/spf13/afero v1.14.0/go.mod h1:acJQ8t0ohCGuMN3O+Pv0V0hgMxNYDlvdk+VTfyZmbYo= github.com/spf13/cast v1.8.0 h1:gEN9K4b8Xws4EX0+a0reLmhq8moKn7ntRlQYgjPeCDk= github.com/spf13/cast v1.8.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= -github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -376,7 +359,6 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg= golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -392,7 +374,6 @@ golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -407,7 +388,6 @@ golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= @@ -443,7 +423,6 @@ gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ= gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8= gorm.io/gorm v1.30.2 h1:f7bevlVoVe4Byu3pmbWPVHnPsLoWaMjEb7/clyr9Ivs= gorm.io/gorm v1.30.2/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= -gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM= @@ -458,6 +437,8 @@ k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOP k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b/go.mod h1:UZ2yyWbFTpuhSbFhv24aGNOdoRdJZgsIObGBUaYVsts= k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 h1:hwvWFiBzdWw1FhfY1FooPn3kzWuJ8tmbZBHi4zVsl1Y= k8s.io/utils v0.0.0-20250604170112-4c0f3b243397/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk= +pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE= sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= diff --git a/mock/docker/checkpoint.go b/mock/docker/checkpoint.go index 27572c43..ee7e886b 100644 --- a/mock/docker/checkpoint.go +++ b/mock/docker/checkpoint.go @@ -5,21 +5,30 @@ package docker import ( "context" - "github.com/docker/docker/api/types/checkpoint" + "github.com/moby/moby/client" ) // CheckpointService implements all the checkpoint // related functions for the Docker mock. type CheckpointService struct{} -func (cp *CheckpointService) CheckpointCreate(_ context.Context, _ string, _ checkpoint.CreateOptions) error { - return nil +func (cp *CheckpointService) CheckpointCreate(_ context.Context, _ string, _ client.CheckpointCreateOptions) (client.CheckpointCreateResult, error) { + return client.CheckpointCreateResult{}, nil } -func (cp *CheckpointService) CheckpointDelete(_ context.Context, _ string, _ checkpoint.DeleteOptions) error { - return nil +func (cp *CheckpointService) CheckpointRemove(_ context.Context, _ string, _ client.CheckpointRemoveOptions) (client.CheckpointRemoveResult, error) { + return client.CheckpointRemoveResult{}, nil } -func (cp *CheckpointService) CheckpointList(_ context.Context, _ string, _ checkpoint.ListOptions) ([]checkpoint.Summary, error) { - return nil, nil +func (cp *CheckpointService) CheckpointList(_ context.Context, _ string, _ client.CheckpointListOptions) (client.CheckpointListResult, error) { + return client.CheckpointListResult{}, nil } + +// WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES +// +// This line serves as a quick and efficient way to ensure that our +// ImageService satisfies the ImageAPIClient interface that +// the Docker client expects. +// +// https://pkg.go.dev/github.com/docker/docker/client#ConfigAPIClient +var _ client.CheckpointAPIClient = (*CheckpointService)(nil) diff --git a/mock/docker/config.go b/mock/docker/config.go index 04d2fc58..ba32d7ac 100644 --- a/mock/docker/config.go +++ b/mock/docker/config.go @@ -6,8 +6,7 @@ package docker import ( "context" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) // ConfigService implements all the config @@ -17,34 +16,36 @@ type ConfigService struct{} // ConfigCreate is a helper function to simulate // a mocked call to create a config for a // Docker swarm cluster. -func (c *ConfigService) ConfigCreate(_ context.Context, _ swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) { - return swarm.ConfigCreateResponse{}, nil +func (c *ConfigService) ConfigCreate(_ context.Context, _ client.ConfigCreateOptions) (client.ConfigCreateResult, error) { + return client.ConfigCreateResult{}, nil } // ConfigInspectWithRaw is a helper function to simulate // a mocked call to inspect a config for a Docker swarm // cluster and return the raw body received from the API. -func (c *ConfigService) ConfigInspectWithRaw(_ context.Context, _ string) (swarm.Config, []byte, error) { - return swarm.Config{}, nil, nil +func (c *ConfigService) ConfigInspect(_ context.Context, _ string, _ client.ConfigInspectOptions) (client.ConfigInspectResult, error) { + return client.ConfigInspectResult{}, nil } // ConfigList is a helper function to simulate // a mocked call to list the configs for a // Docker swarm cluster. -func (c *ConfigService) ConfigList(_ context.Context, _ swarm.ConfigListOptions) ([]swarm.Config, error) { - return nil, nil +func (c *ConfigService) ConfigList(_ context.Context, _ client.ConfigListOptions) (client.ConfigListResult, error) { + return client.ConfigListResult{}, nil } // ConfigRemove is a helper function to simulate // a mocked call to remove a config for a // Docker swarm cluster. -func (c *ConfigService) ConfigRemove(_ context.Context, _ string) error { return nil } +func (c *ConfigService) ConfigRemove(_ context.Context, _ string, _ client.ConfigRemoveOptions) (client.ConfigRemoveResult, error) { + return client.ConfigRemoveResult{}, nil +} // ConfigUpdate is a helper function to simulate // a mocked call to update a config for a // Docker swarm cluster. -func (c *ConfigService) ConfigUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ConfigSpec) error { - return nil +func (c *ConfigService) ConfigUpdate(_ context.Context, _ string, _ client.ConfigUpdateOptions) (client.ConfigUpdateResult, error) { + return client.ConfigUpdateResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/mock/docker/container.go b/mock/docker/container.go index 46ead632..3dbe88b9 100644 --- a/mock/docker/container.go +++ b/mock/docker/container.go @@ -5,267 +5,130 @@ package docker import ( "bytes" "context" - "encoding/json" "errors" - "fmt" "io" "strings" "time" - "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/network" - "github.com/docker/docker/client" - "github.com/docker/docker/errdefs" - "github.com/docker/docker/pkg/stdcopy" - "github.com/docker/docker/pkg/stringid" - v1 "github.com/opencontainers/image-spec/specs-go/v1" + cerrdefs "github.com/containerd/errdefs" + "github.com/moby/moby/api/types/container" + "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/stringid" ) // ContainerService implements all the container // related functions for the Docker mock. type ContainerService struct{} -// ContainerAttach is a helper function to simulate -// a mocked call to attach a connection to a -// Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerAttach -func (c *ContainerService) ContainerAttach(_ context.Context, _ string, _ container.AttachOptions) (types.HijackedResponse, error) { - return types.HijackedResponse{}, nil -} - -// ContainerCommit is a helper function to simulate -// a mocked call to apply changes to a Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerCommit -func (c *ContainerService) ContainerCommit(_ context.Context, _ string, _ container.CommitOptions) (container.CommitResponse, error) { - return container.CommitResponse{}, nil -} - // ContainerCreate is a helper function to simulate // a mocked call to create a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerCreate -func (c *ContainerService) ContainerCreate(_ context.Context, config *container.Config, _ *container.HostConfig, _ *network.NetworkingConfig, _ *v1.Platform, ctn string) (container.CreateResponse, error) { +func (c *ContainerService) ContainerCreate(_ context.Context, opts client.ContainerCreateOptions) (client.ContainerCreateResult, error) { // verify a container was provided - if len(ctn) == 0 { - return container.CreateResponse{}, + if len(opts.Name) == 0 { + return client.ContainerCreateResult{}, errors.New("no container provided") } - // check if the container is notfound and - // check if the notfound should be ignored - if strings.Contains(ctn, "notfound") && - !strings.Contains(ctn, "ignorenotfound") { - return container.CreateResponse{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) - } - // check if the container is not-found and // check if the not-found should be ignored - if strings.Contains(ctn, "not-found") && - !strings.Contains(ctn, "ignore-not-found") { - return container.CreateResponse{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) + if strings.Contains(opts.Name, "not-found") && + !strings.Contains(opts.Name, "ignore-not-found") { + return client.ContainerCreateResult{}, cerrdefs.ErrNotFound } // check if the image is not found - if strings.Contains(config.Image, "notfound") || - strings.Contains(config.Image, "not-found") { - return container.CreateResponse{}, - errdefs.NotFound( - //nolint:staticcheck // messsage is capitalized to match Docker messages - fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", config.Image), - ) + if strings.Contains(opts.Config.Image, "notfound") || + strings.Contains(opts.Config.Image, "not-found") { + return client.ContainerCreateResult{}, cerrdefs.ErrNotFound } // create response object to return - response := container.CreateResponse{ + response := client.ContainerCreateResult{ ID: stringid.GenerateRandomID(), } return response, nil } -// ContainerDiff is a helper function to simulate -// a mocked call to show the differences in the -// filesystem between two Docker containers. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerDiff -func (c *ContainerService) ContainerDiff(_ context.Context, _ string) ([]container.FilesystemChange, error) { - return nil, nil -} - -// ContainerExecAttach is a helper function to simulate -// a mocked call to attach a connection to a process -// running inside a Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecAttach -func (c *ContainerService) ContainerExecAttach(_ context.Context, _ string, _ container.ExecAttachOptions) (types.HijackedResponse, error) { - return types.HijackedResponse{}, nil -} - -// ContainerExecCreate is a helper function to simulate -// a mocked call to create a process to run inside a -// Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecCreate -func (c *ContainerService) ContainerExecCreate(_ context.Context, _ string, _ container.ExecOptions) (container.ExecCreateResponse, error) { - return container.ExecCreateResponse{}, nil -} - -// ContainerExecInspect is a helper function to simulate -// a mocked call to inspect a process running inside a -// Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecInspect -func (c *ContainerService) ContainerExecInspect(_ context.Context, _ string) (container.ExecInspect, error) { - return container.ExecInspect{}, nil -} - -// ContainerExecResize is a helper function to simulate -// a mocked call to resize the tty for a process running -// inside a Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecResize -func (c *ContainerService) ContainerExecResize(_ context.Context, _ string, _ container.ResizeOptions) error { - return nil -} - -// ContainerExecStart is a helper function to simulate -// a mocked call to start a process inside a Docker -// container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExecStart -func (c *ContainerService) ContainerExecStart(_ context.Context, _ string, _ container.ExecStartOptions) error { - return nil -} - -// ContainerExport is a helper function to simulate -// a mocked call to expore the contents of a Docker -// container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExport -func (c *ContainerService) ContainerExport(_ context.Context, _ string) (io.ReadCloser, error) { - return nil, nil -} - // ContainerInspect is a helper function to simulate // a mocked call to inspect a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerInspect -func (c *ContainerService) ContainerInspect(_ context.Context, ctn string) (container.InspectResponse, error) { +func (c *ContainerService) ContainerInspect(_ context.Context, ctn string, _ client.ContainerInspectOptions) (client.ContainerInspectResult, error) { // verify a container was provided if len(ctn) == 0 { - return container.InspectResponse{}, errors.New("no container provided") + return client.ContainerInspectResult{}, errors.New("no container provided") } // check if the container is notfound and // check if the notfound should be ignored if strings.Contains(ctn, "notfound") && !strings.Contains(ctn, "ignorenotfound") { - return container.InspectResponse{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) + return client.ContainerInspectResult{}, cerrdefs.ErrNotFound } // check if the container is not-found and // check if the not-found should be ignored if strings.Contains(ctn, "not-found") && !strings.Contains(ctn, "ignore-not-found") { - return container.InspectResponse{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) + return client.ContainerInspectResult{}, cerrdefs.ErrNotFound } // create response object to return - response := container.InspectResponse{ - ContainerJSONBase: &container.ContainerJSONBase{ + response := client.ContainerInspectResult{ + Container: container.InspectResponse{ ID: stringid.GenerateRandomID(), Image: "alpine:latest", Name: ctn, State: &container.State{Running: true}, }, - Config: &container.Config{ - Image: "alpine:latest", - }, } return response, nil } -// ContainerInspectWithRaw is a helper function to simulate -// a mocked call to inspect a Docker container and return -// the raw body received from the API. +// ContainerList is a helper function to simulate +// a mocked call to list Docker containers. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerInspectWithRaw -func (c *ContainerService) ContainerInspectWithRaw(_ context.Context, ctn string, _ bool) (container.InspectResponse, []byte, error) { - // verify a container was provided - if len(ctn) == 0 { - return container.InspectResponse{}, nil, errors.New("no container provided") - } - - // check if the container is not found - if strings.Contains(ctn, "notfound") || - strings.Contains(ctn, "not-found") { - return container.InspectResponse{}, - nil, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) - } - - // create response object to return - response := container.InspectResponse{ - ContainerJSONBase: &container.ContainerJSONBase{ - ID: stringid.GenerateRandomID(), - Image: "alpine:latest", - Name: ctn, - State: &container.State{Running: true}, - }, - Config: &container.Config{ - Image: "alpine:latest", - }, - } - - // marshal response into raw bytes - b, err := json.Marshal(response) - if err != nil { - return container.InspectResponse{}, nil, err - } +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerList +func (c *ContainerService) ContainerList(_ context.Context, _ client.ContainerListOptions) (client.ContainerListResult, error) { + return client.ContainerListResult{}, nil +} - return response, b, nil +// ContainerUpdate is a helper function to simulate +// a mocked call to update a Docker container. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerUpdate +func (c *ContainerService) ContainerUpdate(_ context.Context, _ string, _ client.ContainerUpdateOptions) (client.ContainerUpdateResult, error) { + return client.ContainerUpdateResult{}, nil } -// ContainerKill is a helper function to simulate -// a mocked call to kill a Docker container. +// ContainerRemove is a helper function to simulate +// a mocked call to remove a Docker container. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerKill -func (c *ContainerService) ContainerKill(_ context.Context, ctn, _ string) error { +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRemove +func (c *ContainerService) ContainerRemove(_ context.Context, ctn string, _ client.ContainerRemoveOptions) (client.ContainerRemoveResult, error) { // verify a container was provided if len(ctn) == 0 { - return errors.New("no container provided") + return client.ContainerRemoveResult{}, errors.New("no container provided") } // check if the container is not found - if strings.Contains(ctn, "notfound") || - strings.Contains(ctn, "not-found") { - //nolint:staticcheck // messsage is capitalized to match Docker messages - return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) + if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { + return client.ContainerRemoveResult{}, cerrdefs.ErrNotFound } - return nil + return client.ContainerRemoveResult{}, nil } -// ContainerList is a helper function to simulate -// a mocked call to list Docker containers. +// ContainersPrune is a helper function to simulate +// a mocked call to prune Docker containers. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerList -func (c *ContainerService) ContainerList(_ context.Context, _ container.ListOptions) ([]container.Summary, error) { - return nil, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainersPrune +func (c *ContainerService) ContainerPrune(_ context.Context, _ client.ContainerPruneOptions) (client.ContainerPruneResult, error) { + return client.ContainerPruneResult{}, nil } // ContainerLogs is a helper function to simulate @@ -273,7 +136,7 @@ func (c *ContainerService) ContainerList(_ context.Context, _ container.ListOpti // Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerLogs -func (c *ContainerService) ContainerLogs(_ context.Context, ctn string, _ container.LogsOptions) (io.ReadCloser, error) { +func (c *ContainerService) ContainerLogs(_ context.Context, ctn string, _ client.ContainerLogsOptions) (client.ContainerLogsResult, error) { // verify a container was provided if len(ctn) == 0 { return nil, errors.New("no container provided") @@ -282,163 +145,75 @@ func (c *ContainerService) ContainerLogs(_ context.Context, ctn string, _ contai // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:staticcheck // messsage is capitalized to match Docker messages - return nil, errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) - } - - // create response object to return - response := new(bytes.Buffer) - - // write stdout logs to response buffer - _, err := stdcopy. - NewStdWriter(response, stdcopy.Stdout). - Write([]byte("hello to stdout from github.com/go-vela/worker/mock/docker")) - if err != nil { - return nil, err - } - - // write stderr logs to response buffer - _, err = stdcopy. - NewStdWriter(response, stdcopy.Stderr). - Write([]byte("hello to stderr from github.com/go-vela/worker/mock/docker")) - if err != nil { - return nil, err + return nil, cerrdefs.ErrNotFound } - return io.NopCloser(response), nil -} - -// ContainerPause is a helper function to simulate -// a mocked call to pause a running Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerPause -func (c *ContainerService) ContainerPause(_ context.Context, _ string) error { - return nil -} - -// ContainerRemove is a helper function to simulate -// a mocked call to remove a Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRemove -func (c *ContainerService) ContainerRemove(_ context.Context, ctn string, _ container.RemoveOptions) error { - // verify a container was provided - if len(ctn) == 0 { - return errors.New("no container provided") - } - - // check if the container is not found - if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:staticcheck // messsage is capitalized to match Docker messages - return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) - } + var buf bytes.Buffer + buf.WriteString("hello to stdout from github.com/go-vela/worker/mock/docker\n") + buf.WriteString("hello to stderr from github.com/go-vela/worker/mock/docker\n") - return nil -} - -// ContainerRename is a helper function to simulate -// a mocked call to rename a Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRename -func (c *ContainerService) ContainerRename(_ context.Context, _ string, _ string) error { - return nil -} - -// ContainerResize is a helper function to simulate -// a mocked call to resize a Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerResize -func (c *ContainerService) ContainerResize(_ context.Context, _ string, _ container.ResizeOptions) error { - return nil -} - -// ContainerRestart is a helper function to simulate -// a mocked call to restart a Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRestart -func (c *ContainerService) ContainerRestart(_ context.Context, _ string, _ container.StopOptions) error { - return nil + return io.NopCloser(&buf), nil } // ContainerStart is a helper function to simulate // a mocked call to start a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStart -func (c *ContainerService) ContainerStart(_ context.Context, ctn string, _ container.StartOptions) error { +func (c *ContainerService) ContainerStart(_ context.Context, ctn string, _ client.ContainerStartOptions) (client.ContainerStartResult, error) { // verify a container was provided if len(ctn) == 0 { - return errors.New("no container provided") + return client.ContainerStartResult{}, errors.New("no container provided") } // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:staticcheck // messsage is capitalized to match Docker messages - return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) + return client.ContainerStartResult{}, cerrdefs.ErrNotFound } - return nil -} - -// ContainerStatPath is a helper function to simulate -// a mocked call to capture information about a path -// inside a Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStatPath -func (c *ContainerService) ContainerStatPath(_ context.Context, _ string, _ string) (container.PathStat, error) { - return container.PathStat{}, nil -} - -// ContainerStats is a helper function to simulate -// a mocked call to capture information about a -// Docker container. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStats -func (c *ContainerService) ContainerStats(_ context.Context, _ string, _ bool) (container.StatsResponseReader, error) { - return container.StatsResponseReader{}, nil + return client.ContainerStartResult{}, nil } // ContainerStop is a helper function to simulate // a mocked call to stop a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStop -func (c *ContainerService) ContainerStop(_ context.Context, ctn string, _ container.StopOptions) error { +func (c *ContainerService) ContainerStop(_ context.Context, ctn string, _ client.ContainerStopOptions) (client.ContainerStopResult, error) { // verify a container was provided if len(ctn) == 0 { - return errors.New("no container provided") + return client.ContainerStopResult{}, errors.New("no container provided") } // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { - //nolint:staticcheck // messsage is capitalized to match Docker messages - return errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) + return client.ContainerStopResult{}, cerrdefs.ErrNotFound } - return nil + return client.ContainerStopResult{}, nil } -// ContainerTop is a helper function to simulate -// a mocked call to show running processes inside -// a Docker container. +// ContainerRestart is a helper function to simulate +// a mocked call to restart a Docker container. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerTop -func (c *ContainerService) ContainerTop(_ context.Context, _ string, _ []string) (container.TopResponse, error) { - return container.TopResponse{}, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRestart +func (c *ContainerService) ContainerRestart(_ context.Context, _ string, _ client.ContainerRestartOptions) (client.ContainerRestartResult, error) { + return client.ContainerRestartResult{}, nil } -// ContainerUnpause is a helper function to simulate -// a mocked call to unpause a Docker container. +// ContainerPause is a helper function to simulate +// a mocked call to pause a running Docker container. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerUnpause -func (c *ContainerService) ContainerUnpause(_ context.Context, _ string) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerPause +func (c *ContainerService) ContainerPause(_ context.Context, _ string, _ client.ContainerPauseOptions) (client.ContainerPauseResult, error) { + return client.ContainerPauseResult{}, nil } -// ContainerUpdate is a helper function to simulate -// a mocked call to update a Docker container. +// ContainerUnpause is a helper function to simulate +// a mocked call to unpause a Docker container. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerUpdate -func (c *ContainerService) ContainerUpdate(_ context.Context, _ string, _ container.UpdateConfig) (container.UpdateResponse, error) { - return container.UpdateResponse{}, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerUnpause +func (c *ContainerService) ContainerUnpause(_ context.Context, _ string, _ client.ContainerUnpauseOptions) (client.ContainerUnpauseResult, error) { + return client.ContainerUnpauseResult{}, nil } // ContainerWait is a helper function to simulate @@ -446,25 +221,29 @@ func (c *ContainerService) ContainerUpdate(_ context.Context, _ string, _ contai // container to finish. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerWait -func (c *ContainerService) ContainerWait(_ context.Context, ctn string, _ container.WaitCondition) (<-chan container.WaitResponse, <-chan error) { +func (c *ContainerService) ContainerWait(_ context.Context, ctn string, _ client.ContainerWaitOptions) client.ContainerWaitResult { ctnCh := make(chan container.WaitResponse, 1) errCh := make(chan error, 1) + result := client.ContainerWaitResult{ + Result: ctnCh, + Error: errCh, + } + // verify a container was provided if len(ctn) == 0 { // propagate the error to the error channel errCh <- errors.New("no container provided") - return ctnCh, errCh + return result } // check if the container is not found if strings.Contains(ctn, "notfound") || strings.Contains(ctn, "not-found") { // propagate the error to the error channel - //nolint:staticcheck // messsage is capitalized to match Docker messages - errCh <- errdefs.NotFound(fmt.Errorf("Error: No such container: %s", ctn)) + errCh <- cerrdefs.ErrNotFound - return ctnCh, errCh + return result } // create goroutine for responding to call @@ -484,39 +263,120 @@ func (c *ContainerService) ContainerWait(_ context.Context, ctn string, _ contai errCh <- nil }() - return ctnCh, errCh + return result } -// ContainersPrune is a helper function to simulate -// a mocked call to prune Docker containers. +// ContainerKill is a helper function to simulate +// a mocked call to kill a Docker container. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainersPrune -func (c *ContainerService) ContainersPrune(_ context.Context, _ filters.Args) (container.PruneReport, error) { - return container.PruneReport{}, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerKill +func (c *ContainerService) ContainerKill(_ context.Context, ctn string, _ client.ContainerKillOptions) (client.ContainerKillResult, error) { + // verify a container was provided + if len(ctn) == 0 { + return client.ContainerKillResult{}, errors.New("no container provided") + } + + // check if the container is not found + if strings.Contains(ctn, "notfound") || + strings.Contains(ctn, "not-found") { + return client.ContainerKillResult{}, cerrdefs.ErrNotFound + } + + return client.ContainerKillResult{}, nil +} + +// ContainerRename is a helper function to simulate +// a mocked call to rename a Docker container. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRename +func (c *ContainerService) ContainerRename(_ context.Context, _ string, _ client.ContainerRenameOptions) (client.ContainerRenameResult, error) { + return client.ContainerRenameResult{}, nil +} + +// ContainerResize is a helper function to simulate +// a mocked call to resize a Docker container. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerResize +func (c *ContainerService) ContainerResize(_ context.Context, _ string, _ client.ContainerResizeOptions) (client.ContainerResizeResult, error) { + return client.ContainerResizeResult{}, nil +} + +// ContainerAttach is a helper function to simulate +// a mocked call to attach a connection to a +// Docker container. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerAttach +func (c *ContainerService) ContainerAttach(_ context.Context, _ string, _ client.ContainerAttachOptions) (client.ContainerAttachResult, error) { + return client.ContainerAttachResult{}, nil } -// ContainerStatsOneShot is a helper function to simulate -// a mocked call to return near realtime stats for a given container. +// ContainerCommit is a helper function to simulate +// a mocked call to apply changes to a Docker container. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStatsOneShot -func (c *ContainerService) ContainerStatsOneShot(_ context.Context, _ string) (container.StatsResponseReader, error) { - return container.StatsResponseReader{}, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerCommit +func (c *ContainerService) ContainerCommit(_ context.Context, _ string, _ client.ContainerCommitOptions) (client.ContainerCommitResult, error) { + return client.ContainerCommitResult{}, nil +} + +// ContainerDiff is a helper function to simulate +// a mocked call to show the differences in the +// filesystem between two Docker containers. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerDiff +func (c *ContainerService) ContainerDiff(_ context.Context, _ string, _ client.ContainerDiffOptions) (client.ContainerDiffResult, error) { + return client.ContainerDiffResult{}, nil +} + +// ContainerExport is a helper function to simulate +// a mocked call to expore the contents of a Docker +// container. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerExport +func (c *ContainerService) ContainerExport(_ context.Context, _ string, _ client.ContainerExportOptions) (client.ContainerExportResult, error) { + return nil, nil +} + +// ContainerStats is a helper function to simulate +// a mocked call to capture information about a +// Docker container. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStats +func (c *ContainerService) ContainerStats(_ context.Context, _ string, _ client.ContainerStatsOptions) (client.ContainerStatsResult, error) { + return client.ContainerStatsResult{}, nil +} + +// ContainerTop is a helper function to simulate +// a mocked call to show running processes inside +// a Docker container. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerTop +func (c *ContainerService) ContainerTop(_ context.Context, _ string, _ client.ContainerTopOptions) (client.ContainerTopResult, error) { + return client.ContainerTopResult{}, nil +} + +// ContainerStatPath is a helper function to simulate +// a mocked call to capture information about a path +// inside a Docker container. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStatPath +func (c *ContainerService) ContainerStatPath(_ context.Context, _ string, _ client.ContainerStatPathOptions) (client.ContainerStatPathResult, error) { + return client.ContainerStatPathResult{}, nil } // CopyFromContainer is a helper function to simulate // a mocked call to copy content from a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.CopyFromContainer -func (c *ContainerService) CopyFromContainer(_ context.Context, _ string, _ string) (io.ReadCloser, container.PathStat, error) { - return nil, container.PathStat{}, nil +func (c *ContainerService) CopyFromContainer(_ context.Context, _ string, _ client.CopyFromContainerOptions) (client.CopyFromContainerResult, error) { + return client.CopyFromContainerResult{}, nil } // CopyToContainer is a helper function to simulate // a mocked call to copy content to a Docker container. // // https://pkg.go.dev/github.com/docker/docker/client#Client.CopyToContainer -func (c *ContainerService) CopyToContainer(_ context.Context, _ string, _ string, _ io.Reader, _ container.CopyToContainerOptions) error { - return nil +func (c *ContainerService) CopyToContainer(_ context.Context, _ string, _ client.CopyToContainerOptions) (client.CopyToContainerResult, error) { + return client.CopyToContainerResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/mock/docker/distribution.go b/mock/docker/distribution.go index 2247baeb..1a71d66c 100644 --- a/mock/docker/distribution.go +++ b/mock/docker/distribution.go @@ -5,8 +5,7 @@ package docker import ( "context" - "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) // DistributionService implements all the distribution @@ -16,8 +15,8 @@ type DistributionService struct{} // DistributionInspect is a helper function to simulate // a mocked call to inspect a Docker image and return // the digest and manifest. -func (d *DistributionService) DistributionInspect(_ context.Context, _ string, _ string) (registry.DistributionInspect, error) { - return registry.DistributionInspect{}, nil +func (d *DistributionService) DistributionInspect(_ context.Context, _ string, _ client.DistributionInspectOptions) (client.DistributionInspectResult, error) { + return client.DistributionInspectResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/mock/docker/exec.go b/mock/docker/exec.go new file mode 100644 index 00000000..26fd0586 --- /dev/null +++ b/mock/docker/exec.go @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: Apache-2.0 + +package docker + +import ( + "context" + + "github.com/moby/moby/client" +) + +// ExecService implements all the exec +// related functions for the Docker mock. +type ExecService struct{} + +// ExecCreate is a helper function to simulate +// a mocked call to create a Docker exec instance. +func (e *ExecService) ExecCreate(_ context.Context, _ string, _ client.ExecCreateOptions) (client.ExecCreateResult, error) { + return client.ExecCreateResult{}, nil +} + +// ExecInspect is a helper function to simulate +// a mocked call to inspect a Docker exec instance. +func (e *ExecService) ExecInspect(_ context.Context, _ string, _ client.ExecInspectOptions) (client.ExecInspectResult, error) { + return client.ExecInspectResult{}, nil +} + +// ExecResize is a helper function to simulate +// a mocked call to resize a Docker exec instance. +func (e *ExecService) ExecResize(_ context.Context, _ string, _ client.ExecResizeOptions) (client.ExecResizeResult, error) { + return client.ExecResizeResult{}, nil +} + +// ExecStart is a helper function to simulate +// a mocked call to start a Docker exec instance. +func (e *ExecService) ExecStart(_ context.Context, _ string, _ client.ExecStartOptions) (client.ExecStartResult, error) { + return client.ExecStartResult{}, nil +} + +// ExecAttach is a helper function to simulate +// a mocked call to attach to a Docker exec instance. +func (e *ExecService) ExecAttach(_ context.Context, _ string, _ client.ExecAttachOptions) (client.ExecAttachResult, error) { + return client.ExecAttachResult{}, nil +} + +// WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES +// +// This line serves as a quick and efficient way to ensure that our +// ExecService satisfies the ExecAPIClient interface that +// the Docker client expects. +var _ client.ExecAPIClient = (*ExecService)(nil) diff --git a/mock/docker/image.go b/mock/docker/image.go index cf70eb6b..18cf89bd 100644 --- a/mock/docker/image.go +++ b/mock/docker/image.go @@ -8,75 +8,125 @@ import ( "errors" "fmt" "io" + "iter" "strings" "time" - "github.com/docker/docker/api/types/build" - "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/api/types/storage" - "github.com/docker/docker/client" - "github.com/docker/docker/errdefs" - "github.com/docker/docker/pkg/stringid" + cerrdefs "github.com/containerd/errdefs" + "github.com/moby/moby/api/types/image" + "github.com/moby/moby/api/types/jsonstream" + "github.com/moby/moby/api/types/storage" + "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/stringid" ) // ImageService implements all the image // related functions for the Docker mock. type ImageService struct{} -// BuildCachePrune is a helper function to simulate -// a mocked call to prune the build cache for the -// Docker daemon. -func (i *ImageService) BuildCachePrune(_ context.Context, _ build.CachePruneOptions) (*build.CachePruneReport, error) { +// ImageImport is a helper function to simulate +// a mocked call to import a Docker image. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageImport +func (i *ImageService) ImageImport(_ context.Context, _ client.ImageImportSource, _ string, _ client.ImageImportOptions) (client.ImageImportResult, error) { return nil, nil } -// BuildCancel is a helper function to simulate -// a mocked call to cancel building a Docker image. -func (i *ImageService) BuildCancel(_ context.Context, _ string) error { +// ImageList is a helper function to simulate +// a mocked call to list Docker images. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageList +func (i *ImageService) ImageList(_ context.Context, _ client.ImageListOptions) (client.ImageListResult, error) { + return client.ImageListResult{}, nil +} + +type mockImagePullResponse struct { + r io.ReadCloser +} + +func (m *mockImagePullResponse) Read(p []byte) (int, error) { + return m.r.Read(p) +} + +func (m *mockImagePullResponse) Close() error { + return m.r.Close() +} + +func (m *mockImagePullResponse) JSONMessages(_ context.Context) iter.Seq2[jsonstream.Message, error] { return nil } -// ImageBuild is a helper function to simulate -// a mocked call to build a Docker image. +func (m *mockImagePullResponse) Wait(_ context.Context) error { + return nil +} + +// ImagePull is a helper function to simulate +// a mocked call to pull a Docker image. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageBuild -func (i *ImageService) ImageBuild(_ context.Context, _ io.Reader, _ build.ImageBuildOptions) (build.ImageBuildResponse, error) { - return build.ImageBuildResponse{}, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ImagePull +func (i *ImageService) ImagePull(_ context.Context, image string, _ client.ImagePullOptions) (client.ImagePullResponse, error) { + // verify an image was provided + if len(image) == 0 { + return nil, errors.New("no container provided") + } + + // check if the image is notfound and + // check if the notfound should be ignored + if strings.Contains(image, "notfound") && + !strings.Contains(image, "ignorenotfound") { + return nil, cerrdefs.ErrNotFound + } + + // check if the image is not-found and + // check if the not-found should be ignored + if strings.Contains(image, "not-found") && + !strings.Contains(image, "ignore-not-found") { + return nil, cerrdefs.ErrNotFound + } + + payload := fmt.Sprintf("%s\n%s\n%s\n%s\n", + fmt.Sprintf("latest: Pulling from %s", image), + fmt.Sprintf("Digest: sha256:%s", stringid.GenerateRandomID()), + fmt.Sprintf("Status: Image is up to date for %s", image), + image, + ) + + // simple non-streaming variant: all data available immediately + reader := io.NopCloser(bytes.NewReader([]byte(payload))) + + return &mockImagePullResponse{r: reader}, nil } -// ImageCreate is a helper function to simulate -// a mocked call to create a Docker image. +// ImagePush is a helper function to simulate +// a mocked call to push a Docker image. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageCreate -func (i *ImageService) ImageCreate(_ context.Context, _ string, _ image.CreateOptions) (io.ReadCloser, error) { +// https://pkg.go.dev/github.com/docker/docker/client#Client.ImagePush +func (i *ImageService) ImagePush(_ context.Context, _ string, _ client.ImagePushOptions) (client.ImagePushResponse, error) { return nil, nil } -// ImageHistory is a helper function to simulate -// a mocked call to inspect the history for a -// Docker image. +// ImageRemove is a helper function to simulate +// a mocked call to remove a Docker image. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageHistory -func (i *ImageService) ImageHistory(_ context.Context, _ string, _ ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) { - return nil, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageRemove +func (i *ImageService) ImageRemove(_ context.Context, _ string, _ client.ImageRemoveOptions) (client.ImageRemoveResult, error) { + return client.ImageRemoveResult{}, nil } -// ImageImport is a helper function to simulate -// a mocked call to import a Docker image. +// ImageTag is a helper function to simulate +// a mocked call to tag a Docker image. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageImport -func (i *ImageService) ImageImport(_ context.Context, _ image.ImportSource, _ string, _ image.ImportOptions) (io.ReadCloser, error) { - return nil, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageTag +func (i *ImageService) ImageTag(_ context.Context, _ client.ImageTagOptions) (client.ImageTagResult, error) { + return client.ImageTagResult{}, nil } -// ImageInspect is a helper function to simulate -// a mocked call to inspect a Docker image. +// ImagesPrune is a helper function to simulate +// a mocked call to prune Docker images. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageInspect -func (i *ImageService) ImageInspectWithRaw(_ context.Context, _ string) (image.InspectResponse, []byte, error) { - return image.InspectResponse{}, nil, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ImagesPrune +func (i *ImageService) ImagePrune(_ context.Context, _ client.ImagePruneOptions) (client.ImagePruneResult, error) { + return client.ImagePruneResult{}, nil } // ImageInspectWithRaw is a helper function to simulate @@ -84,36 +134,29 @@ func (i *ImageService) ImageInspectWithRaw(_ context.Context, _ string) (image.I // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageInspectWithRaw -func (i *ImageService) ImageInspect(_ context.Context, img string, _ ...client.ImageInspectOption) (image.InspectResponse, error) { +func (i *ImageService) ImageInspect(_ context.Context, img string, _ ...client.ImageInspectOption) (client.ImageInspectResult, error) { // verify an image was provided if len(img) == 0 { - return image.InspectResponse{}, errors.New("no image provided") + return client.ImageInspectResult{}, errors.New("no image provided") } // check if the image is not found if strings.Contains(img, "notfound") || strings.Contains(img, "not-found") { - return image.InspectResponse{}, - errdefs.NotFound( - //nolint:staticcheck // messsage is capitalized to match Docker messages - fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", img), - ) + return client.ImageInspectResult{}, cerrdefs.ErrNotFound } path := fmt.Sprintf("/var/lib/docker/overlay2/%s", stringid.GenerateRandomID()) // create response object to return response := image.InspectResponse{ - ID: fmt.Sprintf("sha256:%s", stringid.GenerateRandomID()), - RepoTags: []string{"alpine:latest"}, - RepoDigests: []string{fmt.Sprintf("alpine@sha256:%s", stringid.GenerateRandomID())}, - Created: time.Now().String(), - Container: fmt.Sprintf("sha256:%s", stringid.GenerateRandomID()), - DockerVersion: "19.03.1-ce", - Architecture: "amd64", - Os: "linux", - Size: 5552690, - VirtualSize: 5552690, - GraphDriver: storage.DriverData{ + ID: fmt.Sprintf("sha256:%s", stringid.GenerateRandomID()), + RepoTags: []string{"alpine:latest"}, + RepoDigests: []string{fmt.Sprintf("alpine@sha256:%s", stringid.GenerateRandomID())}, + Created: time.Now().String(), + Architecture: "amd64", + Os: "linux", + Size: 5552690, + GraphDriver: &storage.DriverData{ Data: map[string]string{ "MergedDir": fmt.Sprintf("%s/merged", path), "UpperDir": fmt.Sprintf("%s/diff", path), @@ -128,87 +171,23 @@ func (i *ImageService) ImageInspect(_ context.Context, img string, _ ...client.I Metadata: image.Metadata{LastTagTime: time.Now()}, } - return response, nil + return client.ImageInspectResult{InspectResponse: response}, nil } -// ImageList is a helper function to simulate -// a mocked call to list Docker images. +// ImageHistory is a helper function to simulate +// a mocked call to inspect the history for a +// Docker image. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageList -func (i *ImageService) ImageList(_ context.Context, _ image.ListOptions) ([]image.Summary, error) { - return nil, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageHistory +func (i *ImageService) ImageHistory(_ context.Context, _ string, _ ...client.ImageHistoryOption) (client.ImageHistoryResult, error) { + return client.ImageHistoryResult{}, nil } // ImageLoad is a helper function to simulate // a mocked call to load a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageLoad -func (i *ImageService) ImageLoad(_ context.Context, _ io.Reader, _ ...client.ImageLoadOption) (image.LoadResponse, error) { - return image.LoadResponse{}, nil -} - -// ImagePull is a helper function to simulate -// a mocked call to pull a Docker image. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImagePull -func (i *ImageService) ImagePull(_ context.Context, image string, _ image.PullOptions) (io.ReadCloser, error) { - // verify an image was provided - if len(image) == 0 { - return nil, errors.New("no container provided") - } - - // check if the image is notfound and - // check if the notfound should be ignored - if strings.Contains(image, "notfound") && - !strings.Contains(image, "ignorenotfound") { - return nil, - errdefs.NotFound( - //nolint:staticcheck // messsage is capitalized to match Docker messages - fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", image), - ) - } - - // check if the image is not-found and - // check if the not-found should be ignored - if strings.Contains(image, "not-found") && - !strings.Contains(image, "ignore-not-found") { - return nil, - errdefs.NotFound( - //nolint:staticcheck // messsage is capitalized to match Docker messages - fmt.Errorf("Error response from daemon: manifest for %s not found: manifest unknown", image), - ) - } - - // create response object to return - response := io.NopCloser( - bytes.NewReader( - []byte( - fmt.Sprintf("%s\n%s\n%s\n%s\n", - fmt.Sprintf("latest: Pulling from %s", image), - fmt.Sprintf("Digest: sha256:%s", stringid.GenerateRandomID()), - fmt.Sprintf("Status: Image is up to date for %s", image), - image, - ), - ), - ), - ) - - return response, nil -} - -// ImagePush is a helper function to simulate -// a mocked call to push a Docker image. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImagePush -func (i *ImageService) ImagePush(_ context.Context, _ string, _ image.PushOptions) (io.ReadCloser, error) { - return nil, nil -} - -// ImageRemove is a helper function to simulate -// a mocked call to remove a Docker image. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageRemove -func (i *ImageService) ImageRemove(_ context.Context, _ string, _ image.RemoveOptions) ([]image.DeleteResponse, error) { +func (i *ImageService) ImageLoad(_ context.Context, _ io.Reader, _ ...client.ImageLoadOption) (client.ImageLoadResult, error) { return nil, nil } @@ -216,34 +195,10 @@ func (i *ImageService) ImageRemove(_ context.Context, _ string, _ image.RemoveOp // a mocked call to save a Docker image. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImageSave -func (i *ImageService) ImageSave(_ context.Context, _ []string, _ ...client.ImageSaveOption) (io.ReadCloser, error) { +func (i *ImageService) ImageSave(_ context.Context, _ []string, _ ...client.ImageSaveOption) (client.ImageSaveResult, error) { return nil, nil } -// ImageSearch is a helper function to simulate -// a mocked call to search for a Docker image. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageSearch -func (i *ImageService) ImageSearch(_ context.Context, _ string, _ registry.SearchOptions) ([]registry.SearchResult, error) { - return nil, nil -} - -// ImageTag is a helper function to simulate -// a mocked call to tag a Docker image. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImageTag -func (i *ImageService) ImageTag(_ context.Context, _ string, _ string) error { - return nil -} - -// ImagesPrune is a helper function to simulate -// a mocked call to prune Docker images. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ImagesPrune -func (i *ImageService) ImagesPrune(_ context.Context, _ filters.Args) (image.PruneReport, error) { - return image.PruneReport{}, nil -} - // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES // // This line serves as a quick and efficient way to ensure that our diff --git a/mock/docker/image_build.go b/mock/docker/image_build.go new file mode 100644 index 00000000..6c58dd61 --- /dev/null +++ b/mock/docker/image_build.go @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: Apache-2.0 + +package docker + +import ( + "context" + "io" + + "github.com/moby/moby/client" +) + +// ImageBuildService implements all the image build +// related functions for the Docker mock. +type ImageBuildService struct{} + +// ExecCreate is a helper function to simulate +// a mocked call to create a Docker exec instance. +func (ib *ImageBuildService) ImageBuild(_ context.Context, _ io.Reader, _ client.ImageBuildOptions) (client.ImageBuildResult, error) { + return client.ImageBuildResult{}, nil +} + +// ExecInspect is a helper function to simulate +// a mocked call to inspect a Docker exec instance. +func (ib *ImageBuildService) BuildCachePrune(_ context.Context, _ client.BuildCachePruneOptions) (client.BuildCachePruneResult, error) { + return client.BuildCachePruneResult{}, nil +} + +// ExecResize is a helper function to simulate +// a mocked call to resize a Docker exec instance. +func (ib *ImageBuildService) BuildCancel(_ context.Context, _ string, _ client.BuildCancelOptions) (client.BuildCancelResult, error) { + return client.BuildCancelResult{}, nil +} + +// WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES +// +// This line serves as a quick and efficient way to ensure that our +// ExecService satisfies the ExecAPIClient interface that +// the Docker client expects. +var _ client.ImageBuildAPIClient = (*ImageBuildService)(nil) diff --git a/mock/docker/mock.go b/mock/docker/mock.go index 2b1ba546..a09c9d93 100644 --- a/mock/docker/mock.go +++ b/mock/docker/mock.go @@ -7,8 +7,7 @@ import ( "net" "net/http" - "github.com/docker/docker/api/types" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) type mock struct { @@ -17,14 +16,18 @@ type mock struct { ConfigService ContainerService DistributionService + ExecService ImageService + ImageBuildService NetworkService NodeService PluginService + RegistryService SecretService ServiceService SwarmService SystemService + TaskService VolumeService // Docker API version for the mock @@ -39,25 +42,27 @@ func (m *mock) ClientVersion() string { return m.Version } -// Close is a helper function to simulate -// closing the transport client for the mock. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.Close -func (m *mock) Close() error { - return nil -} - // DaemonHost is a helper function to simulate // returning the host address used by the client. func (m *mock) DaemonHost() string { return "" } -// DialSession is a helper function to simulate -// returning a connection that can be used -// for communication with daemon. -func (m *mock) DialSession(_ context.Context, _ string, _ map[string][]string) (net.Conn, error) { - return nil, nil +// ServerVersion is a helper function to simulate +// a mocked call to return information on the +// Docker client and server host. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ServerVersion +func (m *mock) ServerVersion(_ context.Context, _ client.ServerVersionOptions) (client.ServerVersionResult, error) { + return client.ServerVersionResult{}, nil +} + +// Dialer is a helper function to simulate +// returning a dialer for the raw stream +// connection, with HTTP/1.1 header, that can +// be used for proxying the daemon connection. +func (m *mock) Dialer() func(context.Context) (net.Conn, error) { + return func(context.Context) (net.Conn, error) { return nil, nil } } // DialHijack is a helper function to simulate @@ -67,12 +72,12 @@ func (m *mock) DialHijack(_ context.Context, _ string, _ string, _ map[string][] return nil, nil } -// Dialer is a helper function to simulate -// returning a dialer for the raw stream -// connection, with HTTP/1.1 header, that can -// be used for proxying the daemon connection. -func (m *mock) Dialer() func(context.Context) (net.Conn, error) { - return func(context.Context) (net.Conn, error) { return nil, nil } +// Close is a helper function to simulate +// closing the transport client for the mock. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.Close +func (m *mock) Close() error { + return nil } // HTTPClient is a helper function to simulate @@ -82,25 +87,6 @@ func (m *mock) HTTPClient() *http.Client { return http.DefaultClient } -// NegotiateAPIVersion is a helper function to simulate -// a mocked call to query the API and update the client -// version to match the API version. -func (m *mock) NegotiateAPIVersion(_ context.Context) {} - -// NegotiateAPIVersionPing is a helper function to simulate -// a mocked call to update the client version to match -// the ping version if it's less than the default version. -func (m *mock) NegotiateAPIVersionPing(types.Ping) {} - -// ServerVersion is a helper function to simulate -// a mocked call to return information on the -// Docker client and server host. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ServerVersion -func (m *mock) ServerVersion(_ context.Context) (types.Version, error) { - return types.Version{}, nil -} - // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES // // This line serves as a quick and efficient way to ensure diff --git a/mock/docker/network.go b/mock/docker/network.go index d8df185e..ce57d7aa 100644 --- a/mock/docker/network.go +++ b/mock/docker/network.go @@ -4,175 +4,135 @@ package docker import ( "context" - "encoding/json" "errors" - "fmt" "strings" "time" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/network" - "github.com/docker/docker/client" - "github.com/docker/docker/errdefs" - "github.com/docker/docker/pkg/stringid" + cerrdefs "github.com/containerd/errdefs" + "github.com/moby/moby/api/types/network" + "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/stringid" ) // NetworkService implements all the network // related functions for the Docker mock. type NetworkService struct{} -// NetworkConnect is a helper function to simulate -// a mocked call to connect to a Docker network. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkConnect -func (n *NetworkService) NetworkConnect(_ context.Context, _, _ string, _ *network.EndpointSettings) error { - return nil -} - // NetworkCreate is a helper function to simulate // a mocked call to create a Docker network. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkCreate -func (n *NetworkService) NetworkCreate(_ context.Context, name string, _ network.CreateOptions) (network.CreateResponse, error) { +func (n *NetworkService) NetworkCreate(_ context.Context, name string, _ client.NetworkCreateOptions) (client.NetworkCreateResult, error) { // verify a network was provided if len(name) == 0 { - return network.CreateResponse{}, errors.New("no network provided") + return client.NetworkCreateResult{}, errors.New("no network provided") } // check if the network is notfound and // check if the notfound should be ignored if strings.Contains(name, "notfound") && !strings.Contains(name, "ignorenotfound") { - return network.CreateResponse{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such network: %s", name)) + return client.NetworkCreateResult{}, cerrdefs.ErrNotFound } // check if the network is not-found and // check if the not-found should be ignored if strings.Contains(name, "not-found") && !strings.Contains(name, "ignore-not-found") { - return network.CreateResponse{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such network: %s", name)) + return client.NetworkCreateResult{}, cerrdefs.ErrNotFound } // create response object to return - response := network.CreateResponse{ + response := client.NetworkCreateResult{ ID: stringid.GenerateRandomID(), } return response, nil } -// NetworkDisconnect is a helper function to simulate -// a mocked call to disconnect from a Docker network. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkDisconnect -func (n *NetworkService) NetworkDisconnect(_ context.Context, _, _ string, _ bool) error { - return nil -} - // NetworkInspect is a helper function to simulate // a mocked call to inspect a Docker network. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkInspect -func (n *NetworkService) NetworkInspect(_ context.Context, networkID string, _ network.InspectOptions) (network.Inspect, error) { +func (n *NetworkService) NetworkInspect(_ context.Context, networkID string, _ client.NetworkInspectOptions) (client.NetworkInspectResult, error) { // verify a network was provided if len(networkID) == 0 { - return network.Inspect{}, errors.New("no network provided") + return client.NetworkInspectResult{}, errors.New("no network provided") } // check if the network is notfound if strings.Contains(networkID, "notfound") { - return network.Inspect{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such network: %s", networkID)) + return client.NetworkInspectResult{}, cerrdefs.ErrNotFound } // check if the network is not-found if strings.Contains(networkID, "not-found") { - return network.Inspect{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such network: %s", networkID)) + return client.NetworkInspectResult{}, cerrdefs.ErrNotFound } // create response object to return - response := network.Inspect{ - Attachable: false, - ConfigOnly: false, - Created: time.Now(), - Driver: "host", - ID: stringid.GenerateRandomID(), - Ingress: false, - Internal: false, - Name: networkID, - Scope: "local", + response := client.NetworkInspectResult{ + Network: network.Inspect{ + Network: network.Network{ + Attachable: false, + ConfigOnly: false, + Created: time.Now(), + Driver: "host", + ID: stringid.GenerateRandomID(), + Ingress: false, + Internal: false, + Name: networkID, + Scope: "local", + }, + }, } return response, nil } -// NetworkInspectWithRaw is a helper function to simulate -// a mocked call to inspect a Docker network and return -// the raw body received from the API. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkInspectWithRaw -func (n *NetworkService) NetworkInspectWithRaw(_ context.Context, networkID string, _ network.InspectOptions) (network.Inspect, []byte, error) { - // verify a network was provided - if len(networkID) == 0 { - return network.Inspect{}, nil, errors.New("no network provided") - } - - // create response object to return - response := network.Inspect{ - Attachable: false, - ConfigOnly: false, - Created: time.Now(), - Driver: "host", - ID: stringid.GenerateRandomID(), - Ingress: false, - Internal: false, - Name: networkID, - Scope: "local", - } - - // marshal response into raw bytes - b, err := json.Marshal(response) - if err != nil { - return network.Inspect{}, nil, err - } - - return response, b, nil -} - // NetworkList is a helper function to simulate // a mocked call to list Docker networks. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkList -func (n *NetworkService) NetworkList(_ context.Context, _ network.ListOptions) ([]network.Summary, error) { - return nil, nil +func (n *NetworkService) NetworkList(_ context.Context, _ client.NetworkListOptions) (client.NetworkListResult, error) { + return client.NetworkListResult{}, nil } // NetworkRemove is a helper function to simulate // a mocked call to remove Docker a network. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkRemove -func (n *NetworkService) NetworkRemove(_ context.Context, network string) error { +func (n *NetworkService) NetworkRemove(_ context.Context, network string, _ client.NetworkRemoveOptions) (client.NetworkRemoveResult, error) { // verify a network was provided if len(network) == 0 { - return errors.New("no network provided") + return client.NetworkRemoveResult{}, errors.New("no network provided") } - return nil + return client.NetworkRemoveResult{}, nil } // NetworksPrune is a helper function to simulate // a mocked call to prune Docker networks. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworksPrune -func (n *NetworkService) NetworksPrune(_ context.Context, _ filters.Args) (network.PruneReport, error) { - return network.PruneReport{}, nil +func (n *NetworkService) NetworkPrune(_ context.Context, _ client.NetworkPruneOptions) (client.NetworkPruneResult, error) { + return client.NetworkPruneResult{}, nil +} + +// NetworkConnect is a helper function to simulate +// a mocked call to connect to a Docker network. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkConnect +func (n *NetworkService) NetworkConnect(_ context.Context, _ string, _ client.NetworkConnectOptions) (client.NetworkConnectResult, error) { + return client.NetworkConnectResult{}, nil +} + +// NetworkDisconnect is a helper function to simulate +// a mocked call to disconnect from a Docker network. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkDisconnect +func (n *NetworkService) NetworkDisconnect(_ context.Context, _ string, _ client.NetworkDisconnectOptions) (client.NetworkDisconnectResult, error) { + return client.NetworkDisconnectResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/mock/docker/plugin.go b/mock/docker/plugin.go index 96fe0b94..0360571a 100644 --- a/mock/docker/plugin.go +++ b/mock/docker/plugin.go @@ -6,9 +6,7 @@ import ( "context" "io" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) // PluginService implements all the plugin @@ -19,24 +17,16 @@ type PluginService struct{} // a mocked call to create a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginCreate -func (p *PluginService) PluginCreate(_ context.Context, _ io.Reader, _ types.PluginCreateOptions) error { - return nil +func (p *PluginService) PluginCreate(_ context.Context, _ io.Reader, _ client.PluginCreateOptions) (client.PluginCreateResult, error) { + return client.PluginCreateResult{}, nil } -// PluginDisable is a helper function to simulate -// a mocked call to disable a Docker plugin. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginDisable -func (p *PluginService) PluginDisable(_ context.Context, _ string, _ types.PluginDisableOptions) error { - return nil -} - -// PluginEnable is a helper function to simulate -// a mocked call to enable a Docker plugin. +// PluginInstall is a helper function to simulate +// a mocked call to install a Docker plugin. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginEnable -func (p *PluginService) PluginEnable(_ context.Context, _ string, _ types.PluginEnableOptions) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginInstall +func (p *PluginService) PluginInstall(_ context.Context, _ string, _ client.PluginInstallOptions) (client.PluginInstallResult, error) { + return client.PluginInstallResult{}, nil } // PluginInspectWithRaw is a helper function to simulate @@ -44,59 +34,67 @@ func (p *PluginService) PluginEnable(_ context.Context, _ string, _ types.Plugin // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginInspectWithRaw -func (p *PluginService) PluginInspectWithRaw(_ context.Context, _ string) (*types.Plugin, []byte, error) { - return nil, nil, nil -} - -// PluginInstall is a helper function to simulate -// a mocked call to install a Docker plugin. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginInstall -func (p *PluginService) PluginInstall(_ context.Context, _ string, _ types.PluginInstallOptions) (io.ReadCloser, error) { - return nil, nil +func (p *PluginService) PluginInspect(_ context.Context, _ string, _ client.PluginInspectOptions) (client.PluginInspectResult, error) { + return client.PluginInspectResult{}, nil } // PluginList is a helper function to simulate // a mocked call to list Docker plugins. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginList -func (p *PluginService) PluginList(_ context.Context, _ filters.Args) (types.PluginsListResponse, error) { - return types.PluginsListResponse{}, nil -} - -// PluginPush is a helper function to simulate -// a mocked call to push a Docker plugin. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginPush -func (p *PluginService) PluginPush(_ context.Context, _ string, _ string) (io.ReadCloser, error) { - return nil, nil +func (p *PluginService) PluginList(_ context.Context, _ client.PluginListOptions) (client.PluginListResult, error) { + return client.PluginListResult{}, nil } // PluginRemove is a helper function to simulate // a mocked call to remove a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginRemove -func (p *PluginService) PluginRemove(_ context.Context, _ string, _ types.PluginRemoveOptions) error { - return nil +func (p *PluginService) PluginRemove(_ context.Context, _ string, _ client.PluginRemoveOptions) (client.PluginRemoveResult, error) { + return client.PluginRemoveResult{}, nil } -// PluginSet is a helper function to simulate -// a mocked call to update settings for a -// Docker plugin. +// PluginEnable is a helper function to simulate +// a mocked call to enable a Docker plugin. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginSet -func (p *PluginService) PluginSet(_ context.Context, _ string, _ []string) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginEnable +func (p *PluginService) PluginEnable(_ context.Context, _ string, _ client.PluginEnableOptions) (client.PluginEnableResult, error) { + return client.PluginEnableResult{}, nil +} + +// PluginDisable is a helper function to simulate +// a mocked call to disable a Docker plugin. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginDisable +func (p *PluginService) PluginDisable(_ context.Context, _ string, _ client.PluginDisableOptions) (client.PluginDisableResult, error) { + return client.PluginDisableResult{}, nil } // PluginUpgrade is a helper function to simulate // a mocked call to upgrade a Docker plugin. // // https://pkg.go.dev/github.com/docker/docker/client#Client.PluginUpgrade -func (p *PluginService) PluginUpgrade(_ context.Context, _ string, _ types.PluginInstallOptions) (io.ReadCloser, error) { +func (p *PluginService) PluginUpgrade(_ context.Context, _ string, _ client.PluginUpgradeOptions) (client.PluginUpgradeResult, error) { return nil, nil } +// PluginPush is a helper function to simulate +// a mocked call to push a Docker plugin. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginPush +func (p *PluginService) PluginPush(_ context.Context, _ string, _ client.PluginPushOptions) (client.PluginPushResult, error) { + return client.PluginPushResult{}, nil +} + +// PluginSet is a helper function to simulate +// a mocked call to update settings for a +// Docker plugin. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.PluginSet +func (p *PluginService) PluginSet(_ context.Context, _ string, _ client.PluginSetOptions) (client.PluginSetResult, error) { + return client.PluginSetResult{}, nil +} + // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES // // This line serves as a quick and efficient way to ensure that our diff --git a/mock/docker/registry.go b/mock/docker/registry.go new file mode 100644 index 00000000..077c73f0 --- /dev/null +++ b/mock/docker/registry.go @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: Apache-2.0 + +package docker + +import ( + "context" + + "github.com/moby/moby/client" +) + +// RegistryService implements all the registry +// related functions for the Docker mock. +type RegistryService struct{} + +// ImageSearch is a helper function to simulate +// a mocked call to search for a Docker image. +func (r *RegistryService) ImageSearch(_ context.Context, _ string, _ client.ImageSearchOptions) (client.ImageSearchResult, error) { + return client.ImageSearchResult{}, nil +} + +// WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES +// +// This line serves as a quick and efficient way to ensure that our +// RegistryService satisfies the RegistrySearchClient interface that +// the Docker client expects. +var _ client.RegistrySearchClient = (*RegistryService)(nil) diff --git a/mock/docker/swarm.go b/mock/docker/swarm.go index ab055a09..7476a721 100644 --- a/mock/docker/swarm.go +++ b/mock/docker/swarm.go @@ -5,30 +5,29 @@ package docker import ( "context" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) // SwarmService implements all the swarm // related functions for the Docker mock. type SwarmService struct{} -// SwarmGetUnlockKey is a helper function to simulate -// a mocked call to capture the unlock key for a -// Docker swarm cluster. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmGetUnlockKey -func (s *SwarmService) SwarmGetUnlockKey(_ context.Context) (swarm.UnlockKeyResponse, error) { - return swarm.UnlockKeyResponse{}, nil -} - // SwarmInit is a helper function to simulate // a mocked call to initialize the Docker // swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmInit -func (s *SwarmService) SwarmInit(_ context.Context, _ swarm.InitRequest) (string, error) { - return "", nil +func (s *SwarmService) SwarmInit(_ context.Context, _ client.SwarmInitOptions) (client.SwarmInitResult, error) { + return client.SwarmInitResult{}, nil +} + +// SwarmJoin is a helper function to simulate +// a mocked call to join the Docker swarm +// cluster. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmJoin +func (s *SwarmService) SwarmJoin(_ context.Context, _ client.SwarmJoinOptions) (client.SwarmJoinResult, error) { + return client.SwarmJoinResult{}, nil } // SwarmInspect is a helper function to simulate @@ -36,17 +35,17 @@ func (s *SwarmService) SwarmInit(_ context.Context, _ swarm.InitRequest) (string // cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmInspect -func (s *SwarmService) SwarmInspect(_ context.Context) (swarm.Swarm, error) { - return swarm.Swarm{}, nil +func (s *SwarmService) SwarmInspect(_ context.Context, _ client.SwarmInspectOptions) (client.SwarmInspectResult, error) { + return client.SwarmInspectResult{}, nil } -// SwarmJoin is a helper function to simulate -// a mocked call to join the Docker swarm +// SwarmUpdate is a helper function to simulate +// a mocked call to update the Docker swarm // cluster. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmJoin -func (s *SwarmService) SwarmJoin(_ context.Context, _ swarm.JoinRequest) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmUpdate +func (s *SwarmService) SwarmUpdate(_ context.Context, _ client.SwarmUpdateOptions) (client.SwarmUpdateResult, error) { + return client.SwarmUpdateResult{}, nil } // SwarmLeave is a helper function to simulate @@ -54,26 +53,26 @@ func (s *SwarmService) SwarmJoin(_ context.Context, _ swarm.JoinRequest) error { // cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmLeave -func (s *SwarmService) SwarmLeave(_ context.Context, _ bool) error { - return nil +func (s *SwarmService) SwarmLeave(_ context.Context, _ client.SwarmLeaveOptions) (client.SwarmLeaveResult, error) { + return client.SwarmLeaveResult{}, nil } -// SwarmUnlock is a helper function to simulate -// a mocked call to unlock the Docker swarm -// cluster. +// SwarmGetUnlockKey is a helper function to simulate +// a mocked call to capture the unlock key for a +// Docker swarm cluster. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmUnlock -func (s *SwarmService) SwarmUnlock(_ context.Context, _ swarm.UnlockRequest) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmGetUnlockKey +func (s *SwarmService) SwarmGetUnlockKey(_ context.Context) (client.SwarmGetUnlockKeyResult, error) { + return client.SwarmGetUnlockKeyResult{}, nil } -// SwarmUpdate is a helper function to simulate -// a mocked call to update the Docker swarm +// SwarmUnlock is a helper function to simulate +// a mocked call to unlock the Docker swarm // cluster. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmUpdate -func (s *SwarmService) SwarmUpdate(_ context.Context, _ swarm.Version, _ swarm.Spec, _ swarm.UpdateFlags) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.SwarmUnlock +func (s *SwarmService) SwarmUnlock(_ context.Context, _ client.SwarmUnlockOptions) (client.SwarmUnlockResult, error) { + return client.SwarmUnlockResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/mock/docker/node.go b/mock/docker/swarm_node.go similarity index 72% rename from mock/docker/node.go rename to mock/docker/swarm_node.go index fcdb1c20..27f5cd75 100644 --- a/mock/docker/node.go +++ b/mock/docker/swarm_node.go @@ -5,8 +5,7 @@ package docker import ( "context" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) // NodeService implements all the node @@ -18,8 +17,8 @@ type NodeService struct{} // cluster and return the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NodeInspectWithRaw -func (n *NodeService) NodeInspectWithRaw(_ context.Context, _ string) (swarm.Node, []byte, error) { - return swarm.Node{}, nil, nil +func (n *NodeService) NodeInspect(_ context.Context, _ string, _ client.NodeInspectOptions) (client.NodeInspectResult, error) { + return client.NodeInspectResult{}, nil } // NodeList is a helper function to simulate @@ -27,26 +26,26 @@ func (n *NodeService) NodeInspectWithRaw(_ context.Context, _ string) (swarm.Nod // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.NodeList -func (n *NodeService) NodeList(_ context.Context, _ swarm.NodeListOptions) ([]swarm.Node, error) { - return nil, nil +func (n *NodeService) NodeList(_ context.Context, _ client.NodeListOptions) (client.NodeListResult, error) { + return client.NodeListResult{}, nil } -// NodeRemove is a helper function to simulate -// a mocked call to remove a node from a +// NodeUpdate is a helper function to simulate +// a mocked call to update a node for a // Docker swarm cluster. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.NodeRemove -func (n *NodeService) NodeRemove(_ context.Context, _ string, _ swarm.NodeRemoveOptions) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.NodeUpdate +func (n *NodeService) NodeUpdate(_ context.Context, _ string, _ client.NodeUpdateOptions) (client.NodeUpdateResult, error) { + return client.NodeUpdateResult{}, nil } -// NodeUpdate is a helper function to simulate -// a mocked call to update a node for a +// NodeRemove is a helper function to simulate +// a mocked call to remove a node from a // Docker swarm cluster. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.NodeUpdate -func (n *NodeService) NodeUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.NodeSpec) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.NodeRemove +func (n *NodeService) NodeRemove(_ context.Context, _ string, _ client.NodeRemoveOptions) (client.NodeRemoveResult, error) { + return client.NodeRemoveResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/mock/docker/secret.go b/mock/docker/swarm_secret.go similarity index 69% rename from mock/docker/secret.go rename to mock/docker/swarm_secret.go index f2d42f8b..7b5748cb 100644 --- a/mock/docker/secret.go +++ b/mock/docker/swarm_secret.go @@ -6,8 +6,7 @@ package docker import ( "context" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) // SecretService implements all the secret @@ -19,8 +18,8 @@ type SecretService struct{} // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SecretCreate -func (s *SecretService) SecretCreate(_ context.Context, _ swarm.SecretSpec) (swarm.SecretCreateResponse, error) { - return swarm.SecretCreateResponse{}, nil +func (s *SecretService) SecretCreate(_ context.Context, _ client.SecretCreateOptions) (client.SecretCreateResult, error) { + return client.SecretCreateResult{}, nil } // SecretInspectWithRaw is a helper function to simulate @@ -28,8 +27,8 @@ func (s *SecretService) SecretCreate(_ context.Context, _ swarm.SecretSpec) (swa // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SecretInspectWithRaw -func (s *SecretService) SecretInspectWithRaw(_ context.Context, _ string) (swarm.Secret, []byte, error) { - return swarm.Secret{}, nil, nil +func (s *SecretService) SecretInspect(_ context.Context, _ string, _ client.SecretInspectOptions) (client.SecretInspectResult, error) { + return client.SecretInspectResult{}, nil } // SecretList is a helper function to simulate @@ -37,26 +36,26 @@ func (s *SecretService) SecretInspectWithRaw(_ context.Context, _ string) (swarm // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.SecretList -func (s *SecretService) SecretList(_ context.Context, _ swarm.SecretListOptions) ([]swarm.Secret, error) { - return nil, nil +func (s *SecretService) SecretList(_ context.Context, _ client.SecretListOptions) (client.SecretListResult, error) { + return client.SecretListResult{}, nil } -// SecretRemove is a helper function to simulate -// a mocked call to remove a secret for a +// SecretUpdate is a helper function to simulate +// a mocked call to update a secret for a // Docker swarm cluster. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.SecretRemove -func (s *SecretService) SecretRemove(_ context.Context, _ string) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.SecretUpdate +func (s *SecretService) SecretUpdate(_ context.Context, _ string, _ client.SecretUpdateOptions) (client.SecretUpdateResult, error) { + return client.SecretUpdateResult{}, nil } -// SecretUpdate is a helper function to simulate -// a mocked call to update a secret for a +// SecretRemove is a helper function to simulate +// a mocked call to remove a secret for a // Docker swarm cluster. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.SecretUpdate -func (s *SecretService) SecretUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.SecretSpec) error { - return nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.SecretRemove +func (s *SecretService) SecretRemove(_ context.Context, _ string, _ client.SecretRemoveOptions) (client.SecretRemoveResult, error) { + return client.SecretRemoveResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/mock/docker/service.go b/mock/docker/swarm_service.go similarity index 52% rename from mock/docker/service.go rename to mock/docker/swarm_service.go index 496710ab..a4b8f32f 100644 --- a/mock/docker/service.go +++ b/mock/docker/swarm_service.go @@ -4,11 +4,8 @@ package docker import ( "context" - "io" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) // ServiceService implements all the service @@ -20,8 +17,8 @@ type ServiceService struct{} // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceCreate -func (s *ServiceService) ServiceCreate(_ context.Context, _ swarm.ServiceSpec, _ swarm.ServiceCreateOptions) (swarm.ServiceCreateResponse, error) { - return swarm.ServiceCreateResponse{}, nil +func (s *ServiceService) ServiceCreate(_ context.Context, _ client.ServiceCreateOptions) (client.ServiceCreateResult, error) { + return client.ServiceCreateResult{}, nil } // ServiceInspectWithRaw is a helper function to simulate @@ -29,8 +26,8 @@ func (s *ServiceService) ServiceCreate(_ context.Context, _ swarm.ServiceSpec, _ // the raw body received from the API. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceInspectWithRaw -func (s *ServiceService) ServiceInspectWithRaw(_ context.Context, _ string, _ swarm.ServiceInspectOptions) (swarm.Service, []byte, error) { - return swarm.Service{}, nil, nil +func (s *ServiceService) ServiceInspect(_ context.Context, _ string, _ client.ServiceInspectOptions) (client.ServiceInspectResult, error) { + return client.ServiceInspectResult{}, nil } // ServiceList is a helper function to simulate @@ -38,26 +35,8 @@ func (s *ServiceService) ServiceInspectWithRaw(_ context.Context, _ string, _ sw // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceList -func (s *ServiceService) ServiceList(_ context.Context, _ swarm.ServiceListOptions) ([]swarm.Service, error) { - return nil, nil -} - -// ServiceLogs is a helper function to simulate -// a mocked call to capture the logs from a -// service for a Docker swarm cluster. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceLogs -func (s *ServiceService) ServiceLogs(_ context.Context, _ string, _ container.LogsOptions) (io.ReadCloser, error) { - return nil, nil -} - -// ServiceRemove is a helper function to simulate -// a mocked call to remove a service for a -// Docker swarm cluster. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceRemove -func (s *ServiceService) ServiceRemove(_ context.Context, _ string) error { - return nil +func (s *ServiceService) ServiceList(_ context.Context, _ client.ServiceListOptions) (client.ServiceListResult, error) { + return client.ServiceListResult{}, nil } // ServiceUpdate is a helper function to simulate @@ -65,32 +44,25 @@ func (s *ServiceService) ServiceRemove(_ context.Context, _ string) error { // Docker swarm cluster. // // https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceUpdate -func (s *ServiceService) ServiceUpdate(_ context.Context, _ string, _ swarm.Version, _ swarm.ServiceSpec, _ swarm.ServiceUpdateOptions) (swarm.ServiceUpdateResponse, error) { - return swarm.ServiceUpdateResponse{}, nil +func (s *ServiceService) ServiceUpdate(_ context.Context, _ string, _ client.ServiceUpdateOptions) (client.ServiceUpdateResult, error) { + return client.ServiceUpdateResult{}, nil } -// TaskInspectWithRaw is a helper function to simulate -// a mocked call to inspect a task for a Docker swarm -// cluster and return the raw body received from the API. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.TaskInspectWithRaw -func (s *ServiceService) TaskInspectWithRaw(_ context.Context, _ string) (swarm.Task, []byte, error) { - return swarm.Task{}, nil, nil -} - -// TaskList is a helper function to simulate -// a mocked call to list tasks for a +// ServiceRemove is a helper function to simulate +// a mocked call to remove a service for a // Docker swarm cluster. // -// https://pkg.go.dev/github.com/docker/docker/client#Client.TaskList -func (s *ServiceService) TaskList(_ context.Context, _ swarm.TaskListOptions) ([]swarm.Task, error) { - return nil, nil +// https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceRemove +func (s *ServiceService) ServiceRemove(_ context.Context, _ string, _ client.ServiceRemoveOptions) (client.ServiceRemoveResult, error) { + return client.ServiceRemoveResult{}, nil } -// TaskLogs is a helper function to simulate +// ServiceLogs is a helper function to simulate // a mocked call to capture the logs from a -// task for a Docker swarm cluster. -func (s *ServiceService) TaskLogs(_ context.Context, _ string, _ container.LogsOptions) (io.ReadCloser, error) { +// service for a Docker swarm cluster. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.ServiceLogs +func (s *ServiceService) ServiceLogs(_ context.Context, _ string, _ client.ServiceLogsOptions) (client.ServiceLogsResult, error) { return nil, nil } diff --git a/mock/docker/swarm_task.go b/mock/docker/swarm_task.go new file mode 100644 index 00000000..a85afaa3 --- /dev/null +++ b/mock/docker/swarm_task.go @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: Apache-2.0 + +package docker + +import ( + "context" + + "github.com/moby/moby/client" +) + +// TaskService implements all the task +// related functions for the Docker mock. +type TaskService struct{} + +// TaskInspectWithRaw is a helper function to simulate +// a mocked call to inspect a task for a Docker swarm +// cluster and return the raw body received from the API. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.TaskInspectWithRaw +func (t *TaskService) TaskInspect(_ context.Context, _ string, _ client.TaskInspectOptions) (client.TaskInspectResult, error) { + return client.TaskInspectResult{}, nil +} + +// TaskList is a helper function to simulate +// a mocked call to list tasks for a +// Docker swarm cluster. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.TaskList +func (t *TaskService) TaskList(_ context.Context, _ client.TaskListOptions) (client.TaskListResult, error) { + return client.TaskListResult{}, nil +} + +// TaskLogs is a helper function to simulate +// a mocked call to capture the logs from a +// task for a Docker swarm cluster. +func (t *TaskService) TaskLogs(_ context.Context, _ string, _ client.TaskLogsOptions) (client.TaskLogsResult, error) { + return nil, nil +} + +// WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES +// +// This line serves as a quick and efficient way to ensure that our +// ServiceService satisfies the ServiceAPIClient interface that +// the Docker client expects. +// +// https://pkg.go.dev/github.com/docker/docker/client#ServiceAPIClient +var _ client.TaskAPIClient = (*TaskService)(nil) diff --git a/mock/docker/system.go b/mock/docker/system.go index 58b781d4..593796a6 100644 --- a/mock/docker/system.go +++ b/mock/docker/system.go @@ -5,33 +5,20 @@ package docker import ( "context" - "github.com/docker/docker/api/types" - "github.com/docker/docker/api/types/events" - "github.com/docker/docker/api/types/registry" - "github.com/docker/docker/api/types/system" - "github.com/docker/docker/client" + "github.com/moby/moby/client" ) // SystemService implements all the system // related functions for the Docker mock. type SystemService struct{} -// DiskUsage is a helper function to simulate -// a mocked call to capture the data usage -// from the Docker daemon. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.DiskUsage -func (s *SystemService) DiskUsage(_ context.Context, _ types.DiskUsageOptions) (types.DiskUsage, error) { - return types.DiskUsage{}, nil -} - // Events is a helper function to simulate // a mocked call to capture the events // from the Docker daemon. // // https://pkg.go.dev/github.com/docker/docker/client#Client.Events -func (s *SystemService) Events(_ context.Context, _ events.ListOptions) (<-chan events.Message, <-chan error) { - return nil, nil +func (s *SystemService) Events(_ context.Context, _ client.EventsListOptions) client.EventsResult { + return client.EventsResult{} } // Info is a helper function to simulate @@ -39,17 +26,8 @@ func (s *SystemService) Events(_ context.Context, _ events.ListOptions) (<-chan // information from the Docker daemon. // // https://pkg.go.dev/github.com/docker/docker/client#Client.Info -func (s *SystemService) Info(_ context.Context) (system.Info, error) { - return system.Info{}, nil -} - -// Ping is a helper function to simulate -// a mocked call to ping the Docker -// daemon and return version information. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.Ping -func (s *SystemService) Ping(_ context.Context) (types.Ping, error) { - return types.Ping{}, nil +func (s *SystemService) Info(_ context.Context, _ client.InfoOptions) (client.SystemInfoResult, error) { + return client.SystemInfoResult{}, nil } // RegistryLogin is a helper function to simulate @@ -57,8 +35,26 @@ func (s *SystemService) Ping(_ context.Context) (types.Ping, error) { // daemon against a Docker registry. // // https://pkg.go.dev/github.com/docker/docker/client#Client.RegistryLogin -func (s *SystemService) RegistryLogin(_ context.Context, _ registry.AuthConfig) (registry.AuthenticateOKBody, error) { - return registry.AuthenticateOKBody{}, nil +func (s *SystemService) RegistryLogin(_ context.Context, _ client.RegistryLoginOptions) (client.RegistryLoginResult, error) { + return client.RegistryLoginResult{}, nil +} + +// DiskUsage is a helper function to simulate +// a mocked call to capture the data usage +// from the Docker daemon. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.DiskUsage +func (s *SystemService) DiskUsage(_ context.Context, _ client.DiskUsageOptions) (client.DiskUsageResult, error) { + return client.DiskUsageResult{}, nil +} + +// Ping is a helper function to simulate +// a mocked call to ping the Docker +// daemon and return version information. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.Ping +func (s *SystemService) Ping(_ context.Context, _ client.PingOptions) (client.PingResult, error) { + return client.PingResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/mock/docker/volume.go b/mock/docker/volume.go index 2c18ea49..44b49368 100644 --- a/mock/docker/volume.go +++ b/mock/docker/volume.go @@ -4,18 +4,15 @@ package docker import ( "context" - "encoding/json" "errors" "fmt" "strings" "time" - "github.com/docker/docker/api/types/filters" - "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/api/types/volume" - "github.com/docker/docker/client" - "github.com/docker/docker/errdefs" - "github.com/docker/docker/pkg/stringid" + cerrdefs "github.com/containerd/errdefs" + "github.com/moby/moby/api/types/volume" + "github.com/moby/moby/client" + "github.com/moby/moby/client/pkg/stringid" ) // VolumeService implements all the volume @@ -26,39 +23,37 @@ type VolumeService struct{} // a mocked call to create a Docker volume. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeCreate -func (v *VolumeService) VolumeCreate(_ context.Context, options volume.CreateOptions) (volume.Volume, error) { +func (v *VolumeService) VolumeCreate(_ context.Context, options client.VolumeCreateOptions) (client.VolumeCreateResult, error) { // verify a volume was provided if len(options.Name) == 0 { - return volume.Volume{}, errors.New("no volume provided") + return client.VolumeCreateResult{}, errors.New("no volume provided") } // check if the volume is notfound and // check if the notfound should be ignored if strings.Contains(options.Name, "notfound") && !strings.Contains(options.Name, "ignorenotfound") { - return volume.Volume{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", options.Name)) + return client.VolumeCreateResult{}, cerrdefs.ErrNotFound } // check if the volume is not-found and // check if the not-found should be ignored if strings.Contains(options.Name, "not-found") && !strings.Contains(options.Name, "ignore-not-found") { - return volume.Volume{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", options.Name)) + return client.VolumeCreateResult{}, cerrdefs.ErrNotFound } // create response object to return - response := volume.Volume{ - CreatedAt: time.Now().String(), - Driver: options.Driver, - Labels: options.Labels, - Mountpoint: fmt.Sprintf("/var/lib/docker/volumes/%s/_data", stringid.GenerateRandomID()), - Name: options.Name, - Options: options.DriverOpts, - Scope: "local", + response := client.VolumeCreateResult{ + Volume: volume.Volume{ + CreatedAt: time.Now().String(), + Driver: options.Driver, + Labels: options.Labels, + Mountpoint: fmt.Sprintf("/var/lib/docker/volumes/%s/_data", stringid.GenerateRandomID()), + Name: options.Name, + Options: options.DriverOpts, + Scope: "local", + }, } return response, nil @@ -68,116 +63,71 @@ func (v *VolumeService) VolumeCreate(_ context.Context, options volume.CreateOpt // a mocked call to inspect a Docker volume. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeInspect -func (v *VolumeService) VolumeInspect(_ context.Context, volumeID string) (volume.Volume, error) { +func (v *VolumeService) VolumeInspect(_ context.Context, volumeID string, _ client.VolumeInspectOptions) (client.VolumeInspectResult, error) { // verify a volume was provided if len(volumeID) == 0 { - return volume.Volume{}, errors.New("no volume provided") + return client.VolumeInspectResult{}, errors.New("no volume provided") } // check if the volume is notfound if strings.Contains(volumeID, "notfound") { - return volume.Volume{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID)) + return client.VolumeInspectResult{}, cerrdefs.ErrNotFound } // check if the volume is not-found if strings.Contains(volumeID, "not-found") { - return volume.Volume{}, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID)) + return client.VolumeInspectResult{}, cerrdefs.ErrNotFound } // create response object to return - response := volume.Volume{ - CreatedAt: time.Now().String(), - Driver: "local", - Mountpoint: fmt.Sprintf("/var/lib/docker/volumes/%s/_data", stringid.GenerateRandomID()), - Name: volumeID, - Scope: "local", + response := client.VolumeInspectResult{ + Volume: volume.Volume{ + CreatedAt: time.Now().String(), + Driver: "local", + Mountpoint: fmt.Sprintf("/var/lib/docker/volumes/%s/_data", stringid.GenerateRandomID()), + Name: volumeID, + Scope: "local", + }, } return response, nil } -// VolumeInspectWithRaw is a helper function to simulate -// a mocked call to inspect a Docker volume and return -// the raw body received from the API. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeInspectWithRaw -func (v *VolumeService) VolumeInspectWithRaw(_ context.Context, volumeID string) (volume.Volume, []byte, error) { - // verify a volume was provided - if len(volumeID) == 0 { - return volume.Volume{}, nil, errors.New("no volume provided") - } - - // check if the volume is notfound - if strings.Contains(volumeID, "notfound") { - return volume.Volume{}, nil, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID)) - } - - // check if the volume is not-found - if strings.Contains(volumeID, "not-found") { - return volume.Volume{}, nil, - //nolint:staticcheck // messsage is capitalized to match Docker messages - errdefs.NotFound(fmt.Errorf("Error: No such volume: %s", volumeID)) - } - - // create response object to return - response := volume.Volume{ - CreatedAt: time.Now().String(), - Driver: "local", - Mountpoint: fmt.Sprintf("/var/lib/docker/volumes/%s/_data", stringid.GenerateRandomID()), - Name: volumeID, - Scope: "local", - } - - // marshal response into raw bytes - b, err := json.Marshal(response) - if err != nil { - return volume.Volume{}, nil, err - } - - return response, b, nil -} - // VolumeList is a helper function to simulate // a mocked call to list Docker volumes. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeList -func (v *VolumeService) VolumeList(_ context.Context, _ volume.ListOptions) (volume.ListResponse, error) { - return volume.ListResponse{}, nil +func (v *VolumeService) VolumeList(_ context.Context, _ client.VolumeListOptions) (client.VolumeListResult, error) { + return client.VolumeListResult{}, nil +} + +// VolumeUpdate is a helper function to simulate +// a mocked call to update Docker volumes. +// +// https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeUpdate +func (v *VolumeService) VolumeUpdate(_ context.Context, _ string, _ client.VolumeUpdateOptions) (client.VolumeUpdateResult, error) { + return client.VolumeUpdateResult{}, nil } // VolumeRemove is a helper function to simulate // a mocked call to remove Docker a volume. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeRemove -func (v *VolumeService) VolumeRemove(_ context.Context, volumeID string, _ bool) error { +func (v *VolumeService) VolumeRemove(_ context.Context, volumeID string, _ client.VolumeRemoveOptions) (client.VolumeRemoveResult, error) { // verify a volume was provided if len(volumeID) == 0 { - return errors.New("no volume provided") + return client.VolumeRemoveResult{}, errors.New("no volume provided") } - return nil + return client.VolumeRemoveResult{}, nil } // VolumesPrune is a helper function to simulate // a mocked call to prune Docker volumes. // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumesPrune -func (v *VolumeService) VolumesPrune(_ context.Context, _ filters.Args) (volume.PruneReport, error) { - return volume.PruneReport{}, nil -} - -// VolumeUpdate is a helper function to simulate -// a mocked call to update Docker volumes. -// -// https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeUpdate -func (v *VolumeService) VolumeUpdate(_ context.Context, _ string, _ swarm.Version, _ volume.UpdateOptions) error { - return nil +func (v *VolumeService) VolumePrune(_ context.Context, _ client.VolumePruneOptions) (client.VolumePruneResult, error) { + return client.VolumePruneResult{}, nil } // WARNING: DO NOT REMOVE THIS UNDER ANY CIRCUMSTANCES diff --git a/runtime/docker/container.go b/runtime/docker/container.go index 3f0650d3..921371ad 100644 --- a/runtime/docker/container.go +++ b/runtime/docker/container.go @@ -10,8 +10,9 @@ import ( "strings" "github.com/containerd/errdefs" - dockerContainerTypes "github.com/docker/docker/api/types/container" - "github.com/docker/docker/pkg/stdcopy" + "github.com/moby/moby/api/pkg/stdcopy" + dockerContainerTypes "github.com/moby/moby/api/types/container" + mobyClient "github.com/moby/moby/client" "github.com/go-vela/server/compiler/types/pipeline" "github.com/go-vela/server/constants" @@ -25,7 +26,7 @@ func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container) // send API call to inspect the container // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerInspect - container, err := c.Docker.ContainerInspect(ctx, ctn.ID) + result, err := c.Docker.ContainerInspect(ctx, ctn.ID, mobyClient.ContainerInspectOptions{}) if err != nil { return err } @@ -34,7 +35,7 @@ func (c *client) InspectContainer(ctx context.Context, ctn *pipeline.Container) // // https://pkg.go.dev/github.com/docker/docker/api/types#ContainerState //nolint:gosec // exit codes are truncated by OS - ctn.ExitCode = int32(container.State.ExitCode) + ctn.ExitCode = int32(result.Container.State.ExitCode) return nil } @@ -46,11 +47,13 @@ func (c *client) RemoveContainer(ctx context.Context, ctn *pipeline.Container) e // send API call to inspect the container // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerInspect - container, err := c.Docker.ContainerInspect(ctx, ctn.ID) + result, err := c.Docker.ContainerInspect(ctx, ctn.ID, mobyClient.ContainerInspectOptions{}) if err != nil { return err } + container := result.Container + // if the container is paused, restarting or running // // https://pkg.go.dev/github.com/docker/docker/api/types#ContainerState @@ -60,7 +63,9 @@ func (c *client) RemoveContainer(ctx context.Context, ctn *pipeline.Container) e // send API call to kill the container // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerKill - err := c.Docker.ContainerKill(ctx, ctn.ID, "SIGKILL") + _, err := c.Docker.ContainerKill(ctx, ctn.ID, mobyClient.ContainerKillOptions{ + Signal: "SIGKILL", + }) if err != nil { return err } @@ -69,7 +74,7 @@ func (c *client) RemoveContainer(ctx context.Context, ctn *pipeline.Container) e // create options for removing container // // https://pkg.go.dev/github.com/docker/docker/api/types/container#RemoveOptions - opts := dockerContainerTypes.RemoveOptions{ + opts := mobyClient.ContainerRemoveOptions{ Force: true, RemoveLinks: false, RemoveVolumes: true, @@ -78,7 +83,7 @@ func (c *client) RemoveContainer(ctx context.Context, ctn *pipeline.Container) e // send API call to remove the container // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerRemove - err = c.Docker.ContainerRemove(ctx, ctn.ID, opts) + _, err = c.Docker.ContainerRemove(ctx, ctn.ID, opts) if err != nil { return err } @@ -147,30 +152,28 @@ func (c *client) RunContainer(ctx context.Context, ctn *pipeline.Container, b *p hostConf.Privileged = true } + createOpts := mobyClient.ContainerCreateOptions{ + Config: containerConf, + HostConfig: hostConf, + NetworkingConfig: networkConf, + Name: ctn.ID, + } + // send API call to create the container // // https://godoc.org/github.com/docker/docker/client#Client.ContainerCreate _, err = c.Docker.ContainerCreate( ctx, - containerConf, - hostConf, - networkConf, - nil, - ctn.ID, + createOpts, ) if err != nil { return err } - // create options for starting container - // - // https://pkg.go.dev/github.com/docker/docker/api/types/container#StartOptions - opts := dockerContainerTypes.StartOptions{} - // send API call to start the container // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerStart - err = c.Docker.ContainerStart(ctx, ctn.ID, opts) + _, err = c.Docker.ContainerStart(ctx, ctn.ID, mobyClient.ContainerStartOptions{}) if err != nil { return err } @@ -235,7 +238,7 @@ func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io // create options for capturing container logs // // https://pkg.go.dev/github.com/docker/docker/api/types/container#LogsOptions - opts := dockerContainerTypes.LogsOptions{ + opts := mobyClient.ContainerLogsOptions{ Follow: true, ShowStdout: true, ShowStderr: true, @@ -283,11 +286,13 @@ func (c *client) WaitContainer(ctx context.Context, ctn *pipeline.Container) err // send API call to wait for the container completion // // https://pkg.go.dev/github.com/docker/docker/client#Client.ContainerWait - wait, errC := c.Docker.ContainerWait(ctx, ctn.ID, dockerContainerTypes.WaitConditionNotRunning) + waitResult := c.Docker.ContainerWait(ctx, ctn.ID, mobyClient.ContainerWaitOptions{ + Condition: dockerContainerTypes.WaitConditionNotRunning, + }) select { - case <-wait: - case err := <-errC: + case <-waitResult.Result: + case err := <-waitResult.Error: return err } @@ -300,19 +305,19 @@ func (c *client) PollOutputsContainer(ctx context.Context, ctn *pipeline.Contain return nil, nil } - execConfig := dockerContainerTypes.ExecOptions{ - Tty: true, + opts := mobyClient.ExecCreateOptions{ + TTY: true, Cmd: []string{"sh", "-c", fmt.Sprintf("cat %s", path)}, AttachStderr: true, AttachStdout: true, } - responseExec, err := c.Docker.ContainerExecCreate(ctx, ctn.ID, execConfig) + responseExec, err := c.Docker.ExecCreate(ctx, ctn.ID, opts) if err != nil { return nil, err } - hijackedResponse, err := c.Docker.ContainerExecAttach(ctx, responseExec.ID, dockerContainerTypes.ExecAttachOptions{}) + hijackedResponse, err := c.Docker.ExecAttach(ctx, responseExec.ID, mobyClient.ExecAttachOptions{}) if err != nil { return nil, err } diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go index c2dc7537..931b2a7b 100644 --- a/runtime/docker/docker.go +++ b/runtime/docker/docker.go @@ -3,7 +3,7 @@ package docker import ( - docker "github.com/docker/docker/client" + docker "github.com/moby/moby/client" "github.com/sirupsen/logrus" mock "github.com/go-vela/worker/mock/docker" @@ -74,19 +74,11 @@ func New(opts ...ClientOpt) (*client, error) { // create new Docker client from environment // // https://pkg.go.dev/github.com/docker/docker/client#NewClientWithOpts - _docker, err := docker.NewClientWithOpts(docker.FromEnv) + _docker, err := docker.New(docker.FromEnv, docker.WithVersionFromEnv()) if err != nil { return nil, err } - // pin version to ensure we know what Docker API version we're using - // - // typically this would be inherited from the host environment - // but this ensures the version of client being used - // - // https://pkg.go.dev/github.com/docker/docker/client#WithVersion - _ = docker.WithVersion(Version)(_docker) - // set the Docker client in the runtime client c.Docker = _docker diff --git a/runtime/docker/image.go b/runtime/docker/image.go index 2f489c9d..8201330f 100644 --- a/runtime/docker/image.go +++ b/runtime/docker/image.go @@ -9,7 +9,7 @@ import ( "os" "strings" - dockerImageTypes "github.com/docker/docker/api/types/image" + mobyClient "github.com/moby/moby/client" "github.com/sirupsen/logrus" "github.com/go-vela/server/compiler/types/pipeline" @@ -29,15 +29,10 @@ func (c *client) CreateImage(ctx context.Context, ctn *pipeline.Container) error return err } - // create options for pulling image - // - // https://pkg.go.dev/github.com/docker/docker/api/types/image#PullOptions - opts := dockerImageTypes.PullOptions{} - // send API call to pull the image for the container // // https://pkg.go.dev/github.com/docker/docker/client#Client.ImagePull - reader, err := c.Docker.ImagePull(ctx, _image, opts) + reader, err := c.Docker.ImagePull(ctx, _image, mobyClient.ImagePullOptions{}) if err != nil { return err } diff --git a/runtime/docker/network.go b/runtime/docker/network.go index 97966d8c..de36bbfe 100644 --- a/runtime/docker/network.go +++ b/runtime/docker/network.go @@ -7,7 +7,8 @@ import ( "encoding/json" "fmt" - "github.com/docker/docker/api/types/network" + "github.com/moby/moby/api/types/network" + mobyClient "github.com/moby/moby/client" "github.com/go-vela/server/compiler/types/pipeline" ) @@ -19,7 +20,7 @@ func (c *client) CreateNetwork(ctx context.Context, b *pipeline.Build) error { // create options for creating network // // https://pkg.go.dev/github.com/docker/docker/api/types#NetworkCreate - opts := network.CreateOptions{ + opts := mobyClient.NetworkCreateOptions{ Driver: "bridge", } @@ -35,14 +36,11 @@ func (c *client) CreateNetwork(ctx context.Context, b *pipeline.Build) error { } // InspectNetwork inspects the pipeline network. +// +//nolint:dupl // ignore similar code with InspectVolume func (c *client) InspectNetwork(ctx context.Context, b *pipeline.Build) ([]byte, error) { c.Logger.Tracef("inspecting network for pipeline %s", b.ID) - // create options for inspecting network - // - // https://pkg.go.dev/github.com/docker/docker/api/types#NetworkInspectOptions - opts := network.InspectOptions{} - // create output for inspecting network output := []byte( fmt.Sprintf("$ docker network inspect %s\n", b.ID), @@ -51,7 +49,7 @@ func (c *client) InspectNetwork(ctx context.Context, b *pipeline.Build) ([]byte, // send API call to inspect the network // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkInspect - n, err := c.Docker.NetworkInspect(ctx, b.ID, opts) + n, err := c.Docker.NetworkInspect(ctx, b.ID, mobyClient.NetworkInspectOptions{}) if err != nil { return output, err } @@ -75,7 +73,7 @@ func (c *client) RemoveNetwork(ctx context.Context, b *pipeline.Build) error { // send API call to remove the network // // https://pkg.go.dev/github.com/docker/docker/client#Client.NetworkRemove - err := c.Docker.NetworkRemove(ctx, b.ID) + _, err := c.Docker.NetworkRemove(ctx, b.ID, mobyClient.NetworkRemoveOptions{}) if err != nil { return err } diff --git a/runtime/docker/volume.go b/runtime/docker/volume.go index d14cca4b..a6dc2cd9 100644 --- a/runtime/docker/volume.go +++ b/runtime/docker/volume.go @@ -7,10 +7,10 @@ import ( "encoding/json" "fmt" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/mount" - "github.com/docker/docker/api/types/volume" "github.com/docker/go-units" + "github.com/moby/moby/api/types/container" + "github.com/moby/moby/api/types/mount" + mobyClient "github.com/moby/moby/client" "github.com/sirupsen/logrus" "github.com/go-vela/server/compiler/types/pipeline" @@ -25,7 +25,7 @@ func (c *client) CreateVolume(ctx context.Context, b *pipeline.Build) error { // create options for creating volume // // https://pkg.go.dev/github.com/docker/docker/api/types/volume#CreateOptions - opts := volume.CreateOptions{ + opts := mobyClient.VolumeCreateOptions{ Name: b.ID, Driver: "local", } @@ -42,6 +42,8 @@ func (c *client) CreateVolume(ctx context.Context, b *pipeline.Build) error { } // InspectVolume inspects the pipeline volume. +// +//nolint:dupl // ignore similar code with InspectNetwork func (c *client) InspectVolume(ctx context.Context, b *pipeline.Build) ([]byte, error) { c.Logger.Tracef("inspecting volume for pipeline %s", b.ID) @@ -53,7 +55,7 @@ func (c *client) InspectVolume(ctx context.Context, b *pipeline.Build) ([]byte, // send API call to inspect the volume // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeInspect - v, err := c.Docker.VolumeInspect(ctx, b.ID) + v, err := c.Docker.VolumeInspect(ctx, b.ID, mobyClient.VolumeInspectOptions{}) if err != nil { return output, err } @@ -77,7 +79,9 @@ func (c *client) RemoveVolume(ctx context.Context, b *pipeline.Build) error { // send API call to remove the volume // // https://pkg.go.dev/github.com/docker/docker/client#Client.VolumeRemove - err := c.Docker.VolumeRemove(ctx, b.ID, true) + _, err := c.Docker.VolumeRemove(ctx, b.ID, mobyClient.VolumeRemoveOptions{ + Force: true, + }) if err != nil { return err } diff --git a/runtime/setup.go b/runtime/setup.go index aae289a7..d865a913 100644 --- a/runtime/setup.go +++ b/runtime/setup.go @@ -4,9 +4,7 @@ package runtime import ( "fmt" - "strings" - "github.com/docker/docker/oci/caps" "github.com/sirupsen/logrus" v1 "k8s.io/api/core/v1" @@ -110,23 +108,6 @@ func (s *Setup) Validate() error { // process the secret driver being provided switch s.Driver { case constants.DriverDocker: - // check to make sure drop capabilities is configured correctly - if len(s.DropCapabilities) != 0 { - for _, configCap := range s.DropCapabilities { - valid := false - - for _, validCap := range caps.DefaultCapabilities() { - if strings.EqualFold(configCap, validCap) { - valid = true - break - } - } - - if !valid { - return fmt.Errorf("invalid capability %s provided in RUNTIME_DROP_CAPABILITIES", configCap) - } - } - } case constants.DriverKubernetes: // check if a runtime namespace was provided if len(s.Namespace) == 0 { diff --git a/runtime/setup_test.go b/runtime/setup_test.go index 57f4b2c7..6571e426 100644 --- a/runtime/setup_test.go +++ b/runtime/setup_test.go @@ -78,14 +78,6 @@ func TestRuntime_Validate(t *testing.T) { DropCapabilities: []string{"CAP_DAC_OVERRIDE"}, }, }, - { - name: "docker driver bad cap", - failure: true, - setup: &Setup{ - Driver: constants.DriverDocker, - DropCapabilities: []string{"BAD"}, - }, - }, { name: "kubernetes driver", failure: false,