manifest

package
v0.0.0-...-669fbe5 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2020 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Overview

Example
package main

import (
	"bufio"
	"fmt"
	"strings"

	"github.com/docker-library/go-dockerlibrary/manifest"
)

func main() {
	man, err := manifest.Parse(bufio.NewReader(strings.NewReader(`# RFC 2822

	# I LOVE CAKE

Maintainers: InfoSiftr <github@infosiftr.com> (@infosiftr),
             Johan Euphrosine <proppy@google.com> (@proppy)
GitFetch: refs/heads/master
GitRepo: https://github.com/docker-library/golang.git
SharedTags: latest
arm64v8-GitRepo: https://github.com/docker-library/golang.git
Architectures: amd64, amd64


 # hi


 	 # blasphemer


# Go 1.6
Tags: 1.6.1, 1.6, 1
arm64v8-GitRepo: https://github.com/docker-library/golang.git
Directory: 1.6
GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a
Constraints: some-random-build-server


# Go 1.5
Tags: 1.5.3
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
SharedTags: 1.5.3-debian, 1.5-debian
Directory: 1.5
s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df
i386-GitFetch: refs/heads/i386
ppc64le-Directory: 1.5/ppc64le/


Tags: 1.5
SharedTags: 1.5-debian
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
Directory: 1.5
s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df
i386-GitFetch: refs/heads/i386
ppc64le-Directory: 1.5/ppc64le

Tags: 1.5-alpine
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
Directory: 1.5
File: Dockerfile.alpine
s390x-File: Dockerfile.alpine.s390x.bad-boy

SharedTags: raspbian
GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
Tags: raspbian-s390x
Architectures: s390x, i386
File: Dockerfile-raspbian
s390x-File: Dockerfile


`)))
	if err != nil {
		panic(err)
	}
	fmt.Printf("-------------\n2822:\n%s\n", man)

	fmt.Printf("\nShared Tag Groups:\n")
	for _, group := range man.GetSharedTagGroups() {
		fmt.Printf("\n  - %s\n", strings.Join(group.SharedTags, ", "))
		for _, entry := range group.Entries {
			fmt.Printf("    - %s\n", entry.TagsString())
		}
	}
	fmt.Printf("\n")

	man, err = manifest.Parse(bufio.NewReader(strings.NewReader(`
# maintainer: InfoSiftr <github@infosiftr.com> (@infosiftr)
# maintainer: John Smith <jsmith@example.com> (@example-jsmith)

# first set
a: b@c d
e: b@c d

 # second set
f: g@h
i: g@h j
`)))
	if err != nil {
		panic(err)
	}
	fmt.Printf("-------------\nline-based:\n%v\n", man)

}
Output:

-------------
2822:
Maintainers: InfoSiftr <github@infosiftr.com> (@infosiftr), Johan Euphrosine <proppy@google.com> (@proppy)
SharedTags: latest
GitRepo: https://github.com/docker-library/golang.git
arm64v8-GitRepo: https://github.com/docker-library/golang.git

Tags: 1.6.1, 1.6, 1
GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a
Directory: 1.6
Constraints: some-random-build-server

Tags: 1.5.3, 1.5
SharedTags: 1.5.3-debian, 1.5-debian
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
Directory: 1.5
i386-GitFetch: refs/heads/i386
ppc64le-Directory: 1.5/ppc64le
s390x-GitCommit: b6c460e7cd79b595267870a98013ec3078b490df

Tags: 1.5-alpine
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
Directory: 1.5
File: Dockerfile.alpine
s390x-File: Dockerfile.alpine.s390x.bad-boy

Tags: raspbian-s390x
SharedTags: raspbian
Architectures: i386, s390x
GitCommit: deadbeefdeadbeefdeadbeefdeadbeefdeadbeef
File: Dockerfile-raspbian
s390x-File: Dockerfile

Shared Tag Groups:

  - latest
    - 1.6.1, 1.6, 1
    - 1.5-alpine

  - 1.5.3-debian, 1.5-debian
    - 1.5.3, 1.5

  - raspbian
    - raspbian-s390x

-------------
line-based:
Maintainers: InfoSiftr <github@infosiftr.com> (@infosiftr), John Smith <jsmith@example.com> (@example-jsmith)
GitFetch: refs/heads/*

Tags: a, e
GitRepo: b
GitCommit: c
Directory: d

Tags: f
GitRepo: g
GitFetch: refs/tags/h
GitCommit: FETCH_HEAD

Tags: i
GitRepo: g
GitFetch: refs/tags/h
GitCommit: FETCH_HEAD
Directory: j

Index

Examples

Constants

View Source
const (
	MaintainersNameRegex   = `[^\s<>()][^<>()]*`
	MaintainersEmailRegex  = `[^\s<>()]+`
	MaintainersGitHubRegex = `[^\s<>()]+`

	MaintainersFormat = `Full Name <contact-email-or-url> (@github-handle) OR Full Name (@github-handle)`
)
View Source
const DefaultLineBasedFetch = "refs/heads/*" // backwards compatibility
View Source
const StringSeparator2822 = ", "

Variables

View Source
var (
	GitCommitRegex = regexp.MustCompile(`^[0-9a-f]{1,64}$`)
	GitFetchRegex  = regexp.MustCompile(`^refs/(heads|tags)/[^*?:]+$`)

	// https://github.com/docker/distribution/blob/v2.7.1/reference/regexp.go#L37
	ValidTagRegex = regexp.MustCompile(`^\w[\w.-]{0,127}$`)
)
View Source
var (
	DefaultArchitecture = "amd64"

	DefaultManifestEntry = Manifest2822Entry{
		Architectures: []string{DefaultArchitecture},

		GitFetch:  "refs/heads/master",
		Directory: ".",
		File:      "Dockerfile",
	}
)
View Source
var (
	MaintainersRegex = regexp.MustCompile(`^(` + MaintainersNameRegex + `)(?:\s+<(` + MaintainersEmailRegex + `)>)?\s+[(]@(` + MaintainersGitHubRegex + `)[)]$`)
)

Functions

This section is empty.

Types

type Manifest2822

type Manifest2822 struct {
	Global  Manifest2822Entry
	Entries []Manifest2822Entry
}

func Fetch

func Fetch(library, repo string) (string, string, *Manifest2822, error)

"library" is the default "library directory" returns the parsed version of (in order):

if "repo" is a URL, the remote contents of that URL
if "repo" is a relative path like "./repo", that file
the file "library/repo"

(repoName, tagName, man, err)

Example (Local)
package main

import (
	"fmt"

	"github.com/docker-library/go-dockerlibrary/manifest"
)

func main() {
	repoName, tagName, man, err := manifest.Fetch("testdata", "bash:4.4")
	if err != nil {
		panic(err)
	}

	fmt.Printf("%s:%s\n\n", repoName, tagName)

	fmt.Println(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String())

}
Output:

bash:4.4

Maintainers: Tianon Gravi <admwiggin@gmail.com> (@tianon)
Tags: 4.4.12, 4.4, 4, latest
GitRepo: https://github.com/tianon/docker-bash.git
GitCommit: 1cbb5cf49b4c53bd5a986abf7a1afeb9a80eac1e
Directory: 4.4
Example (Remote)
package main

import (
	"fmt"

	"github.com/docker-library/go-dockerlibrary/manifest"
)

func main() {
	repoName, tagName, man, err := manifest.Fetch("/home/jsmith/docker/official-images/library", "https://github.com/docker-library/official-images/raw/1a3c4cd6d5cd53bd538a6f56a69f94c5b35325a7/library/bash:4.4")
	if err != nil {
		panic(err)
	}

	fmt.Printf("%s:%s\n\n", repoName, tagName)

	fmt.Println(man.GetTag(tagName).ClearDefaults(manifest.DefaultManifestEntry).String())

}
Output:

bash:4.4

Maintainers: Tianon Gravi <admwiggin@gmail.com> (@tianon)
Tags: 4.4.12, 4.4, 4, latest
GitRepo: https://github.com/tianon/docker-bash.git
GitCommit: 1cbb5cf49b4c53bd5a986abf7a1afeb9a80eac1e
Directory: 4.4

func Parse

func Parse(reader io.Reader) (*Manifest2822, error)

try parsing as a 2822 manifest, but fallback to line-based if that fails

func Parse2822

func Parse2822(readerIn io.Reader) (*Manifest2822, error)

func ParseLineBased

func ParseLineBased(readerIn io.Reader) (*Manifest2822, error)

func (*Manifest2822) AddEntry

func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error

func (Manifest2822) GetAllSharedTags

func (manifest Manifest2822) GetAllSharedTags() []string

GetAllSharedTags returns a list of the sum of all SharedTags in all entries of this image manifest (in the order they appear in the file).

func (Manifest2822) GetSharedTag

func (manifest Manifest2822) GetSharedTag(tag string) []*Manifest2822Entry

GetSharedTag returns a list of entries with the given tag in entry.SharedTags (or the empty list if there are no entries with the given tag).

func (Manifest2822) GetSharedTagGroups

func (manifest Manifest2822) GetSharedTagGroups() []SharedTagGroup

GetSharedTagGroups returns a map of shared tag groups to the list of entries they share (as described in https://github.com/docker-library/go-dockerlibrary/pull/2#issuecomment-277853597).

func (Manifest2822) GetTag

func (manifest Manifest2822) GetTag(tag string) *Manifest2822Entry

func (Manifest2822) String

func (manifest Manifest2822) String() string

type Manifest2822Entry

type Manifest2822Entry struct {
	control.Paragraph

	Maintainers []string `delim:"," strip:"\n\r\t "`

	Tags       []string `delim:"," strip:"\n\r\t "`
	SharedTags []string `delim:"," strip:"\n\r\t "`

	Architectures []string `delim:"," strip:"\n\r\t "`

	GitRepo   string
	GitFetch  string
	GitCommit string
	Directory string
	File      string

	// architecture-specific versions of the above fields
	ArchValues map[string]string

	Constraints []string `delim:"," strip:"\n\r\t "`
}

func ParseLineBasedLine

func ParseLineBasedLine(line string, defaults Manifest2822Entry) (*Manifest2822Entry, error)

TODO write more of a proper parser? (probably not worthwhile given that 2822 is the preferred format)

func (Manifest2822Entry) ArchDirectory

func (entry Manifest2822Entry) ArchDirectory(arch string) string

func (Manifest2822Entry) ArchFile

func (entry Manifest2822Entry) ArchFile(arch string) string

func (Manifest2822Entry) ArchGitCommit

func (entry Manifest2822Entry) ArchGitCommit(arch string) string

func (Manifest2822Entry) ArchGitFetch

func (entry Manifest2822Entry) ArchGitFetch(arch string) string

func (Manifest2822Entry) ArchGitRepo

func (entry Manifest2822Entry) ArchGitRepo(arch string) string

func (Manifest2822Entry) ArchitecturesString

func (entry Manifest2822Entry) ArchitecturesString() string

func (*Manifest2822Entry) CleanDirectoryValues

func (entry *Manifest2822Entry) CleanDirectoryValues()

func (Manifest2822Entry) ClearDefaults

func (entry Manifest2822Entry) ClearDefaults(defaults Manifest2822Entry) Manifest2822Entry

returns a new Entry with any of the values that are equal to the values in "defaults" cleared

func (Manifest2822Entry) Clone

func (entry Manifest2822Entry) Clone() Manifest2822Entry

func (Manifest2822Entry) ConstraintsString

func (entry Manifest2822Entry) ConstraintsString() string

func (*Manifest2822Entry) DeduplicateArchitectures

func (entry *Manifest2822Entry) DeduplicateArchitectures()

DeduplicateArchitectures will remove duplicate values from entry.Architectures and sort the result.

func (*Manifest2822Entry) DeduplicateSharedTags

func (entry *Manifest2822Entry) DeduplicateSharedTags()

DeduplicateSharedTags will remove duplicate values from entry.SharedTags, preserving order.

func (Manifest2822Entry) HasArchitecture

func (entry Manifest2822Entry) HasArchitecture(arch string) bool

HasArchitecture returns true if the given architecture exists in entry.Architectures

func (Manifest2822Entry) HasSharedTag

func (entry Manifest2822Entry) HasSharedTag(tag string) bool

HasSharedTag returns true if the given tag exists in entry.SharedTags.

func (Manifest2822Entry) HasTag

func (entry Manifest2822Entry) HasTag(tag string) bool

func (Manifest2822Entry) InvalidArchitectures

func (entry Manifest2822Entry) InvalidArchitectures() []string

func (Manifest2822Entry) InvalidMaintainers

func (entry Manifest2822Entry) InvalidMaintainers() []string

func (Manifest2822Entry) InvalidTags

func (entry Manifest2822Entry) InvalidTags() []string

func (Manifest2822Entry) MaintainersString

func (entry Manifest2822Entry) MaintainersString() string

func (Manifest2822Entry) SameBuildArtifacts

func (a Manifest2822Entry) SameBuildArtifacts(b Manifest2822Entry) bool

if this method returns "true", then a.Tags and b.Tags can safely be combined (for the purposes of building)

func (*Manifest2822Entry) SeedArchValues

func (entry *Manifest2822Entry) SeedArchValues()

func (*Manifest2822Entry) SetGitCommit

func (entry *Manifest2822Entry) SetGitCommit(arch string, commit string)

func (*Manifest2822Entry) SetGitRepo

func (entry *Manifest2822Entry) SetGitRepo(arch string, repo string)

func (Manifest2822Entry) SharedTagsString

func (entry Manifest2822Entry) SharedTagsString() string

func (Manifest2822Entry) String

func (entry Manifest2822Entry) String() string

func (Manifest2822Entry) TagsString

func (entry Manifest2822Entry) TagsString() string

type SharedTagGroup

type SharedTagGroup struct {
	SharedTags []string
	Entries    []*Manifest2822Entry
}

Jump to

Keyboard shortcuts

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