Help us understand the problem. What is going on with this article?

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

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 restart
down:
    docker-compose down
destroy:
    docker-compose down --rmi all --volumes
ps:
    docker-compose ps
app:
    docker-compose exec app ash -l
fresh:
    docker-compose exec app php artisan migrate:fresh
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
db-testing:
    docker-compose exec db-testing bash
mysql:
    docker-compose exec db bash -c 'mysql -u $$MYSQL_USER -p$$MYSQL_PASSWORD $$MYSQL_DATABASE'
mysql-testing:
    docker-compose exec db-testing 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 run dev

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

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした