Skip to content

Instantly share code, notes, and snippets.

@n1215
Last active November 9, 2021 14:03
Show Gist options
  • Save n1215/8be6237863380c2f77850f5128b4760a to your computer and use it in GitHub Desktop.
Save n1215/8be6237863380c2f77850f5128b4760a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# コンテナを起動
function up {
docker-compose up -d
}
# コンテナ停止
function down {
docker-compose down
}
# コンテナ再起動
function restart {
docker-compose down && docker-compose up -d
}
# アプリケーション初期化
function init {
docker-compose exec php bash bin/setup.sh
front_install
}
# コンテナの中に入る
function login {
if [ -z "${1}" ]; then
container=php
else
container=${1}
fi
echo "Attempt Login to ${container} container..."
docker-compose exec ${container} bash
}
# バックエンドの依存をインストール
function back_install {
echo "Install PHP dependencies..."
docker-compose exec php composer install
}
# バックエンドのテスト
function back_test {
echo "Test backend code..."
docker-compose exec php vendor/bin/phpunit
}
# バックエンドのテスト準備
function back_test_prepare {
echo "Prepare for backend test..."
echo "Ensure test database exists..."
docker-compose exec mysql mysql -u root -proot -e "create database if not exists test_db character set utf8mb4 collate utf8mb4_bin;"
docker-compose exec mysql mysql -u root -proot -e "grant all on test_db.* to 'db_user';"
echo "Migrate test database..."
docker-compose exec php php artisan migrate:fresh --env=testing
echo "Seed test database..."
docker-compose exec php php artisan db:seed --class="Tests\Seeder\TestDatabaseSeeder" --env=testing
}
# フロントの依存をインストール
function front_install {
echo "Install JavaScript dependencies..."
docker-compose exec node npm install
}
# フロントのアセットをビルド(開発用)
function front_build {
echo "Build assets for development..."
docker-compose exec node npm run dev
}
# フロントのアセットの変更を監視してビルド(開発用)
function front_watch {
echo "Start watching assets for development..."
docker-compose exec node npm run watch
}
subcommand="$1"
shift
case $subcommand in
up)
up
;;
down)
down
;;
restart)
restart
;;
init)
init
;;
login)
login ${1}
;;
back:install)
back_install
;;
back:test:prepare)
back_test_prepare
;;
back:test)
back_test ${1}
;;
front:install)
front_install
;;
front:build)
front_build
;;
front:watch)
front_watch
;;
*)
echo "help"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment