LoginSignup
5
2

More than 3 years have passed since last update.

レンタルサーバーFTPでもTravis CI使ってCIしたい

Last updated at Posted at 2019-08-02

背景

レンタルサーバーFTP手動アップがひたすら面倒。
レンタルサーバーFTPでもデプロイスクリプトを用意してデプロイを楽するの記事のようにレンタルサーバーFTPでもコマンドでデプロイできるが、もっと楽したい。

環境

もっと簡単にDockerでNuxt.jsを始めてみる(続Dockerでローカル環境を汚さずにNuxt.jsを始めてみる).

こちらの記事の環境が前提で一旦はNuxt.jsの構築ができており、Nuxt.jsをレンタルサーバーFTPでアップします。

結論

Travis CIのCustom Deployment
にはSFTPの記述がありますが、全然うまく行きません。Git + CI + lftp で自動アップロードする方法という記事を参考にlftpを使います。

.travis.yml

.travis.yml
language: node_js
node_js:
  - "10"

cache:
  directories:
    - "node_modules"

install:
  - npm install
  - npm run generate

before_install:
  - chmod +x deploy.sh
  - sudo apt update
  - sudo apt install -y lftp

script:
  - echo "Skipping tests" #本来は駄目ですがテストは一旦スルーする。

after_success:
  - sh deploy.sh

deploy.sh

FTP_USER,FTP_PASSWORD FTP_HOST
はそれぞれ、環境変数をTravis CIで設定してください。
FTP_REMOTE_ROOTはFTPの反映したいディレクトリです。ここは別に環境変数じゃなくても良さそうです。

deploy.sh
#!/bin/bash

lftp -c "set ftp:use-mdtm off;set ftp:ssl-allow no; open -u $FTP_USER,$FTP_PASSWORD $FTP_HOST; mirror --ignore-time -R dist/. /$FTP_REMOTE_ROOT/ --parallel=20"

set ftp:use-mdtm off;set ftp:ssl-allow no--ignore-timeがコツです。

set ftp:use-mdtm off--ignore-timeを設定しないとFTPアップロードが激遅ですし、set ftp:ssl-allow noを設定しないとそもそも証明書の関連でエラーが発生します。

あとはNuxt.jsのリポジトリをGitHubに登録して、Travis CIと連携させて、masterにpushすればCIができます。

参考

《Git》GitLabにコミットしたら、FTPでサーバにアップロードする自動化を1分で行う方法。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2