graphql-engine
graphql-engine copied to clipboard
cli-ext no such file or directory on cloud build
Version Information
Server Version: v2.3.1 CLI Version (for CLI related issue): Dev?
Environment
Hasura in cloud run hasura-cli in cloud build
What is the expected behaviour?
I expect hasura cli to be able to apply metadata on the cloud run instance
Keywords
cli-ext no such file or directory error in converting sdl to metadata
What is the current behaviour?
I use nix, when I run the CLI locally connected to the cloud run hasura, I have no problem applying metadata. But when It's in cloud build it throws this error:
error applying metadata \ncannot build actions from project: error parsing metadata \nobject: actions\nfile: actions.yaml\nerror: error in converting sdl to metadata: fork/exec /builder/home/.hasura/cli-ext/dev/cli-ext-572389094/cli-ext: no such file or directory:
How to reproduce the issue?
- Set up hasura on a cloud run thats open to all traffic (if you dont then you need to set up some gcp auth)
- Add cloud build with a step with
nix-shell -p hasura-cli --run 'hasura metadata apply --endpoint=${cloud run url}'
- Run it
Please provide any traces or logs that could help here.
{"level":"debug","msg":"global config is pre-set to \u0026cli.GlobalConfig{UUID:\"REDACTED\", EnableTelemetry:true, ShowUpdateNotification:true, CLIEnvironment:\"default\"}","time":"2022-04-26T20:48:30Z"}
{"level":"debug","msg":"cannot get config information from server, this might be because config API is not enabled: json: cannot unmarshal array into Go struct field HasuraServerInternalConfig.jwt of type string","time":"2022-04-26T20:48:33Z"}
{"level":"debug","msg":"versions: cli: [dev] server: [v2.3.1]","time":"2022-04-26T20:48:33Z"}
{"level":"debug","msg":"compatibility check: [true] dev version of cli, there could be inconsistencies","time":"2022-04-26T20:48:33Z"}
{"level":"debug","msg":"server: uuid: REDACTED","time":"2022-04-26T20:48:33Z"}
{"level":"info","msg":"Applying metadata...","time":"2022-04-26T20:48:33Z"}
{"level":"debug","msg":"building metadata: functions node not found for default","time":"2022-04-26T20:48:33Z"}
{"level":"warning","msg":"Unable to find an embedded cli-ext. So trying to fetch it from CDN","time":"2022-04-26T20:48:33Z"}
{"level":"warning","msg":"Tip: --cli-ext-path can be used for setting up cli-ext from local file system","time":"2022-04-26T20:48:33Z"}
"command":"sdl from","level":"debug","msg":"output: ","time":"2022-04-26T20:48:34Z"}
"apply-metadata": time="2022-04-26T20:48:34Z" level=fatal msg="error applying metadata \ncannot build actions from project: error parsing metadata \nobject: actions\nfile: actions.yaml\nerror: error in converting sdl to metadata: fork/exec /builder/home/.hasura/cli-ext/dev/cli-ext-572389094/cli-ext: no such file or directory: "
Any possible solutions?
My alternative would be to switch to using curl, which I do not want to do
Can you identify the location in the source code where the problem exists?
I assumed somewhere in metadata apply its using cli-ext to convert yaml to json?
If the bug is confirmed, would you be willing to submit a PR?
I could give it a shot
Related
https://github.com/hasura/graphql-engine/issues/6441 I've tried several proposed solutions, such as removing ~/.hasura and clearing NODE_OPTIONS (it was empty anyways) And I ruled out version mismatch because I am using the same version locally and on cloud build and it works locally
I was running into the same problem.
My dockerfile (in my case it was gitlab-ci.yml
) looked roughly like this
image: node:16-alpine
before_script:
- npm install --global firebase-tools hasura-cli
It seems to be connected to the alpine image. When I replace it by node:16
it works.
Note: if you want to save space and use node:16-slim
you need to apt install ca-certificates
as well, otherwise you get an error x509: certificate signed by unknown authority
when trying to GET your HTTPS graphQL endpoint.
Oh wow, I remember that from my research @pe224 but I didn't think it applied to me. But you bringing it up again made me dig into our base image.
I currently use nix
to install all the packages. Our companies image is based on https://github.com/NixOS/docker which is based on alpine 😮💨
I'm also having this issue on NixOS, no matter how I install hasura-cli (nix/npm/binary download)
@kevin-meyers FYI it looks like the NixOS Docker image is no longer based on alpine, but is built with Nix from scratch (like NixOS itself is)
I'm also having this issue on NixOS, no matter how I install hasura-cli (nix/npm/binary download)
Same. Any workaround?
Same. Any workaround?
Distrobox (https://github.com/89luca89/distrobox) was what I used on NixOS to use the Hasura CLI
I'm also having this issue on NixOS, no matter how I install hasura-cli (nix/npm/binary download)
Same. Any workaround?
Not a nix workaround, but a workaround to not use nix for my problem. I literally tried for weeks to get that cli working in cloud build... eventually I stumbled onto what should've been the obvious solution for my needs!
I set up a custom Dockerfile with the Hasura-cli-migrations image as base, and copy over the metadata files into it. So now I just use cloud build to push up a new Docker image with all the metadata changes already in it
As of CLI v2, the a pre-built cli-ext
binary is embedded into the Hasura CLI itself using Golang's embed package. The cli-ext
binary is produced using a now-archived project, pkg. This approach allows for the node-based cli-ext
to run on machines that don't have NodeJS installed.
In lieu of the pkg binary, the file embedded into the Hasura CLI can be a bash script! As such, I've built the cli-ext
in Nix, and embedded its invocation script directly into the Hasura CLI binary.
My flake uses the std project layout, but you should be able to get an idea of what's going on here.
hasura-cli.nix
{ inputs, cell }:
let
inherit (inputs.nixpkgs) lib buildGoModule fetchFromGitHub buildNpmPackage stdenv;
version = "2.38.1";
src = fetchFromGitHub {
owner = "hasura";
repo = "graphql-engine";
rev = "v${version}";
sha256 = "sha256-B1C7CQuuIaaVqM8mVjJ6nJfixId3+X/oCkX8Tuet0Ho=";
};
os = if stdenv.isDarwin then "darwin" else "linux";
arch = if stdenv.isAarch64 then "arm64" else "amd64";
in
rec {
cli-ext = buildNpmPackage rec {
inherit version src;
pname = "cli-ext";
sourceRoot = "source/cli-ext";
npmDepsHash = "sha256-CLoPXElfqT4Bbn3L7MkTNAc429JT++HL4/vEyhzgnC4=";
patches = [ ./cli-ext.patch ];
npmInstallFlags = [ "--no-optional" ];
npmBuildScript = "transpile";
meta = {
homepage = "https://www.hasura.io";
license = lib.licenses.asl20;
description = "Hasura GraphQL Engine cli-ext";
platforms = with lib.platforms; linux ++ darwin;
};
};
hasura-cli = buildGoModule rec {
inherit version src;
pname = "hasura-cli";
modRoot = "./cli";
subPackages = [ "cmd/hasura" ];
vendorHash = "sha256-vZKPVQ/FTHnEBsRI5jOT6qm7noGuGukWpmrF8fK0Mgs=";
preBuild = ''
cp ${cli-ext}/bin/cli-ext internal/cliext/static-bin/${os}/${arch}/cli-ext
'';
ldflags = [
"-X github.com/hasura/graphql-engine/cli/v2/version.BuildVersion=${version}"
"-s"
"-w"
];
doCheck = false;
postInstall = ''
mkdir -p $out/share/{bash-completion/completions,zsh/site-functions}
export HOME=$PWD
$out/bin/hasura completion bash > $out/share/bash-completion/completions/hasura
$out/bin/hasura completion zsh > $out/share/zsh/site-functions/_hasura
'';
meta = {
homepage = "https://www.hasura.io";
license = lib.licenses.asl20;
description = "Hasura GraphQL Engine CLI";
platforms = with lib.platforms; linux ++ darwin;
};
};
}
cli-ext.patch
diff --git a/package.json b/package.json
index ee54d80..381ad19 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,7 @@
{
- "name": "scaffolder",
- "version": "1.0.0",
+ "name": "cli-ext",
+ "version": "2.38.1",
+ "bin": "build/command.js",
"description": "A service to generate Hasura action scaffolds",
"main": "src/server.js",
"scripts": {
@adamgoose Thanks so much!