Commit d7762da7 authored by Davide Rovelli's avatar Davide Rovelli
Browse files

feat3: display custom metadata for matching labels

parent 10482908
......@@ -33,14 +33,18 @@ make install GOBUILDIMAGE=golang:1.13.8 COMPILETAG=compile_golangimage
### Rebuild / reconfigure
One harbor is installed, it can be reconfigured and rebuilt directly with docker composer
- Go to `make` directory:
```bash
cd make
```
- Stop the service
```bash
docker-compose down -v
sudo docker-compose down -v
```
- Change configuration
- Populate the configuration
```bash
sudo make/prepare
sudo ./prepare
```
- restart and recreate Harbor instance
```bash
......
# CSAN custom data
Custom logic and files for CSAN project that are separated from the main harbor application can be found in this folder.
## Deployment info
This folder is copied into the *harbor-core* (Harbor backend) container in the `/habor` folder. To access any element from
the Harbor core code the folder `./csan` (corresponding to `/habor/csan` inside the container) can be used.
## Metadata
Fields added in the *metadata* file will be added in the artifact/container Overview section IF a corresponding label is found
inside the container that was push. (no enforcement)
**metadata file syntax:** add one field per line, comments with "#" are supported
\ No newline at end of file
# list of metadata to display for an artifiact
example # comments allowed such as this one
mesocentre
software_version
description
\ No newline at end of file
FROM godlovedc/lolcow
LABEL maintainer="drovelli" mesocentre="ICI - Centrale Nantes"
LABEL example="is this displayed in the artifact view?"
LABEL software_version="v1.0"
LABEL description="LOLCOW light container for label testing on artifacts attributes"
LABEL test="this label should not be displayed"
\ No newline at end of file
module example.com/read_loop
go 1.16
package main
import ( "fmt"
"bufio"
"os"
"log"
"strings"
)
func main() {
f, err := os.Open("metadata")
if err != nil {
log.Fatal(err)
}
s := bufio.NewScanner(f)
for s.Scan() {
var line = strings.TrimSpace(s.Text())
if line[0] == '#' {
continue
} else if strings.Contains(line,"#") {
line = line[0:strings.Index(line,"#")]
}
fmt.Println(line)
}
err = s.Err()
if err != nil {
log.Fatal(err)
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ COPY ./make/photon/core/harbor_core /harbor/
COPY ./src/core/views /harbor/views
COPY ./make/migrations /harbor/migrations
COPY ./icons /harbor/icons
COPY ./csan /harbor/csan
RUN chown -R harbor:harbor /etc/pki/tls/certs \
&& chown harbor:harbor /harbor/entrypoint.sh && chmod u+x /harbor/entrypoint.sh \
......
......@@ -25,6 +25,10 @@ import (
"github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/pkg/artifact"
"github.com/opencontainers/image-spec/specs-go/v1"
"strings"
"bufio"
"os"
)
// const definitions
......@@ -67,10 +71,36 @@ func (m *manifestV2Processor) AbstractMetadata(ctx context.Context, artifact *ar
// if the author is null, try to get it from labels:
// https://docs.docker.com/engine/reference/builder/#maintainer-deprecated
author := config.Author
if len(author) == 0 && len(config.Config.Labels) > 0 {
author = config.Config.Labels["maintainer"]
}
artifact.ExtraAttrs["author"] = author
// CSAN implementaion
// daviderovell0 - 07/06/2021
// extract each line from the metadata file
var metadataFilePath = "./csan/metadata"
f, err := os.Open(metadataFilePath)
if err != nil {
return err
}
s := bufio.NewScanner(f)
for s.Scan() {
var line = strings.TrimSpace(s.Text())
if line[0] == '#' {
continue
} else if strings.Contains(line,"#") {
line = line[0:strings.Index(line,"#")]
}
// add it to the artifact attributes IF matches container label
artifact.ExtraAttrs[line] = config.Config.Labels[line]
}
err = s.Err()
if err != nil {
return err
}
return nil
}
......
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