Skip to content
This repository has been archived by the owner on Sep 3, 2020. It is now read-only.

[Feature] Upload file to DockerHub Description #18

Open
zicklag opened this issue Jul 10, 2019 · 6 comments
Open

[Feature] Upload file to DockerHub Description #18

zicklag opened this issue Jul 10, 2019 · 6 comments
Assignees

Comments

@zicklag
Copy link
Contributor

zicklag commented Jul 10, 2019

It would be awesome if you could push a file like the README of the repo to the DockerHub description automatically.

@bonifaido bonifaido self-assigned this Jul 10, 2019
@bonifaido
Copy link
Member

You mean to here https://hub.docker.com/r/banzaicloud/drone-kaniko ?

@zicklag
Copy link
Contributor Author

zicklag commented Jul 10, 2019

Yes.

@annProg
Copy link
Contributor

annProg commented Nov 7, 2019

my solution for harbor

desc.go

package main
import (
	"encoding/json"
	"net/http"
	"io/ioutil"
	"fmt"
	"flag"
	"bytes"
	"strings"
	"os"
)
// Generated by curl-to-Go: https://mholt.github.io/curl-to-go

type Payload struct {
	Description string `json:"description"`
}

func main () {
	api := flag.String("api", "http://harbor-api-proxy.intra.xx.com/api/repositories", "harbor api for repo description")
	desc := flag.String("desc", "README.md", "description filename")
	repo := flag.String("repo", "", "repo name")
	flag.Parse()

	if *repo == "" {
		fmt.Println("must provide repo name")
		os.Exit(1)
	}

	repository := strings.Replace(*repo, "/", "%2F", -1)

	// read description from desc file
	b, err := ioutil.ReadFile(*desc)
	if err != nil {
		fmt.Print(err)
	}
	str := string(b)

	data := Payload{Description: str}
	payloadBytes, err := json.Marshal(data)
	if err != nil {
		fmt.Print(err)
	}
	body := bytes.NewReader(payloadBytes)

	url := *api + "/" + repository
	req, err := http.NewRequest("PUT", url, body)
	if err != nil {
		fmt.Print(err)
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("Content-Type", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		fmt.Print(err)
	}

	fmt.Println(resp.Status)
	defer resp.Body.Close()
}

static build desc

CGO_ENABLED go build -o bin/desc desc.go

add bin/desc in Dockerfile

ADD bin/desc /kaniko/desc

desc command usage

# ./bin/desc -h
Usage of ./bin/desc:
  -api string
    	harbor api for repo description (default "http://harbor-api-proxy.intra.xx.com/api/repositories")
  -desc string
    	description filename (default "README.md")
  -repo string
    	repo name

use desc in plugin.sh

# update repo description. use harbor api. Should run after image push. Otherwise in first build harbor api will return 404 Not Found
/kaniko/desc -api "${PLUGIN_DESC_API:-http://harbor-api-proxy.intra.xx.com/api/repositories}" -desc "${PLUGIN_DESC_FILE:-README.md}" -repo "${PLUGIN_REPO:-}"

@bonifaido
Copy link
Member

Sorry @annProg what it this program for exactly? :)

@annProg
Copy link
Contributor

annProg commented Nov 11, 2019

Sorry @annProg what it this program for exactly? :)

Update repo description(default use README.md) in Harbor. It is similar to DockerHub Description.for reference only

@annProg
Copy link
Contributor

annProg commented Nov 11, 2019

Screenshot in harbor
image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants