使用Google Cloud Run和Google Cloud SQL运行早期迁移的正确方式是什么 [英] Which is the right way to run laravel migrations using Google Cloud Run and Google Cloud SQL
本文介绍了使用Google Cloud Run和Google Cloud SQL运行早期迁移的正确方式是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我来这里是为了展示我发现的使用Google Cloud SQL和Laravel将迁移运行到Google Cloud Run项目中的具体方法,这很简单,我只需从我的.env
Laravel连接到Cloud SQL(使用Cloud SQL代理),然后从我的本地控制台使用经典命令php artisan migrate
运行迁移。
我从来没有找到其他方法来运行迁移,因为我目前正在进行迁移,而且实际上我从来没有找到有关它的更多信息,所以这就是问题:
有没有比在本地环境中运行更简单、更安全的方式来运行到Google Cloud Run的早期迁移?
推荐答案
短版(超短版):
- 创建一个新文件并将其命名为任何名称(例如";db-Migration.sh";)并添加以下内容:
#!/bin/bash
# Run Laravel migration (by force, since it would be a prod-environment)
php artisan migrate --force
# Run Apache in "foreground" mode (the default mode that runs in Docker)
apache2-foreground
- 将以下2行添加到您的文档文件
# Make the file executable, or use "chmod 777" instead of "chmod +x"
RUN chmod +x /var/www/html/db-migration.sh
# This will run the shell file at the time when container is up-and-running successfully (and NOT at the BUILD time)
ENTRYPOINT ["/var/www/html/db-migration.sh"]
假设:
- Docker镜像具有PHP/APACHE组合(而不是ALPINE/NGINX版本)
- 云运行配置正确
- Cloud SQL已启动并与Cloud Run正确连接
这篇关于使用Google Cloud Run和Google Cloud SQL运行早期迁移的正确方式是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文