Skip to content

Commit

Permalink
Merge pull request #27 from bkneis/POD-823/cache
Browse files Browse the repository at this point in the history
POD-823: Add repo cache
  • Loading branch information
bkneis authored Sep 5, 2024
2 parents 88b71f8 + 6359888 commit 0316292
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
14 changes: 13 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Dockerless is a tool that allows you to build and run Docker containers without

## Installation

For example, to build an image:
WARN: running dockerless on your host can delete key files and destroy your working environment.

For example, to build an image, run the following in the gcr.io/kaniko-project/executor image:

``` bash
dockerless build --dockerfile Dockerfile --context .
Expand All @@ -20,3 +22,13 @@ And to run a container:
``` bash
dockerless start
```

## Development

Build dockerless and new image

```bash
just build
cp dist/dockerless_{arch}/dockerless .
docker build -t {repo}/dockerless:{tag} -f Dockerfile --build-arg TARGETARCH=$(uname -m) --build-arg TARGETOS=linux .
```
66 changes: 41 additions & 25 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ import (
"github.com/spf13/cobra"
)

const defaultCacheDir = "/.dockerless/cache"

var ImageConfigOutput = "/.dockerless/image.json"

type BuildCmd struct {
Dockerfile string
Context string

Target string
BuildArgs []string

IgnorePaths []string
Insecure bool
Dockerfile string
Context string
Target string
RegistryCache string
BuildArgs []string
IgnorePaths []string
Insecure bool
ExportCache bool
}

// NewBuildCmd returns a new build command
Expand All @@ -46,6 +48,8 @@ func NewBuildCmd() *cobra.Command {
cobraCmd.Flags().StringArrayVar(&cmd.BuildArgs, "build-arg", []string{}, "Docker build args.")
cobraCmd.Flags().StringArrayVar(&cmd.IgnorePaths, "ignore-path", []string{}, "Extra paths to exclude from deletion.")
cobraCmd.Flags().BoolVar(&cmd.Insecure, "insecure", true, "If true will not check for certificates")
cobraCmd.Flags().StringVar(&cmd.RegistryCache, "registry-cache", "", "Registry to use as remote cache.")
cobraCmd.Flags().BoolVar(&cmd.ExportCache, "export-cache", false, "If true kanoiko build push cache to registry.")
return cobraCmd
}

Expand Down Expand Up @@ -129,8 +133,7 @@ func (cmd *BuildCmd) build() (v1.Image, error) {
return nil, fmt.Errorf("change dir: %w", err)
}

// let's build!
image, err := executor.DoBuild(&config.KanikoOptions{
opts := &config.KanikoOptions{
Destinations: []string{"local"},
Unpack: true,
BuildArgs: cmd.BuildArgs,
Expand All @@ -140,24 +143,37 @@ func (cmd *BuildCmd) build() (v1.Image, error) {
InsecurePull: cmd.Insecure,
SkipTLSVerify: cmd.Insecure,
},
SrcContext: cmd.Context,
Target: cmd.Target,
CustomPlatform: platforms.Format(platforms.Normalize(platforms.DefaultSpec())),
SnapshotMode: "time",
RunV2: true,
NoPush: true,
KanikoDir: "/.dockerless",
CacheRunLayers: true,
CacheCopyLayers: true,
CompressedCaching: true,
SkipUnusedStages: true,
Compression: config.ZStd,
CompressionLevel: 3,
SrcContext: cmd.Context,
Target: cmd.Target,
CustomPlatform: platforms.Format(platforms.Normalize(platforms.DefaultSpec())),
SnapshotMode: "redo",
RunV2: true,
NoPush: true,
KanikoDir: "/.dockerless",
Cache: true,
CacheRunLayers: true,
CacheCopyLayers: true,
CompressedCaching: true,
SkipUnusedStages: true,
ImageFSExtractRetry: 3,
NoPushCache: !cmd.ExportCache,
Compression: config.ZStd,
CompressionLevel: 3,
CacheOptions: config.CacheOptions{
CacheDir: "/.dockerless/cache",
CacheTTL: time.Hour * 24 * 7,
},
})
}
if cmd.RegistryCache != "" {
opts.CacheRepo = cmd.RegistryCache
} else {
opts.CacheOptions.CacheDir = defaultCacheDir
}
if !cmd.ExportCache {
opts.SingleSnapshot = true
}

// let's build!
image, err := executor.DoBuild(opts)
if err != nil {
// add a passwd as other we won't be able to exec into this container
if addPwdErr := addPasswd(); addPwdErr != nil {
Expand Down

0 comments on commit 0316292

Please sign in to comment.