Commit e32e20b3 authored by odatskov's avatar odatskov
Browse files

CVMFS target as part of repo

parent b8633391
Pipeline #459928 passed with stage
in 36 seconds
......@@ -25,6 +25,7 @@ import (
// Global constants for available registries
const docker = "docker.registry.io"
const gitlab = "gitlab-registry.cern.ch"
const cvmfs_path = "/cvmfs/unpacked.cern.ch/"
type Repo struct {
url string // Clean repository path
......@@ -32,29 +33,31 @@ type Repo struct {
target string // CVMFS target path
}
//--- Repo struct constructor -----------------//
// Constructor for Repo struct
func makeRepo(path string, file string) Repo {
var url string
var registry string
prefix := strings.Split(path,"/")
log.Printf("This is a prefix: %s",prefix)
switch prefix[0] {
case "docker:":
registry = docker ; url = strings.TrimLeft(path,"docker://")
registry = docker ; url = strings.TrimPrefix(path,"docker://")
case "docker.io":
registry = docker; url = strings.TrimLeft(path,"docker.io/")
registry = docker; url = strings.TrimPrefix(path,"docker.io/")
case gitlab:
registry = gitlab ; url = strings.TrimLeft(path,gitlab)
registry = gitlab ; url = strings.TrimPrefix(path,gitlab+"/")
default:
log.Printf("Unknown repository specified: %s", path)
}
log.Printf("URL: %s, Registry: %s, File: %s",url)
return Repo{url, registry, file}
group_path := strings.Split(file,"/")
target := cvmfs_path + strings.Join(group_path[:len(group_path)-1],"/") + "/" + strings.Replace(url,":","/",1)
return Repo{url, registry, target}
}
//--- Retrieve file line containing a field ----//
// Returns field value containing specified field name
func getField(field string, path string) string {
file_data, err := ioutil.ReadFile(path)
......@@ -63,8 +66,8 @@ func getField(field string, path string) string {
} else {
file_lines := strings.Split(string(file_data), "\n")
for _, line := range file_lines {
if strings.Contains(line, field) {
repo_url := strings.Split(line, field)
if strings.Contains(line, field+":") {
repo_url := strings.Split(line, field+":")
return strings.TrimSpace(repo_url[1])
}
}
......@@ -73,7 +76,7 @@ func getField(field string, path string) string {
return "na"
}
//--- Return list of repositories --------//
// Returns list of repositories based on input arguments to main
func getRepoList(root string, args *[]string, repos *[]Repo) {
if len(*args) == 1 {
......@@ -82,13 +85,11 @@ func getRepoList(root string, args *[]string, repos *[]Repo) {
filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() && strings.HasSuffix(path, ".yaml") {
*repos = append(*repos, makeRepo(getField("url:", path),path))
*repos = append(*repos, makeRepo(getField("url", path),path))
}
return nil
})
if len(*repos) == 0 {
log.Fatalf("No Repositories found")
}
if len(*repos) == 0 { log.Fatalf("No Repositories found") }
} else {
var err_files []string
......@@ -99,13 +100,9 @@ func getRepoList(root string, args *[]string, repos *[]Repo) {
if os.IsNotExist(err) {
err_files = append(err_files, file)
}
} else {
*repos = append(*repos, makeRepo(getField("url:", file),file))
}
}
if len(err_files) > 0 {
log.Fatalf("File(s) not found: %s", err_files)
} else { *repos = append(*repos, makeRepo(getField("url", file),file)) }
}
if len(err_files) > 0 { log.Fatalf("File(s) not found: %s", err_files) }
}
}
......@@ -115,7 +112,7 @@ func getManifest(repo Repo) {
// Find diffs
}
//----------------------------------------//
//----------------------------------------
func main() {
var repos []Repo
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment