vue.js - 使用 Gitlab CI 部署 Vue.js 构建

标签 vue.js gitlab-ci gitlab-ci-runner

这是我的 gitlab 管道。 Vue.js 工件构建在运行器上。如何部署到我的测试服务器?仅供引用:Fab pull 在存储库上执行 git pull

deploy_staging:
  image: python:3.6
  stage: deploy
  only:
    - master
  before_script:
    - curl -sL https://deb.nodesource.com/setup_13.x | bash -
    - apt-get update -y
    - apt-get install -y curl git gnupg nodejs
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - |
      cat >~/.ssh/config <<EOF
      Host testserver
          ForwardAgent yes
          HostName dev.testserver.ts
          User testuser
      EOF
    - cat ~/.ssh/config
  script:
    - pip install -r requirements.txt
    - npm install
    - npm run production
    - fab pull

最佳答案

因为你想从 GitLab runner 复制文件到你的服务器,这可以使用 scp 命令。 例如:

⋮
 script:
    - pip install -r requirements.txt
    - npm install
    - npm run production
    - scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /PATH/TO/BUILD_ARTIFACTS testserver:~/PATH/TO/DESTINATION
    - fab pull

UserKnownHostsFileStrictHostKeyChecking 是 SSH 选项,可防止错误 Host key verification failed。因此,在您的情况下,它们应该与 scp 命令一起使用。
此外,工件文件的目标路径必须从 testuser 的主目录(波浪字符 ~)开始。否则您可能会遇到 Permission denied 错误。

关于vue.js - 使用 Gitlab CI 部署 Vue.js 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61768739/

相关文章:

vue.js - Vue/Nuxt : How to define a global method accessible to all components?

validation - 使用多个规则验证验证

javascript - VueRouter等待ajax完成

javascript - 使用 VeeValidate,我如何查看某个字段是否已被触摸并且是否有效?

github - 如果 gitlab 管道中的条件为真,则运行依赖项作业

github - Gitlab 可以向匿名用户公开构建和覆盖徽章吗?

c# - 使用 C# 构建的 Gitlab CI

powershell - 自托管 gitlab 运行器。 PATH 环境变量的内容与常规 powershell 不同

gitlab:运行者离线,最后一次联系是在几个小时前

Docker GitLab CI 不工作