簡體   English   中英

使用GitLab CI使用ftp部署應用程序

[英]Use GitLab CI to deploy app with ftp

我目前正在開展一個小型的Angular Web項目。 我發現這個名為Gitlab CI的好工具。

我閱讀了文檔並設置了一個節點docker來構建webapp。 然后我想用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訪問權限。

我有一個解決方案。 正如所建議的那樣,我試圖創建一個自己的docker鏡像。 我注意到我也無法安裝lftp。 因此,在創建docker鏡像時,您必須先運行apt-get update

所以我在我的腳本中嘗試了這個,它起作用了。

所以你需要首先運行apt-get update,然后安裝你想要的任何軟件包。

使用lftp而不是ftp

runDeployProd:
  before_script:
    - apt-get install lftp

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM