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

[Bug] Unable to install grafana-app-sdk@latest #189

Open
L2D2Grafana opened this issue Jan 26, 2024 · 6 comments · Fixed by #190
Open

[Bug] Unable to install grafana-app-sdk@latest #189

L2D2Grafana opened this issue Jan 26, 2024 · 6 comments · Fixed by #190
Assignees
Labels
area/cli type/bug Something isn't working

Comments

@L2D2Grafana
Copy link

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
@IfSentient
Copy link
Collaborator

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.

@IfSentient IfSentient self-assigned this Jan 26, 2024
@IfSentient
Copy link
Collaborator

We should also probably add a point to the workflow to test this. In the meantime, a workaround is:

  1. Clone the repo
  2. Run make build
  3. Copy target/grafana-app-sdk into your $GOPATH/bin (default location for go install) or another executable path

@L2D2Grafana
Copy link
Author

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

@radiohead
Copy link
Contributor

@L2D2Grafana @IfSentient you can download the binary from GH releases page - it's how we got it automated in a few places.

@radiohead radiohead added type/bug Something isn't working area/cli labels Jan 29, 2024
@radiohead
Copy link
Contributor

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)

IfSentient added a commit that referenced this issue Jan 31, 2024
…190)

This PR introduces extra go submodules for the `cmd/grafana-app-sdk` and
`plugin` directories, and a `go.work` to allow them to incorporate
properly. It also moves the `codegen`, `kindsys`, and `internal`
packages into the `cmd/grafana-app-sdk` submodule. This accomplishes two
major things:
1. The CLI and library dependencies are no longer "mixed." The CLI still
have some upward dependencies on the`resource` and `k8s` packages, but
now using any of the libraries (`resource`, `k8s`, `operator`, etc.)
does not require the dependencies of the `codegen` package or CLI. The
`plugin` package has been similarly isolated because dependency versions
in the root module will overwrite the ones in the submodule, and the
`codegen` package requires an older version of `getkin/kin-openapi` than
`plugin` requires.
2. Removes the need for the `replace` directive version pinning, which
was preventing `go install` from working correctly, and _also_ required
that a user of the app-sdk as a library also provided that `replace`
directive in their `go.mod`.

Resolves #189
@IfSentient
Copy link
Collaborator

My proposed fix didn't quite work, will try another approach for now.

@IfSentient IfSentient reopened this Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli type/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants