8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

レンタルサーバーFTPでもデプロイスクリプトを用意してデプロイを楽する

Last updated at Posted at 2019-07-20

背景

本番環境レンタルサーバーでFTPで手動アップは面倒くさい。もっと楽したい。
なんとか一部だけでも自動化できないかと思って試した。

環境

  • 本番環境レンタルサーバー
  • ローカル環境macOS Mojave(Laravel-Mix4を使っている)

主に使うもの

package.jsonの設定

{
	"private": true,
	"scripts": {
		"dev": "npm run development",
		"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
		"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
		"watch-poll": "npm run watch -- --watch-poll",
		"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
		"prod": "npm run production",
		"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
		"test": "jest",
		"predeploy": "npm install && npm run prod",
		"deploy": "node ftp-deploy"
	},

... 

こんな感じでscriptを用意する

ルートディレクトリにftp-deploy.jsを用意する

ftp-deploy.jsの設定

ルートディレクトリに.envはおいてある前提。
FTP_USER FTP_PASSWORD FTP_HOSTを定義しておく

var FtpDeploy = require("ftp-deploy");
var ftpDeploy = new FtpDeploy();
require('dotenv').config({path: __dirname + '/.env'})

var config = {
	user: process.env.FTP_USER,
	password: process.env.FTP_PASSWORD,
	host: process.env.FTP_HOST,
	localRoot: "/",
	remoteRoot: "/html",
	include: ["*.js"],
	deleteRemote: false,
	forcePasv: false
};

ftpDeploy.deploy(config)
    .then(res => console.log('finished:', res))
    .catch(err => console.log(err))

あとは

npm run deploy

を実行すれば、OK

念の為
inquirer-confirmとか用意しておくと良いかも。

参考

ftp-deploy

8
0
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
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?