[PYTHON] Deploy script to jboss using fabric

Script for deploying to jboss with fabric. It is assumed that the post-build artifacts have been created.

script

from fabric.api import run, env, put

env.use_ssh_config = True

def deploy():
    put("./trunk/project/build/libs/app.war", "/home/ec2-user/app.war")
    run("sudo chown jboss:jboss /home/ec2-user/app.war")
    run("sudo /opt/jboss7/bin/./jboss-cli.sh -c --command='undeploy app.war'")
    run("sudo /opt/jboss7/bin/./jboss-cli.sh -c --command='deploy /home/ec2-user/app.war'")
    run("sudo /etc/init.d/jboss restart")

Run

fab -H {hostname} deploy

bonus

How to use a stepping server. Introducing two methods, one is to specify it as an argument and the other is to describe it in the config file.

Specified by argument

Describe the settings of each server in .ssh / config.

Host           proxy                         #Name of bastion server
HostName       XXX.XXX.XXX.XXX               #Stepping stone server host
User           deploy                        #Ssh connection username
IdentityFile   /home/ec2-user/.ssh/key.pem   #Ssh connection key file

Host           remote                        #Name of the connection destination
HostName       XXX.XXX.XXX.XXX               #Host to connect to
User           deploy                        #Ssh connection username
IdentityFile   /home/ec2-user/.ssh/key.pem   #Ssh connection key file

Execute the command by specifying the host name of the bastion server with the "-g" option.

fab -H remote -g proxy deploy

Specified in config

Specify directly in config as shown below.

Host           proxy                         #Name of bastion server
HostName       XXX.XXX.XXX.XXX               #Stepping stone server host
User           deploy                        #Ssh connection username
IdentityFile   /home/ec2-user/.ssh/key.pem   #Ssh connection key file

Host           remote                        #Name of the connection destination
HostName       XXX.XXX.XXX.XXX               #Host to connect to
User           deploy                        #Ssh connection username
IdentityFile   /home/ec2-user/.ssh/key.pem   #Ssh connection key file
ProxyCommand   ssh -W %h:%p proxy            #Specify the bastion server

Execute the command by specifying the host name.

fab -H remote deploy

Recommended Posts

Deploy script to jboss using fabric
Summary when using Fabric
Create a deploy script with fabric and cuisine and reuse it
Post to Twitter using Python
Start to Selenium using python
Introduction to discord.py (3) Using voice
Deploy django project to heroku