The pkg/tarfs
package in the Chainguard Dev’s APKO project is used to create filesystems in memory. It is a Go package that provides an implementation of the io/fs
interface using tar format. This package is used to build container images using a declarative language based on YAML.
Here are the possible options for using the pkg/tarfs
package:
- DirFS: This function returns a
dirFS
type, which is aio/fs.FS
that serves the contents of a directory on the filesystem. It is suitable for use as aBaseFS
. Here’s an example:
import (
"vfs"
"path/filepath"
)
func main() {
baseFS, err := vfs.DirFS(filepath.Clean("/path/to/directory"))
if err != nil {
// handle error
}
// use baseFS
}
- ExpandAPK: This function expands an APK package into a
memFS
instance. It takes atar.File
object, afs.FS
object, and anapk.Package
object as arguments. Here’s an example:
import (
"vfs"
"apk"
"io/ioutil"
"path/filepath"
)
func main() {
pkg, err := apk.NewPackage("path/to/apk/file")
if err != nil {
// handle error
}
f, err := os.Open("path/to/apk/file")
if err != nil {
// handle error
}
defer f.Close()
tf, err := ioutil.ReadAll(f)
if err != nil {
// handle error
}
tr := tar.NewReader(bytes.NewReader(tf))
baseFS, err := vfs.ExpandAPK(tr, nil, pkg)
if err != nil {
// handle error
}
// use baseFS
}
- SetXattr: This function sets an extended attribute on a file in a
memFS
instance. It takes a file path, an attribute name, and an attribute value as arguments. Here’s an example:
import (
"vfs"
)
func main() {
baseFS, err := vfs.DirFS(filepath.Clean("/path/to/directory"))
if err != nil {
// handle error
}
err = baseFS.SetXattr("path/to/file", "user.test", []byte("test"))
if err != nil {
// handle error
}
// use baseFS
}
For more information, see the following links:
- https://edu.chainguard.dev/open-source/slsa/what-is-slsa
- https://edu.chainguard.dev/open-source/melange/overview
- https://edu.chainguard.dev/open-source/sigstore/cosign/how-to-verify-file-signatures-with-cosign
- https://edu.chainguard.dev/open-source/apko/faq
- https://edu.chainguard.dev/open-source/sigstore/rekor/how-to-verify-file-signatures-with-rekor-or-curl
- https://edu.chainguard.dev/open-source/apko/getting-started-with-apko
- https://edu.chainguard.dev/open-source/apko/bazel-rules
- https://edu.chainguard.dev/open-source/apko/reference
- https://opensource.com/article/22/8/linux-tar-command
- https://github.com/chainguard-dev/apko/releases/download/v0.6.0/apko_0.6.0_linux_amd64.tar.gz.crt
- https://opensource.com/article/17/7/how-unzip-targz-file
- https://edu.chainguard.dev/chainguard/chainguard-images/reference/argo-cli/tags_history
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/dirfs.go
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/fs.go
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/vfs.go
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/fsmode.go