Created
July 6, 2018 08:42
-
-
Save gh640/802b4a33cdc3dfa9876e2b82172505b3 to your computer and use it in GitHub Desktop.
Fabric コマンドサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''デプロイ関連タスクのための Fabric コマンド''' | |
# .env ファイルの中身は次のとおり | |
# hosts=ホスト名A|ホスト名B | |
# shell='/usr/local/bin/bash -l -c' | |
# project_path='/var/www/プロジェクト名' | |
from functools import wraps | |
from pathlib import Path | |
from dotenv import dotenv_values | |
from fabric.api import cd, env, run, task | |
parsed = dotenv_values(dotenv_path=Path('.') / '.env') | |
env.use_ssh_config = True | |
env.hosts = parsed['hosts'].split('|') | |
env.shell = parsed['shell'] | |
CONFIG = { | |
'project_path': parsed['project_path'] | |
} | |
def in_project_root(func): | |
@wraps(func) | |
def wrap(*args, **kwargs): | |
with cd(CONFIG['project_path']): | |
func(*args, **kwargs) | |
return wrap | |
@task | |
def deploy(): | |
git_pull() | |
drush_cc() | |
@task | |
def deploy_with_updb(): | |
git_pull() | |
drush_updb() | |
drush_cc() | |
@task | |
@in_project_root | |
def drush_en(name): | |
run('drush en {}'.format(name)) | |
@task | |
@in_project_root | |
def drush_dis(name): | |
run('drush dis {}'.format(name)) | |
@task | |
@in_project_root | |
def drush_kill(name): | |
run('drush dis {}'.format(name)) | |
run('drush pm-uninstall {}'.format(name)) | |
@task | |
@in_project_root | |
def git_status(): | |
run('git status') | |
@task | |
@in_project_root | |
def git_pull(): | |
run('git pull') | |
@task | |
@in_project_root | |
def drush_st(): | |
run('drush st') | |
@task | |
@in_project_root | |
def drush_updb(): | |
run('drush updb') | |
@task | |
@in_project_root | |
def drush_cc(): | |
run('drush cc all') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment