gpt4 book ai didi

docker - 使用 BitBucket Pipelines 通过 SSH 访问部署到 VPS

转载 作者:行者123 更新时间:2023-12-02 13:00:51 26 4
gpt4 key购买 nike

我一直在尝试思考如何利用 BitBucket 的 Pipelines 将我的 (Laravel) 应用程序自动部署到 Vultr Server 实例上。

我手动执行了以下步骤,我正在尝试自主复制:

  • commit我的更改和push到 BitBucket 存储库
  • 我使用终端登录我的服务器:ssh root@ipaddress
  • cd到正确的目录:cd /var/www/html/app/
  • 然后我pull来 self 的 BitBucket 存储库:git pull origin master
  • 然后我运行一些命令:composer install , php artisan migrate等等..
  • 然后我注销:exit

我的理解是,您可以使用管道来自动化此操作,这是真的吗?

到目前为止,我已经为管道和我的服务器设置了 SSH key 对,所以我的服务器的 authorized_keys文件包含来自 BitBucket Pipelines 的公钥。

我的管道文件 bitbucket-pipelines.yml如下:

image: atlassian/default-image:latest

pipelines:
default:
- step:
deployment: staging
caches:
- composer
script:
- ssh root@ipaddress
- cd /var/www/html/app/
- git pull origin master
- php artisan down
- composer install --no-dev --prefer-dist
- php artisan cache:clear
- php artisan config:cache
- php artisan route:cache
- php artisan migrate
- php artisan up
- echo 'Deploy finished.'

当管道执行时,我收到错误:bash: cd: /var/www/html/app/: No such file or directory .

我读到每个脚本步骤都在其自己的容器中运行。

Each step in your pipeline will start a separate Docker container to run the commands configured in the script

如果没有执行,我得到的错误是有意义的 cd /var/www/html/app使用 SSH 登录后在 VPS 内。

有人可以引导我走向正确的方向吗?

谢谢

最佳答案

您在 script 下定义的命令将在 Docker 容器中运行,而不是在您的 VPS 上运行。

相反,请将所有命令放入服务器上的 bash 文件中。

1 - 在您的 VPS 上创建一个 bash 文件 pull.sh,以执行所有部署任务

#/var/www/html
php artisan down
git pull origin master
composer install --no-dev --prefer-dist
php artisan cache:clear
php artisan config:cache
php artisan route:cache
php artisan migrate
php artisan up
echo 'Deploy finished.'

2 - 在存储库中创建一个脚本 deploy.sh,如下所示

echo "Deploy script started"
cd /var/www/html
sh pull.sh
echo "Deploy script finished execution"

3 - 最后更新您的 bitbucket-pipelines.yml 文件

image: atlassian/default-image:latest

pipelines:
default:
- step:
deployment: staging
script:
- cat ./deploy.sh | ssh <user>@<host>
- echo "Deploy step finished"

我建议您将存储库克隆到您的 VPS 上的 /var/www/html 中,并首先手动测试您的 pull.sh 文件。

关于docker - 使用 BitBucket Pipelines 通过 SSH 访问部署到 VPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50053687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com