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

remove include: feature #1008

Draft
wants to merge 4 commits into
base: main
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
3 changes: 0 additions & 3 deletions docs/apko_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ The `paths` element contains the following children:
- `permissions`: file permissions to set. Permissions should be specified in octal e.g. 0o755 (see `man chmod` for details).
- `source`: used in `hardlink` and `symlink`, this represents the path to link to.


### Includes

`include` defines a path to a configuration file which should be used as the base configuration,
the configuration data is layered on top of this base configuration. By default, there is no
base configuration used.
Expand Down
1 change: 0 additions & 1 deletion examples/include.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions examples/overlay.yaml

This file was deleted.

1 change: 0 additions & 1 deletion examples/remote-include.yaml

This file was deleted.

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/google/go-containerregistry v0.16.1
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/invopop/jsonschema v0.12.0
github.com/jinzhu/copier v0.4.0
github.com/klauspost/pgzip v1.2.6
github.com/package-url/packageurl-go v0.1.2
github.com/sigstore/cosign/v2 v2.2.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10C
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jmhodges/clock v1.2.0 h1:eq4kys+NI0PLngzaHEe7AmPT90XMGIEySD1JfV1PDIs=
github.com/jmhodges/clock v1.2.0/go.mod h1:qKjhA7x7u/lQpPB1XAqX1b1lCI/w3/fNuYpI/ZjLynI=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func WithConfig(configFile string) Option {
bc.o.Log.Printf("loading config file: %s", configFile)

var ic types.ImageConfiguration
if err := ic.Load(configFile, bc.Logger()); err != nil {
if err := ic.Load(configFile); err != nil {
return fmt.Errorf("failed to load image configuration: %w", err)
}

Expand Down
68 changes: 3 additions & 65 deletions pkg/build/types/image_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ import (
"os"
"strings"

"github.com/jinzhu/copier"
"gopkg.in/yaml.v3"

"chainguard.dev/apko/pkg/fetch"
"chainguard.dev/apko/pkg/log"
"chainguard.dev/apko/pkg/vcs"
)
Expand All @@ -42,51 +40,11 @@ func (ic *ImageConfiguration) ProbeVCSUrl(imageConfigPath string, logger log.Log
}

// Parse a configuration blob into an ImageConfiguration struct.
func (ic *ImageConfiguration) parse(configData []byte, logger log.Logger) error {
func (ic *ImageConfiguration) parse(configData []byte) error {
if err := yaml.Unmarshal(configData, ic); err != nil {
return fmt.Errorf("failed to parse image configuration: %w", err)
}

if ic.Include != "" {
logger.Printf("including %s for configuration", ic.Include)

baseIc := ImageConfiguration{}

if err := baseIc.Load(ic.Include, logger); err != nil {
return fmt.Errorf("failed to read include file: %w", err)
}

mergedIc := ImageConfiguration{}

// Copy the base configuration...
if err := copier.Copy(&mergedIc, &baseIc); err != nil {
return fmt.Errorf("failed to copy base configuration: %w", err)
}

// ... and then overlay the local configuration on top.
if err := copier.CopyWithOption(&mergedIc, ic, copier.Option{IgnoreEmpty: true}); err != nil {
return fmt.Errorf("failed to overlay specific configuration: %w", err)
}

// Now copy the merged configuration back to ic.
if err := copier.Copy(ic, &mergedIc); err != nil {
return fmt.Errorf("failed to copy merged configuration: %w", err)
}

// Merge packages, repositories and keyrings.
keyring := append([]string{}, baseIc.Contents.Keyring...)
keyring = append(keyring, mergedIc.Contents.Keyring...)
ic.Contents.Keyring = keyring

repos := append([]string{}, baseIc.Contents.Repositories...)
repos = append(repos, mergedIc.Contents.Repositories...)
ic.Contents.Repositories = repos

pkgs := append([]string{}, baseIc.Contents.Packages...)
pkgs = append(pkgs, mergedIc.Contents.Packages...)
ic.Contents.Packages = pkgs
}

repos := make([]string, 0, len(ic.Contents.Repositories))
for _, repo := range ic.Contents.Repositories {
repo = strings.TrimRight(repo, "/")
Expand All @@ -97,34 +55,14 @@ func (ic *ImageConfiguration) parse(configData []byte, logger log.Logger) error
return nil
}

func (ic *ImageConfiguration) maybeLoadRemote(imageConfigPath string, logger log.Logger) error {
data, err := fetch.Fetch(imageConfigPath)
if err != nil {
return fmt.Errorf("unable to fetch remote include from git: %w", err)
}

return ic.parse(data, logger)
}

// Loads an image configuration given a configuration file path.
func (ic *ImageConfiguration) Load(imageConfigPath string, logger log.Logger) error {
func (ic *ImageConfiguration) Load(imageConfigPath string) error {
data, err := os.ReadFile(imageConfigPath)
if err != nil {
logger.Warnf("loading config file failed: %v", err)
logger.Warnf("attempting to load remote configuration")
logger.Warnf("NOTE: remote configurations are an experimental feature and subject to change.")

if err := ic.maybeLoadRemote(imageConfigPath, logger); err == nil {
return nil
} else {
// At this point, we're doing a remote config file.
logger.Warnf("loading remote configuration failed: %v", err)
}

return err
}

return ic.parse(data, logger)
return ic.parse(data)
}

// Do preflight checks and mutations on an image configuration.
Expand Down
4 changes: 0 additions & 4 deletions pkg/build/types/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@
"type": "object",
"description": "Optional: Annotations to apply to the images manifests"
},
"include": {
"type": "string",
"description": "Optional: Path to a local file containing additional image configuration\n\nThe included configuration is deep merged with the parent configuration"
},
"options": {
"additionalProperties": {
"$ref": "#/$defs/BuildOption"
Expand Down
5 changes: 1 addition & 4 deletions pkg/build/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ type ImageConfiguration struct {
VCSUrl string `json:"vcs-url,omitempty" yaml:"vcs-url,omitempty"`
// Optional: Annotations to apply to the images manifests
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
// Optional: Path to a local file containing additional image configuration
//
// The included configuration is deep merged with the parent configuration
Include string `json:"include,omitempty" yaml:"include,omitempty"`

// Optional: A map of named build option deviations
//
// Deprecated: Use WithExtraPackages.
Expand Down
Loading