Más contenido relacionado La actualidad más candente (20) Similar a Phing i Fabric - Budowanie i deployment aplikacji webowych (20) Phing i Fabric - Budowanie i deployment aplikacji webowych16. CECHY
• Łatwy do rozszerzania
• Składnia XML
• Gotowe taski integrujące z popularnymi pakietami
• Wywoływanie kodu PHP
20. <?xml version="1.0" encoding="UTF-8"?>
<project name="FooBar" default="dist">
<target name="prepare">
<echo msg="Making directory ./build" />
<mkdir dir="./build" />
</target>
<target name="build" depends="prepare">
<echo msg="Copying files to build directory..." />
<echo msg="Copying ./about.php to ./build directory..." />
<copy file="./about.php" tofile="./build/about.php" />
<echo msg="Copying ./browsers.php to ./build directory..." />
<copy file="./browsers.php" tofile="./build/browsers.php" />
<echo msg="Copying ./contact.php to ./build directory..." />
<copy file="./contact.php" tofile="./build/contact.php" />
</target>
<target name="dist" depends="build">
<echo msg="Creating archive..." />
<tar destfile="./build/build.tar.gz" compression="gzip">
<fileset dir="./build">
<include name="*" />
</fileset>
</tar>
<echo msg="Files copied and compressed in build directory OK!" />
</target>
</project>
34. # Pary klucz/wartość
#klucz=wartość
# This dir must contain the local application
build.dir=../
# Credentials for the database migrations
db.host=localhost
db.user=user
db.pass=password
db.name=example
# paths to programs
progs.mysql=/usr/bin/mysql
37. <?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="hello">
<target name="hello"
description="Wyświetla powitanie">
<property file="./build.properties" />
<echo msg="Cześć, ${imie}!" />
</target>
<target name="bye">
<echo msg="Papa!" />
</target>
</project>
41. <?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="bye">
<target name="hello"
description="Wyświetla powitanie">
<property file="./build.properties" />
<echo msg="Cześć, ${imie}!" />
</target>
<target name="bye" depends=”hello”>
<echo msg="Papa!" />
</target>
</project>
54. <target name="copyfiles">
<property file="./build.properties" />
<copy todir="/tmp/deploy">
<filterchain>
<replacetokens begintoken="@@" endtoken="@@">
<token key="DBNAME" value="${db.name}" />
<token key="DBUSER" value="${db.user}" />
<token key="DBPASS" value="${db.pass}" />
</replacetokens>
</filterchain>
<fileset dir="." includes="**/*.php" />
</copy>
</target>
59. <if>
<equals arg1="${foo}" arg2="bar" />
<then>
<echo message="The value of property foo is bar" />
</then>
<else>
<echo message="The value of property foo is not bar" />
</else>
</if>
66. <-- List the contents of "/home". -->
<exec command="ls -l" dir="/home" />
<-- Start the make process in "/usr/src/php-4.0". -->
<exec command="make" dir="/usr/src/php-4.0" />
<-- List the contents of "/tmp" out to a file. -->
<exec command="ls -l /tmp > foo.out" escape="false" />
67. <-- Exit with message -->
<fail message="Failed for some reason!" />
<-- Exit if ${errorprop} is defined -->
<fail if="errorprop" message="Detected error!" />
<-- Exit unless ${dontfail} prop is defined. -->
<fail unless="dontfail" message="Detected error!" />
94. WINDOWS
• Ze strony python.org:
• instalator python
• instalator setup-tools
• easy_install pip
• pip install fabric
97. $ fab -H localhost,linuxbox host_type
[localhost] run: uname -s
[localhost] out: Darwin
[linuxbox] run: uname -s
[linuxbox] out: Linux
Done.
Disconnecting from localhost... done.
Disconnecting from linuxbox... done.
101. from fabric.api import local
def test():
local("phing unittest")
def commit():
local("git add -p && git commit")
def push():
local("git push")
def prepare_deploy():
test()
commit()
push()
105. def deploy():
deploy_dir = '/var/www/app'
with settings(warn_only=True):
if run("test -d %s" % code_dir).failed:
run("git clone user@host:repo.git %s" % code_dir)
with cd(code_dir):
run("git pull")
run("phing")
107. REAKCJE[my_server] run: test -d /srv/django/myproject
Warning: run() encountered an error (return code 1) while executing 'test -d /var/
www/app'
[my_server] run: git clone user@pass:repo.git /var/www/app
[my_server] out: Cloning into /srv/django/myproject...
[my_server] out: Password: <enter password>
[my_server] out: remote: Counting objects: 6698, done.
[my_server] out: remote: Compressing objects: 100% (2237/2237), done.
[my_server] out: remote: Total 6698 (delta 4633), reused 6414 (delta 4412)
[my_server] out: Receiving objects: 100% (6698/6698), 1.28 MiB, done.
[my_server] out: Resolving deltas: 100% (4633/4633), done.
[my_server] out:
[my_server] run: git pull
[my_server] out: Already up-to-date.
109. from fabric.api import *
from datetime import datetime
env.hosts = ['appserver']
def get_ts():
d = datetime.now()
return d.strftime("%Y-%m-%d_%H-%M")
def deploy():
ts = get_ts()
with cd("/var/www"):
run("mkdir app-"+ts)
put(".", "/var/www/app-"+ts)
build("/var/www/app-"+ts)
with cd("/var/www"):
run("rm app")
run("ln -s app-"+ts+" app")