使用CircleCI部署到Firebase托管

时间:2015-02-17 19:37:23

标签: node.js continuous-integration firebase circleci

我正在尝试使用CircleCI了解如何部署到Firebase托管。据我所知,没有办法使用SSH密钥设置部署,所以我试图找到一种在部署期间登录Firebase并推送代码的方法。到目前为止我所尝试的是我的circle.yml中的以下内容:

// circle.yml
deployment:
  production:
    branch: circle-deploy
    commands:
      - npm install -g firebase-tools
      - firebase login | echo -e "${FIREBASE_EMAIL}\n${FIREBASE_PASSWORD}"
      - firebase deploy

但是,我一直收到以下错误,我不知道如何解决它。

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error: write EPIPE
    at errnoException (net.js:904:11)
at Object.afterWrite (net.js:720:19)

5 个答案:

答案 0 :(得分:35)

我必须这样做,并且有一种更简单的方法

  1. 在您的计算机上,您可以输入

    来获取访问令牌
    $FIREBASE_TOKEN
  2. 将该令牌保存为circleci中的环境变量deployment: production: branch: master commands: - firebase deploy --token=$FIREBASE_TOKEN --non-interactive
  3. 对于部署步骤,您可以跳过登录:

    {
        "itemNumber" : "ABATAH000",
        "effectiveDate" : "2015-11-03T15:30:05.7118023-05:00",
        "expiryDate" : "2015-05-03T15:30:05.7118023-04:00",
        "minimumPremium" : 25,
        "zSubItems" : [{
                "zSubItemName" : "Mine",
                "unitDistance" : 100000,
                "zSubSubItems" : [{
                        "zSubSubItemName" : "CoverageA",
                        "zSubSubItemPremium" : 100.0,
                        "id" : 0
                    }
                ],
                "id" : 1
            }
        ],
        "id" : 0
    }
    

答案 1 :(得分:14)

上面其他答案的一小部分......

为了避免在每个版本的circle ci中全局安装firebase-tools:

修改你的package.json文件,将firebase-tools包含为dev依赖项,如下所示:

npm install --save-dev firebase-tools

然后在你的circle.yml文件中:

deployment:
  production:
    branch: master
    commands:
      - ./node_modules/.bin/firebase deploy --token=$FIREBASE_TOKEN --non-interactive

答案 2 :(得分:6)

对于偶然发现这个问题的其他人来说,这些是我必须采取的步骤才能让CircleCI(可能是其他任何CI)使用Firebase Hosting。

  1. 生成CI令牌:firebase login:ci
  2. 将该令牌保存为ENV var(FIREBASE_TOKEN
  3. 在部署脚本中使用令牌:firebase deploy --token=$FIREBASE_TOKEN --non-interactive
  4. Firebase最近添加了login:ci,以防止人们使用个人部署令牌进行CI服务。

答案 3 :(得分:3)

这是我的初始设置,仅部署master,跳过测试

  1. 在本地计算机上运行 npm install -g firebase-tools
  2. 运行 firebase login:ci 以获取本地计算机上的令牌
  3. 运行firebase init。这将创建firebase.json以确保它已提交
  4. 在circileci项目的BUILD SETTINGS中的环境变量中配置 FIREBASE_TOKEN
  5. // circle.yml

    general:
      branches:
        only:
          - master
    
    test:
      override:
        - echo "test"
    
    deployment:
      production:
        branch: master
        commands:
          - npm install -g firebase-tools
          - firebase deploy --token=$FIREBASE_TOKEN --non-interactive
    

答案 4 :(得分:1)

以下是我们部署到CircleCi的过程。

  1. 将您的用户名和密码作为环境变量存储在CircleCi的项目级别。

  2. 编辑你的circle.yml

    deployment:
      production:
        branch: your_branch
        commands:
          - npm install -g firebase-tools
          - firebase login --email $FIREBASE_USERNAME --password $FIREBASE_PASSWORD
          - firebase deploy
    
  3. 推送到您的分支

  4. 似乎工作正常。