[Bug] Unable to install grafana-app-sdk@latest
L2D2Grafana opened this issue · comments
Description
Error
go install github.com/grafana/grafana-app-sdk/cmd/grafana-app-sdk@latest
go: github.com/grafana/grafana-app-sdk/cmd/grafana-app-sdk@latest (in github.com/grafana/grafana-app-sdk@v0.14.7):
The go.mod file for the module providing named packages contains one or
more replace directives. It must not contain directives that would cause
it to be interpreted differently than if it were the main module.
Perhaps it is due to this line https://github.com/grafana/grafana-app-sdk/blob/main/go.mod#L6
Successful older versions install
go install github.com/grafana/grafana-app-sdk/cmd/grafana-app-sdk@v0.9.6
Looks like this is an issue since the pinning of github.com/getkin/kin-openapi
(for codegen) with the replace
directive in the go.mod
file. I think a temporary fix for this should be cloning kin-openapi
into the internal
package and updating deepmap/oapi-codegen
to use the cloned internal one. I'll get a PR up to do this, and we can see if it resolves the issue.
The longer-term fix is to split the CLI and codegen packages into a separate go module from the libraries (as the reason the version has to be pinned with the replace directive is that grafana-plugin-sdk-go
uses it as well, and that is used by the plugin
package). This will allow a cleaner set of dependencies for both the CLI and libraries.
We should also probably add a point to the workflow to test this. In the meantime, a workaround is:
- Clone the repo
- Run
make build
- Copy
target/grafana-app-sdk
into your$GOPATH/bin
(default location forgo install
) or another executable path
Also ran into this on make build
› mage
# github.com/grafana/grafana-plugin-sdk-go/experimental/e2e/storage
../vendor/github.com/grafana/grafana-plugin-sdk-go/experimental/e2e/storage/openapi.go:142:20: cannot range over op.Responses (variable of type *openapi3.Responses)
Error: error compiling magefiles
@L2D2Grafana @IfSentient you can download the binary from GH releases page - it's how we got it automated in a few places.
Here's a script we're using together with a Makefile for installing the SDK:
#!/bin/sh
set -e
version=$1
baseUrl="https://github.com/grafana/grafana-app-sdk/releases/download/v${version}"
if [[ -z $version ]]; then
echo "Please specify which version you want to install!"
exit 1
fi
outDir=$2
if [[ -z $outDir ]]; then
outDir="./bin"
fi
platform=""
case $(uname -s) in
Linux*) platform=linux;;
Darwin*) platform=darwin;;
esac
if [[ -z $platform ]]; then
echo "Unsupported platform!"
exit 1
fi
arch=""
case $(uname -m) in
x86_64) arch="amd64" ;;
arm) arch="arm64" ;;
esac
if [[ -z $arch ]]; then
echo "Unsupported architecure!"
exit 1
fi
asset="grafana-app-sdk_${version}_${platform}_${arch}.tar.gz"
url="${baseUrl}/${asset}"
echo "Will download from: ${url} into ${outDir}"
curl -Ls "${url}" | tar xvzf - -C "${outDir}"
rm -f "${outDir}/LICENSE" "${outDir}/README.md"
mv "${outDir}/grafana-app-sdk" "${outDir}/grafana-app-sdk-${version}"
# Targets for installing the SDK
SDK_DIR := bin
SDK_VER := 0.14.6
SDK_CLI := $(SDK_DIR)/grafana-app-sdk-$(SDK_VER)
$(SDK_CLI):
mkdir -p $(SDK_DIR)
./scripts/install-sdk.sh $(SDK_VER) $(SDK_DIR)
sdk-cli: $(SDK_CLI)
# Targets for generating Go types & CRDs using the SDK
KINDSS_DIR := kinds
CRDGEN_DIR := ops/crds
GOFGEN_DIR := pkg/generated
KIND_FILES := $(shell find $(KINDSS_DIR) -type f -name "*.cue")
$(GOFGEN_DIR): $(KIND_FILES) $(SDK_CLI)
@$(SDK_CLI) generate --cuepath=$(KINDSS_DIR) --crdencoding=json --crdpath=$(CRDGEN_DIR) --gogenpath=$(GOFGEN_DIR)
@touch $@
go/generate: $(GOFGEN_DIR)
My proposed fix didn't quite work, will try another approach for now.
go install
should function as of version v0.17.8
, the replace
directive in go.mod
has been removed.