如何解决 Dokku 部署中的 pre-receive hook declined 错误?
How do I solve the pre-receive hook declined error in Dokku deployment?
我目前正在 dokku 实例上部署 Angular4 应用程序,但是,我一直收到此错误 ! [remote rejected] develop -> master (pre-receive hook declined)
。
我正在从开发分支部署到主分支,所以我 运行 部署命令如此 git push mediafactory develop:master
我正在通过 Dockerfile 进行部署,它看起来像这样;
FROM node:carbon
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY package*.json ./
RUN npm install --save @angular/cli@1.3.0
RUN npm install --only=production
COPY .angular-cli.json .
COPY . .
RUN ng build --aot -prod
ENV APP_ID setYourAppId
ENV MASTER_KEY setYourMasterKey
ENV DATABASE_URI setMongoDBURI
EXPOSE 1337
CMD ["npm", "start"]
我试过了运行宁
sudo wget -O /etc/init/docker.conf https://raw.github.com/dotcloud/docker/master/contrib/init/upstart/docker.conf
sudo service docker restart
但是,好像并没有解决问题。
我终于找到了解决问题的方法。我知道有人可能会遇到和我一样的问题。
出现上述问题的主要原因有以下三个。
首先,如果您遇到此错误,
remote: <app name> is currently being deployed. Exiting...
To <dokku remote>:<app name>
! [remote rejected] develop -> master (pre-receive hook declined)
您可以通过在您的 dokku 主机上 运行 执行这两个命令轻松解决上述问题。
$ sudo wget -O /etc/init/docker.conf https://raw.github.com/dotcloud/docker/master/contrib/init/upstart/docker.conf
$ sudo service docker restart
其次,对于我的情况,这是全局节点模块文件夹的权限问题,当您尝试全局安装@angular/cli 时,会导致无限循环。不幸的是,即使在提供权限后,pre-receive hook declined
错误仍然存在。这是因为我使用的是 @ngular/cli 图片。
错误看起来像这样
...
/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-
gyp/8.9.1
gyp WARN EACCES user "nobody" does not have permission to access the
dev dir
"/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-
gyp/8.9.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir
"/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"
...
当且仅当命令 $ npm config get prefix
returns 类似于 /usr/local
时,您可以通过将以下行添加到 Dockerfile
来解决上述错误,否则您可能会弄乱您的权限。
RUN chown -R $(whoami) $(npm config get prefix)/lib/node_modules
使用此命令在您的容器中全局安装@angular/cli
RUN npm install -g --unsafe-perm @angular/cli
这是解决问题的解决方法。
可能导致此问题的另一个问题是将 package-lock.json
添加到您的容器中。您也可以考虑忽略它,因为它可能会导致同样的问题。
因此,新的 Dockerfile 看起来像这样;
FROM node:carbon
RUN mkdir -p /opt/app
WORKDIR /opt/app
RUN chown -R $(whoami) $(npm config get prefix)/lib/node_modules
RUN npm install -g --unsafe-perm @angular/cli
COPY package.json .
RUN npm install --only=production
COPY .angular-cli.json .
COPY . .
RUN ng build --aot -prod
ENV APP_ID setYourAppId
ENV MASTER_KEY setYourMasterKey
ENV DATABASE_URI setMongoDBURI
EXPOSE 1337
CMD ["npm", "start"]
第三也是最后一点,如果您使用的是 Vagrant
dokku 安装,pre-receive hook declined
错误可能是由于虚拟机内存分配不足造成的。
您可以编辑您的 dokku 存储库的 Vagrantfile
并为您的虚拟机分配更多内存。例如,您可以通过将以下行添加到 Vagrantfile
;
来将内存从 1GB 增加到 2GB
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
end
之后,您 运行 $ vangrant reload
应用您在 Vagrant 文件中指定的更改。
如果问题仍然存在,并且您正在使用 mongoDB
,您可能需要检查您的 mongo 实例,并确保它们按预期 运行ning。您可以在您的 dokku 主机上通过 运行ning $ dokku mongo:list
检查您的 mongo 实例状态。
最后,如果上述 none 有帮助,但问题仍然存在,您可能需要销毁您的 dokku 应用并重新创建一个新应用。执行此操作之前请格外小心!!!
You may checkout a tutorial I wrote about deploying 2 apps in the same docker container, with dokku
我目前正在 dokku 实例上部署 Angular4 应用程序,但是,我一直收到此错误 ! [remote rejected] develop -> master (pre-receive hook declined)
。
我正在从开发分支部署到主分支,所以我 运行 部署命令如此 git push mediafactory develop:master
我正在通过 Dockerfile 进行部署,它看起来像这样;
FROM node:carbon
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY package*.json ./
RUN npm install --save @angular/cli@1.3.0
RUN npm install --only=production
COPY .angular-cli.json .
COPY . .
RUN ng build --aot -prod
ENV APP_ID setYourAppId
ENV MASTER_KEY setYourMasterKey
ENV DATABASE_URI setMongoDBURI
EXPOSE 1337
CMD ["npm", "start"]
我试过了运行宁
sudo wget -O /etc/init/docker.conf https://raw.github.com/dotcloud/docker/master/contrib/init/upstart/docker.conf
sudo service docker restart
但是,好像并没有解决问题。
我终于找到了解决问题的方法。我知道有人可能会遇到和我一样的问题。
出现上述问题的主要原因有以下三个。
首先,如果您遇到此错误,
remote: <app name> is currently being deployed. Exiting...
To <dokku remote>:<app name>
! [remote rejected] develop -> master (pre-receive hook declined)
您可以通过在您的 dokku 主机上 运行 执行这两个命令轻松解决上述问题。
$ sudo wget -O /etc/init/docker.conf https://raw.github.com/dotcloud/docker/master/contrib/init/upstart/docker.conf
$ sudo service docker restart
其次,对于我的情况,这是全局节点模块文件夹的权限问题,当您尝试全局安装@angular/cli 时,会导致无限循环。不幸的是,即使在提供权限后,pre-receive hook declined
错误仍然存在。这是因为我使用的是 @ngular/cli 图片。
错误看起来像这样
...
/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-
gyp/8.9.1
gyp WARN EACCES user "nobody" does not have permission to access the
dev dir
"/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-
gyp/8.9.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir
"/usr/local/lib/node_modules/@angular/cli/node_modules/node-sass/.node-gyp"
...
当且仅当命令 $ npm config get prefix
returns 类似于 /usr/local
时,您可以通过将以下行添加到 Dockerfile
来解决上述错误,否则您可能会弄乱您的权限。
RUN chown -R $(whoami) $(npm config get prefix)/lib/node_modules
使用此命令在您的容器中全局安装@angular/cli
RUN npm install -g --unsafe-perm @angular/cli
这是解决问题的解决方法。
可能导致此问题的另一个问题是将 package-lock.json
添加到您的容器中。您也可以考虑忽略它,因为它可能会导致同样的问题。
因此,新的 Dockerfile 看起来像这样;
FROM node:carbon
RUN mkdir -p /opt/app
WORKDIR /opt/app
RUN chown -R $(whoami) $(npm config get prefix)/lib/node_modules
RUN npm install -g --unsafe-perm @angular/cli
COPY package.json .
RUN npm install --only=production
COPY .angular-cli.json .
COPY . .
RUN ng build --aot -prod
ENV APP_ID setYourAppId
ENV MASTER_KEY setYourMasterKey
ENV DATABASE_URI setMongoDBURI
EXPOSE 1337
CMD ["npm", "start"]
第三也是最后一点,如果您使用的是 Vagrant
dokku 安装,pre-receive hook declined
错误可能是由于虚拟机内存分配不足造成的。
您可以编辑您的 dokku 存储库的 Vagrantfile
并为您的虚拟机分配更多内存。例如,您可以通过将以下行添加到 Vagrantfile
;
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
end
之后,您 运行 $ vangrant reload
应用您在 Vagrant 文件中指定的更改。
如果问题仍然存在,并且您正在使用 mongoDB
,您可能需要检查您的 mongo 实例,并确保它们按预期 运行ning。您可以在您的 dokku 主机上通过 运行ning $ dokku mongo:list
检查您的 mongo 实例状态。
最后,如果上述 none 有帮助,但问题仍然存在,您可能需要销毁您的 dokku 应用并重新创建一个新应用。执行此操作之前请格外小心!!!
You may checkout a tutorial I wrote about deploying 2 apps in the same docker container, with dokku