Skip to content

Commit

Permalink
Support skipping artifacts synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
juamedgod committed Feb 26, 2024
1 parent edf5bd3 commit 77edda3
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 54 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Sync chart packages and associated container images between chart repositories
+ [Sync all charts](#sync-all-helm-charts)
+ [Sync all charts from specific date](#sync-all-charts-from-specific-date)
- [Advanced Usage](#advanced-usage)
+ [Skip syncing artifacts](#skip-syncing-artifacts)
+ [Sync only specific container platforms](#sync-only-specific-container-platforms)
+ [Sync Helm Charts and Container Images to different registries](#sync-helm-charts-and-container-images-to-different-registries)
+ [Sync charts between repositories without direct connectivity](#sync-charts-between-repositories-without-direct-connectivity)
Expand Down Expand Up @@ -75,6 +76,44 @@ charts:
- mariadb
```
### Skip syncing artifacts
If your chart and docker images include artifacts such as signatures or metadata, they will be synced to the destination repository. If you want to disable this behavior, you can opt out by setting `skipArtifacts` to true:

```yaml
source:
repo:
kind: OCI
url: http://localhost:8080
target:
repo:
kind: OCI
url: http://localhost:9090/charts
charts:
- redis
skipArtifacts: true
```

This is especially useful when you filter the container platforms to sync, which would invalidate the signatures. Using `skipArtifacts: true` will prevent syncing the now invalid signatures:

```yaml
source:
repo:
kind: OCI
url: http://localhost:8080
target:
repo:
kind: OCI
url: http://localhost:9090/charts
charts:
- redis
skipArtifacts: true
containerPlatforms:
- linux/amd64
```


### Sync Helm Charts and Container Images to different registries

By default, charts-syncer syncs Helm Charts packages and their container images to the same registry specified in the `target.repo.url` property. If you require to configure a different destination registry for the images, this can be configured in the `target.containers.url` property:
Expand Down
115 changes: 63 additions & 52 deletions api/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions api/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ message Config {
repeated string container_platforms = 4;
// Opposite of charts property. It indicates the list of charts to skip during sync
repeated string skip_charts = 5;
// Do not sync chart and container artifacts (signatures and metadata)
bool skip_artifacts = 6;

}

// SourceRepo contains the required information of the source chart repository
Expand Down
1 change: 1 addition & 0 deletions cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func newSyncCmd() *cobra.Command {
syncer.WithContainerPlatforms(c.GetContainerPlatforms()),
syncer.WithInsecure(rootInsecure),
syncer.WithLatestVersionOnly(syncLatestVersionOnly),
syncer.WithSkipArtifacts(c.GetSkipArtifacts()),
syncer.WithSkipCharts(c.SkipCharts),
syncer.WithUsePlainHTTP(usePlainHTTP),
syncer.WithLogger(l),
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {
Logger log.SectionLogger
WorkDir string
ContainerPlatforms []string
SkipArtifacts bool
}

// Option is a function that modifies the Config
Expand All @@ -23,6 +24,13 @@ func WithWorkDir(workdir string) func(*Config) {
}
}

// WithSkipArtifacts sets the skip artifacts flag
func WithSkipArtifacts(skipArtifacts bool) func(*Config) {
return func(c *Config) {
c.SkipArtifacts = skipArtifacts
}
}

// WithContainerPlatforms sets the container platforms to sync
func WithContainerPlatforms(containerPlatforms []string) func(*Config) {
return func(c *Config) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/client/source/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ func (t *Source) Wrap(tgz, destWrap string, opts ...config.Option) (string, erro
}
defer os.RemoveAll(wrapWorkdir)

outputFile, err := wrap.Chart(tgz, wrap.WithFetchArtifacts(true),
fetchArtifacts := !cfg.SkipArtifacts

outputFile, err := wrap.Chart(tgz, wrap.WithFetchArtifacts(fetchArtifacts),
wrap.WithInsecure(t.insecure), wrap.WithTempDirectory(wrapWorkdir),
wrap.WithAuth(t.username, t.password),
wrap.WithPlatforms(cfg.ContainerPlatforms),
Expand Down
3 changes: 2 additions & 1 deletion pkg/syncer/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func (s *Syncer) syncChart(ch *Chart, l log.SectionLogger) error {

wrappedChartPath, err := s.cli.src.Wrap(ch.TgzPath,
filepath.Join(workdir, "wraps", fmt.Sprintf("%s-%s.wrap.tgz", ch.Name, ch.Version)),
config.WithLogger(l), config.WithWorkDir(workdir), config.WithContainerPlatforms(s.containerPlatforms),
config.WithLogger(l), config.WithWorkDir(workdir),
config.WithContainerPlatforms(s.containerPlatforms), config.WithSkipArtifacts(s.skipArtifacts),
)
if err != nil {
return errors.Annotatef(err, "unable to move chart %q with charts-syncer", id)
Expand Down
10 changes: 10 additions & 0 deletions pkg/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type Syncer struct {
// up re-runs
index ChartIndex

// skip syncing artifacts
skipArtifacts bool

// Storage directory for required artifacts
workdir string

Expand Down Expand Up @@ -91,6 +94,13 @@ func WithUsePlainHTTP(enable bool) Option {
}
}

// WithSkipArtifacts configures the syncer to skip syncing artifacts
func WithSkipArtifacts(skip bool) Option {
return func(s *Syncer) {
s.skipArtifacts = skip
}
}

// WithWorkdir configures the syncer to store artifacts in a specific directory.
func WithWorkdir(dir string) Option {
return func(s *Syncer) {
Expand Down

0 comments on commit 77edda3

Please sign in to comment.