在git post-receive钩子中克隆github包时,yarn安装失败 [英] yarn install fails on cloning github packages in git post-receive hook

查看:362
本文介绍了在git post-receive钩子中克隆github包时,yarn安装失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个post-receive钩子,以将更改部署到应用程序并通过Yarn安装软件包.看起来像这样:

I have created a post-receive hook to deploy changes to an app and install packages via Yarn. It looks like this:

#!/bin/sh

echo "Checking out changes..."
git --work-tree=/home/me/apps/app --git-dir=/home/me/repos/repo.git 
checkout -f

echo "Yarn install..."
cd /home/me/apps/app
yarn install

注释(正​​在工作的东西):

第一部分工作正常.挂钩肯定正在运行.主要应用程序文件已按预期更新.

Notes (stuff that is working):

The first portion works fine. The hook is definitely running. The primary app files are updated as expected.

在ssh到服务器的同时从命令行执行yarn install时,所有软件包的安装都没有问题. (ssh'd进入服务器的用户是推提交并运行该钩子的同一用户.)

When doing yarn install from the command line while ssh'd into the server, all packages are installed with no problem. (The user ssh'd into the server is the same user pushing commits and running the hook.)

已检查所有目录的权限问题.

All directories have been checked for permissions issues.

在尝试通过Yarn安装软件包时,挂钩每次都失败.具体来说,它在尝试从Github安装软件包依赖项时失败. 确实正在检索软件包(或者至少它没有告诉我在检索它们时有任何问题),尝试将其移至node_modules目录时它做错了什么.

The hook fails every time while trying to install packages via Yarn. Specifically, it fails while trying to install package dependencies from Github. It does seem to retrieve the packages (or at least it doesn't tell me there was any problem retrieving them), it just is doing something wrong when trying to move them into the node_modules directory.

我得到两个错误之一:

remote: error Command failed.
remote: Exit code: 128
remote: Command: git
remote: Arguments: pull
remote: Directory: 
/home/me/.cache/yarn/v2/.tmp/45d918f2ecb73f845db6f9b2f91617a3
remote: Output:
remote: fatal: Not a git repository: '.'

或者:

remote: error Command failed.
remote: Exit code: 128
remote: Command: git
remote: Arguments: clone https://github.com/Account/package.git /home/me/.cache/yarn/v2/.tmp/45d918f2ecb73f845db6f9b2f91617a3
remote: Directory: /home/me/apps/app
remote: Output:
remote: fatal: Working tree '/home/me/apps/app' already exists

上面的某些软件包和用户详细信息已进行了一些修改,但是任何与git相关的软件包安装都失败了,但仅限于post-receive挂钩中.

Some of the package and user details above have been modified a little, but any git-related package installation is failing, but only in the post-receive hook.

在第二个错误中,这很奇怪,因为git命令似乎表明它试图将存储库克隆到缓存中,但是随后出现一条消息,提示它正试图将软件包克隆到主应用程序目录中.

In the second error, it's weird, because the git command seems to suggest it's trying to clone the repo into cache, but then has a message suggesting that it was trying to clone the package into the primary app directory.

我什至可以使用钩子将package.json复制到新目录中,然后将cd复制到新目录中,然后尝试复制到yarn install.产生了同样的错误.

I went so far as to use the hook to copy the package.json into a new directory, cd into it, and try to yarn install. Same sort of errors resulted.

我完全迷住了.

推荐答案

我不知道Git操作利用GIT_DIRGIT_WORK_TREE环境变量,因此我设置的变量干扰了Yarn的Git.操作.

I was ignorant of the fact that Git operations utilize the GIT_DIR and GIT_WORK_TREE environment variables, so that the variables I was setting were interfering with Yarn's Git operations.

解决方案,取消设置yarn install之前的变量:

Solution, unset the variables before yarn install:

#!/bin/sh

export GIT_WORK_TREE=/home/me/apps/app

echo "Checking out changes..."
git --work-tree=$GIT_WORK_TREE --git-dir=/home/me/repos/repo.git 
checkout -f

echo "Yarn install..."
cd $GIT_WORK_TREE
unset GIT_WORK_TREE
yarn install

这篇关于在git post-receive钩子中克隆github包时,yarn安装失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆