LoginSignup
21
13

More than 5 years have passed since last update.

CircleCI 2.0 でGithubにpushした時herokuにデプロイする

Last updated at Posted at 2017-08-25

ここ読めば全部書いてる

※ githubとの連携は終わっている前提で話します

Circle CIとherokuの接続

circle ciの Environment Variablesに
HEROKU_API_KEY と HEROKU_LOGIN を追加

API_KEYには

$ heroku auth:token

の結果を

LOGINにはherokuのemailを記入

ssh keyの作成

ローカルでもどこでもいいので

$ ssh-keygen

でキーペアを作成

秘密鍵を
SSH Permissions
に追加
Hostname は

git.heroku.com

登録した後に出てくる文字列をメモしておく

公開鍵を
https://dashboard.heroku.com/account
に登録

Circle CI の設定ファイルを書く

プロジェクトのrootに.circleciディレクトリを作成

circleci/config.yml
version: 2

jobs:
  build:
    docker:
      - image:  circleci/php:7.1.8-browsers
    steps:
      - checkout
      - run:  wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
      - run:  bash .circleci/setup-heroku.sh
      - add_ssh_keys:
          fingerprints:
          - "<メモした文字列>"
      - deploy:
          name: heroku deploy
          command: |
              if [ "${CIRCLE_BRANCH}" == "master" ]; then
                  git push heroku master
              fi 
setup-heroku.sh
#!/bin/bash
git remote add heroku https://git.heroku.com/<your-app-name>.git
wget https://cli-assets.heroku.com/branches/stable/heroku-linux-amd64.tar.gz
mkdir -p /usr/local/lib /usr/local/bin
tar -xvzf heroku-linux-amd64.tar.gz -C /usr/local/lib
ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku

cat > ~/.netrc << EOF
machine api.heroku.com
    login $HEROKU_LOGIN
    password $HEROKU_API_KEY
machine git.heroku.com
    login $HEROKU_LOGIN
    password $HEROKU_API_KEY
EOF

# Add heroku.com to the list of known hosts
ssh-keyscan -H heroku.com >> ~/.ssh/known_hosts
21
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
13