如何在码头工人环境中成功CI后部署到自定义服务器?



我已经做了CI,但现在我想部署到我的服务器。我的服务器与我执行 CI 的机器相同,但我在 docker 执行器中执行 CI。所以我无法访问服务器文件夹来更新生产。 有我的脚本:

image: node:9.11.2
cache:
paths:
- node_modules/
before_script:
- npm install
stages:
- test  
- deploy
test:
stage: test
script:
- npm run test
deploy: 
stage: deploy
script: 
#here I want to go to /home/projectFolder and make git pull, npm i, npm start
# but I can't beause I run CI in docker-environment which hasn't acces to my server's dirictories.

首先,你应该考虑使用 gitlab auto cicd(如果你不想使用 kubernetes,或者使用它作为自定义的基础(

您有多种方法可以做到这一点,但最简单的方法应该是使用高山图像和 - 安装 SSH(如有必要( - 加载您的私有 SSH 密钥(从管道机密( - 通过 SSH 运行 npm 命令。

最干净的方法是: - 生成将有效的 Dockerfile 添加到您的项目 - 为主服务器上的每个提交添加 Docker 映像生成(在管道中( - 添加 docker rm 运行映像(在您的管道中( - 添加 docker 运行新生成的映像(在管道中((通过共享 docker 卷( - 使nginx重定向到您的容器。

我可以根据您的决定提供更详细的建议。

希望我有帮助。

相关内容

最新更新