使用Gitlab CI部署Vue.js构建

时间:2020-05-13 07:29:30

标签: 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

1 个答案:

答案 0 :(得分:2)

由于您要将文件从GitLab运行程序复制到服务器中,因此可以使用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是防止错误Host key verification failed的SSH选项。因此,在您的情况下,应将它们与scp命令一起使用。
另外,工件文件的目标路径必须从testuser的主目录(波浪号~)开始。否则,您可能会遇到Permission denied错误。