forked from acquia/blt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.xml
175 lines (145 loc) · 9.31 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
<project name="deploy" default="deploy">
<target name="deploy" description="Builds separate artifact and pushes to git.remotes defined project.yml.">
<!-- Prompt for user input -->
<echo>This will build a production-safe artifact, commit it to a branch, and push it to your git.remotes.</echo>
<propertyprompt propertyName="deploy.commitMsg" useExistingValue="true" promptText="Enter a valid commit message" promptCharacter=":" />
<propertyprompt propertyName="deploy.branch" useExistingValue="true" promptText="Enter a deploy branch" promptCharacter=":" />
<!-- Check necessary runtime parameters. -->
<if>
<or>
<not><isset property="deploy.commitMsg"/></not>
<not><isset property="deploy.branch"/></not>
</or>
<then>
<echo message="You must pass deploy.commitMsg and deploy.branch as runtime parameters."/>
<echo message="Command should match syntax:"/>
<echo message="blt deploy -Ddeploy.commitMsg='BLT-123: The commit message.' -Ddeploy.branch='master-build'"/>
<fail message="Missing required parameters."/>
<!-- @todo create default values for these params. E.g., the last commit msg from the source branch, and "[source-branch]-build". -->
</then>
</if>
<!-- Delete the existing deploy directory and re-initialize as an empty git repository. -->
<phingcall target="deploy:prepare-dir"/>
<!-- Add remotes and fetch upstream refs. Checkout local branch tracking
tracking upstream branch, if it exists. Otherwise create new branch
locally. -->
<phingcall target="deploy:add-remotes"/>
<!-- Build artifact and commit locally. -->
<phingcall target="deploy:build"/>
<!--Commit artifact. -->
<phingcall target="deploy:commit"/>
<!-- Push up changes to remotes if this is not a dry run.-->
<if>
<not><isset property="deploy.dryRun"/></not>
<then>
<phingcall target="deploy:push-all"/>
</then>
</if>
</target>
<target name="deploy:remote:add" description="Adds a git remote and checks out deploy branch from upstream." hidden="true">
<echo message="Fetching from git remote ${deploy.remote}"/>
<!-- Generate an md5 sum of the remote URL to use as remote name. -->
<exec command="echo ${deploy.remote} | openssl md5 | cut -d' ' -f 2" outputProperty="remoteName" checkreturn="true" level="${blt.exec_level}"/>
<exec command="git remote add ${remoteName} ${deploy.remote}" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<!-- @todo Only call this for the first remote. -->
<phingcall target="deploy:remote:pull" />
</target>
<target name="deploy:remote:pull" description="Checks out deploy branch from upstream remote." hidden="true">
<exec command="git fetch ${remoteName} ${deploy.branch}" dir="${deploy.dir}" logoutput="true" level="${blt.exec_level}" passthru="true"/>
<!-- Create the new branch, "[source-branch-name]-build". -->
<!-- We intentionally use checkreturn="false" in case the branch already exists. `git checkout -B` does not seem to work as advertised -->
<exec command="git checkout -b ${deploy.branch}" dir="${deploy.dir}" logoutput="true" checkreturn="false" level="${blt.exec_level}" passthru="true"/>
<!-- Pull the latest updates (if available). -->
<exec command="git merge ${remoteName}/${deploy.branch}" dir="${deploy.dir}" logoutput="true" passthru="true"/>
</target>
<target name="deploy:add-remotes" description="Add remotes and fetch upstream refs." hidden="true">
<foreach list="${git.remotes}" param="deploy.remote" target="deploy:remote:add"/>
</target>
<target name="deploy:build" description="Generates a deploy-ready build in deploy.dir."
depends="frontend, setup:hash-salt, deploy:copy, deploy:composer:install, deploy:sanitize">
<!--Allow custom commands to be run before commit.-->
<phingcall target="target-hook:invoke">
<property name="hook-name" value="post-deploy-build"/>
</phingcall>
<if>
<equals arg1="${simplesamlphp}" arg2="true"/>
<then>
<phingcall target="simplesamlphp:deploy:config"/>
</then>
</if>
</target>
<target name="deploy:commit" hidden="true">
<!-- We make these commands quiet because they can cause the output to be so long that Travis CI stops logging. -->
<exec command="git add -A" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec command="git commit -m '${deploy.commitMsg}' --quiet" dir="${deploy.dir}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</target>
<target name="deploy:composer:install" description="Downloads core and contrib to deploy folder." hidden="true">
<if>
<equals arg1="${deploy.build-dependencies}" arg2="true"/>
<then>
<echo>Rebuilding composer dependencies without require-dev.</echo>
<delete dir="${deploy.dir}/vendor"/>
<copy todir="${deploy.dir}" overwrite="true">
<fileset dir="${repo.root}">
<include name="composer.json"/>
<include name="composer.lock"/>
</fileset>
</copy>
<exec dir="${deploy.dir}" command="export COMPOSER_EXIT_ON_PATCH_FAILURE=1; composer install --no-dev --no-interaction --optimize-autoloader" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</then>
<else>
<echo>Dependencies will not be built because deploy.build-dependencies is not enabled.</echo>
<echo>You should define a custom deploy.exclude_file to ensure that dependecies are copied from the root repository.</echo>
</else>
</if>
</target>
<target name="deploy:copy" description="Copy required files from /docroot/sites to /deploy/docroot/sites." hidden="true">
<!-- Make sites/default writable so that we can copy files. -->
<!-- @todo Support multisite. -->
<chmod file="${docroot}/sites/default" mode="0777" />
<exec dir="${repo.root}" command="rsync -a --no-g --delete --delete-excluded --exclude-from=${deploy.exclude_file} ${repo.root}/ ${deploy.dir}/ --filter 'protect /.git/'" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<!-- Use our own .gitignore -->
<copy file="${deploy.gitignore_file}" tofile="${deploy.dir}/.gitignore" overwrite="true"/>
<!-- Set sites/default back to 755 permissions. -->
<!-- @todo Support multisite. -->
<chmod file="${docroot}/sites/default" mode="0755" />
</target>
<target name="deploy:prepare-dir" description="Delete the existing deploy directory and re-initialize as an empty git repository." hidden="true">
<delete dir="${deploy.dir}" failonerror="false" quiet="true" />
<exec command="git init ${deploy.dir}" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec dir="${deploy.dir}" command="git config --local core.excludesfile false" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<echo>Global .gitignore file is being disabled for this repository to prevent unexpected behavior.</echo>
</target>
<target name="deploy:push-all" hidden="true">
<foreach list="${git.remotes}" param="deploy.remote" target="deploy:push-remote"/>
</target>
<target name="deploy:push-remote" description="Pushes to a git remote." hidden="true">
<exec command="echo ${deploy.remote} | openssl md5 | cut -d' ' -f 2" outputProperty="remoteName"/>
<exec command="git push ${remoteName} ${deploy.branch}" dir="${deploy.dir}" outputProperty="deploy.push.output" logoutput="true" checkreturn="true" level="${blt.exec_level}"/>
<exec command="export DEPLOY_UPTODATE=$(echo '${deploy.push.output}' | grep --quiet 'Everything up-to-date')" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
</target>
<target name="deploy:sanitize" description="Removes sensitive files from the deploy docroot." hidden="true">
<exec command="find . -type d | grep '\.git' | xargs rm -rf" dir="${deploy.dir}/docroot" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<exec command="find . -type d | grep '\.git' | xargs rm -rf" dir="${deploy.dir}/vendor" logoutput="true" checkreturn="true" level="${blt.exec_level}" passthru="true"/>
<delete>
<fileset dir="${deploy.dir}/docroot">
<include name="core/*.txt"/>
<include name="**/CHANGELOG.txt"/>
</fileset>
</delete>
</target>
<target name="deploy:update" description="Update current database to reflect the state of the Drupal file system; uses local drush alias." depends="deploy:toggle-modules">
<phingcall target="setup:update">
<property name="drush.alias" value="self"/>
<!-- Most sites store their version-controlled configuration in /config/default. -->
<!-- ACE internally sets the vcs configuration directory to /config/default, so we use that. -->
<property name="cm.core.config-dir" value="vcs"/>
</phingcall>
</target>
<target name="deploy:toggle-modules" description="Enables modules.deploy.enable projects and uninstalls modules.deploy.uninstall projects.">
<phingcall target="setup:toggle-modules">
<param name="enable" value="${modules.deploy.enable}"/>
<param name="uninstall" value="${modules.deploy.uninstall}"/>
</phingcall>
</target>
</project>