mirror of
https://github.com/fluxcd/flux2.git
synced 2025-11-02 10:48:03 +08:00
This commit changes the way the build of manifests is triggered by making smarter use of the capabilities of Make. The result should be that the manifests are only regenerated if: 1. There is no `cmd/flux/manifests/` directory. 2. There have been made changes to the YAML files in the `manifests/` directory that are newer than the files in `cmd/flux/manifests/`. Signed-off-by: Hidde Beydals <hello@hidde.co>
32 lines
627 B
Go
32 lines
627 B
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
"io/fs"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
//go:embed manifests/*.yaml
|
|
var embeddedManifests embed.FS
|
|
|
|
func writeEmbeddedManifests(dir string) error {
|
|
manifests, err := fs.ReadDir(embeddedManifests, "manifests")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, manifest := range manifests {
|
|
data, err := fs.ReadFile(embeddedManifests, path.Join("manifests", manifest.Name()))
|
|
if err != nil {
|
|
return fmt.Errorf("reading file failed: %w", err)
|
|
}
|
|
|
|
err = os.WriteFile(path.Join(dir, manifest.Name()), data, 0666)
|
|
if err != nil {
|
|
return fmt.Errorf("writing file failed: %w", err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|