阿东的笔记_  工具
## php+mysql+docker-compose shell环境集成部署更新管理脚本 新建保存 deploy 文本文件,增加可执行权限 chmod +x deploy ``` Bash #!/usr/bin/env bash env_init() { if [ ! -f ".env" ];then cp .env.example .env fi } COMPOSE="docker-compose" env_init if [ $# -gt 0 ];then if [[ "$1" == "install" ]]; then shift 1 rm -rf composer.lock $COMPOSE up -d $COMPOSE restart php $COMPOSE exec php bash -c "composer install" $COMPOSE exec php bash -c "php artisan key:generate" $COMPOSE exec php bash -c "php artisan migrate --seed" $COMPOSE restart elif [[ "$1" == "artisan" ]]; then shift 1 e="php artisan $@" && $COMPOSE exec php bash -c "$e" elif [[ "$1" == "php" ]]; then shift 1 e="php $@" && $COMPOSE exec php bash -c "$e" elif [[ "$1" == "composer" ]]; then shift 1 e="composer $@" && $COMPOSE exec php bash -c "$e" elif [[ "$1" == "mysql" ]]; then shift 1 e="mysql $@" && $COMPOSE exec mysql sh -c "$e" elif [[ "$1" == "restart" ]]; then shift 1 $COMPOSE stop "$@" $COMPOSE start "$@" else $COMPOSE "$@" fi else $COMPOSE ps fi ``` ### 使用 ``` Bash # 初始化安装整个开发环境,以及数据迁移 ./deploy install # php容器内运行artisan命令脚本 ./deploy artisan [arguments] # php容器内运行脚本 ./deploy php [arguments] # php容器内运行composer命令 ./deploy composer [arguments] # mysql容器内运行脚本 ./deploy mysql [arguments] # 重启docker-compose ./deploy restart # docker-compose 命令 ./deploy [arguments] # 无参数 运行docker-compose ps ./deploy # 其他如redis、rabbitmq 可以自己扩展,简化命令执行 ```
adddge@sohu.com  | 桂ICP备2022009838号-2