2016年2月2日火曜日

遅まきのHerokuデビューを無料枠でしたよ。準備編〜その2

このエントリーをはてなブックマークに追加
さて昨日の遅まきのHerokuデビューを無料枠でしたよ。準備編〜その1からの続き。

さてHeroku上にアプリケーションを作成する。

Deploy the app

In this step you will deploy the app to Heroku.
Create an app on Heroku, which prepares Heroku to receive your source code:
$ heroku create
Creating sharp-rain-871... done, stack is cedar-14
http://sharp-rain-871.herokuapp.com/ | https://git.heroku.com/sharp-rain-871.git
Git remote heroku added
When you create an app, a git remote (called heroku) is also created and associated with your local git repository.
Heroku generates a random name (in this case sharp-rain-871) for your app, or you can pass a parameter to specify your own app name.

この後、GitHubから取ってきたソースをHerokuにデプロイしていくようだ。ローカルのgitリポジトリからHerokuのリモートリポジトリへアップする。なんかいっぱい入った。

$ git push heroku master
Counting objects: 140, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (140/140), 28.30 KiB | 0 bytes/s, done.
Total 140 (delta 51), reused 140 (delta 51)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> PHP app detected
remote: -----> Bootstrapping...
remote: -----> Installing system packages...
remote:        NOTICE: No runtime required in composer.json; requirements
remote:        from dependencies in composer.lock will be used for selection
remote:        - php (7.0.2)
remote:        - Apache (2.4.16)
remote:        - Nginx (1.8.0)
remote: -----> Enabling PHP extensions...
remote:        - ext-zend-opcache (automatic)
remote: -----> Installing dependencies...
remote:        Composer version 1.0.0-alpha11 2015-11-14 16:21:07
remote:        Loading composer repositories with package information
remote:        Installing dependencies from lock file
remote:          - Installing psr/log (1.0.0)
remote:            Downloading: 100%
remote:
remote:          - Installing monolog/monolog (1.16.0)
remote:            Downloading: 100%
remote:
remote:          - Installing symfony/routing (v2.7.3)
remote:            Downloading: 100%
remote:
remote:          - Installing symfony/http-foundation (v2.7.3)
remote:            Downloading: 100%
remote:
remote:          - Installing symfony/event-dispatcher (v2.7.3)
remote:            Downloading: 100%
remote:
remote:          - Installing symfony/debug (v2.7.3)
remote:            Downloading: 100%
remote:
remote:          - Installing symfony/http-kernel (v2.7.3)
remote:            Downloading: 100%
remote:
remote:          - Installing pimple/pimple (v1.1.1)
remote:            Downloading: 100%
remote:
remote:          - Installing silex/silex (v1.3.1)
remote:            Downloading: 100%
remote:
remote:          - Installing twig/twig (v1.19.0)
remote:            Downloading: 100%
remote:
remote:          - Installing symfony/twig-bridge (v2.7.3)
remote:            Downloading: 100%
remote:
remote:        Generating optimized autoload files
remote: -----> Preparing runtime environment...
remote: -----> Checking for additional extensions to install...
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 83.6M
remote: -----> Launching...
remote:        Released v3
remote:        https://dry-springs-12517.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy.... done.
To https://git.heroku.com/dry-springs-12517.git
 * [new branch]      master -> master

ここでwebインスタンスを1つ動かす。

The application is now deployed. Ensure that at least one instance of the app is running:
$ heroku ps:scale web=1

これでサイトの準備ができたので、下記のコマンドでデプロイされたアプリがブラウザで確認できる。
Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website as follows:
$ heroku open

できた!


起動させた時のログはheroku logsを使う。
$ heroku logs
2016-02-01T15:47:23.734744+00:00 heroku[api]: Enable Logplex by xxx@example.com
2016-02-01T15:47:23.734926+00:00 heroku[api]: Release v2 created by xxx@example.com
2016-02-01T15:58:25.346315+00:00 heroku[api]: Scale to web=1 by xxx@example.com
2016-02-01T15:58:25.441370+00:00 heroku[api]: Deploy b6e3898 by xxx@example.com
2016-02-01T15:58:25.441432+00:00 heroku[api]: Release v3 created by xxx@example.com
2016-02-01T15:58:25.818992+00:00 heroku[slug-compiler]: Slug compilation started
2016-02-01T15:58:25.818998+00:00 heroku[slug-compiler]: Slug compilation finished
2016-02-01T15:58:30.607022+00:00 heroku[web.1]: Starting process with command `vendor/bin/heroku-php-apache2 web/`
2016-02-01T15:58:33.451421+00:00 app[web.1]: 4 processes at 128MB memory limit.
2016-02-01T15:58:33.246369+00:00 app[web.1]: DOCUMENT_ROOT changed to 'web/'
2016-02-01T15:58:33.457058+00:00 app[web.1]: Starting php-fpm...
2016-02-01T15:58:33.289875+00:00 app[web.1]: Optimizing defaults for 1X dyno...
2016-02-01T15:58:35.463051+00:00 app[web.1]: Starting httpd...
2016-02-01T15:58:36.118632+00:00 heroku[web.1]: State changed from starting to up
2016-02-01T16:31:55.317376+00:00 heroku[web.1]: Idling
2016-02-01T16:31:55.318091+00:00 heroku[web.1]: State changed from up to down
2016-02-01T16:31:57.921272+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2016-02-01T16:31:58.417151+00:00 app[web.1]: Going down, terminating child processes...
2016-02-01T16:31:59.165323+00:00 heroku[web.1]: Process exited with status 143
2016-02-01T16:56:47.735067+00:00 heroku[web.1]: Unidling
2016-02-01T16:56:47.735426+00:00 heroku[web.1]: State changed from down to starting
2016-02-01T16:56:53.261661+00:00 heroku[web.1]: Starting process with command `vendor/bin/heroku-php-apache2 web/`
2016-02-01T16:56:55.081581+00:00 app[web.1]: 4 processes at 128MB memory limit.
2016-02-01T16:56:54.967333+00:00 app[web.1]: DOCUMENT_ROOT changed to 'web/'
2016-02-01T16:56:54.980799+00:00 app[web.1]: Optimizing defaults for 1X dyno...
2016-02-01T16:56:55.085368+00:00 app[web.1]: Starting php-fpm...
2016-02-01T16:56:57.086777+00:00 app[web.1]: Starting httpd...
2016-02-01T16:56:57.159387+00:00 heroku[web.1]: State changed from starting to up

WEBワーカを止めるにはheroku ps:scale web=0で行う。

$ heroku ps:scale web=0
2016-02-01T18:14:22.506008+00:00 heroku[run.2596]: State changed from up to complete
2016-02-01T18:14:22.519362+00:00 heroku[run.2596]: Process exited with status 0
2016-02-01T18:21:32.196197+00:00 heroku[api]: Scale to web=0

2016年2月1日月曜日

遅まきのHerokuデビューを無料枠でしたよ。準備編〜その1

このエントリーをはてなブックマークに追加
結構前(3年ぐらい?)からHerokuは流行ってるのは知ってたんだけど、仕事内容でいまいち関わることが無かったのでスルーしてた。
でも最近になって触るような機会とPaaSの流行りがやっと来た感があるので試してみた。もうこんな記事はちまたに出回りすぎるぐらい出ているんだけど。

ちょっと前(2015年5月)にプライス設定が見直しになってたみたいで今は無料利用での制限が色々と厳しくなってる模様。それでも開発の時やテスト的には全然使えると思う。


  • SLEEPS AFTER 30 MINS OF INACTIVITY
    • 30分稼働がないとスリープしてしまう
  • MUST SLEEP 6 HOURS IN A 24 HOUR PERIOD
    • 24時間中、6時間はスリープする必要あり
  • CUSTOM DOMAINS
    • 独自ドメインが使える
  • 512 MB RAM │ 1 web/1 worker
    • dynoと呼ばれるプロセス?コンテナ?みたいな考えのWebタイプとWorkerタイプが1つずつ使える
    • Dynos and the Dyno Managerに書いてあった

さっそくサインアップを済ませてログイン。ダッシュボードは本日時点でこんな感じ。


"PHP Get Started"を選ぶ。


StartまでのTutorialが出てきた。

Introduction

This tutorial will have you deploying a PHP app in minutes.
Hang on for a few more minutes to learn how it all works, so you can make the most out of Heroku.
The tutorial assumes that you have:
・a free Heroku account.
・PHP installed locally.
・Composer installed.

はじめにPCにHerokuを使うために"Heroku Toolbelt"なるものをインストールしなきゃならんらしい。なのでこれをダウンロードしてインストールする。Windows版しかなかったら暴れているところだが、無事Mac版も用意されていた。

Set up

In this step you will install the Heroku Toolbelt. This provides you access to the Heroku Command Line Interface (CLI), which can be used for managing and scaling your applications and add-ons. A key part of the toolbelt is the heroku local command, which can help in running your applications locally.

Once installed, you can use the heroku command from your command shell.
Log in using the email address and password you used when creating your Heroku account:

pkgをダウンロードし、インストール完了したらおもむろにTerminalを開いてheroku loginと打ってコマンド実行。
$ heroku login
heroku-cli: Installing Toolbelt v4... done
For more information on Toolbelt v4: https://github.com/heroku/heroku-cli
heroku-cli: Adding dependencies... done
heroku-cli: Installing core plugins... done
Enter your Heroku credentials.
Email: hogehoge@example.com
Password (typing will be hidden):
Logged in as hogehoge@example.com
$

成功したみたいだけれど、恐ろしく成功感がない。次はGitHubからサンプルソースを引っ張ってこいみたいなことが書いてあるので、適当な場所にHeroku用のフォルダを作ってそこで作業することにした。

Prepare the app

In this step, you will prepare a simple application that can be deployed.
Execute the following commands to clone the sample application:
$ git clone https://github.com/heroku/php-getting-started.git
$ cd php-getting-started
You now have a functioning git repository that contains a simple application as well as a composer.json file. Make sure you've installed Composer. Heroku uses Composer for dependency management in PHP projects, and the composer.json file indicates to Heroku that your application is written in PHP.

パッケージ管理にComposerを使っているみたい。だからComposer入れとけとか書いている。正直準備でだいぶだるい。

先にComposerをインストールする。
$ curl -sS https://getcomposer.org/installer | php
Some settings on your machine may cause stability issues with Composer.
If you encounter issues, try to change the following:

The OpenSSL library (0.9.8zc) used by PHP does not support TLSv1.2 or TLSv1.1.
If possible you should upgrade OpenSSL to version 1.0.1 or above.

Downloading...

Composer successfully installed to: /Users/fumio/Documents/HerokuProject/php-getting-started/composer.phar
Use it: php composer.phar

/usr/local/binあたりに移動させる。

$mv composer.phar /usr/local/bin/composer

実行してこうなったら入ってるんじゃないかと思う。
$ composer
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.0-dev (cff35071b68e286f68ac64908c990c15b3ac4a0d) 2016-01-31 15:50:19

Usage:
command [options] [arguments]

Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this app



さてGitHubから引っ張ってくる。
$ git  clone https://github.com/heroku/php-getting-started.git
Cloning into 'php-getting-started'...
remote: Counting objects: 148, done.
remote: Total 148 (delta 0), reused 0 (delta 0), pack-reused 148
Receiving objects: 100% (148/148), 32.44 KiB | 0 bytes/s, done.
Resolving deltas: 100% (55/55), done.
Checking connectivity... done.

php-getting-startedの中身はこんな感じ。
$ ls -aFC
./ .git/ Procfile app.json composer.lock
../ .gitignore README.md composer.json web/
$ ls -aFC web/
./ ../ .htaccess images/ index.php* stylesheets/ views/
$ ls -aFC web/views/
./ ../ header.html index.twig layout.html nav.html
$ ls -aFC web/images/
./ ../ favicon.png lang-logo.png
$ ls -aFC web/stylesheets/
./ ../ main.css

index.phpの中身だけ見てみた。
require('../vendor/autoload.php');

$app = new Silex\Application();
$app['debug'] = true;

// Register the monolog logging service
$app->register(new Silex\Provider\MonologServiceProvider(), array(
  'monolog.logfile' => 'php://stderr',
));

// Register view rendering
$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__.'/views',
));

// Our web handlers

$app->get('/', function() use($app) {
  $app['monolog']->addDebug('logging output.');
  return $app['twig']->render('index.twig');
});

$app->run();
だめだ。今日はここまで!

2016年1月31日日曜日

イメージキャプチャ用Chrome Extension:Awesome Screenshot

このエントリーをはてなブックマークに追加
この前、ブラウザの画面キャプチャ用にブラウザキャプチャ用Chrome Extension:FireShotを紹介したのだが、今度はスクリーンショットを撮った後に簡単に隠したいとこにぼかしやハイライトをつけたいなぁと思った時、FireShotではできなかったので、もう一度探してみるとこに。

そこで見つかったのが拡張機能Awesome Screenshotだった。


Chromeのツールバーからこんな感じで選べる。


例えばスクリーンショットに映った個人名などのあまり人に見せたくないものにぼかしを入れたい場合、Awesome Screenshotでスクリーンショットを撮った後、この水滴みたいな部分をクリックする。


するとシェイプでぼかしを入れたい部分を範囲選択できるので、これでどんどんぼかすことができる。


ただし、ローカルに保存するファイル名がWEBページのタイトルしかつかないので、同じページでいくつかのスクリーンショットを撮る場合はいちいち名前を変えてやらないといけない。

前回紹介したブラウザキャプチャ用Chrome Extension:FireShotだとデフォルトはWEBページのタイトルと時分秒などを設定でテンプレートとして設定できるので便利。

なので、スクリーンショットに簡単に加工を付けたい時と、ただ撮るだけの時とは使い分けるようにしてる。しかもChromeで完結しているのでWindowsやMacなどOSによって使い勝手のいいアプリを探す手間も省けて便利。