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

时间:2019-03-29 13:50:30

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

我正在尝试使用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

1 个答案:

答案 0 :(得分: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