-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add database migrations as an Ant target #9823
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ | |
<property name="branding.src.dir" value="${basedir}/../branding/java/code/src"/> | ||
<property name="frontend.src.dir" value="${basedir}/../web/html/src"/> | ||
<property name="frontend.dist.dir" value="${basedir}/../web/html/src/dist"/> | ||
<property name="schema.src.dir" value="${basedir}/../schema/spacewalk/upgrade"/> | ||
|
||
<property name="ssh.socket.file" value="${user.home}/.ssh/manager-build-tunnel-${deploy.host}-${deploy.user}"/> | ||
<property name="ssh.socket.option" value="-o ControlPath=${ssh.socket.file}"/> | ||
|
@@ -119,30 +120,44 @@ | |
</condition> | ||
|
||
<!-- macros for deployment --> | ||
<macrodef name="deploy-directory"> | ||
<macrodef name="deploy-to-temp-directory"> | ||
<attribute name="source"/> | ||
<attribute name="destination"/> | ||
<attribute name="syncParameters" default=""/> | ||
<element name="tasks" implicit="true" optional="true" /> | ||
<sequential> | ||
<echo message="Creating temp directory" level="verbose" /> | ||
<!-- Define a temporary directory or fallback to /tmp/deploy-dir --> | ||
<local name="deploy.temp.dir" /> | ||
<deploy-execute outputProperty="deploy.temp.dir" command="mktemp -d" /> | ||
<property name="deploy.temp.dir" value="/tmp/deploy-temp-dir" /> | ||
|
||
<echo message="Deploying directory @{source} to @{destination} using ${deploy.temp.dir}" /> | ||
|
||
<!-- Extract to the temporary directory --> | ||
<echo message="Executing sh -c "tar c -C @{source} -f - . | ${deploy.executor.command} ${deploy.executor.parameters} 'tar xf - -C ${deploy.temp.dir}/'"" level="verbose"/> | ||
<exec failonerror="true" executable="sh" logerror="true"> | ||
<arg line="-c "tar c -C @{source} -f - . | ${deploy.executor.command} ${deploy.executor.parameters} 'tar xf - -C ${deploy.temp.dir}/ --no-same-owner --no-same-permissions'""/> | ||
</exec> | ||
<!-- Use rsync to synchronize the folder --> | ||
<deploy-execute command="rsync -a @{syncParameters} ${deploy.temp.dir}/ @{destination}" /> | ||
<!-- Remove the temporary stuff --> | ||
|
||
<tasks/> | ||
|
||
<echo message="Cleaning up temp directory ${deploy.temp.dir}" level="verbose" /> | ||
<!-- Cleanup --> | ||
<deploy-execute command="rm -rf ${deploy.temp.dir}" /> | ||
</sequential> | ||
</macrodef> | ||
|
||
<macrodef name="deploy-directory"> | ||
<attribute name="source"/> | ||
<attribute name="destination"/> | ||
<attribute name="syncParameters" default=""/> | ||
<sequential> | ||
<deploy-to-temp-directory source="@{source}"> | ||
<echo message="Deploying directory @{source} to @{destination} using ${deploy.temp.dir}" /> | ||
|
||
<!-- Use rsync to synchronize the folder --> | ||
<deploy-execute command="rsync -a @{syncParameters} ${deploy.temp.dir}/ @{destination}" /> | ||
</deploy-to-temp-directory> | ||
</sequential> | ||
</macrodef> | ||
|
||
<macrodef name="deploy-execute"> | ||
<attribute name="command"/> | ||
<attribute name="outputProperty" default="" /> | ||
|
@@ -643,4 +658,28 @@ | |
<echo message="This target is obsolete and will be removed. Please use:" /> | ||
<echo message=" ant -f manager-build.xml -Ddeploy.mode=container deploy-restart" /> | ||
</target> | ||
|
||
<target name="apply-schema-migrations" depends="check-deploy-mode, ensure-server-access" description="Apply all available schema migrations"> | ||
<echo message="Applying all schema migrations..."/> | ||
<sequential> | ||
<deploy-to-temp-directory source="${schema.src.dir}"> | ||
<echo message="Stopping spacewalk-service..." /> | ||
<deploy-execute command="spacewalk-service stop" /> | ||
|
||
<property name="match" value="susemanager-schema-5.*" /> | ||
<property name="argline" value="-c "${deploy.executor.command} ${deploy.executor.parameters} 'find ${deploy.temp.dir}/${match} -type f -name "*.sql" -exec spacewalk-sql --select-mode-direct {} \\\;'"" /> | ||
|
||
<echo message="Finding and applying migrations with:" level="verbose" /> | ||
<echo message="${argline}" level="verbose" /> | ||
<local name="result" /> | ||
<exec failonerror="true" executable="sh" logerror="true" outputproperty="result"> | ||
<arg line="${argline}"/> | ||
</exec> | ||
Comment on lines
+675
to
+677
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem here is that the escaping of the On top of that, I'm not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I selected the wrong lines. I was referring to the <property name="argline" value="-c "${deploy.executor.command} ${deploy.executor.parameters} 'find ${deploy.temp.dir}/${match} -type f -name "*.sql" -exec spacewalk-sql --select-mode-direct {} \\\;'"" /> |
||
<echo message="${result}" /> | ||
|
||
<echo message="Starting spacewalk-service..." /> | ||
<deploy-execute command="spacewalk-service start" /> | ||
</deploy-to-temp-directory> | ||
</sequential> | ||
</target> | ||
</project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's probably not possible to do better than this in plain ant, but this is not totally correct and might lead to errors.