2

# ./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

当我推送到 master 时,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
4

2 回答 2

3

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

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

更正这两个并检查是否可以解决您的问题。

于 2014-03-21T18:40:21.090 回答
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
于 2015-01-22T22:25:23.013 回答