import "github.com/egdaemon/eg/runtime/x/wasi/egtarball"
Package egtarball basic functionality for creating tar balls. it proves the following functionality: - build deterministic paths to a directory for adding contents. - build dterministric archive names from patterns using information provided by the eg environment. - common patterns Assumptions: - tar/gh cli commands are available. - the archive patterns used are unique within the repository the workload is associated with. Compability guarentee: as long as you only use the functions provided by this package for accessing and generating the tarballs we'll ensure no breaking changes.
func Archive(pattern string) string
Return the path to the archive for the given pattern after Pack has been called.
func EnvPattern(pattern string, env func(string) string) string
func GitPattern(prefix string) string
simple template for naming a tarball from git commit information. see eggit.commit.StringReplace for details.
func Name(pattern string) string
replaces the substitution values within the pattern, resulting in the final resulting archive file's name.
func Pack(pattern string) eg.OpFn
create a tarball from the contents of the archive's folder.
package main
import (
"context"
"log"
"github.com/egdaemon/eg/runtime/wasi/eg"
"github.com/egdaemon/eg/runtime/wasi/egenv"
"github.com/egdaemon/eg/runtime/wasi/shell"
"github.com/egdaemon/eg/runtime/x/wasi/egtarball"
)
func archive() string {
return egtarball.GitPattern("example")
}
func Pack(ctx context.Context, op eg.Op) error {
archive := egtarball.GitPattern("example")
return eg.Perform(
ctx,
egtarball.Pack(archive),
egtarball.SHA256Op(archive),
)
}
func Populate(ctx context.Context, _ eg.Op) error {
runtime := shell.Runtime().
Environ("CONTENT", egenv.EphemeralDirectory("example.txt")).
Environ("ARCHIVE", egtarball.Path(archive()))
return shell.Run(
ctx,
runtime.Newf("printf \"hello world\n\" | tee ${CONTENT}"),
runtime.Newf("cp ${CONTENT} ${ARCHIVE}"),
)
}
func main() {
var (
err error
)
ctx := context.Background()
err = eg.Perform(
ctx,
Populate,
Pack,
)
if err != nil {
log.Fatalln(err)
}
}
func Path(pattern string) string
Path generate a unique directory for the contents that will be inside the archive can be placed.
func SHA256(pattern string) string
Reads the cached sha256 from disk, if it cant locate it, recalculates and stores it. will panic if there is an issue calculating the sha256/persisting
func SHA256Op(pattern string) eg.OpFn
func Targz(pattern string) string
suffixes the pattern with the the .tar.gz extension.
func Tarxz(pattern string) string
suffixes the pattern with the the .tar.xz extension.