从CircleCI推送到Heroku时出现协议错误

时间:2014-03-07 18:01:57

标签: git heroku continuous-integration circleci

#./circle.yml

deployment:
  acceptance:
    branch: master
    commands:
      - ./script/heroku_deploy.sh thecatch-staging:
          timeout: 300

#。/ script /heroku_deploy.sh

#!/bin/sh -e
APP_NAME=$1

git remote add heroku git@heroku.com:$APP_NAME.git
git fetch heroku
MIGRATION_CHANGES=$(git diff HEAD heroku/master --name-only -- db | wc -l)
echo "$MIGRATION_CHANGES db changes."

PREV_WORKERS=$(heroku ps --app $APP_NAME | grep "^worker." | wc -l | tr -d ' ')

# migrations require downtime so enter maintenance mode
if test $MIGRATION_CHANGES -gt 0; then
  heroku maintenance:on --app $APP_NAME

  # Make sure workers are not running during a migration
  heroku scale worker=0 --app $APP_NAME
fi

# deploy code changes (and implicitly restart the app and any running workers)
git push heroku $CIRCLE_SHA1:refs/heads/master

# run database migrations if needed and restart background workers once finished
if test $MIGRATION_CHANGES -gt 0; then
  heroku run rake db:migrate db:seed --app $APP_NAME
  heroku scale worker=$PREV_WORKERS --app $APP_NAME
  heroku restart --app $APP_NAME
fi

heroku run rake cache:flush --app $APP_NAME
heroku maintenance:off --app $APP_NAME

当我推动掌握时,circleci运行我的测试,测试通过,并在部署到Heroku时出现以下错误:

fatal: protocol error: expected old/new/ref, got 'shallow 0966e85b342cb4daaace954d68c928acf743490f'
fatal: The remote end hung up unexpectedly

完整部署日志:

$ ./script/heroku_deploy.sh thecatch-staging
 Warning: Permanently added 'heroku.com,50.19.85.132' (RSA) to the list of known hosts.

Fetching repository, done.
From heroku.com:thecatch-staging
 * [new branch]      master     -> heroku/master
0 db changes.
Warning: Permanently added the RSA host key for IP address '50.19.85.156' to the list of known hosts.

Fetching repository, done.
Unshallowing... 
remote: Counting objects: 2126, done.
remote: Compressing objects: 100% (614/614), done.
remote: Total 1810 (delta 1255), reused 1663 (delta 1140)
Receiving objects: 100% (1810/1810), 1006.69 KiB | 330.00 KiB/s, done.
Resolving deltas: 100% (1255/1255), completed with 130 local objects.
Counting objects: 55, done.
Delta compression using up to 32 threads.
Compressing objects: 100% (39/39), done.
Writing objects: 100% (41/41), 4.40 KiB | 0 bytes/s, done.
Total 41 (delta 27), reused 0 (delta 0)
fatal: protocol error: expected old/new/ref, got 'shallow 0966e85b342cb4daaace954d68c928acf743490f'
fatal: The remote end hung up unexpectedly
./script/heroku_deploy.sh thecatch-staging returned exit code 128action ./script/heroku_deploy.sh thecatch-staging failed

2 个答案:

答案 0 :(得分:3)

您在代码中使用的是git push heroku $CIRCLE_SHA1:refs/heads/master而不是git push heroku $CIRCLE_SHA1:master

此外,您正在定义$CIRCLE_SHA1变量,但其值未在脚本中的任何位置分配。

纠正这两项并检查是否能解决您的问题。

答案 1 :(得分:0)

对于任何尝试这一点的人,在与Circle人交谈后,我不得不将超时调用更改为括号circle.yml到

deployment:
  production:
    branch: master
    commands:
      - ./script/heroku_deploy.sh myHerokuApp $CIRCLE_SHA1: { timeout: 400 }
      - ./script/heroku_deploy_restart.sh myHerokuApp

我的脚本现在有变量,appName和CircleSha:

#!/bin/sh -e
APP_NAME=$1
CIRCLE_SHA1=$2

#and so on...

(我也遇到了PREV_WORKERS行没有按预期工作的问题,所以我在我的情况下硬编码。)

要考虑的另一个问题是,在超时的情况下,您可能无法重新启动工作程序或将应用程序恢复为维护模式。

因此,我将这些命令移动到名为heroku_deploy_restart.sh

的第二个脚本
#!/bin/sh -e
APP_NAME=$1

#restart background workers once finished
heroku scale worker=1 --app $APP_NAME
heroku run rake memcached:flush --app $APP_NAME
heroku maintenance:off --app $APP_NAME