使用GitLab CI来使用ftp部署应用程序

我目前正在做一个有点Angular Web项目。 我发现这个名为Gitlab CI的伟大工具。

我阅读文档并设置节点泊坞窗来构buildWeb应用程序。 然后,我想用ftp上传应用程序到我的服务器上。 这是我的麻烦开始的地方。

首先这里是我的gitlab-ci.yml

image: node:7.5.0 cache: key: "$CI_BUILD_REF_NAME" untracked: true paths: - node_modules/ - dist/ stages: - build # - test - deploy - cleanup # - deployProd runBuild: before_script: - npm install -g angular-cli - npm install stage: build script: - ng build --target=production --environment=test except: - tags runProdBuild: before_script: - npm install -g angular-cli - npm install stage: build script: - ng build --target=production --environment=prod only: - tags runDeployTest: before_script: - apt-get install ftp variables: DATABASE: "" URL: "http://test.domain.de" stage: deploy environment: name: Entwicklungssystem url: https://test.domain.de artifacts: name: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME" paths: - dist/ expire_in: 2d except: - tags script: - echo '<?php ini_set("max_execution_time", 300); function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (is_dir($dir."/".$object)) { rrmdir($dir."/".$object); } else { echo "unlink :".$dir."/".$object; unlink($dir."/".$object); } } } rmdir($dir); } } rrmdir(__DIR__."."); ?>' > delete.php - lftp -d -c "set ftp:ssl-allow no; open -u $ftp_user,$ftp_password $ftp_server; cd $ftp_path; put -O . delete.php" - wget "$URL/delete.php" - cd ./dist - zip -r install.zip . - lftp -d -c "set ftp:ssl-allow no; open -u $ftp_user,$ftp_password $ftp_server; cd $ftp_path; put -O . install.zip" - echo "<?php \$dateiname = __DIR__.'/install.zip'; \$ofolder = str_replace('/public','',__DIR__); exec('unzip '.\$dateiname.' -d '.\$ofolder.' 2>&1', \$out); print(implode('<br>', \$out)); unlink(\$dateiname); unlink('entpacker.php'); unlink(__DIR__.'/../delete.php'); unlink(__DIR__.'/../delete.php.1'); ?>" > entpacker.php - lftp -d -c "set ftp:ssl-allow no; open -u $ftp_user,$ftp_password $ftp_server; cd $ftp_path; put -O . entpacker.php" # Install - wget $URL/entpacker.php runDeployProd: before_script: - apt-get install ftp variables: DATABASE: "" URL: "http://test.domain.de" stage: deploy environment: name: Produktivsystem url: https://prod.domain.de artifacts: name: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME" paths: - dist/ expire_in: 2d script: - echo '<?php ini_set("max_execution_time", 300); function rrmdir($dir) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { if ($object != "." && $object != "..") { if (is_dir($dir."/".$object)) { rrmdir($dir."/".$object); } else { echo "unlink :".$dir."/".$object; unlink($dir."/".$object); } } } rmdir($dir); } } rrmdir(__DIR__."."); ?>' > delete.php - lftp -d -c "set ftp:ssl-allow no; open -u $ftp_user,$ftp_password $ftp_server; cd $ftp_path; put -O . delete.php" - wget "$URL/delete.php" - cd ./dist - zip -r install.zip . - lftp -d -c "set ftp:ssl-allow no; open -u $ftp_user,$ftp_password $ftp_server; cd $ftp_path; put -O . install.zip" - echo "<?php \$dateiname = __DIR__.'/install.zip'; \$ofolder = str_replace('/public','',__DIR__); exec('unzip '.\$dateiname.' -d '.\$ofolder.' 2>&1', \$out); print(implode('<br>', \$out)); unlink(\$dateiname); unlink('entpacker.php'); unlink(__DIR__.'/../delete.php'); unlink(__DIR__.'/../delete.php.1'); ?>" > entpacker.php - lftp -d -c "set ftp:ssl-allow no; open -u $ftp_user,$ftp_password $ftp_server; cd $ftp_path; put -O . entpacker.php" # Install - wget $URL/entpacker.php only: - tags cleanup: stage: cleanup script: - rm -rf ./dist - rm -rf ./node_modules when: manual 

所以它工作正常,直到我想要安装到docker图像的FTP。

我的问题是现在:是否有可能安装FTP到图像?

还是有其他方式来处理这样的事情? 我不能使用ssh,因为没有ssh访问webspace。

使用lftp而不是ftp

 runDeployProd: before_script: - apt-get install lftp 

https://forum.gitlab.com/t/deploy-via-ftp-via-ci/2631/2

我有一个解决scheme。 如build议我试图创build一个自己的docker形象。 在那里我注意到我也不能安装lftp。 所以在创builddocker镜像时,必须先运行apt-get update

所以我试着在我的脚本里面,它的工作。

所以你需要先运行apt-get update,然后安装你想要的软件包。