Skip to content

Commit

Permalink
Print plugin version (#4288)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 authored Oct 27, 2023
1 parent f5955ed commit dc69a82
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/plugin-versions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Print plugins' version

https://github.com/cs3org/reva/pull/4288
27 changes: 25 additions & 2 deletions cmd/revad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ import (
"fmt"
"io"
"io/fs"
"slices"

"os"
"path"
"reflect"
"regexp"
"runtime/debug"
"strings"
"sync"
"syscall"
Expand All @@ -40,6 +43,7 @@ import (
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/plugin"
"github.com/cs3org/reva/pkg/sysinfo"
"github.com/cs3org/reva/pkg/utils/maps"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -123,12 +127,22 @@ func handlePluginsFlag() {
// For now we just list all the plugins.
plugins := reva.GetPlugins("")
grouped := groupByNamespace(plugins)
bi, ok := debug.ReadBuildInfo()
if !ok {
bi = &debug.BuildInfo{}
}

namespaces := maps.Keys(grouped)
slices.Sort(namespaces)

count := 0
for ns, plugins := range grouped {
for _, ns := range namespaces {
plugins := grouped[ns]

fmt.Printf("[%s]\n", ns)
for _, p := range plugins {
fmt.Printf("%s -> %s\n", p.ID.Name(), pkgOfFunction(p.New))
pkgName := pkgOfFunction(p.New)
fmt.Printf("%s -> %s (%s)\n", p.ID.Name(), pkgName, pkgVersion(bi.Deps, pkgName))
}
count++
if len(grouped) != count {
Expand All @@ -148,6 +162,15 @@ func pkgOfFunction(f any) string {
return name[:i]
}

func pkgVersion(deps []*debug.Module, name string) string {
for _, dep := range deps {
if strings.HasPrefix(name, dep.Path) {
return dep.Version
}
}
return "<unknown>"
}

func groupByNamespace(plugins []reva.PluginInfo) map[string][]reva.PluginInfo {
m := make(map[string][]reva.PluginInfo)
for _, p := range plugins {
Expand Down
12 changes: 6 additions & 6 deletions docker/Dockerfile.revad-ceph
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ RUN dnf update --exclude=ceph-iscsi -y && dnf install -y \
librbd-devel \
librados-devel

ADD https://golang.org/dl/go1.19.linux-amd64.tar.gz \
go1.19.linux-amd64.tar.gz
ADD https://go.dev/dl/go1.21.3.linux-amd64.tar.gz \
go1.21.3.linux-amd64.tar.gz

RUN rm -rf /usr/local/go && \
tar -C /usr/local -xzf go1.19.linux-amd64.tar.gz && \
rm go1.19.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.21.3.linux-amd64.tar.gz && \
rm go1.21.3.linux-amd64.tar.gz

ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go
Expand All @@ -44,8 +44,8 @@ ARG VERSION
ENV GIT_COMMIT=$GIT_COMMIT
ENV VERSION=$VERSION
RUN mkdir -p /go/bin && \
make revad-ceph && \
cp /go/src/github/cs3org/reva/cmd/revad/revad /usr/bin/revad
make revad-ceph && \
cp /go/src/github/cs3org/reva/cmd/revad/revad /usr/bin/revad

RUN cp -r examples/ceph /etc/

Expand Down

0 comments on commit dc69a82

Please sign in to comment.