k3s/pkg/static/stage.go
Brad Davidson fcaeebaa18 Add support for disabling all staged content
This reduces the binary footprint for downstream users that won't use
these files anyway.

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2020-09-14 14:21:37 -07:00

29 lines
536 B
Go

// +build !no_stage
package static
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
func Stage(dataDir string) error {
for _, name := range AssetNames() {
content, err := Asset(name)
if err != nil {
return err
}
p := filepath.Join(dataDir, name)
logrus.Info("Writing static file: ", p)
os.MkdirAll(filepath.Dir(p), 0700)
if err := ioutil.WriteFile(p, content, 0600); err != nil {
return errors.Wrapf(err, "failed to write to %s", name)
}
}
return nil
}