I'm trying to use envoy from laravel to call some scripts on my server.
Right now I'm doing it with a virtual machine installed on my mac.
I'm trying to run my envoy scripts from a controller as follow:
function __construct()
{
$command = "/Users/test_user/.composer/vendor/bin/envoy run test --filename=new_folder"
$process = new Process($command);
$process->start();
foreach ($process as $type => $data) {
if ($process::OUT === $type) {
echo "\nRead from stdout: ".$data;
} else { // $process::ERR === $type
echo "\nRead from stderr: ".$data;
}
}
exit();
}
Now when let this run I get the following response:
Read from stdout: Valet requires Homebrew to be installed on your Mac.
If I open my terminal and run: which brew
which brew
/usr/local/bin/brew
and my $PATH
/Users/test_user/Android/platform-tools:/Users/test_user/Android/tools:~/.composer/vendor/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin alias numFiles='echo 14'
I'm not exactly sure why this seems to fail?
Valet was installed with the composer global require laravel/valet command, and was not installed locally for the project.
Is there any way of fixing this?
You should install envoy locally in your project:
composer require laravel/envoy
and execute it from vendor/bin/envoy.
Also don't forget to set the working directory for the process to base path, assuming your Envoy.blade.php is in the root path of your app.
function __construct()
{
$command = base_path('vendor/bin') . "/envoy run test --filename=new_folder"
$process = new Process($command);
$process->setWorkingDirectory(base_path());
$process->start();
foreach ($process as $type => $data) {
if ($process::OUT === $type) {
echo "\nRead from stdout: ".$data;
} else { // $process::ERR === $type
echo "\nRead from stderr: ".$data;
}
}
exit();
}
Related
Running Pktgen with Lua scripts generates a failure User State for CLI not set for Lua.
The command I'm running is:
sudo -E ./usr/local/bin/pktgen --no-telemetry -l 4,6,8,10 -n 4 -a 0000:03:02.0 -m 1024 -- -T -P -m [6:8].0 -f test/hello-world.lua
Which gives the following result:
I have set the environment variables RTE_SDK=/root/Program/dpdk and
RTE_TARGET=x86_64-native-linux-gcc.
The failure comes from cli.c (link to code):
/**
* Load and execute a command file or Lua script file.
*
*/
int
cli_execute_cmdfile(const char *filename)
{
if (filename == NULL)
return 0;
gb_reset_buf(this_cli->gb);
if (strstr(filename, ".lua") || strstr(filename, ".LUA") ) {
if (!this_cli->user_state) {
cli_printf(">>> User State for CLI not set for Lua\n");
return -1;
}
if (lua_dofile) {
/* Execute the Lua script file. */
if (lua_dofile(this_cli->user_state, filename) != 0)
return -1;
} else
cli_printf(">>> Lua is not enabled in configuration!\n");
} else {
FILE *fd;
char buff[256];
fd = fopen(filename, "r");
if (fd == NULL)
return -1;
/* Read and feed the lines to the cmdline parser. */
while (fgets(buff, sizeof(buff), fd))
cli_input(buff, strlen(buff));
fclose(fd);
}
return 0;
}
So it would seem this_cli->user_state is not set, but how do you set it?
I have looked through the documentation for CLI, but it doesn't mention setting any user state from what I can see.
Update:
After having installed Lua and cmake, I ran meson -Denable_lua=true build which worked fine. But when I run ninja -C build I receive this error:
user_state is set in pktgen-main.c, but within a #ifdef LUA_ENABLED section.
Looking at meson_options.txt, which is at the base directory of a pktgen extraction, it contains:
option('enable_lua', type: 'boolean', value: false, description: 'Enable Lua support')
That means that you must enable Lua support when building (after installing dependencies, as shown below):
meson -Denable_lua=true build
This is going to require a few more dependencies, so you may have to install them, e.g. in Ubuntu:
sudo apt-get install cmake
And then installing Lua - I had to install it from source as per the instructions, because installing it with Ubuntu's package manager apt didn't give me the library that was needed:
curl -R -O http://www.lua.org/ftp/lua-5.4.4.tar.gz
tar zxf lua-5.4.4.tar.gz
cd lua-5.4.4
make all test
sudo make install
I am working on a set of build scripts which are called from a ubuntu hosted CI environment. The powershell build script calls jest via react-scripts via npm. Unfortunately jest doesn't use stderr correctly and writes non-errors to the stream.
I have redirected the error stream using 3>&1 2>&1 and this works fine from just powershell core ($LASTEXITCODE is 0 after running, no content from stderr is written in red).
However when I introduce docker via docker run, the build script appears to not behave and outputs the line that should be redirected from the error stream in red (and crashes). i.e. something like: docker : PASS src/App.test.js. Error: Process completed with exit code 1..
Can anyone suggest what I am doing wrong? because I'm a bit stumped. I include the sample PowerShell call below:-
function Invoke-ShellExecutable
{
param (
[ScriptBlock]
$Command
)
$Output = Invoke-Command $Command -NoNewScope | Out-String
if($LASTEXITCODE -ne 0) {
$CmdString = $Command.ToString().Trim()
throw "Process [$($CmdString)] returned a failure status code [$($LASTEXITCODE)]. The process may have outputted details about the error."
}
return $Output
}
Invoke-ShellExecutable {
($env:CI = "true") -and (npm run test:ci)
} 3>&1 2>&1
I'm a developer who's recently moved from macOS to WSL2 on Windows 10. I've finally managed to get everything working, but when I call a lambda locally through Docker, the os.Getenv() function returns my whole env file, instead of just the one key.
Things I've tried:
Set "files.eol" = "\n" in vscode settings.json
Set core.autocrlf = input in git config --global
Set eol = lf in git config --global
I've been super stumped for ages, and haven't been able to find any solutions online. Any help would be super appreciated!
Edit: Apologies, I should have had the foresight to post the code and env. necessary to replicate the problem
////////////
// Code: //
////////////
func init() {
if err := config.Load(); err != nil {
api.ReportError(err)
}
dbo = db.Instance{
DSN: os.Getenv("DBReadDataSourceName"),
}
log.Println("DSN: ", dbo.DSN)
}
// Load ...
func Load() error {
stage := os.Getenv("Stage")
log.Println("stage: ", stage)
if len(data) <= 0 && stage != "local" {
log.Println("stage != local")
log.Println("do production config and ssm stuff")
}
return nil
}
//////////
// Env: //
//////////
Stage=local
ServerPort=:1234
DBDriverName=mysql
DBReadDataSourceName=MySQLReadDataSourceCredentials
DBWriteDataSourceName=MySQLWriteDataSourceCredentials
RiakAddress=RiakAddress
RedisAddress=RedisAddress
ElasticSearchUrl=ElasticSearchUrl
ElasticSearchPrefix=ElasticSearchPrefix
ThidPartyBaseURL=https://api-sandbox.ThirdParty.com
ThidPartyCountryCode=SG
ThidPartyClientID=asdf12345qwertyuiadsf
ThidPartyClientSecret=asdf12345qwertyuiadsf
/////////////
// Output: //
/////////////
2020/07/13 17:04:03 stage: local
ServerPort=:1234
DBDriverName=mysql
DBReadDataSourceName=MySQLReadDataSourceCredentials
DBWriteDataSourceName=MySQLWriteDataSourceCredentials
RiakAddress=RiakAddress
RedisAddress=RedisAddress
ElasticSearchUrl=ElasticSearchUrl
ElasticSearchPrefix=ElasticSearchPrefix
ThidPartyBaseURL=https://api-sandbox.ThirdParty.com
ThidPartyCountryCode=SG
ThidPartyClientID=asdf12345qwertyuiadsf
ThidPartyClientSecret=asdf12345qwertyuiadsf
2020/07/13 17:04:03 stage != local
2020/07/13 17:04:03 do production config and ssm stuff
2020/07/13 17:04:03 DSN: DBReadDataSourceName
When I run this lambda locally on a mac, os.Getenv() functions as intended, returning local for Stage, and returning MySQLReadDataSourceCredentials for DBReadDataSourceName. However, running this lambda locally through WSL2 on a windows machine results in the above output. Stage returns the entire file, and DBReadDataSourceName returns DBReadDataSourceName.
I'm super stumped, and have tried everything I could think of, including manually writing \r\n on the end of each env. value. Any help would be extremely appreciated! Thank you very much for your time
Edit 2: From the comments
The command I used to load the env. file is env -S "`cat env.local`" sam local start-api --template template.yaml --profile company_local, with env.local being the file name.
The command env -S $'a=5\nb=6' sh -c 'echo "$a"' prints
5
b=6
The command env -S $'a=5\r\nb=6' sh -c 'echo "$a"' prints the exact same output as above,
5
b=6
The command env -S 'a=5;b=6' sh -c 'echo "$a"' prints
5;b=6
And env -S 'a=5:b=6' sh -c 'echo "$a"' prints
5:b=6
And the command xxd env.local | head -n 3 prints
00000000: 5374 6167 653d 6c6f 6361 6c0a 5365 7276 Stage=local.Serv
00000010: 6572 506f 7274 3d3a 3132 3334 0a44 4244 erPort=:1234.DBD
00000020: 7269 7665 724e 616d 653d 6d79 7371 6c0a riverName=mysql.
I'm packaging a node script with an external dependency (GraphicsMagick), and when attempting to override the derivation generated from node2nix I get the error:
wrapProgram: command not found
The following text goes into detail of what I've tried to solve this error.
Reproducing the problem from scratch
I've created a minimal git repository that reproduces this problem if you'd just like to take a look there. Else, the steps to reproduce the problem are below.
Initial Shell Session:
In an empty directory, run:
npm init -y
npm install --save gm
curl https://i.imgur.com/addSfQi.jpg > image.png
(npm version: 5.6.0 & node version v8.9.4)
Create index.js
#!/usr/bin/env node
const path = require("path"); // node.js builtin
const gm = require("gm"); // GraphicsMagick module
const imagePath = path.join(__dirname, "image.png");
// Flip image horizontally and write to disk
gm(imagePath)
.flop()
.write(imagePath, error => {
console.log("error:", error);
});
Add a "bin" section to package.json:
"bin": "index.js"
Generate *.nix files with node2nix
node2nix -8 -l package-lock.json
Create override.nix
{ pkgs ? import <nixpkgs> {}
, system ? builtins.currentSystem
}:
let
nodePackages = import ./default.nix {
inherit pkgs system;
};
in
nodePackages // {
package = nodePackages.package.override (oldAttrs: {
postInstall = ''
wrapProgram "$out/bin/test-nodejs-gm-nixpkg" --prefix PATH : "${pkgs.graphicsmagick}/bin"
'';
});
}
Build nix package
nix-build override.nix -A package
The above fails with:
/nix/store/*/setup: line 95: wrapProgram: command not found
Helpful Resources
node2nix git repository - includes some basic examples.
example override in nixpkgs - example of how nixpkgs uses wrapProgram in postInstall with files generated by node2nix.
wrapProgram is contained within the makeWrapper package.
nativeBuildInputs = oldAttrs.nativeBuildInputs or [] ++ [ pkgs.makeWrapper ];
As mentioned by #ppb in the comments.
I would like to use the first function sayHello in my jobs.js in parse-server-example.
In my jobs.js I have this:
var Parse = require('parse/node');
Parse.initialize('xx', 'xx','xx');
Parse.serverURL = 'xx';
Parse.Cloud.useMasterKey();
function sayHello() {
console.log('Hello');
}
I tried to run it with this terminal line command:
heroku run sayHello -a myAppName
returns:
Running sayHello on myAppName... up, run.6148
bash: sayHello: command not found
You should put the job you want to run in its own file (without a .js extension) outside of a function.
var Parse = require('parse/node');
Parse.initialize('xx', 'xx','xx');
Parse.serverURL = 'xx';
console.log('Hello');
You can then run the following from the command line.
heroku run node nameOfFile --app yourAppName