tarscrub

package
v0.1.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Example (GitHello)
package main

import (
	"crypto/sha256"
	"fmt"
	"io/fs"

	"github.com/docker-library/bashbrew/pkg/gitfs"
	"github.com/docker-library/bashbrew/pkg/tarscrub"

	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/storage/memory"
)

func main() {
	repo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
		URL:          "https://github.com/docker-library/hello-world.git",
		SingleBranch: true,
	})
	if err != nil {
		panic(err)
	}

	commit, err := gitfs.CommitHash(repo, "3fb6ebca4163bf5b9cc496ac3e8f11cb1e754aee")
	if err != nil {
		panic(err)
	}

	f, err := fs.Sub(commit, "amd64/hello-world")
	if err != nil {
		panic(err)
	}

	h := sha256.New()

	if err := tarscrub.WriteTar(f, h); err != nil {
		panic(err)
	}

	fmt.Printf("%x\n", h.Sum(nil))
}
Output:
22266b0a36deee72428cffd00859ce991f1db101260999c40904ace7d634b788
Example (GitVarnish)

this example is nice because it has some intentionally dangling symlinks in it that trip things up if they aren't implemented correctly! (see also pkg/gitfs/tarscrub_test.go)

package main

import (
	"crypto/sha256"
	"fmt"
	"io/fs"

	"github.com/docker-library/bashbrew/pkg/gitfs"
	"github.com/docker-library/bashbrew/pkg/tarscrub"

	"github.com/go-git/go-git/v5"
	"github.com/go-git/go-git/v5/storage/memory"
)

func main() {
	repo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
		URL:          "https://github.com/varnish/docker-varnish.git",
		SingleBranch: true,
	})
	if err != nil {
		panic(err)
	}

	commit, err := gitfs.CommitHash(repo, "0c295b528f28a98650fb2580eab6d34b30b165c4")
	if err != nil {
		panic(err)
	}

	f, err := fs.Sub(commit, "stable/debian")
	if err != nil {
		panic(err)
	}

	h := sha256.New()

	if err := tarscrub.WriteTar(f, h); err != nil {
		panic(err)
	}

	fmt.Printf("%x\n", h.Sum(nil))
}
Output:
3aef5ac859b23d65dfe5e9f2a47750e9a32852222829cfba762a870c1473fad6

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScrubHeader

func ScrubHeader(hdr *tar.Header) *tar.Header

takes a tar header object and "scrubs" it (uid/gid zeroed, timestamps zeroed)

func WriteTar

func WriteTar(f fs.FS, w io.Writer) error

this writes a "scrubbed" tarball to the given io.Writer (uid/gid zeroed, timestamps zeroed)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL