Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add support for remote registry cache #94

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ _(As a convention in the list below, all task parameters are specified with a
to build.

* `$BUILDKIT_SSH` your ssh key location that is mounted in your `Dockerfile`. This is
generally used for pulling dependencies from private repositories.
generally used for pulling dependencies from private repositories.

For Example. In your `Dockerfile`, you can mount a key as
```
RUN --mount=type=ssh,id=github_ssh_key pip install -U -r ./hats/requirements-test.txt
```
```

Then in your Concourse YAML configuration:
```
Expand Down Expand Up @@ -257,13 +257,28 @@ set `image: image`.)

### `caches`

Caching can be enabled by caching the `cache` path on the task:
Task caching can be enabled by caching the `cache` path on the task:

```yaml
caches:
- path: cache
```

Alternatively, one may configure caching via docker registry:

```yaml
params:
REGISTRY_CACHE: registry.example.com/my-org/my-image:cache
```

#### Which one to use?

Registry cache allows the caches to be shared by all concourse workers, but it
enables side-effects such as pulling and pushing of cache images to the
docker registry, which may require [authentication](https://github.com/concourse/oci-build-task/issues/14#issuecomment-596731775).

Task cache is easy to set up, but it is not shared by concourse workers.

### `run`

Your task should run the `build` executable:
Expand Down
14 changes: 11 additions & 3 deletions buildkitd.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,24 @@ func (buildkitd *Buildkitd) Cleanup() error {
func generateConfig(req Request, configPath string) error {
var config BuildkitdConfig

var registryConfigs map[string]RegistryConfig
registryConfigs = make(map[string]RegistryConfig)

if len(req.Config.RegistryMirrors) > 0 {
var registryConfigs map[string]RegistryConfig
registryConfigs = make(map[string]RegistryConfig)
registryConfigs["docker.io"] = RegistryConfig{
Mirrors: req.Config.RegistryMirrors,
}
}

config.Registries = registryConfigs
for _, r := range req.Config.InsecureRegistries {
registryConfigs[r] = RegistryConfig{
Insecure: true,
PlainHTTP: true,
}
}

config.Registries = registryConfigs

err := os.MkdirAll(filepath.Dir(configPath), 0700)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions buildkitd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type BuildkitdConfig struct {

type RegistryConfig struct {
Mirrors []string `toml:"mirrors"`
PlainHTTP *bool `toml:"http"`
Insecure *bool `toml:"insecure"`
PlainHTTP bool `toml:"http"`
Insecure bool `toml:"insecure"`
RootCAs []string `toml:"ca"`
KeyPairs []TLSKeyPair `toml:"keypair"`
TLSConfigDir []string `toml:"tlsconfigdir"`
Expand Down
7 changes: 4 additions & 3 deletions buildkitd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ func (s *BuildkitdSuite) TestGenerateConfig() {
var err error

s.req.Config.RegistryMirrors = []string{"hub.docker.io"}
s.req.Config.InsecureRegistries = []string{"my-registry:5000"}

s.buildkitd, err = task.SpawnBuildkitd(s.req, &task.BuildkitdOpts{
ConfigPath: s.configPath("mirrors.toml"),
ConfigPath: s.configPath("cfg.toml"),
})
s.NoError(err)

configContent, err := ioutil.ReadFile(s.configPath("mirrors.toml"))
configContent, err := ioutil.ReadFile(s.configPath("cfg.toml"))
s.NoError(err)

expectedContent, err := ioutil.ReadFile("testdata/buildkitd-config/mirrors.toml")
expectedContent, err := ioutil.ReadFile("testdata/buildkitd-config/cfg.toml")
s.NoError(err)

s.Equal(expectedContent, configContent)
Expand Down
26 changes: 6 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
module github.com/concourse/oci-build-task

go 1.12
go 1.16

require (
github.com/BurntSushi/toml v0.3.1
github.com/BurntSushi/toml v0.4.1
github.com/VividCortex/ewma v1.1.1 // indirect
github.com/concourse/go-archive v1.0.1
github.com/containerd/stargz-snapshotter/estargz v0.0.0-20210105085455-7f45f7438617 // indirect
github.com/docker/cli v20.10.2+incompatible // indirect
github.com/docker/docker v20.10.2+incompatible // indirect
github.com/fatih/color v1.10.0
github.com/golang/protobuf v1.4.3 // indirect
github.com/google/go-containerregistry v0.3.0
github.com/fatih/color v1.13.0
github.com/google/go-containerregistry v0.10.0
github.com/julienschmidt/httprouter v1.3.0
github.com/onsi/gomega v1.10.3 // indirect
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6 // indirect
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.6.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/u-root/u-root v7.0.0+incompatible
github.com/vbauerster/mpb v3.4.0+incompatible
github.com/vrischmann/envconfig v1.3.0
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
golang.org/x/sys v0.0.0-20210108172913-0df2131ae363 // indirect
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gotest.tools/v3 v3.0.3 // indirect
)
Loading