-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy.xml
237 lines (192 loc) · 8.42 KB
/
deploy.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?xml version="1.0" encoding="UTF-8"?>
<project name="Symfony2 :: Release Management" default="start" basedir="." description="Symfony2 deployment">
<target name="start" description="Start Release">
<echo message="Deployment console" />
<echo message="**************************" />
<echo message="Commands:" />
<echo message="start_release" />
<echo message="update" />
<echo message="**************************" />
</target>
<target name="start_release" description="Start Release">
<property name="project" value="myproject" />
<property name="mailfile" value="config/mail.properties" />
<property name="gitfile" value="config/git.properties" />
<property name="tmp_dir" value="/home/${project}/deploy/${project}/" />
<property name="package_name" value="${project}_${version}.tar" />
<property file="${mailfile}" />
<available file="${mailfile}" property="mailfilefound" value="true"/>
<fail unless="mailfilefound" message="Missing Mail configuration file (${mailfile})!" />
<property file="${gitfile}" />
<available file="${gitfile}" property="gitfilefound" value="true"/>
<fail unless="gitfilefound" message="Missing Git configuration file (${gitfile})!" />
<if>
<not>
<isset property="host" />
</not>
<then>
<!-- Set default host flag -->
<property name="host"
value="testing"
override="true" />
<echo message="The value of hostname has been set to ${host}" />
<!-- /SYNC/ -->
</then>
</if>
<if>
<not>
<isset property="version" />
</not>
<then>
<!-- Set default host flag -->
<property name="version"
value="master"
override="true" />
<echo message="The value of Version has been set to ${version}" />
<!-- /SYNC/ -->
</then>
</if>
<echo message="Clone Repository" />
<phing phingfile="deploy.xml" inheritRefs="true" target="clone_repository" />
<echo message="Refresh release Tag..." />
<phing phingfile="deploy.xml" inheritRefs="true" target="refresh_release_tag" />
<if>
<not>
<isset property="no-assets" />
</not>
<then>
<!-- Set no asset gen -->
<echo message="Create assets..." />
<phing phingfile="deploy.xml" inheritRefs="true" target="create_assets" />
<!-- /SYNC/ -->
</then>
</if>
<echo message="Warmup cache..." />
<phing phingfile="deploy.xml" inheritRefs="true" target="warmup_cache" />
<echo message="Check Repository for errors..." />
<phing phingfile="deploy.xml" inheritRefs="true" target="ckeck_php" />
<echo message="Build Package..." />
<phing phingfile="deploy.xml" inheritRefs="true" target="build_package" />
<echo message="Sync Package..." />
<phing phingfile="deploy.xml" inheritRefs="true" target="sync_package" />
</target>
<target name="sync_package" description="Check Repository">
<foreach list="${host}" param="hostname" target="push_package" />
</target>
<target name="push_package" description="Push package to server">
<!-- /SYNC/ -->
<echo message="Push package ${package_name} to ${hostname} " />
<property name="host_credital_file" value="config/hosts/${hostname}.properties" />
<property file="${host_credital_file}" />
<available file="${host_credital_file}" property="hostfilefound" value="true"/>
<fail unless="hostfilefound" message="Missing Hostfile configuration file (${host_credital_file})!" />
<property name="server_deploy_path" value="${host.server_deploy_path}" />
<ssh username="${host.username}"
password="${host.password}"
host="${host.servername}"
command="rm -rf /tmp/${host.username}/" />
<scp username="${host.username}" password="${host.password}"
host="${host.servername}"
todir="/tmp/${host.username}/"
file="${tmp_dir}${package_name}"
level="debug"
/>
<echo message="execute mkdir" />
<ssh username="${host.username}"
password="${host.password}"
host="${host.servername}"
command="mkdir -p /tmp/${host.username}/${version} "
/>
<ssh username="${host.username}"
password="${host.password}"
host="${host.servername}"
command="mkdir -p ${host.server_deploy_path}${project}"
/>
<echo message="untar file ${package_name}" />
<ssh username="${host.username}"
password="${host.password}"
host="${host.servername}"
command="tar xf /tmp/${host.username}/${package_name} -C /tmp/${host.username}/${version}"
/>
<echo message="copy file to ${server_deploy_path}" />
<ssh username="${host.username}"
password="${host.password}"
host="${host.servername}"
command="rsync --recursive --links --exclude='.git/' --exclude='log/' -u /tmp/${host.username}/${version}/* ${server_deploy_path}${project}"
/>
<echo message="call fix_perms.sh" />
<ssh username="${host.username}"
password="${host.password}"
host="${host.servername}"
command="sh ${server_deploy_path}${project}/app/fix_perms.sh"
/>
<ssh username="${host.username}"
password="${host.password}"
host="${host.servername}"
command="rm -rf /tmp/${host.username}/"
/>
</target>
<target name="ckeck_php" description="Check Repository">
<phplint deprecatedAsError="true" haltonfailure="true">
<fileset dir="${tmp_dir}src/">
<include name="**/*.php"/>
</fileset>
</phplint>
</target>
<target name="clone_repository" description="Clone Repository">
<delete dir="${tmp_dir}" includeemptydirs="true" quiet="true" verbose="false" />
<mkdir dir="/tmp/${project}/" />
<!-- gitPath="/usr/local/git/bin/git" -->
<gitclone
repository="${git.repository.url}"
targetPath="${tmp_dir}"
/>
<gitcheckout
repository="${tmp_dir}"
branchname="${version}"
quiet="false"
forcecreate="true"
force="true"
/>
</target>
<target name="refresh_release_tag" description="Refresh release Tag...">
<reflexive>
<fileset dir="${tmp_dir}app/config/parameters/">
<include pattern="parameters_prod.ini" />
<include pattern="parameters_dev.ini" />
<include pattern="parameters_test.ini" />
<include pattern="parameters.ini" />
</fileset>
<filterchain>
<replaceregexp>
<regexp pattern="{{RELEASE_TAG}}" replace="${version}"/>
</replaceregexp>
</filterchain>
</reflexive>
</target>
<target name="create_assets" description="Create assets....">
<SymfonyConsole console="php ${tmp_dir}app/console" command="assetic:dump">
<arg name="env" value="prod" />
</SymfonyConsole>
</target>
<target name="warmup_cache" description="Warmup cache...">
<SymfonyConsole console="php ${tmp_dir}app/console" command="cache:warmup">
<arg name="env" value="prod" />
</SymfonyConsole>
</target>
<target name="build_package" description="Build Package...">
<tar destfile="${tmp_dir}/${package_name}" basedir="${tmp_dir}" compression="gzip"/>
<available file="${tmp_dir}/${package_name}" property="packagefilefound" value="true"/>
<fail unless="packagefilefound" message="Missing ${tmp_dir} file!" />
</target>
<target name="send_notification" description="send notification">
<mail tolist="${mail}" subject="Deploy ${project} complete" from="[email protected]">
Deploy Complete
-----------------------
Deploy Tag: ${version}
Modul: ${project}
Servers: ${hostnames}
-----------------------
</mail>
</target>
</project>