dockerhub

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Index

Constants

View Source
const BaseURL = "https://hub.docker.com/v2/"

BaseURL represents Docker Hub endpoint

Variables

View Source
var BG = color.New(color.FgGreen, color.Bold).SprintFunc()

BG returns bold green color

View Source
var BR = color.New(color.FgRed, color.Bold).SprintFunc()

BR returns bold red color

View Source
var BW = color.New(color.FgWhite, color.Bold).SprintFunc()

BW returns bold white color

View Source
var BY = color.New(color.FgYellow, color.Bold).SprintFunc()

BY returns bold yellow color

View Source
var RepositoriesURL = BaseURL + "repositories"

RepositoriesURL represents Docker Hub repositories endpoint

Functions

func GetFlags

func GetFlags(flags *pflag.FlagSet) (string, bool, error)

GetFlags returns variables from provided commandline flags

Types

type AuthResponse

type AuthResponse struct {
	Token string `json:"token"`
}

AuthResponse represents auth response

type Client

type Client struct {
	*http.Client
	Header    http.Header
	AuthToken string
	URL       string
	ORG       string
}

Client represents new HTTP client

func NewClient

func NewClient(org, url string) *Client

NewClient initialize new docker hub client

func (*Client) DeleteRepository

func (c *Client) DeleteRepository(image string) error

DeleteRepository delete docker repository from docker hub

curl \
  -H "Authorization: JWT ${TOKEN}" \
  -X DELETE \
  https://hub.docker.com/v2/repositories/${ORG}/${IMAGE}/

func (*Client) DescribeRepository

func (c *Client) DescribeRepository(image string) (*Repository, error)

DescribeRepository print details about docker repository from docker hub

func (*Client) GetAuthToken

func (c *Client) GetAuthToken() (string, error)

GetAuthToken returns JWT Token from docker hub login page

curl --silent \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{"username": "'${DOCKERHUB_USERNAME}'", "password": "'${DOCKERHUB_PASSWORD}'"}' \
  https://hub.docker.com/v2/users/login/ | jq -r .token

func (*Client) GetAvgTagsSize

func (c *Client) GetAvgTagsSize(image string) (float64, error)

GetAvgTagsSize returns size docker image tag from docker hub for selected repository

func (*Client) GetLatestTag

func (c *Client) GetLatestTag(image string) (string, error)

GetLatestTag returns latest (by LastUpdated field) docker image tag from docker hub

func (*Client) GetTagsCount

func (c *Client) GetTagsCount(image string) (int, error)

GetTagsCount returns count docker image tag from docker hub for selected repository

func (*Client) ListRepositories

func (c *Client) ListRepositories() (repos []*Repository, err error)

ListRepositories returns list of docker images from docker hub

func (*Client) ListTags

func (c *Client) ListTags(image string) ([]*Tag, error)

ListTags returns list of docker image tags for selected image from docker hub

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, payload io.Reader) (*http.Request, error)

NewRequest prepare request to docker hub

func (*Client) RenewDockerImage

func (c *Client) RenewDockerImage(image string) error

RenewDockerImage renew docker image tags older than 20 days from docker hub

func (*Client) TruncateTags

func (c *Client) TruncateTags(image string, truncateInactive bool, regularExpression string) error

TruncateTags deletes docker image tags tags that match `regularExpression` OR are older than `expiredRange` except latest `leaveTagsCounter` ones

type Image

type Image struct {
	Architecture string    `json:"architecture"`
	Features     string    `json:"features"`
	Variant      string    `json:"variant"`
	Digest       string    `json:"digest"`
	OS           string    `json:"os"`
	OSFeatures   string    `json:"os_features"`
	OSVersion    string    `json:"os_version"`
	Size         int       `json:"size"`
	Status       string    `json:"status"`
	LastPulled   time.Time `json:"last_pulled"`
	PastPushed   time.Time `json:"last_pushed"`
}

Image represents docker image information returned from hub.docker.com

type Repository

type Repository struct {
	User              string    `json:"user"`
	Name              string    `json:"name"`
	Namespace         string    `json:"namespace"`
	RepositoryType    string    `json:"repository_type"`
	Status            int       `json:"status"`
	Description       string    `json:"description"`
	IsPrivate         bool      `json:"is_private"`
	IsAutomated       bool      `json:"is_automated"`
	CanEdit           bool      `json:"can_edit"`
	StarCount         int       `json:"star_count"`
	PullCount         int       `json:"pull_count"`
	LastUpdated       time.Time `json:"last_updated"`
	IsMigrated        bool      `json:"is_migrated"`
	CollaboratorCount int       `json:"collaborator_count"`
	Affiliation       string    `json:"affiliation"`
	HubUser           string    `json:"hub_user"`
}

Repository represents docker repository information returned from hub.docker.com

type RepositoryList

type RepositoryList struct {
	Count    int           `json:"count"`
	Next     string        `json:"next"`
	Previous string        `json:"previous"`
	Results  []*Repository `json:"results"`
}

RepositoryList represents the search repositories results from hub.docker.com

type Tag

type Tag struct {
	Creator         int64     `json:"creator"`
	ID              int64     `json:"id"`
	ImageID         string    `json:"image_id"`
	Images          []*Image  `json:"images"`
	LastUpdated     time.Time `json:"last_updated"`
	LastUpdater     int64     `json:"last_updater"`
	LastUpdaterUser string    `json:"last_updater_username"`
	Name            string    `json:"name"`
	Repository      int64     `json:"repository"`
	FullSize        int       `json:"full_size"`
	V2              bool      `json:"v2"`
	TagStatus       string    `json:"tag_status"`
	TagLastPulled   time.Time `json:"tag_last_pulled"`
	TagLstaPushed   time.Time `json:"tag_last_pushed"`
}

Tag represents docker tag information returned from hub.docker.com

type TagList

type TagList struct {
	Count    int    `json:"count"`
	Next     string `json:"next"`
	Previous string `json:"previous"`
	Results  []*Tag `json:"results"`
}

TagList represents the search tags results from hub.docker.com

Jump to

Keyboard shortcuts

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