使用GitLab配置项通过ftp部署应用程序 [英] Use GitLab CI to deploy app with ftp

查看:0
本文介绍了使用GitLab配置项通过ftp部署应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在进行一个小小的角度Web项目。我发现了一个很棒的工具,叫做GitLab CI。

我阅读了文档并设置了一个节点停靠器来构建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访问Web空间。

推荐答案

我有一个解决方案。正如建议的那样,我试图创建一个自己的码头形象。在那里我注意到我也不能安装lftp。因此,在创建docker映像时,您必须首先运行apt-get update

所以我在我的脚本中尝试了这一点,它起作用了。

因此,您需要首先运行apt-get更新,然后安装所需的任何程序包。

这篇关于使用GitLab配置项通过ftp部署应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆