Skip to content

Instantly share code, notes, and snippets.

@nishinoshake
Last active August 1, 2016 12:53
Show Gist options
  • Save nishinoshake/87c5a2037ceffabe9e26fc8abb1006aa to your computer and use it in GitHub Desktop.
Save nishinoshake/87c5a2037ceffabe9e26fc8abb1006aa to your computer and use it in GitHub Desktop.
シンプルな自動デプロイ

リモートリポジトリ作る

  cd /var/www/git
  git init --bare --shared sample.git

なにかプッシュする

作成したリモートリポジトリに対して、
ローカルからなにかをプッシュする。

デプロイするところを作る

mkdir /var/www/html/sample
cd /var/www/html/sample
git clone /var/www/git/sample.git

プッシュをフックにプルするスクリプトを書く

何かアクションがあったら、
deploy-sampleブランチをプルする的なシンプルスクリプト。

vi /var/www/git/sample.git/hooks/post-receive

#!/bin/sh

PUBLIC_DIR=/var/www/html/sample/
DEPLOY_BRANCH=deploy-sample

cd ${PUBLIC_DIR}
git --git-dir=.git pull origin ${DEPLOY_BRANCH}

シェルスクリプトに実行権あげる

chmod a+w /var/www/git/sample.git/hooks/post-receive

ローカルからdeployブランチをプッシュ

適当なコミットしてプッシュする

リモートのdeployディレクトリをdeployブランチに切り替え

git checkout -b deploy-inbox origin/deploy-inbox

ローカルからdeployブランチを再度プッシュ

したら反映される・・・はず。

反映されなかった場合

  • deployディレクトリの権限はどうなってるか
  • gitのスクリプトを実行するユーザで書き込み権限がないとだめ
  • SSH接続の場合は接続するユーザでスクリプトが実行される
  • post-receiveの実行権はしっかりあるか
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment