【问题标题】:How to install dependencies after automatic deployment from GitLab CI/CD从 GitLab CI/CD 自动部署后如何安装依赖项
【发布时间】:2019-03-31 01:00:40
【问题描述】:

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

我的项目有几个通过 Composer 管理的依赖项,我在某处读到这些依赖项(vendor 目录)理想情况下应该添加到 .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

【问题讨论】:

    标签: continuous-integration gitlab dependency-management continuous-deployment continuous-delivery


    【解决方案1】:

    如果您查看 GitLab 的 documentation for caching PHP dependencies,您会注意到它通过 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      相关资源
      最近更新 更多