GitHub中的验证问题



我们的server_deploy.sh

#!/bin/bash
set -e
echo "Deploying application ..... branch = $1"
BRANCH_DIR="/var/www/html/devserver/$1"
if [ ! -d "$BRANCH_DIR" ]
then
mkdir -p "$BRANCH_DIR"
chown $USER:www-data -R $BRANCH_DIR
cd $BRANCH_DIR
echo "Cloning API Repo..."
mkdir api
git config --global --add safe.directory $BRANCH_DIR/api
git clone git@github.com:{API URL HERE} api
echo "Cloning UI Repo..."
mkdir ui
git config --global --add safe.directory $BRANCH_DIR/ui
git clone git@github.com:{UI URL HERE} ui
chown $USER:www-data -R $BRANCH_DIR
fi
# back to home directory
cd
# setup Node version
source ~/.nvm/nvm.sh
nvm use 12.16.3
# setup API
cd $BRANCH_DIR/api
chmod 777 -R storage bootstrap/cache
chown $USER:www-data -R $BRANCH_DIR
#switch branch
git stash
git reset --hard origin/master
git pull
if git branch -a | grep $1
then
git checkout $1
else
git checkout master 
fi
cp /var/www/html/devserver/.env $BRANCH_DIR/api/
sed -i -e "s/BRANCH/$1/g" $BRANCH_DIR/api/.env
composer install --no-interaction --prefer-dist --optimize-autoloader
php artisan config:clear
php artisan cache:clear
php artisan migrate --force
php artisan db:seed
php artisan optimize
npm install
npm run prod
#setup UI
cd $BRANCH_DIR/ui
#switch branch
git stash
git reset --hard origin/master
git pull
if  git branch -a | grep $1
then
git checkout $1
else
git checkout master
fi
cp /var/www/html/devserver/config.js $BRANCH_DIR/ui/src/api/
sed -i -e "s/BRANCH/$1/g" $BRANCH_DIR/ui/src/api/config.js
npm install
npm run build

我们的laravel.yml

name: Laravel
on:
pull_request
jobs:
devserver:
runs-on: ubuntu-latest
services:
# mysql-service Label used to access the service container
mysql-service:
# Docker Hub image (also with version)
image: mysql:5.7
env:
## Accessing to Github secrets, where you can store your configuration
MYSQL_ROOT_PASSWORD: ******
MYSQL_DATABASE: db_test
## map the "external" 33306 port with the "internal" 3306
** REST OF THE CODE HERE, LIKE UNIT TESTING AND CODE QUALITY **

- name: Deploy to Devserver
env:
PUSHED_BRANCH_NAME: ${{ steps.branch-name.outputs.head_ref_branch }}
uses: appleboy/ssh-action@master
with:
username: ${{ secrets.DEVSERVER_SSH_USER }}
host: ${{secrets.DEVSERVER_HOST}}
envs: PUSHED_BRANCH_NAME
password: ${{ secrets.DEVSERVER_SSH_PASS }}
script: sudo /home/$USER/.server_deploy.sh $PUSHED_BRANCH_NAME

嗨,我们在开发服务器上有一个名为server_deploy.sh的脚本,当合作者创建PR时会触发该脚本。分支被部署到开发服务器,每个分支都有一个特定的URL。直到3月23日GitHub发布更新之前,该设置一直运行良好。

我们开始得到以下错误:

======CMD======
sudo /home/***/.server_deploy.sh $PUSHED_BRANCH_NAME
======END======
out: Deploying application ..... branch = lg-30rvkhp
out: Now using node v12.16.3 (npm v6.14.4)
err: chmod: cannot access 'storage': No such file or directory
err: chmod: cannot access 'bootstrap/cache': No such file or directory
2023/03/27 07:45:20 Process exited with status 1

我们注意到克隆不起作用,这就造成了这个问题。我们试图在开发服务器上手动克隆存储库,但也没有成功。

我们能够通过修复开发服务器上的known_hosts来解决这个问题,这使我们能够手动执行部署脚本。但是,当被操作触发时,脚本仍然会失败。

手动克隆存储库后,我们再次运行该作业,但它引发了以下错误:

======CMD======
sudo /home/***/.server_deploy.sh $PUSHED_BRANCH_NAME
======END======
out: Deploying application ..... branch = lg-85zruc0ph
out: Cloning API Repo...
err: Cloning into 'api'...
err: Host key verification failed.
err: fatal: Could not read from remote repository.
err: Please make sure you have the correct access rights
err: and the repository exists.
2023/04/04 06:41:41 Process exited with status 128

通过服务器部署脚本的gitclone或gitpull似乎无法正常工作。

我们遵循了博客文章中概述的说明https://github.blog/2023-03-23-we-updated-our-rsa-ssh-host-key/.

我们还查看了GitHub社区上的讨论(下面的链接),并尝试了建议的解决方案。

  1. https://github.com/orgs/community/discussions/51502?sort=new
  2. https://github.com/orgs/community/discussions/27405?sort=new

这些步骤允许我们手动部署脚本,但在运行由操作触发的脚本时仍会遇到问题。

有人能帮我们解决这个问题吗?如果您有任何建议或解决方案,我们将不胜感激。

我们能够通过修复dev服务器上的known_hosts来解决问题

仔细检查您使用哪个帐户修复了dev服务器上的known_hosts问题。

您的脚本以sudo:的形式执行

sudo /home/$USER/.server_deploy.sh $PUSHED_BRANCH_NAME

因此,它可能使用/root/.ssh/known_hosts文件而不是/home/${secrets.DEVSERVER_SSH_USER}/.ssh/known_hosts


如果你得到了Host key verification failed,不要忘记GitHub最近(2023年3月24日)更改了他们的RSA SSH主机密钥:

ssh-keygen -R github.com
curl -L https://api.github.com/meta | jq -r '.ssh_keys | .[]' | sed -e 's/^/github.com /' >> ~/.ssh/known_hosts

相关内容

  • 没有找到相关文章

最新更新