Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print plugin version #4288

Merged
merged 4 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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