2022-04-08 17:44:40 +00:00
|
|
|
//go:build !no_stage
|
2020-09-11 21:51:45 +00:00
|
|
|
|
2019-01-22 21:14:58 +00:00
|
|
|
package deploy
|
|
|
|
|
|
|
|
import (
|
2019-03-06 23:22:55 +00:00
|
|
|
"bytes"
|
2019-01-22 21:14:58 +00:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2019-11-05 21:30:50 +00:00
|
|
|
"strings"
|
2019-03-25 04:54:52 +00:00
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/sirupsen/logrus"
|
2019-01-22 21:14:58 +00:00
|
|
|
)
|
|
|
|
|
2020-01-29 23:40:49 +00:00
|
|
|
func Stage(dataDir string, templateVars map[string]string, skips map[string]bool) error {
|
2019-11-05 21:30:50 +00:00
|
|
|
staging:
|
2019-01-22 21:14:58 +00:00
|
|
|
for _, name := range AssetNames() {
|
2019-11-05 21:30:50 +00:00
|
|
|
nameNoExtension := strings.TrimSuffix(name, filepath.Ext(name))
|
|
|
|
if skips[name] || skips[nameNoExtension] {
|
|
|
|
continue staging
|
|
|
|
}
|
|
|
|
namePath := strings.Split(name, string(os.PathSeparator))
|
|
|
|
for i := 1; i < len(namePath); i++ {
|
|
|
|
subPath := filepath.Join(namePath[0:i]...)
|
|
|
|
if skips[subPath] {
|
|
|
|
continue staging
|
|
|
|
}
|
2019-03-23 21:22:58 +00:00
|
|
|
}
|
2019-11-05 21:30:50 +00:00
|
|
|
|
2019-01-22 21:14:58 +00:00
|
|
|
content, err := Asset(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-03-06 23:22:55 +00:00
|
|
|
for k, v := range templateVars {
|
|
|
|
content = bytes.Replace(content, []byte(k), []byte(v), -1)
|
|
|
|
}
|
2019-01-22 21:14:58 +00:00
|
|
|
p := filepath.Join(dataDir, name)
|
2019-11-05 21:30:50 +00:00
|
|
|
os.MkdirAll(filepath.Dir(p), 0700)
|
2019-01-22 21:14:58 +00:00
|
|
|
logrus.Info("Writing manifest: ", p)
|
|
|
|
if err := ioutil.WriteFile(p, content, 0600); err != nil {
|
|
|
|
return errors.Wrapf(err, "failed to write to %s", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|