Run yarn from Dockerfile in ddev - hadoop-yarn

This is a followup to How can I add and use nvm in a DDEV web container?
My dockerfile now looks like this:
ARG BASE_IMAGE
FROM $BASE_IMAGE
ENV NVM_DIR=/usr/local/nvm
ENV NODE_DEFAULT_VERSION=v8.16.1
RUN curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh -o install_nvm.sh
RUN mkdir -p $NVM_DIR && bash install_nvm.sh
RUN echo "source $NVM_DIR/nvm.sh" >>/etc/profile
RUN bash -ic "nvm install $NODE_DEFAULT_VERSION && nvm use $NODE_DEFAULT_VERSION"
RUN chmod -R ugo+w $NVM_DIR
RUN npm install -g foundation-cli
RUN npm install -g gulp-cli
RUN yarn --cwd foundation-src install
The last line returns an error: Service 'web' failed to build: The command '/bin/sh -c yarn --cwd foundation-src install' returned a non-zero code: 1'
When I ddev ssh and then run yarn --cwd foundation-src install it does the job (running yarn in the foundation-src folder).
I also tried RUN (cd foundation-src; yarn install;) but no luck either. I prefer the first command anyway. But what is going on? Why can I run stuff from inside the container but not from the dockerfile?

Your command is RUN yarn --cwd foundation-src install - it's assuming that there is a subdirectory "foundation-src" under the current directory.
But the Dockerfile is running long, long before your source is anywhere useful. The container has not been run yet, nothing is mounted. So you can't do things that require your source code to be present.
Since this command appears to require your source code to be present, I think you'll be better doing this as a post-start hook, perhaps
hooks:
post-start:
- exec: "yarn --cwd foundation-src install"
Since actions like yarn install happen irregularly, it's also easy to ddev exec yarn --cwd foundation-src install and also easy to create a custom command to do that when you need it.

Related

Yarn re-load or pass new config after 'preinstall'

I'm trying to utilize a private repo using AWS CodeArtifact. The instructions there mention executing a aws-cli npm login command. This login command grabs a token from AWS and places it in the users .npmrc.
I had tried to put this login function in a preinstall script in the projects package.json but the problem is that .npmrc is only modified in this step and not reloaded when proceeding to the yarn install task.
Is there any way to load this token into yarn while keeping the login / install process seamless?
I had a similar problem with gcloud. I managed to hack it by adding a yarn preinstall hook to package.json
"preinstall": "yarn install --ignore-scripts; kill -9 $(ps | grep 'yarn.js install' | awk 'NR==1' | awk '{print $1}')"
It's always not necessary to also kill the yarn install either. Your "second" install would just get a cache hit and it will be fast.
You can also add /bin/bash -c ' if [[ -n ${ENV_VARIABLE:-} ]]; then blabla; fi' to make the command only run in the environment you want.

How to use the brew version of a command (aws-es-proxy) instead of node?

I used npm -i -g aws-es-proxy. But I actually wanted to do brew install aws-es-proxy because the commands are slightly different for these two packages depending on whether installed with npm or brew. So I did npm uninstall -g aws-es-proxy and after uninstalling and deleting the folder that was still left over
$ cd /Users/USER_NAME/.nvm/versions/node/v10.17.0/bin/
$ ls
aws-azure-login node npm npx
bin USER_NAME$ rm -r aws-azure-login
I still would get
$ aws-es-proxy -listen :9200 -ENDPOINT
-bash: /Users/USER_NAME/.nvm/versions/node/v10.17.0/bin/aws-es-proxy: No such file or directory
It seems like this terminal is using npm version instead of brew version. Can you let me know how I can force to use the brew installation for this command?
Actually, all I had to do was open a new terminal session and it recognized the command. Not sure what behind the scenes stuff was happening.

I've installed Yarn at a global level. Why can't I see run yarn -v at a project level?

New to Yarn and I've installed it at global level npm install -g yarn
At ~ I can run yarn -v and see the version number fine.
However, when I cd into my project (currently just an empty folder on the desktop) and run yarn -v I get yarn: command not found.
Wouldn't having installed it globally allow me to run Yarn anywhere?

Error: node_modules directory is missing. Please run `npm install` in your project directory

expo start
[21:03:34] Starting project at /home/sadaif/Documents/React-Native-App/my
[21:03:35] Expo DevTools is running at http://localhost:19002
[21:03:35] Opening DevTools in the browser... (press shift-d to disable)
[21:03:41] Error: node_modules directory is missing. Please run `npm install` in your project directory.
[21:03:41] Couldn't start project. Please fix the errors and restart the project.
[21:03:41] Set EXPO_DEBUG=true in your env to view the stack trace.
I run this command npm install but noting happened
then i run these commands
rm -rf node_modules
rm package-lock.json
npm cache clear --force
npm install
When I run command expo start then this error show in the terminal .I'm Using first time expo cli i m a beginner so that's why have no idea how to fix this issue if anyone know please help me.
either you are using Mac or Ubuntu the directory you have created the project in needs superuser permissions to modify it.
either run all commands with sudo or change the ownership
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
or re-install the node with
npm install -g node#latest --unsafe-perm

How to run the official vue.js examples?

I git cloned vue, cd'ed into one of the examples folder and ran npm install. Everything went fine, then I ran npm run dev and it gets stuck at this stage. Is there anything else I should do to run this locally?
npm run dev
> vue#2.4.2 dev /vue
> rollup -w -c build/config.js --environment TARGET:web-full-dev
bundling...
bundled in 2456ms. Watching for changes...
You need to run a local web server.
Try this:
Install http-server package with npm:
$ sudo npm install -g http-server
Run it in the root of the vue cloned folder:
$ git clone git#github.com:vuejs/vue.git
$ cd vue
$ http-server -o -c .
In yout browser, navigate to the examples folder, for instance:
http://127.0.0.1:8081/examples/select2/
They are the same from here:
https://v2.vuejs.org/v2/examples/