【发布时间】:2021-12-10 23:27:19
【问题描述】:
当我提交对 gitlab 的更改并在 cpanel 上部署项目时。但在管道中出现此错误。 我在这个项目中使用 laravel deployer,我想通过 gitlab 在 cpanel 上部署我的项目。
The command "cd /home/sfd/public_html && (/usr/local/cpanel/3rdparty/lib/pa
th-bin/git clone --recursive https://gitlab.com/nas-project
.git /home/sfd/public_html/releases/1 2>&1)" failed.
Exit Code: 128 (Invalid exit argument)
Host Name: 51.75.174.102
================
Cloning into '/home/sfd/public_html/releases/1'...
fatal: could not read Username for 'https://gitlab.com': No such device or
address
我在这里发布我的一些代码,(运行器代码,gitlab-ci.yml,部署代码)
运行器代码
[[runners]]
name = "DESKTOP-1OOOT34"
url = "https://gitlab.com/nas-project.git"
token = "mytoken"
executor = "shell"
shell = "powershell"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
Deploy.php 代码
<?php
return [
'default' => 'basic',
'strategies' => [
//
],
'hooks' => [
'ready' => [
'artisan:storage:link',
'artisan:view:clear',
'artisan:config:cache',
'artisan:migrate',
],
],
'options' => [
'application' => env('APP_NAME', 'Laravel'),
'repository' => 'https://gitlab.com/n1063/suntop/nas-project.git',
],
'hosts' => [
'mysiteIP' => [
'deploy_path' => '/home/sfd/public_html',
'user' => 'sfd',
'multiplexing' => true,
'sshOptions' => [
'StrictHostKeyChecking' => 'no',
// ...
],
],
],
'localhost' => [
//
],
'include' => [
//
],
'custom_deployer_file' => false,
];
gitlab-ci.yml
image: edbizarro/gitlab-ci-pipeline-php:7.4
stages:
- preparation
- deploy
composer:
stage: preparation
script:
- php -v
- composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts --no-suggest
- cp .env.example .env
- php artisan key:generate
artifacts:
paths:
- vendor/
- .env
expire_in: 1 days
when: always
cache:
paths:
- vendor/
yarn:
stage: preparation
script:
- yarn --version
- yarn install --pure-lockfile
artifacts:
paths:
- node_modules/
expire_in: 1 days
when: always
.init_ssh_live: &init_ssh_live |
mkdir -p ~/.ssh
echo -e "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
deploy:
stage: deploy
script:
- *init_ssh_live
- php artisan deploy mySiteIP -s upload
environment:
name: live
url: mySiteIP
only:
- dev
【问题讨论】:
-
使用 https 时,您没有使用 ssh。当您使用
https://URL 时,为什么这会被标记为ssh-keys? (也许这就是整个错误,您应该使用 ssh URL?) -
@torek 所以我在部署文件中使用 ssh URL 我将 git htts url 放在哪里?
-
我通常会这样做。生成机器密钥并在机器访问私有存储库时使用它。
-
你能给我解释一下吗?我从过去 3 天开始就陷入了这个问题。请告诉我我在哪个文件中进行了更改?上面我提到了 2 个文件及其代码(deploy.php | gitlab-ci.yml)。请帮助我@torek
-
我从来没有使用过 GitLab 的管道和 CI 系统,所以我不知道那里的任何细节。但一般来说,当您有一些机器用户(构建软件)克隆存储库时,它不会代表某些 user 运行,因此没有可用的用户名或用户密钥。因此,您使用
ssh://git@<host>/path/to/repo.gitURL 并确保 this ssh 命令在设置$HOME/.ssh/的情况下运行,以便它发送一个授权从给定主机读取 URL 的 ssh 密钥。
标签: laravel git gitlab ssh-keys cicd