[英]How do I solve the pre-receive hook declined error in Dokku deployment?
I'm currently in the middle of deploying an Angular4 application on a dokku instance, but, I keep on getting this error ! [remote rejected] develop -> master (pre-receive hook declined)
我目前正在在dokku实例上部署Angular4应用程序,但是,我不断遇到此错误
! [remote rejected] develop -> master (pre-receive hook declined)
! [remote rejected] develop -> master (pre-receive hook declined)
. ! [remote rejected] develop -> master (pre-receive hook declined)
。
I'm deploying from a develop branch to master, so I run the deployment command as so git push mediafactory develop:master
我正在从开发分支部署到主服务器,因此我按
git push mediafactory develop:master
运行部署命令
I'm deploying via a Dockerfile, which looks like this; 我正在通过一个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"]
I tried running 我尝试跑步
sudo wget -O /etc/init/docker.conf https://raw.github.com/dotcloud/docker/master/contrib/init/upstart/docker.conf
sudo service docker restart
But, it doesn't seem to solve the problem. 但是,它似乎无法解决问题。
I finally got the solution to the problem. 我终于找到了解决问题的办法。 I know someone may face the same problem as I had.
我知道有人可能会遇到与我相同的问题。
There are three main reasons as to why the above problem might come up. 关于出现上述问题的原因有三个主要原因。
First, If you land into this error, 首先,如果您遇到此错误,
remote: <app name> is currently being deployed. Exiting...
To <dokku remote>:<app name>
! [remote rejected] develop -> master (pre-receive hook declined)
You can easily solve the above problem by running these two commands from your dokku host. 通过从dokku主机运行这两个命令,可以轻松解决上述问题。
$ sudo wget -O /etc/init/docker.conf https://raw.github.com/dotcloud/docker/master/contrib/init/upstart/docker.conf
$ sudo service docker restart
Secondly, as for my case, it was a problem with the permissions of the global node modules folder which would result into an infinite loop when you try to globally install the @angular/cli. 其次,就我的情况而言,这是全局节点模块文件夹权限的问题,当您尝试全局安装@ angular / cli时,这将导致无限循环。 Unfortunately even after providing permissions, the
pre-receive hook declined
error would persist. 不幸的是,即使在提供权限之后,
pre-receive hook declined
错误仍将持续。 This was because of the @ngular/cli image I was using. 这是因为我正在使用@ ngular / cli图像。
The error looked like this 错误看起来像这样
...
/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"
...
You can solve the above error by adding the following line to your Dockerfile
, if and only if the command $ npm config get prefix
returns something like /usr/local
, otherwise you may mess up your permissions. 您可以通过在
Dockerfile
添加以下行来解决上述错误,当且仅当命令$ npm config get prefix
返回类似/usr/local
,否则您可能会弄乱您的权限。
RUN chown -R $(whoami) $(npm config get prefix)/lib/node_modules
Install the @angular/cli globally in your container with this command 使用此命令在容器中全局安装@ angular / cli
RUN npm install -g --unsafe-perm @angular/cli
That's a work around that solves the problem. 这是解决问题的一种解决方法。
The other problem that might cause the problem, is adding package-lock.json
to your container. 另一个可能导致该问题的问题是将
package-lock.json
添加到您的容器中。 You might consider ignoring it too, for it may cause the same problem. 您可能也考虑忽略它,因为它可能导致相同的问题。 The new Dockerfile hence looks like this;
因此,新的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"]
Thirdly and lastly, if you are using a Vagrant
dokku installation, the pre-receive hook declined
error might be caused by low memory allocation to the virtual machine. 第三,最后,如果您使用的是
Vagrant
dokku安装,则pre-receive hook declined
错误可能是由于虚拟机内存分配不足而引起的。
You may edit the Vagrantfile
of your dokku repo and allocate more memory to your virtual machine. 您可以编辑
Vagrantfile
存储库的Vagrantfile
,并为虚拟机分配更多内存。 For example, you may increase the memory from 1GB to 2GB by adding the following line to your Vagrantfile
; 例如,您可以通过
Vagrantfile
添加到Vagrantfile
来将内存从1GB增加到2GB;
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
end
Afterwards, you run $ vangrant reload
to apply the changes you have specified in your Vagrant file. 然后,您运行
$ vangrant reload
以应用您在Vagrant文件中指定的更改。
If the problem still persists, and you are using mongoDB
, you may want to checkout your mongo instances, and ensure that they are running as expected. 如果问题仍然存在,并且您正在使用
mongoDB
,则可能需要检出mongo实例,并确保它们按预期运行。 You can check your mongo instances status by running $ dokku mongo:list
on your dokku host. 您可以通过在dokku主机上运行
$ dokku mongo:list
来检查mongo实例的状态。
Finally, If none of the above helps, and the problem still persists, you may have to destroy your dokku app and re-create a new one. 最后,如果以上方法均无济于事,但问题仍然存在,则可能必须销毁dokku应用程序并重新创建一个新的应用程序。 TAKE EXTRA EXTRA CAUTION BEFORE DOING THIS!!!
在执行此操作之前要格外小心!!!
You may checkout a tutorial I wrote about deploying 2 apps in the same docker container, with dokku 您可以查看我写的关于使用dokku在同一个Docker容器中部署2个应用程序的教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.