mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-20 09:39:08 +00:00
Rename pkgsrc to pkglib
Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
ba60937754
commit
c84c997383
@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/pkgsrc"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/pkglib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pkgBuild(args []string) {
|
func pkgBuild(args []string) {
|
||||||
@ -21,15 +21,15 @@ func pkgBuild(args []string) {
|
|||||||
|
|
||||||
force := flags.Bool("force", false, "Force rebuild")
|
force := flags.Bool("force", false, "Force rebuild")
|
||||||
|
|
||||||
ps, err := pkgsrc.NewFromCLI(flags, args)
|
ps, err := pkglib.NewFromCLI(flags, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts []pkgsrc.BuildOpt
|
var opts []pkglib.BuildOpt
|
||||||
if *force {
|
if *force {
|
||||||
opts = append(opts, pkgsrc.WithBuildForce())
|
opts = append(opts, pkglib.WithBuildForce())
|
||||||
}
|
}
|
||||||
if err := ps.Build(opts...); err != nil {
|
if err := ps.Build(opts...); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/pkgsrc"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/pkglib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pkgPush(args []string) {
|
func pkgPush(args []string) {
|
||||||
@ -21,16 +21,16 @@ func pkgPush(args []string) {
|
|||||||
|
|
||||||
force := flags.Bool("force", false, "Force rebuild")
|
force := flags.Bool("force", false, "Force rebuild")
|
||||||
|
|
||||||
ps, err := pkgsrc.NewFromCLI(flags, args)
|
ps, err := pkglib.NewFromCLI(flags, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
var opts []pkgsrc.BuildOpt
|
var opts []pkglib.BuildOpt
|
||||||
opts = append(opts, pkgsrc.WithBuildPush())
|
opts = append(opts, pkglib.WithBuildPush())
|
||||||
if *force {
|
if *force {
|
||||||
opts = append(opts, pkgsrc.WithBuildForce())
|
opts = append(opts, pkglib.WithBuildForce())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ps.Build(opts...); err != nil {
|
if err := ps.Build(opts...); err != nil {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/pkgsrc"
|
"github.com/linuxkit/linuxkit/src/cmd/linuxkit/pkglib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pkgShowTag(args []string) {
|
func pkgShowTag(args []string) {
|
||||||
@ -19,7 +19,7 @@ func pkgShowTag(args []string) {
|
|||||||
flags.PrintDefaults()
|
flags.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
ps, err := pkgsrc.NewFromCLI(flags, args)
|
ps, err := pkglib.NewFromCLI(flags, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package pkgsrc
|
package pkglib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -31,7 +31,7 @@ func WithBuildPush() BuildOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build builds the package
|
// Build builds the package
|
||||||
func (ps PkgSrc) Build(bos ...BuildOpt) error {
|
func (ps Pkg) Build(bos ...BuildOpt) error {
|
||||||
var bo buildOpts
|
var bo buildOpts
|
||||||
for _, fn := range bos {
|
for _, fn := range bos {
|
||||||
if err := fn(&bo); err != nil {
|
if err := fn(&bo); err != nil {
|
@ -1,4 +1,4 @@
|
|||||||
package pkgsrc
|
package pkglib
|
||||||
|
|
||||||
// Thin wrappers around Docker CLI invocations
|
// Thin wrappers around Docker CLI invocations
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package pkgsrc
|
package pkglib
|
||||||
|
|
||||||
// Thin wrappers around git CLI invocations
|
// Thin wrappers around git CLI invocations
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package pkgsrc
|
package pkglib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
@ -20,8 +20,8 @@ type pkgInfo struct {
|
|||||||
Cache bool `yaml:"cache"`
|
Cache bool `yaml:"cache"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PkgSrc encapsulates information about a package's source
|
// Pkg encapsulates information about a package's source
|
||||||
type PkgSrc struct {
|
type Pkg struct {
|
||||||
// These correspond to pkgInfo fields
|
// These correspond to pkgInfo fields
|
||||||
image string
|
image string
|
||||||
org string
|
org string
|
||||||
@ -38,8 +38,8 @@ type PkgSrc struct {
|
|||||||
commitHash string
|
commitHash string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFromCLI creates a PkgSrc from a set of CLI arguments. Calls fs.Parse()
|
// NewFromCLI creates a Pkg from a set of CLI arguments. Calls fs.Parse()
|
||||||
func NewFromCLI(fs *flag.FlagSet, args []string) (PkgSrc, error) {
|
func NewFromCLI(fs *flag.FlagSet, args []string) (Pkg, error) {
|
||||||
// Defaults
|
// Defaults
|
||||||
pi := pkgInfo{
|
pi := pkgInfo{
|
||||||
Org: "linuxkit",
|
Org: "linuxkit",
|
||||||
@ -71,16 +71,16 @@ func NewFromCLI(fs *flag.FlagSet, args []string) (PkgSrc, error) {
|
|||||||
fs.Parse(args)
|
fs.Parse(args)
|
||||||
|
|
||||||
if fs.NArg() < 1 {
|
if fs.NArg() < 1 {
|
||||||
return PkgSrc{}, fmt.Errorf("A pkg directory is required")
|
return Pkg{}, fmt.Errorf("A pkg directory is required")
|
||||||
}
|
}
|
||||||
if fs.NArg() > 1 {
|
if fs.NArg() > 1 {
|
||||||
return PkgSrc{}, fmt.Errorf("Unknown extra arguments given: %s", fs.Args()[1:])
|
return Pkg{}, fmt.Errorf("Unknown extra arguments given: %s", fs.Args()[1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
pkg := fs.Arg(0)
|
pkg := fs.Arg(0)
|
||||||
pkgPath, err := filepath.Abs(pkg)
|
pkgPath, err := filepath.Abs(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PkgSrc{}, err
|
return Pkg{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if hashPath == "" {
|
if hashPath == "" {
|
||||||
@ -88,11 +88,11 @@ func NewFromCLI(fs *flag.FlagSet, args []string) (PkgSrc, error) {
|
|||||||
} else {
|
} else {
|
||||||
hashPath, err = filepath.Abs(hashPath)
|
hashPath, err = filepath.Abs(hashPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PkgSrc{}, err
|
return Pkg{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !strings.HasPrefix(pkgPath, hashPath) {
|
if !strings.HasPrefix(pkgPath, hashPath) {
|
||||||
return PkgSrc{}, fmt.Errorf("Hash path is not a prefix of the package path")
|
return Pkg{}, fmt.Errorf("Hash path is not a prefix of the package path")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(ijc) pkgPath and hashPath really ought to be in the same git tree too...
|
// TODO(ijc) pkgPath and hashPath really ought to be in the same git tree too...
|
||||||
@ -100,14 +100,14 @@ func NewFromCLI(fs *flag.FlagSet, args []string) (PkgSrc, error) {
|
|||||||
|
|
||||||
b, err := ioutil.ReadFile(filepath.Join(pkgPath, buildYML))
|
b, err := ioutil.ReadFile(filepath.Join(pkgPath, buildYML))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PkgSrc{}, err
|
return Pkg{}, err
|
||||||
}
|
}
|
||||||
if err := yaml.Unmarshal(b, &pi); err != nil {
|
if err := yaml.Unmarshal(b, &pi); err != nil {
|
||||||
return PkgSrc{}, err
|
return Pkg{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if pi.Image == "" {
|
if pi.Image == "" {
|
||||||
return PkgSrc{}, fmt.Errorf("Image field is required")
|
return Pkg{}, fmt.Errorf("Image field is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go's flag package provides no way to see if a flag was set
|
// Go's flag package provides no way to see if a flag was set
|
||||||
@ -128,16 +128,16 @@ func NewFromCLI(fs *flag.FlagSet, args []string) (PkgSrc, error) {
|
|||||||
|
|
||||||
if hash == "" {
|
if hash == "" {
|
||||||
if hash, err = gitTreeHash(hashPath, hashCommit); err != nil {
|
if hash, err = gitTreeHash(hashPath, hashCommit); err != nil {
|
||||||
return PkgSrc{}, err
|
return Pkg{}, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dirty, err := gitIsDirty(hashPath, hashCommit)
|
dirty, err := gitIsDirty(hashPath, hashCommit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PkgSrc{}, err
|
return Pkg{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return PkgSrc{
|
return Pkg{
|
||||||
image: pi.Image,
|
image: pi.Image,
|
||||||
org: pi.Org,
|
org: pi.Org,
|
||||||
hash: hash,
|
hash: hash,
|
||||||
@ -153,12 +153,12 @@ func NewFromCLI(fs *flag.FlagSet, args []string) (PkgSrc, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hash returns the hash of the package
|
// Hash returns the hash of the package
|
||||||
func (ps PkgSrc) Hash() string {
|
func (ps Pkg) Hash() string {
|
||||||
return ps.hash
|
return ps.hash
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReleaseTag returns the tag to use for a particular release of the package
|
// ReleaseTag returns the tag to use for a particular release of the package
|
||||||
func (ps PkgSrc) ReleaseTag(release string) (string, error) {
|
func (ps Pkg) ReleaseTag(release string) (string, error) {
|
||||||
if release == "" {
|
if release == "" {
|
||||||
return "", fmt.Errorf("A release tag is required")
|
return "", fmt.Errorf("A release tag is required")
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ func (ps PkgSrc) ReleaseTag(release string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tag returns the tag to use for the package
|
// Tag returns the tag to use for the package
|
||||||
func (ps PkgSrc) Tag() string {
|
func (ps Pkg) Tag() string {
|
||||||
tag := ps.org + "/" + ps.image + ":" + ps.hash
|
tag := ps.org + "/" + ps.image + ":" + ps.hash
|
||||||
if ps.dirty {
|
if ps.dirty {
|
||||||
tag += "-dirty"
|
tag += "-dirty"
|
||||||
@ -178,7 +178,7 @@ func (ps PkgSrc) Tag() string {
|
|||||||
return tag
|
return tag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps PkgSrc) archSupported(want string) bool {
|
func (ps Pkg) archSupported(want string) bool {
|
||||||
for _, supp := range ps.arches {
|
for _, supp := range ps.arches {
|
||||||
if supp == want {
|
if supp == want {
|
||||||
return true
|
return true
|
||||||
@ -187,7 +187,7 @@ func (ps PkgSrc) archSupported(want string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ps PkgSrc) cleanForBuild() error {
|
func (ps Pkg) cleanForBuild() error {
|
||||||
if ps.commitHash != "HEAD" {
|
if ps.commitHash != "HEAD" {
|
||||||
return fmt.Errorf("Cannot build from commit hash != HEAD")
|
return fmt.Errorf("Cannot build from commit hash != HEAD")
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user