Laravel+Rocketeer+CircleCIの構成でAWSにデプロイする





Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 1384

Warning: preg_match_all(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 700

Warning: Invalid argument supplied for foreach() in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 707

Warning: preg_match_all(): Compilation failed: invalid range in character class at offset 4 in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 700

Warning: Invalid argument supplied for foreach() in /home/dotlab/webmake.info/public_html/wp-content/plugins/lightbox-plus/classes/shd.class.php on line 707




目次

何故やったか

以前、Amazon EC2+Jenkins+capistranoでLaravel5をデプロイするという記事を書きましたが

  • Jenkinsは職人化する
  • Laravelとの相性はCapistrano < Rocketeer

ということで、CircleCIと、Rocketeerを試してみました。

概要

・Rocketeer
https://github.com/rocketeers/rocketeer

PHP製のデプロイツール。
RubyでいうCapistrano。
Laravelプロジェクトと親和性が高く、各種チャットアプリにも通知が行える。

・CircleCI

https://circleci.com/
俗に言うCIツール。
テスト・デプロイなどが行える。
Githubでソース管理をしていれば利用が可能。(Private/Public問わず)
基本無料。早く処理させたいなどがあれば有料化するとよい。

構成方法

1.LaravelプロジェクトにRocketeerをインストール

rocketeerはComposerでも管理されており、バージョン管理的にもComposerでインストールするのが定石的には良いのでしょうが、2015-05-31現在のバージョンではLaravel4のimmutateを参照しにいくため、エラーとなってしまいLaravelプロジェクトのフォルダと同一フォルダに入れることが出来ません。

せっかくLaravel Likeなデプロイツールなのに、管理を煩雑にするのは好ましくないため、今後のUPDATEに期待し手作業でインストールすることとします。

$ wget http://rocketeer.autopergamene.eu/versions/rocketeer.phar
$ chmod +x rocketeer.phar

2.Rocketeerの設定ファイルを作成

$ php rocketeer.phar ignite

※ いろいろと聞かれますが、後ほど設定ファイルをいじるためすべて[ENTER]でOKです。

3. Rocketeer リモートの設定ファイルを編集する

.rocketeer/config.php

リモートの接続関連の設定を行ないます。

    'connections'      => [
        'production' => [
            'host'      => 'ec2-xxx.xxx.xxx.xxx.ap-northeast-1.compute.amazonaws.com',
            'username'  => 'user_name',
            'password'  => '',
            'key'       => '.rocketeer/id_rsa',
            'keyphrase' => '',
            'agent'     => '',
            'db_role'   => true,
        ],
    ],

.rocketeer/remote.php

リモートのファイルパスや権限などを設定します。
Laravelベースで指定されているので、ディレクトリ関連だけ編集します。

    // The root directory where your applications will be deployed
    // This path *needs* to start at the root, ie. start with a /
    'root_directory' => '/var/www/',

    // The folder the application will be cloned in
    // Leave empty to use `application_name` as your folder name
    'app_directory'  => 'app_name',

.rocketeer/scm.php

Deployするアプリケーションのリポジトリを指定します。
デプロイはsvnとgitをサポートしています。

    // The SCM used (supported: "git", "svn")
    'scm'        => 'git',

    // The SSH/HTTPS address to your repository
    // Example: https://github.com/vendor/website.git
    'repository' => 'git@github.com:user/project.git',

    // The repository credentials : you can leave those empty
    // if you're using SSH or if your repository is public
    // In other cases you can leave this empty too, and you will
    // be prompted for the credentials on deploy. If you don't want
    // to be prompted (public repo, etc) set the values to null
    'username'   => 'user@hogehoge.com',
    'password'   => 'password',

4.デプロイのテスト

設定ファイルが正しく指定出来たかを確認するためコマンドラインでチェックを行ないます。

$ php rocketeer.phar check
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/20-mcrypt.ini on line 2 in Unknown on line 0
| Check (Check if the server is ready to receive the application) [~0.78s]
|-- Check/Php (Checks if the server is ready to receive a PHP application)
|=> Checking presence of git
$ git --version
[deployuser@ec2-xxx.xxx.xxx.xxx.ap-northeast-1.compute.amazonaws.com] (production) git version 2.1.0
|=> Checking presence of Composer
|=> Checking PHP version
|=> Checking presence of required extensions
 ・・・中略

[deployuser@ec2-xxx.xxx.xxx.xxx.ap-northeast-1.compute.amazonaws.com] (production) 
|=> Checking presence of required drivers
|=> Your server is ready to deploy
Execution time: 1.2934s
Saved logs to /var/www/app_name/.rocketeer/logs/production--20150531.log

パーミッションなどでエラーが出た場合はCapistranoの時と同様、エラーメッセージを読み地道に対処しましょう。

5. デプロイのシェルファイルを作成する

CircleCIでデプロイするために、シェルファイルを作成する。
circle.ymlに直接コマンドを書いても稼働するのですが、細かいカスタマイズを行ないたいためシェルファイル化します。

#!/bin/sh
set -ex

export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
export AWS_DEFAULT_REGION="ap-northeast-1"

MYSECURITYGROUP="sg-828d31e7"
MYIP=`curl -s ifconfig.me`

aws ec2 authorize-security-group-ingress --group-id $MYSECURITYGROUP --protocol tcp --port 22 --cidr $MYIP/32
php ./rocketeer.phar deploy
aws ec2 revoke-security-group-ingress --group-id $MYSECURITYGROUP --protocol tcp --port 22 --cidr $MYIP/32

やっていることは

  1. AWSのアクセスキー、シークレットキーをCircleCIの設定から取得する。
  2. CircleCIが動いている筐体のIPを取得する
  3. AWS CLIより、セキュリティグループの設定変更を行ない、現IPからのアクセスを許可する
  4. デプロイ処理を行う
  5. AWS CLIより、セキュリティグループの変更を行ない、IP遮断を行う

という流れになります。

CircleCIはAWS上で動いているため、IPが毎回異なるためこのようなHackを行っています。

6.  CircleCIの設定ファイルを作成する

CircleCIはプロジェクト直下の「circle.yml」ファイルを元に稼働するため、circle.ymlを作成します。

machine:
  timezone: Asia/Tokyo
  php:
    version: 5.5.21
dependencies:
  pre:
    - sudo pip install awscli
deployment:
  master:
    branch: master
    commands:
      - ./deploy.sh

ymlファイルの記述法は公式ドキュメントを参照しながら作成して下さい。

CircleCIのawsは若干古いため、シェルファイルのIP許可などが動きません。
そのため、dependeciesのpreにフックし、awscliのインストールを行っています。

phpのバージョンなどは適宜自分の環境に合わせて設定して下さい。

7. envファイルを何とかする

Laravelプロジェクトは環境設定をenvファイルに持たせることを推奨しています。

しかし、Gitに.envファイルを管理させるのは開発効率的にもよろしくないので、.envファイルは除外しています。

Rocketeerのデプロイは該当サーバに入り、その中で「git clone」を行うため、管理されていないファイルをデプロイすることが出来ません。

ベストプラクティスは何なのかわかりませんが、今回は「.env.production.php」というファイルをGit管理下に置き、デプロイした後にリネームコピーするように変更しました。

.rocketeer/hooks.php

    // Tasks to execute after the core Rocketeer Tasks
    'after'  => [
        'setup'   => [],
        'deploy'  => [
	  'cp .env.production .env',
	],
        'cleanup' => [],
    ],

rocketeerでは、デプロイ前・デプロイ後にタスクを登録することが出来ます。
その機能を利用し、リネームコピーで.envファイルを設置することにしました。

ベストプラクティスがあれば、ぜひ教えていただければ助かります。

Composer管理が出来るようになれば「artisan」との連携なども容易になるため、どんどん使いやすくしていければなーと思っています。

スポンサーリンク
スポンサーリンク




スポンサーリンク




シェアする

  • このエントリーをはてなブックマークに追加

フォローする

スポンサーリンク
スポンサーリンク