diff options
Diffstat (limited to 'actions/ostree_commit_action.go')
-rw-r--r-- | actions/ostree_commit_action.go | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/actions/ostree_commit_action.go b/actions/ostree_commit_action.go new file mode 100644 index 0000000..6d41b89 --- /dev/null +++ b/actions/ostree_commit_action.go @@ -0,0 +1,84 @@ +/* +OstreeCommit Action + +Create OSTree commit from rootfs. + +Yaml syntax: + - action: ostree-commit + repository: repository name + branch: branch name + subject: commit message + +Mandatory properties: + +- repository -- path to repository with OSTree structure; the same path is +used by 'ostree' tool with '--repo' argument. +This path is relative to 'artifact' directory. +Please keep in mind -- you will need a root privileges for 'bare' repository +type (https://ostree.readthedocs.io/en/latest/manual/repo/#repository-types-and-locations). + +- branch -- OSTree branch name that should be used for the commit. + +Optional properties: + +- subject -- one line message with commit description. +*/ +package actions + +import ( + "log" + "os" + "path" + + "github.com/go-debos/debos" + "github.com/sjoerdsimons/ostree-go/pkg/otbuiltin" +) + +type OstreeCommitAction struct { + debos.BaseAction `yaml:",inline"` + Repository string + Branch string + Subject string + Command string +} + +func emptyDir(dir string) { + d, _ := os.Open(dir) + defer d.Close() + files, _ := d.Readdirnames(-1) + for _, f := range files { + os.RemoveAll(f) + } +} + +func (ot *OstreeCommitAction) Run(context *debos.DebosContext) error { + ot.LogStart() + repoPath := path.Join(context.Artifactdir, ot.Repository) + + emptyDir(path.Join(context.Rootdir, "dev")) + + repo, err := otbuiltin.OpenRepo(repoPath) + if err != nil { + return err + } + + _, err = repo.PrepareTransaction() + if err != nil { + return err + } + + opts := otbuiltin.NewCommitOptions() + opts.Subject = ot.Subject + ret, err := repo.Commit(context.Rootdir, ot.Branch, opts) + if err != nil { + return err + } else { + log.Printf("Commit: %s\n", ret) + } + _, err = repo.CommitTransaction() + if err != nil { + return err + } + + return nil +} |