I am trying to use javascript generator and yield in k6.
When I try to run the script I get this error:
SyntaxError: ...yield is a reserved word
Is it possible to use yield in k6?
Unfortunately this is not natively supported in the JavaScript VM used by k6 (goja). According to this comment generators might eventually be supported, but there's no current plans for it.
That said, you can workaround this by using the template-es6 project to transform your script to an ES5 variant with Babel, which can polyfill support for generators.
First clone the template-es6 Git repo locally.
Install all dependencies with yarn add or npm install.
Add #babel/plugin-transform-runtime to the plugins list in the .babelrc. It should look like this:
{
"presets": [
[
"#babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": 3
}
]
],
"plugins": [
"#babel/plugin-transform-runtime"
]
}
Install the plugin with yarn add -D #babel/plugin-transform-runtime or npm install --save-dev #babel/plugin-transform-runtime.
Modify the main.js script and install whatever other dependencies you need.
Run npm run-script webpack to bundle everything.
Finally run the script with k6 with k6 run --compatibility-mode=base build/app.bundle.js.
You can also run it without --compatibility-mode=base, but since it's already transformed to an ES5 script you can avoid the extra transformation done by k6, which improves performance and memory usage.
Yeah, this is not as straightforward as we'd like it to be, but it should be familiar to JavaScript developers and we hope to improve support of these features in the future.
Related
I want these programs to be installed in my user environment while not using nix-shell and nix-env (I was told to not use nix-env). I tried to use home-manager but I can't do program.file/ripgrep bc it's not an option. May I ask what is the common approach to install things like file and ripgrep in NixOS?
With home-manager, you can install programs by adding them by adding them in home.packages. For instance, if you want to install ripgrep, you could add in your home.nix:
home.packages = [
pkgs.ripgrep
];
Or, more conveniently
home.packages = with pkgs; [
ripgrep
];
You can add any program you want in that list.
Note that there is a difference between installing them with home-manager, and by adding it in environment.systemPackages, which is that the former will only install them for the user, while the latter will install system-wide. Besides that, both work similarly.
You should be able to set this in your nixos config:
environment.systemPackages = [
rigrep
file
];
I have no experience with home-manager so I don't know how it compares, but you should surely be able to install ripgrep with it.
I've been using nix-env for years without issue, only negatives is it's harder to keep track of things. But works fine for things you want to install 'temporarily' to have them available in your $PATH without having to invoke nix-shell.
I'm trying to run a lambda function with sharp installed. Sharp has instructions to install on AWS Lambda, but they are specific to npm. Specifically it requires me to run this:
npm install --arch=x64 --platform=linux --libc=glibc sharp
pnpm doesn't explicitly support the arch and platform options however.
I'm developing on a Max but am using Seed.run for CI/CD.
So far I really like pnpm and seed and I don't want to change either one. Is there a way for pnpm to install the right library?
You can pass unknown options to pnpm by prefixing them with config:
pnpm install --config.arch=x64 --config.platform=linux --config.libc=glibc sharp
I'm trying to build an executable file for windows from my linux but so far I have not been able to do it.
According to the documentation, it tells me that here I could configure, for example, the output folder.
pluginOptions: {
electronBuilder: {
outputDir: 'desktop-for-windows',
},
},
and if it works but does not say anything about how to change the platform (s.o) to build.
also try testing the following command:
npm run electron:build --win
but by default it builds for linux
Ran into same thing trying to move from an older boiler plate to using Vue-CLI 3 just now.
Run this from within the project directory and see if it works:
./node_modules/.bin/vue-cli-service electron:build --windows
I got the --windows from the ui.js file in the vue-cli-plugin-electron-builder directory under node_modules. Other options are --linux and --macos. I'm surprised I don't see a --all flag or that all isn't the default.
If you add "build:win": "vue-cli-service electron:build --windows" under scripts in your package.json then you can instead run npm run build:win from there on.
I just faced the same problem and found pretty easy answer.
You can just run npm run electron:build -- --linux deb --win nsis in the project directory.
There is more about it here: https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/recipes.html#multi-platform-build
I'm not sure if I should create different Dockerfile files for my Node.js app. One for production without the development dependencies and one for testing with the development dependencies included.
Or one file which is basically the development Dockerfile.dev. Then main difference of both files is the npm install command:
Production:
FROM ...
...
RUN npm install --quiet --production
...
CMD ...
Development/Test:
FROM ...
...
RUN npm install
...
CMD ...
The question arises because I want to be able to run my tests inside the container via docker run command. Therefore I need the test dependencies (typically dev dependencies for me).
Seems a little bit odd to put dependencies not needed in production into the image. On the other hand creating/maintaining a second Dockerfile.dev which just minor differences seems also not right. So what is the a good practise for this kind of problem.
No, you don't need to have different Dockerfiles and in fact you should avoid that.
The goal of docker is to ship your app in an immutable, well tested artifact (docker images) which is identical for production and test and even dev.
Why? Because if you build different artifacts for test and production how can you guarantee what you have already tested is working in production too? you can't because they are two different things.
Given all that, if by test you mean unit tests, then you can mount your source code inside docker container and run tests without building any docker images. And that's fine. Remember you can build image for tests but that terribly slow and makes development quiet difficult and slow which is not good at all. Then if your test passed you can build you app container safely.
But if you mean acceptance test that actually needs to run against your running application then you should create one image for your app (only one) and run tests in another container (mount test source code for example) and run tests against that container. This obviously means what your build for your app is different for npm installs for your tests.
I hope this gives you some over view.
Well then you'll have to support several Dockerfiles that are almost identical. Instead I recommend to use NodeJS feature like production profile. And another one recommendation regarding to
RUN npm install --quiet --production
It is better to create separate .sh file and do something like this instead:
ADD ./scripts/run.sh /run.sh
RUN chmod +x /*.sh
And also think about to start using Gulp.
UPD #1
By default npm install installs devDependencies. In order to get around this - use npm install --production OR set the NODE_ENV environment variable to production value.
Putting script line in separate file is a good practice in order not to change Dockerfile often. If you'll need changes next time then you'll have to update only script-file and you're done. In future you could also have some additional work to do.
I have a requirement that before an application runs, some part of it needs to read the environmental variable. For this I have the following docker file
FROM nodesource/jessie:0.12.7
# install gettext for envsubst
RUN apt-get update
RUN apt-get install -y gettext-base
# cache package.json and node_modules to speed up builds
ADD package.json package.json
RUN npm install
# Add source files
ADD src src
# Substiture value for backend endpoint env var
RUN envsubst < src/js/envapp.js > src/js/app.js
ADD node_modules node_modules
EXPOSE 8000
CMD ["npm","start"]
The above envsubst line reads (should read) an env variable $MYENV and substitutes it. But when I open the file app.js, its empty.
I checked if the environmental variable exists in the container and it does. Any reason its value is not read and substituted?
I also tried the same command in teh container and it works. It only does not work when I run the image
This is likely because $MYENV is not available for envsubst when you run the image.
Each RUN command runs on its own shell.
From the Docker documentations:
RUN (the command is run in a shell - /bin/sh -c - shell form)
You need to source your profile as well, for example if the $MYENV environment variable is available in the .bashrc file, you can modify your Dockerfile like this:
RUN source ~/.bashrc && envsubst < src/js/envapp.js > src/js/app.js
I encountered the same issues, and after much research and fishing through the internet. I managed to find a few work arounds to this issue. Below I'll list them and identifiable risks at the time of this "Answer post"
Solutions:
1.) apt-get install -y gettext its a standard GNU package language library, one of these libraries that it includes is envsubst` and I can confirm that it works for docker UBUNTU:latest and it should work for every flavored version.
2.) npm install envsub dependent on the "use case" - this approach would be better supported by node based projects.
3.) enstub cli project lib in my opinion it seems a bit overkill to downloading a custom cli from a random stranger but, it's also another option.
Risk:
apt-get install -y gettext:
1.) gettext - this approach would NOT be ideal for VM's as with any package library, it requires maintenance and updates as time passes. However, this isn't necessary for docker because once an a container is initialized and up and running we can create a bashscript to add the package, substitute env vars and then remove the package.
2.) It's a bad idea for VM's because it can be used to execute arbitrary code
npm install ensub
1.) envsub - updating packages and this approach wouldn't be ideal if your dealing with a different stack and not using nodejs.
NOTE:
There's also a PHP version for those developing a PHP application and it seems to work PHP's cli if you need a custom environment.
Resources:
GetText package library info: https://www.gnu.org/software/gettext/
GetText Risk - https://ubuntu.com/security/notices/USN-3815-2
PHP-GetText - apt-get install -y php-gettext
Custom ensubst cli: https://github.com/a8m/envsubst
I suggest that since your are using Node, you use the npm envsub module.
This module is well tested and is developed with docker in mind.
It avoids the need for relying on other dependencies when you already have the full Node arsenal at your fingertips.
envsub is described as
envsub is envsubst for NodeJS
NodeJS global CLI module providing file-level environment variable substitution via Handlebars
I am the author of the package. I think you will enjoy it.
I had some issues with envsubst in Docker.
For some reasons envsubst doesn't work when I try to copy the output in the same file. For example, this is not working:
RUN envsubst < file.conf > file.conf
But when I when I tried to use a temp file the issue disappeared:
RUN envsubst < file.conf > file.conf.temp && cp -f file.conf.temp file.conf