65
61

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravel開発時に便利なmake(Makefile)コマンド集

Last updated at Posted at 2019-12-31

2020年最速の記事です😇

Laravel で開発する際、よく実行する docker-compose のように長いコマンドや環境構築時に多数のコマンドを実行する機会が多くあるかと思います。

各個人でalias定義したりshellの補完機能を設定しても良いですが、共有するのは手間です。

そんな時に Makefile を用意しておくと複数のコマンドを一度に実行するようにタスク登録できて便利です。 Makefile をGitで管理しておけば共有もとても楽になります。

make コマンド

$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

make コマンドが使える環境ならokです。

Makefile 使い方

コマンドを実行するディレクトリに Makefile という名前で配置すればokです。

$ make up
# docker-compose up -d # このコマンドが実行される

Makefile 例

参照ファイル: ucan-lab/docker-laravel/Makefile

あくまでも例なので参考程度にしてください。

Makefile
up:
    docker-compose up -d
build:
    docker-compose build
create-project:
    docker-compose up -d --build
    docker-compose exec app composer create-project --prefer-dist laravel/laravel .
    docker-compose exec app composer require predis/predis
install:
    docker-compose up -d --build
    docker-compose exec app composer install
    docker-compose exec app cp .env.example .env
    docker-compose exec app php artisan key:generate
    docker-compose exec app php artisan migrate:fresh --seed
reinstall:
    @make destroy
    @make install
stop:
    docker-compose stop
restart:
    docker-compose down
    docker-compose up -d
down:
    docker-compose down
destroy:
    docker-compose down --rmi all --volumes
ps:
    docker-compose ps
app:
    docker-compose exec app bash
fresh:
    docker-compose exec app php artisan migrate:fresh --seed
seed:
    docker-compose exec app php artisan db:seed
tinker:
    docker-compose exec app php artisan tinker
dump:
    docker-compose exec app php artisan dump-server
test:
    docker-compose exec app php ./vendor/bin/phpunit
cache:
    docker-compose exec app composer dump-autoload -o
    docker-compose exec app php artisan optimize:clear
    docker-compose exec app php artisan optimize
cache-clear:
    docker-compose exec app php artisan optimize:clear
cs:
    docker-compose exec app ./vendor/bin/phpcs
cbf:
    docker-compose exec app ./vendor/bin/phpcbf
db:
    docker-compose exec db bash
sql:
    docker-compose exec db bash -c 'mysql -u $$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE'
node:
    docker-compose exec node ash
npm:
    docker-compose exec node npm install
    docker-compose exec node npm run dev
yarn:
    docker-compose exec node yarn
    docker-compose exec node yarn dev

これをベースに各プロジェクト用のコマンドを追加して使うと良い感じかなと思います。

参考

65
61
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
65
61

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?