Skip to content

Add support for max layer caching in build #477

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions cmd/drone-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"github.com/sirupsen/logrus"
"github.com/urfave/cli"

docker "github.com/drone-plugins/drone-docker"
"github.com/drone-plugins/drone-plugin-lib/drone"

docker "github.com/drone-plugins/drone-docker"
)

var (
Expand Down Expand Up @@ -102,6 +103,11 @@ func main() {
Usage: "docker daemon Experimental mode",
EnvVar: "PLUGIN_EXPERIMENTAL",
},
cli.BoolFlag{
Name: "daemon.containerd-image-store",
Usage: "docker daemon containerd image store",
EnvVar: "PLUGIN_CONTAINERD_IMAGE_STORE",
},
cli.BoolFlag{
Name: "daemon.debug",
Usage: "docker daemon executes in debug mode",
Expand Down Expand Up @@ -177,6 +183,16 @@ func main() {
Usage: "images to consider as cache sources",
EnvVar: "PLUGIN_CACHE_FROM",
},
cli.StringFlag{
Name: "cache-from-explicit",
Usage: "image to consider as cache source fully specified",
EnvVar: "PLUGIN_CACHE_FROM_EXPLICIT",
},
cli.StringFlag{
Name: "cache-to",
Usage: "images to consider as cache stores",
EnvVar: "PLUGIN_CACHE_TO",
},
cli.BoolFlag{
Name: "squash",
Usage: "squash the layers at build time",
Expand Down Expand Up @@ -364,6 +380,7 @@ func run(c *cli.Context) error {
Squash: c.Bool("squash"),
Pull: c.BoolT("pull-image"),
CacheFrom: c.StringSlice("cache-from"),
CacheTo: c.String("cache-to"),
Compress: c.Bool("compress"),
Repo: c.String("repo"),
Labels: c.StringSlice("custom-labels"),
Expand All @@ -380,20 +397,21 @@ func run(c *cli.Context) error {
SSHAgentKey: c.String("ssh-agent-key"),
},
Daemon: docker.Daemon{
Registry: c.String("docker.registry"),
Mirror: c.String("daemon.mirror"),
StorageDriver: c.String("daemon.storage-driver"),
StoragePath: c.String("daemon.storage-path"),
Insecure: c.Bool("daemon.insecure"),
Disabled: c.Bool("daemon.off"),
IPv6: c.Bool("daemon.ipv6"),
Debug: c.Bool("daemon.debug"),
Bip: c.String("daemon.bip"),
DNS: c.StringSlice("daemon.dns"),
DNSSearch: c.StringSlice("daemon.dns-search"),
MTU: c.String("daemon.mtu"),
Experimental: c.Bool("daemon.experimental"),
RegistryType: registryType,
Registry: c.String("docker.registry"),
Mirror: c.String("daemon.mirror"),
StorageDriver: c.String("daemon.storage-driver"),
StoragePath: c.String("daemon.storage-path"),
Insecure: c.Bool("daemon.insecure"),
Disabled: c.Bool("daemon.off"),
IPv6: c.Bool("daemon.ipv6"),
Debug: c.Bool("daemon.debug"),
Bip: c.String("daemon.bip"),
DNS: c.StringSlice("daemon.dns"),
DNSSearch: c.StringSlice("daemon.dns-search"),
MTU: c.String("daemon.mtu"),
Experimental: c.Bool("daemon.experimental"),
RegistryType: registryType,
ContainerdImageStoreEnabled: c.Bool("daemon.containerd-image-store"),
},
BaseImageRegistry: c.String("docker.baseimageregistry"),
BaseImageUsername: c.String("docker.baseimageusername"),
Expand Down
43 changes: 28 additions & 15 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@ import (
"strings"
"time"

"github.com/drone-plugins/drone-docker/internal/docker"
"github.com/drone-plugins/drone-plugin-lib/drone"

"github.com/drone-plugins/drone-docker/internal/docker"
)

type (
// Daemon defines Docker daemon parameters.
Daemon struct {
Registry string // Docker registry
Mirror string // Docker registry mirror
Insecure bool // Docker daemon enable insecure registries
StorageDriver string // Docker daemon storage driver
StoragePath string // Docker daemon storage path
Disabled bool // DOcker daemon is disabled (already running)
Debug bool // Docker daemon started in debug mode
Bip string // Docker daemon network bridge IP address
DNS []string // Docker daemon dns server
DNSSearch []string // Docker daemon dns search domain
MTU string // Docker daemon mtu setting
IPv6 bool // Docker daemon IPv6 networking
Experimental bool // Docker daemon enable experimental mode
RegistryType drone.RegistryType // Docker registry type
Registry string // Docker registry
Mirror string // Docker registry mirror
Insecure bool // Docker daemon enable insecure registries
StorageDriver string // Docker daemon storage driver
StoragePath string // Docker daemon storage path
Disabled bool // DOcker daemon is disabled (already running)
Debug bool // Docker daemon started in debug mode
Bip string // Docker daemon network bridge IP address
DNS []string // Docker daemon dns server
DNSSearch []string // Docker daemon dns search domain
MTU string // Docker daemon mtu setting
IPv6 bool // Docker daemon IPv6 networking
Experimental bool // Docker daemon enable experimental mode
RegistryType drone.RegistryType // Docker registry type
ContainerdImageStoreEnabled bool // Docker daemon containerd image store enabled
}

// Login defines Docker login parameters.
Expand Down Expand Up @@ -59,6 +61,8 @@ type (
Squash bool // Docker build squash
Pull bool // Docker build pull
CacheFrom []string // Docker build cache-from
CacheFromExplicit string // Docker build cache-from with comma support
CacheTo string // Docker build cache-to
Compress bool // Docker build compress
Repo string // Docker build repository
LabelSchema []string // label-schema Label map
Expand Down Expand Up @@ -412,6 +416,12 @@ func commandBuild(build Build) *exec.Cmd {
for _, arg := range build.CacheFrom {
args = append(args, "--cache-from", arg)
}
if build.CacheFromExplicit != "" {
args = append(args, "--cache-from", build.CacheFromExplicit)
}
if build.CacheTo != "" {
args = append(args, "--cache-to", build.CacheTo)
}
for _, arg := range build.ArgsEnv {
addProxyValue(&build, arg)
}
Expand Down Expand Up @@ -593,6 +603,9 @@ func commandDaemon(daemon Daemon) *exec.Cmd {
"--data-root", daemon.StoragePath,
"--host=unix:///var/run/docker.sock",
}
if daemon.ContainerdImageStoreEnabled {
args = append(args, "--feature", "containerd-snapshotter=true")
}

if _, err := os.Stat("/etc/docker/default.json"); err == nil {
args = append(args, "--seccomp-profile=/etc/docker/default.json")
Expand Down