Continuous integration 如何在从GitLab CI/CD自动部署后安装依赖项

Continuous integration 如何在从GitLab CI/CD自动部署后安装依赖项,continuous-integration,gitlab,dependency-management,continuous-deployment,continuous-delivery,Continuous Integration,Gitlab,Dependency Management,Continuous Deployment,Continuous Delivery,我尝试使用GitLab的CI/CD进行自动部署 我的项目有几个依赖项是通过Composer管理的,我在某处读到,理想情况下,这些依赖项(供应商目录)应该添加到.gitignore文件中,这样它们就不会上传到存储库中,我就是这么做的 当我测试自动部署时,修改后的文件会被上传,但我收到了关于丢失供应商文件的错误,这是我所期望的——所以现在的问题是如何从GitLab CI/CD环境在远程服务器的上下文中安装这些依赖项 我的.gitlab ci.yml文件如下所示: staging: stage:

我尝试使用GitLab的CI/CD进行自动部署

我的项目有几个依赖项是通过Composer管理的,我在某处读到,理想情况下,这些依赖项(
供应商
目录)应该添加到
.gitignore
文件中,这样它们就不会上传到存储库中,我就是这么做的

当我测试自动部署时,修改后的文件会被上传,但我收到了关于丢失供应商文件的错误,这是我所期望的——所以现在的问题是如何从GitLab CI/CD环境在远程服务器的上下文中安装这些依赖项

我的
.gitlab ci.yml
文件如下所示:

staging:
  stage: staging
  before_script:
    - apt-get update -qq && apt-get install -y -qq lftp
  script:
    - lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rev . /public_html  --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
  environment:
    name: staging
    url: http://staging.example.com
  only:
    - staging
如果您查看GitLab,您会注意到它通过CI安装Composer。我认为您可以利用它下载项目依赖项,然后再通过
lftp
上传它们

staging:
  stage: staging
  before_script:
    # Install git since Composer usually requires this if installing from source
    - apt-get update -qq && apt-get install -y -qq git
    # Install lftp to upload files to remote server
    - apt-get update -qq && apt-get install -y -qq lftp
    # Install Composer
    - curl --show-error --silent https://getcomposer.org/installer | php
    # Install project dependencies through Composer (downloads the vendor directory)
    - php composer.phar install
  script:
    # Upload files including the vendor directory
    - lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rev . /public_html  --ignore-time --parallel=10 --exclude-glob .git* --exclude .git/"
  environment:
    name: staging
    url: http://staging.example.com
  only:
    - staging