Let's setup a post-receive hook for git like this:
#!/bin/sh
git --work-tree=/path/to/www --git-dir=/path/to/git/test_CI.git checkout -f
export PATH=$PATH:/usr/bin #(<- this export does not help much)
yarn build
The first line work well, but yarn build fails, because the hook doesn't know yarn at all.
(Running yarn in my host-terminal works perfeclty, though. The host is running on Ubuntu 18.04. by the way.)
which yarn tells me the exact location of yarn:
/home/.../.nvm/versions/node/v12.18.3/bin/yarn
I can use this for the hook. But the path contains the current yarn versionnumber, which will cause other problems, once the systems gets updated.
Plus, nvm, or node or nuxt and so on won't be found next. So this is not a clever workaround.
How can you make all the things that you have access to in your teminal (not only yarn) available for the hook?
export PATH=$PATH:/usr/bin #(<- this export does not help much)
This adds /usr/bin, which should already be part of $PATH to begin with, so... it does not do much.
I would check, as seen in nvm-sh/nvm issue 355 if you can have ~/.nvm/current/ symlink (symbolic link), in order for the $PATH to remain constant, even when npm is updated.
Related
I recently added my node_modules directory to version control per this answer's advice.
(By the way, I'm not necessarily of the opinion that adding node_modules to version control is a good practice, but I'm trying to get a deployment working and I don't have anything else to try right now.)
My problem now is that every command I run is followed by about a five-second pause before I get my command prompt back. I assume that this is because I have an ~700MB node_modules directory.
Is there a way to speed up ZSH or do I just have to live with this slowness if I decide to check in node_modules?
Your question is not clear but what I infer is happening is:
You have zsh and/or your zsh plugins configured to include some aspects of git repo status in your prompt
thus each time zsh goes to render your prompt, it has to run one or more git commands
because your repository is so large, these commands tend to be slow
If this is indeed the case, the first thing you should do is alter your zsh configuration to keep these details out of your prompt. This can be done temporarily just while you are working on this particular project. That might alleviate the biggest pain point without much cost/effort.
Secondly, you could try to make node_modules as small as possible with npm dedupe. Then you could eliminate dev dependencies with npm prune --production so the dev deps could be local files but only the deps necessary for prod would be in git. That might require some clever/verbose configuration in .gitignore but may be workable.
But ultimately deps-in-git is the path to failure for reasons like this. Source Code Management is for Source Code.
So, I'm trying to install gitlab on a subdirectory. A lot of articles online suggest it is now possible to do so.
I installed omnibus-gitlab but it didn't seem to contain the files required to make gitlab run in a subdirectory like application.rb and stuff. Did a little research and discovered it is not yet supported on omnibus.
So why the differences? I actually thought they were all different ways of getting the same thing. My question again: difference between cookbook, omnibus and normal manual installation. Thanks!
Cookbook : the installation is done by Chef recipes
Manual : you install all the components one by one, manually, with a lot of pain and suffering
Omnibus : The installation in simplified with a .RPM (red hat) or a .deb (Debian), much more simple.
The results are differents: with a manual install, the home dir of gitlab will be somehting like /home/git/... while it will be /opt/gitlab/... in omnibus. Also, the commands to manage your GitLab instance are a little differents. By example, in manual install to seed an external DB you have to type sudo -u git -H bundle exec rake gitlab:setup while gitlab omnibus will need a sudo gitlab-rake gitlab:setup.
From what I tested, they all leed to the same GitLab features, but with a different way to manage it.
Now for the subdirectory (it doesn't works for me, but that's what the documentation say) : after an omnibus install, modifiy the non_root_url in the following files :
/opt/gitlab/embedded/service/gitlab-rails/conf/gitlab.yml
/opt/gitlab/embedded/service/gitlab-rails/conf/application.rb (read the comments at the bottom of the file)
/opt/gitlab/embedded/service/gitlab-rails/conf/unicorn.rb
/opt/gitlab/embedded/service/gitlab-shell/config.yml
And then restart GitLab. I repeat: that's what the gitlab's doc say, but it doesn't works for me. In my case it just create a redirection. Look:
#gitlab is configured to run in subdirectory "/gitlab" :
curl -v http:127.0.0.1:3000/gitlab
----> Error 404
curl -v http://127.0.0.1:3000
----> <html><body>You are being redirected.</body></html>
I have a test VM with Debian Wheezy and no ruby installed. Gitlab 6.9.2 has been installed using the provided installer which brings an embedded ruby. Now, I want to import some old repos into Gitlab, but I cannot find the correct procedure. I think it should be this way:
su - git
export PATH=$PATH:/opt/gitlab/embedded/bin
cd ~
bundle exec rake gitlab:import:repos RAILS_ENV=production
Though, I only get the error "Could not locate Gemfile". I have tried several other ways, also installing Debians ruby, searched multiple Google and StackOverflow results, but I couldnĀ“t get it to work.
You should first place the bare repos in the repo dir. The default path for omnibus is /var/opt/gitlab/git-data/repositories/<namespace>. Then you just run the rake task:
sudo -u git -H cp -r my-project/.git /var/opt/gitlab/git-data/repositories/<namespace>/my-project.git
sudo gitlab-rake gitlab:import:repos
See invoking rake tasks and the import mechanism.
Edit: Sent an MR upstream to include this info in the readme.
I have run into same issue with "Could not locate Gemfile". So I searched for Gemfile and tried several folders. Until it worked.
The solution is related to Gitlab from source (or in my case it run inside offical docker container).
Place your .git bare repository (or several of them) in
"/var/opt/gitlab/git-data/repositories//my-project.git"
switch to user "git".
su git
Try if you have correct PATH by just "rake". If not available, extend your PATH:
export PATH=$PATH:/opt/gitlab/embedded/bin
after that switch to the shell were the rake command to import your bare projects will work and do the import.
cd /opt/gitlab/embedded/service/gitlab-rails/
bundle exec rake gitlab:import:repos RAILS_ENV=production
Output will be similar to this:
Processing raspberry/apollo-web.git
* Created apollo-web (raspberry/apollo-web.git)
Processing raspberry/apollo-web.wiki.git
* Skipping wiki repo
Processing dhbw/dhbw-prototyping-node-rest-course.git
...
EDIT:
Ok I was happy a bit too early. Although the ouput says it was imported. On the Web GUI no new projects.
I will investiage further...
I'm on a unix box where I don't have root access.
I changed my .npmrc file (in my user's root directory) to:
prefix=~/global_npm
Now when I do "npm install -g packagename" it installs inside my global_npm directory. Which is good.
And then I gave myself path access to it by updating my .bashrc file with:
export PATH=$PATH:~/global_npm/bin
Do I need to do anything else? I think I need to set NODE_PATH but I'm not sure?
Many setups already expect binaries to be found in ~/.local/bin/. So this answer follows that convention. Other files will get installed to ~/.local/lib/node_modules/.
1. Configure npm
Run:
npm config set prefix '~/.local/'
This modifies ~/.npmrc to include this line:
prefix=~/.local/
2. Make sure ~/.local/bin exists and is in your PATH
Run echo "$PATH" to have a look at your path. If it does not include ~/.local/bin/ already, you will need to configure your system to include it.
mkdir -p ~/.local/bin
echo 'export PATH=~/.local/bin/:$PATH' >> ~/.bashrc
Replace .bashrc with the configuration file of the shell that you are using.
3. Install packages globally
npm install -g packagename
Sindre Sorhus has a great guide at github.com/sindresorhus/guides which I've reposted here.
Install npm packages globally without sudo on OS X and Linux
npm installs packages locally within your projects by default. You can also install packages globally (e.g. npm install -g <package>) (useful for command-line apps). However the downside of this is that you need to be root (or use sudo) to be able to install globally.
Here is a way to install packages globally for a given user.
1. Create a directory for your global packages
mkdir "${HOME}/.npm-packages"
2. Reference this directory for future usage in your .bashrc/.zshrc:
NPM_PACKAGES="${HOME}/.npm-packages"
3. Indicate to npm where to store your globally installed package. In your $HOME/.npmrc file add:
prefix=${HOME}/.npm-packages
4. Ensure node will find them. Add the following to your .bashrc/.zshrc:
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
5. Ensure you'll find installed binaries and man pages. Add the following to your .bashrc/.zshrc:
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
Check out npm-g_nosudo for doing the above steps automagically
NOTE: If you are running OS X, the .bashrc file may not yet exist, and the terminal will be obtaining its environment parameters from another file, such as .profile or .bash_profile. These files also reside in the user's home folder. In this case, simply adding the following line to them will instruct Terminal to also load the .bashrc file:
source ~/.bashrc
Unless you require a package installation due to dependencies, which are rare, I would recommend you use NVM (https://github.com/creationix/nvm) to install Node.
If you do this without sudo, you will also not need to use sudo when globally installing modules.
My edit to Rowno's answer has been rejected and I can't make a comment yet so I'll just post my version of the lines added in .bashrc here.
The edit I made in it was adding export to the assignments of NODE_PATH and MAN_PATH, and then simplifying the MANPATH assignment. I also made : optional for NODE_PATH just in case it doesn't have a prior value. The other modifications here are just personal preference but I haven't included them in the original edit.
npm_global=~/.npm-global
export NODE_PATH="$npm_global/lib/node_modules${NODE_PATH:+:}$NODE_PATH"
PATH="$npm_global/bin:$PATH"
export MANPATH="$npm_global/share/man:$(unset MANPATH; manpath)"
Having export makes sure variables are shared across child processes that may need them (e.g. node and man), just in case they haven't been declared yet, or assigned with export attribute previously. Specifying export to PATH OTOH is very much optional.
I actually find it unusual to reset MANPATH before prepending a value to it because some scripts may also add custom values to it earlier. I recommend that the user makes sure .bashrc or any other user-based initialization scripts doesn't add other lines like this at least. For global configurations, I think the path should be added formally through /etc/manpath.config, or something similar, so it's a different worry most likely.
Either start a new terminal session or just type "source ~/.bashrc"
Now you can run any executables like grunt/bower/yo/whatever (depending on what npm packages you have installed globally).
P.S. BTW changing the global npm directory can be done with a command: npm config set prefix ~/global_npm
That's pretty much all you need to do if you are installing binary utilities (which I gather you are as you updated your PATH).
NODE_PATH will only need to be set you have installed a module that you want to require() from unrelated node scripts, but you shouldn't really do this anyway. Modules that are required as dependencies for other modules/scripts should be installed locally (i.e. specified in a package.json) as that way you keep strict control over versions.
Edit:
The accepted answer here explains it much better than I was able to:
How do I install a module globally using npm?
The answer by Rowno works for me, but only after making a slight edit to step 4:
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
and changed it to:
NODE_PATH="$NPM_PACKAGES/node_modules:$NODE_PATH"
Try to switch user:
su - username
If you don't have another user try:
useradd username
Then,
su - username
I probably missed something here. I'm using Node 0.10.1 on Win7/64bit and installed grunt 0.4.1 with
npm install grunt
npm install -g grunt-cli
npm install -g grunt-init
Then I tried to install a template while in folder %USERPROFILE%
git clone git#github.com:gruntjs/grunt-init-gruntfile.git ~/.grunt-init/gruntfile
But git wants a passphrase for key [current folder]. So I just created a folder
%USERPROFILE%\.grunt-init\gruntfile\
and copied
https://raw.github.com/gruntjs/grunt-init-gruntfile/master/template.js
to it. Now I switched to the project folder and was able to start grunt-init with
grunt-init gruntfile
DOM involved? n
files concatenated or minified? Y
package.json? n
any changes? N
Process ends with "Done, without errors", but no file ist created, or at least I can't find it.
dont know how to clone into your userhome on windows, but IMPORTANT(!) you also need to copy the whole "root" directory ( https://raw.github.com/gruntjs/grunt-init-gruntfile/master/root) to '%USERPROFILE%.grunt-init\gruntfile\'
you know that this init-template will just create a gruntfile.js for you? (inside the root-directory you can see that). if you want to create a node-module, jquery-plugin and so on, use one of the other templates (grunt-init-node, grunt-init-jquery) and so on.
creating your own template is easy. just create a new folder in '%USERPROFILE%.grunt-init' with your template-name. add the template.js. add a root-directory where all the files are which you want to be copied, maybe add a rename.json (for folder and file-renamings) and maybe change some stuff in the template.js.
I think you are have few a different issues here - from your comments it looks like you are using a Windows.
The first issue is that you can't clone the repository. Having tried this myself, I found the problem was fixed by setting up a valid ssh key on my github account. So to clone this repository you need to create a github account and install ssh keys on both your machine and your github account. Github's documentation on how to do this is very good and can be found here for Windows https://help.github.com/articles/set-up-git#platform-windows.
The second issue is that the git clone command you are using won't work on a Windows machine as it supplies a path to a Linux home directory ~/.grunt-init/gruntfile.
From your comments I am guessing the %USERPROFILE%.grunt-init\gruntfile\ is the correct install directory for Windows and so changing your working directory to that and using the command git clone git#github.com:gruntjs/grunt-init-gruntfile.git should install it.
You may also consider working using Cygwin which allows you to use a linux working environment on a windows machine.
Happy node hacking.