How I made my blog cheap to host, customizable, and lightning-fast. — Part 5: Build and Deploy with Azure DevOps
Part 1: Setting up — Azure DevOps and Our Headless CMS
Part 2: Building out our Angular Site
Part 3: Meet Scully, our Static Site Generator
Part 4: Hosting on the Cheap
Part 5: Build and Deploy with Azure DevOps — you are here
When I started using Azure DevOps(ADO) I didn’t really like it. It’s really grown on me over the past couple of years though, and one of my favorite parts is the build and release pipelines.
There used to be a GUI for creating builds (you can still use it) but now the standard is to use Yaml. Yaml is a little nasty in my opinion, but I do like the idea of having the build/release in source control.
The first thing we’ll do is to create our Yaml files and commit them to source control. I like to keep them in the root, so they can’t be missed.
Create our Yaml files
First things first, let’s start with “build-pipeline.yml”. Create that file in your favorite text editor and add this:
Replace the “MyProjectName” with your project name.
Here’s what’s the yaml says:
- Trigger when we commit to master.
- Build on ubuntu (why not?)
- Check out the code from the triggering branch (self)
- run
npm install
- run a prod build
- run Scully
- Publish the app to an artifact called “staticApp”
This is almost all stuff we did locally. Once we tell ADO about this, when we commit to master, we’ll get a Scully Generated static site in ADO that is ready for our release to pick up.
Open another file called “release-pipeline.yml”. Insert the content below:
- Change “MyRelease” to whatever you’d like to call your release
- Change “MyBuildPipelinesName” to whatever you’d like to call your build pipeline, and make a note, as we’ll need it soon.
- Change “MyEnvrionmentAsSetUpInAzureDevOps” to “Prod” or “Production”, just remember which, as we’ll need that soon too.
- Fill in both “azureSubscription” lines with the name/Guid of your subscription, and the storage line with the name of your storage account.
- Fill in the “inlinescript” line with your details (for your CDN)
Commit these two files.
Azure DevOps — Create our Environment
- Click Pipelines > Environments
- Click “New Environment”
- Use the value you used to replace “MyEnvrionmentAsSetUpInAzureDevOps” above
- Click “Create”
Azure DevOps — Create our Build Pipeline
- Log into the Azure DevOps account you created in Part 1.
- Go to your project>pipelines
- Click “New Pipeline”
- Connect to your source control
- Choose your repository
- Click “Existing Azure Pipelines Yaml File”
- In the “path” dropdown to the right, select “build-pipeline.yml”
- Click “Continue”
- Click “Save” (It’s under the “run” dropdown)
- Find your pipeline and its ellipses menu and select “rename/move”
- Rename it to the “MyBuildPipelinesName” value you noted above
- Click into your build
- look at the URL in the browser
- note the value for the definitionId
Azure DevOps — Create our Release Pipeline
- Repeat Steps 2–6 from above
- In the “path” dropdown to the right, select “release-pipeline.yml”
- Click “Continue”
- Click “Save” (It’s under the “run” dropdown again)
At this point, any commit to master will kick off a build. Any build will kick off a release. Sweet right?
Before we go, we have one more thing to do in ADO.
- Find “User Settings” in the upper right, and click “Personal Access Tokens.”
- Click “New Token”
- Fill in the form, ensuring you have “Read & Execute” selected for builds
- Note the token
- Also, make note of the expiration…as you’ll need to renew it
Let’s get Squidex involved.
Trigger builds from Squidex
If we go back into Squidex we’ll see a blade called “Rules.”
- Create a new rule for “Content Changed”
- For the trigger schema, add “posts”
- set the condition to
event.type == 'Created' || event.type == 'Updated'|| event.type == 'Changed'
- For the action select “Send Webhook”
- Set the Url to https://dev.azure.com/[AzureInstanceName]/[MyProject]/_apis/build/builds?definitionId=[buildDefinitionId]&api-version=6.0
- replace the bracketed items with your values, including the definitionId you noted earlier.
- Set the Method to “Post”
- for the Headers, set the value to “Authorization= Basic [MyTokenValue]”
- Replace “[MyTokenValue]” with the Personal Access Token you created in ADO
- Save it.
Now, whenever you make a change in Squidex, your build will kick off, and Scully will generate static a Jamstack site that your release pipeline will deploy to your azure blob, it will then purge the CDN.
This is great if you’re selling basic marketing-type sites to a non-technical audience and want to give them a CMS and keep hosting cheap. Let me know if you like this and want to see more things like it, think I’ve missed something, or have any questions.
Cheers, and thanks for sticking with it.