LoginSignup
9
4

More than 5 years have passed since last update.

wercker(deployer)を使ったbitbucketからさくらレンタルサーバへの自動デプロイ

Last updated at Posted at 2016-08-31

デプロイフロー

デプロイフロー.png

躓いたところだけまとめます。

werckerのworkflowsの設定がわからなかった

workflowsのpipelineはwercker.ymlに記述する以下の箇所と名前を合わせる

wercker.yml
box: boedy/wercker-php
no-response-timeout: 25

build:  <- ココと名前を合わせる
    steps:
       - script:

wercker.ymlの設定

cdの仕方がわからかなった

cwdを使ってワーキングディレクトリを切り替える

wercker.yml
- script:
    name: deploy application
    cwd: deploy/
    code: php deployer.phar deploy -vvv production

ymlの設定がわからなかった。

wercker.yml
box: boedy/wercker-php
no-response-timeout: 25
build:
    steps:
       - script:
          name: deployer install
          cwd: deploy/
          code: curl -L -O http://deployer.org/deployer.phar

deploy:
    steps:
       - script:
            name: make .ssh directory
            code: mkdir -p "$HOME/.ssh"

       - create-file:
          name: write id_rsa
          filename: $HOME/.ssh/id_rsa
          content: $SAKURA_KEY_PRIVATE
          overwrite: true
          hide-from-log: true

       - create-file:
          name: write id_rsa pub
          filename: $HOME/.ssh/id_rsa.pub
          content: $SAKURA_KEY_PUBLIC
          overwrite: true
          hide-from-log: true

       - script:
          name: deploy application
          cwd: deploy/
          code: php deployer.phar deploy -vvv production

deployerの設定がわからなかった

gitをさくらにインストールする必要があったのでbinの場所を指定
※サクラにデフォルトでインストールされているgitは使えなかった

deploy.php
<?php
require 'recipe/laravel.php';

serverList('server.yml'); // server情報はserver.ymlにまとめた
set('repository', 'git@bitbucket.org:xxx/xxx.git'); // デプロイするリポジトリ
set('writable_use_sudo', false); // sudo 権限ないので false
env('bin/git', '/home/xxx/local/bin/git'); //インストールしたgitのbin

set('shared_files', ['.env']);
set('shared_dirs', [
    'storage/app',
    'storage/framework/cache',
    'storage/framework/sessions',
    'storage/framework/views',
    'storage/logs',
]);
set('writable_dirs', ['bootstrap/cache', 'storage']);

/**
 * Make writable dirs.
 */
task('deploy:writable', function () {

//略

})->desc('Make writable dirs');

「//略」の部分・・・
deployerのdeploy:writableがchmod 777 -Rとなっており、
実行時にエラーになったので、タスクを上書くため内容をコピーして所定の箇所を修正した
chmod 777 -R -> chmod -R 777

追記
上記の「//略」の部分は以下のPRがマージされたため対応不要となりました。(^o^)/
https://github.com/deployphp/deployer/commit/fa46d3f58f22f2d917a10854d54c9419fabbdb28

server.ymlの設定がわからなかった

sercer.yml
production:
  host: xxx.sakura.ne.jp
  identity_file:
    private_key: "/root/.ssh/id_rsa"
    public_key:  "/root/.ssh/id_rsa.pub"
  user: username
  stage: production
  deploy_path: "~/export"
  branch: master

productionはwercker.ymlの
php deployer.phar deploy -vvv productionで指定している

さくらでの設定がわからなかった

cshからbashに変える

コマンドライン上でシェルが実行できなかった。
さくらのデフォルトのシェルを変更した

bashの場所を調べる
$ cat /etc/shells

変更する
$ chsh -s /usr/local/bin/bash

exitして入り直し、反映されていることを確認する。

さくらのgitが対応していなかった

deployer実行時にgitコマンドででエラーが発生した。

fatal: git was built without support for git-submodule (NO_PERL=1).

インストール

$ wget https://github.com/git/git/archive/v2.10.0-rc2.tar.gz
$ tar xjvf v2.10.0-rc2.tar.gz
$ cd git-2.10.0-rc2/
$ gmake configure
$ ./configure --prefix=$HOME/local
$ gmake all install

パスを通す.bashrc

PATH=$HOME/local/bin:$PATH

確認

$ which git
/home/userid/bin/bin/git
$ git --version
git version 2.10.0-rc2

参考にしたサイト

Laravel5をさくらのレンタルサーバで動かす(スタンダードプラン以上)
werckerを使って、さくらサーバに自動デプロイできました
さくらインターネットのデフォルトのシェルをbash に変更してみた
さくらインターネットレンタルサーバにGitをインストールする
デプロイツールを使ってLaravelをデプロイする
deployer docs

9
4
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
9
4