Rename some variables following rename of PkgSrc to Pkg

Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
Ian Campbell 2017-10-09 11:24:03 +01:00
parent 4cdc90e221
commit 896cfaab63
5 changed files with 33 additions and 33 deletions

View File

@ -21,7 +21,7 @@ func pkgBuild(args []string) {
force := flags.Bool("force", false, "Force rebuild") force := flags.Bool("force", false, "Force rebuild")
ps, err := pkglib.NewFromCLI(flags, args...) p, 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)
@ -31,7 +31,7 @@ func pkgBuild(args []string) {
if *force { if *force {
opts = append(opts, pkglib.WithBuildForce()) opts = append(opts, pkglib.WithBuildForce())
} }
if err := ps.Build(opts...); err != nil { if err := p.Build(opts...); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err) fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1) os.Exit(1)
} }

View File

@ -21,7 +21,7 @@ func pkgPush(args []string) {
force := flags.Bool("force", false, "Force rebuild") force := flags.Bool("force", false, "Force rebuild")
ps, err := pkglib.NewFromCLI(flags, args...) p, 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)
@ -33,7 +33,7 @@ func pkgPush(args []string) {
opts = append(opts, pkglib.WithBuildForce()) opts = append(opts, pkglib.WithBuildForce())
} }
if err := ps.Build(opts...); err != nil { if err := p.Build(opts...); err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err) fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1) os.Exit(1)
} }

View File

@ -19,11 +19,11 @@ func pkgShowTag(args []string) {
flags.PrintDefaults() flags.PrintDefaults()
} }
ps, err := pkglib.NewFromCLI(flags, args...) p, 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)
} }
fmt.Println(ps.Tag()) fmt.Println(p.Tag())
} }

View File

@ -31,7 +31,7 @@ func WithBuildPush() BuildOpt {
} }
// Build builds the package // Build builds the package
func (ps Pkg) Build(bos ...BuildOpt) error { func (p 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 {
@ -39,16 +39,16 @@ func (ps Pkg) Build(bos ...BuildOpt) error {
} }
} }
if _, ok := os.LookupEnv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"); !ok && ps.trust && bo.push { if _, ok := os.LookupEnv("DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE"); !ok && p.trust && bo.push {
return fmt.Errorf("Pushing with trust enabled requires $DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE to be set") return fmt.Errorf("Pushing with trust enabled requires $DOCKER_CONTENT_TRUST_REPOSITORY_PASSPHRASE to be set")
} }
arch := runtime.GOARCH arch := runtime.GOARCH
if !ps.archSupported(arch) { if !p.archSupported(arch) {
return fmt.Errorf("Arch %s not supported by this package", arch) return fmt.Errorf("Arch %s not supported by this package", arch)
} }
if err := ps.cleanForBuild(); err != nil { if err := p.cleanForBuild(); err != nil {
return err return err
} }
@ -65,10 +65,10 @@ func (ps Pkg) Build(bos ...BuildOpt) error {
return err return err
} }
d := newDockerRunner(ps.trust, ps.cache) d := newDockerRunner(p.trust, p.cache)
if !bo.force { if !bo.force {
ok, err := d.pull(ps.Tag() + suffix) ok, err := d.pull(p.Tag() + suffix)
if err != nil { if err != nil {
return err return err
} }
@ -80,10 +80,10 @@ func (ps Pkg) Build(bos ...BuildOpt) error {
var args []string var args []string
if ps.gitRepo != "" { if p.gitRepo != "" {
args = append(args, "--label", "org.opencontainers.image.source="+ps.gitRepo) args = append(args, "--label", "org.opencontainers.image.source="+p.gitRepo)
} }
if !ps.dirty { if !p.dirty {
commit, err := gitCommitHash("HEAD") commit, err := gitCommitHash("HEAD")
if err != nil { if err != nil {
return err return err
@ -91,11 +91,11 @@ func (ps Pkg) Build(bos ...BuildOpt) error {
args = append(args, "--label", "org.opencontainers.image.revision="+commit) args = append(args, "--label", "org.opencontainers.image.revision="+commit)
} }
if !ps.network { if !p.network {
args = append(args, "--network=none") args = append(args, "--network=none")
} }
if err := d.build(ps.Tag()+suffix, ps.pkgPath, args...); err != nil { if err := d.build(p.Tag()+suffix, p.pkgPath, args...); err != nil {
return err return err
} }
@ -104,7 +104,7 @@ func (ps Pkg) Build(bos ...BuildOpt) error {
return nil return nil
} }
if ps.dirty { if p.dirty {
return fmt.Errorf("build complete, refusing to push dirty package") return fmt.Errorf("build complete, refusing to push dirty package")
} }
@ -114,7 +114,7 @@ func (ps Pkg) Build(bos ...BuildOpt) error {
// matters given we do either pull or build above in the // matters given we do either pull or build above in the
// !force case. // !force case.
if err := d.pushWithManifest(ps.Tag(), suffix); err != nil { if err := d.pushWithManifest(p.Tag(), suffix); err != nil {
return err return err
} }
@ -123,12 +123,12 @@ func (ps Pkg) Build(bos ...BuildOpt) error {
return nil return nil
} }
relTag, err := ps.ReleaseTag(release) relTag, err := p.ReleaseTag(release)
if err != nil { if err != nil {
return err return err
} }
if err := d.tag(ps.Tag()+suffix, relTag+suffix); err != nil { if err := d.tag(p.Tag()+suffix, relTag+suffix); err != nil {
return err return err
} }

View File

@ -163,33 +163,33 @@ func NewFromCLI(fs *flag.FlagSet, args ...string) (Pkg, error) {
} }
// Hash returns the hash of the package // Hash returns the hash of the package
func (ps Pkg) Hash() string { func (p Pkg) Hash() string {
return ps.hash return p.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 Pkg) ReleaseTag(release string) (string, error) { func (p 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")
} }
if ps.dirty { if p.dirty {
return "", fmt.Errorf("Cannot release a dirty package") return "", fmt.Errorf("Cannot release a dirty package")
} }
tag := ps.org + "/" + ps.image + ":" + release tag := p.org + "/" + p.image + ":" + release
return tag, nil return tag, nil
} }
// Tag returns the tag to use for the package // Tag returns the tag to use for the package
func (ps Pkg) Tag() string { func (p Pkg) Tag() string {
tag := ps.org + "/" + ps.image + ":" + ps.hash tag := p.org + "/" + p.image + ":" + p.hash
if ps.dirty { if p.dirty {
tag += "-dirty" tag += "-dirty"
} }
return tag return tag
} }
func (ps Pkg) archSupported(want string) bool { func (p Pkg) archSupported(want string) bool {
for _, supp := range ps.arches { for _, supp := range p.arches {
if supp == want { if supp == want {
return true return true
} }
@ -197,8 +197,8 @@ func (ps Pkg) archSupported(want string) bool {
return false return false
} }
func (ps Pkg) cleanForBuild() error { func (p Pkg) cleanForBuild() error {
if ps.commitHash != "HEAD" { if p.commitHash != "HEAD" {
return fmt.Errorf("Cannot build from commit hash != HEAD") return fmt.Errorf("Cannot build from commit hash != HEAD")
} }
return nil return nil