使用 GitLab CI 部署应用 ftp
Use GitLab CI to deploy app with ftp
我目前正在做一个 Angular Web 项目。我发现了这个名为 Gitlab CI 的好工具。
我阅读了文档并设置了一个节点 docker 来构建 Web 应用程序。然后我想将 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
所以它工作正常,直到我想将 ftp 安装到 docker 图像。
我现在的问题是:是否可以将ftp安装到镜像中?
或者有其他方法可以处理这样的事情吗?我无法使用 ssh,因为无法通过 ssh 访问网络空间。
使用lftp
代替ftp
runDeployProd:
before_script:
- apt-get install lftp
我找到了解决办法。按照建议,我尝试创建一个自己的 docker 图像。在那里我注意到我也无法安装 lftp。因此,在创建 docker 图像时,您必须先 运行 apt-get update
。
所以我在我的脚本中尝试了这个,它成功了。
因此您需要先 运行 apt-get 更新,然后再安装任何您想要的软件包。
我目前正在做一个 Angular Web 项目。我发现了这个名为 Gitlab CI 的好工具。
我阅读了文档并设置了一个节点 docker 来构建 Web 应用程序。然后我想将 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
所以它工作正常,直到我想将 ftp 安装到 docker 图像。
我现在的问题是:是否可以将ftp安装到镜像中?
或者有其他方法可以处理这样的事情吗?我无法使用 ssh,因为无法通过 ssh 访问网络空间。
使用lftp
代替ftp
runDeployProd:
before_script:
- apt-get install lftp
我找到了解决办法。按照建议,我尝试创建一个自己的 docker 图像。在那里我注意到我也无法安装 lftp。因此,在创建 docker 图像时,您必须先 运行 apt-get update
。
所以我在我的脚本中尝试了这个,它成功了。
因此您需要先 运行 apt-get 更新,然后再安装任何您想要的软件包。