This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
[Feature] Upload file to DockerHub Description #18
Comments
You mean to here https://hub.docker.com/r/banzaicloud/drone-kaniko ? |
Yes. |
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 CGO_ENABLED go build -o bin/desc desc.go add ADD bin/desc /kaniko/desc
# ./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 # 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:-}" |
Sorry @annProg what it this program for exactly? :) |
Screenshot in harbor |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
It would be awesome if you could push a file like the README of the repo to the DockerHub description automatically.
The text was updated successfully, but these errors were encountered: