In our current deployment process, we have some database scripts that need to be run only once. What complicates this, is that we have more than one database server. We are using SQL AlwaysOn . Any changes we make to the active node will get replicated across to the passive nodes. What is the best way of using octopus deploy in this situation?
Thanks for reaching out. The first idea that came to my mind was “Install a Tentacle on the active node and run the scripts there”, but of course this doesn’t solve the fact that you need this to always be executed on the Active Node.
A possible setup could be:
Get a Powershell script that figures out which node is currently active, and make it return the name of that node/database.
Create a VS Project for your database scripts using DBUp. Make the DBup console take the database connection string from its App.config file. More info on DBUp (and a video) at the bottom of this doc: http://docs.octopusdeploy.com/display/OD/SQL+Server+databases
A Powershell step that runs your script to figure out the Active Node, and that uses that info to create an output variable that could later on be used by further steps using Set-OctopusVariable (read blog post about it). This step could run on the Tentacle on the Octopus server with the role “DBUpdate”.
A Nuget Package Deploy step that deploys your DBUp project (which will contain your scripts and the console that executes them). Before executing the DBUp console, you’ll need to put the right connnection string on the app.config file using the Configuration Variables method and the variable you created on the previous step. This way you’ll make sure that the scripts will always be executed on the node that was active at that moment. This step could also run on the new Tentacle.
You can totally disable the targets with Octoposh. The problem is that if Octopus detects that a target has suddendly been disabled during the deployment, It’ll end up failing the deployment the next time it tries to run something on it. You can solve this by adding a “Health Check” step right after the “Disable Targets” step. You can read more about this step type here: http://docs.octopusdeploy.com/display/OD/Deploying+to+transient+targets