Background
As noted in Antora basics the Antora build pipeline generates a static website bundle in ./build/site
.
Although it is possible to manually upload the contents of that directory to any webserver, in a real project we want to have automated publishing triggered by pushing changes to either the playbook project or any of the content root repositories.
Publishing destinations
In our real world project we set up a total of three websites - one for our customers, and two restricted sites for internal staff documentation.
The public site is hosted on Netlify, and the two internal sites hosted on Azure App Service with authentication switched on - to visit those sites you have to authenticate with our Azure Active Directory.
Continuous deployment
All of our sites are published automatically whenever changes to either the playbook project or any of the relevant content root repositories are pushed to GitHub.
Change | Site type | Hosting | Build engine | Trigger |
---|---|---|---|---|
Playbook project | Public | Netlify | Netlify | Automatic build triggered by GitHub push |
Playbook project | Restricted | Azure | Azure DevOps | Automatic build triggered by GitHub push |
Content roots | Public | Netlify | Netlify | GitHub action fires build of associated playbook project via netlify webhook |
Content roots | Restricted | Azure | Azure Devops | GitHub action fires build of associated playbook project via Azure DevOps API |
Netlify
- Ensure playbook project is connected to Netlify
- In playbook project add
build-site.sh
(includes addition of search):This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersDOCSEARCH_ENABLED=true DOCSEARCH_ENGINE=lunr NODE_PATH="$(npm -g root)" antora --fetch --generator antora-site-generator-lunr antora-playbook.yml - In playbook project add
netlify.toml
:This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters# Note you must also set the following environment varibables in the Netlify UI: # GITHUB_CREDENTIALS - a credential that can access private source repos linked from this publishing repo # See https://docs.antora.org/antora/2.3/playbook/private-repository-auth/#pass-credentials-via-an-environment-variable # Settings in the [build] context are global and are applied to all contexts # unless otherwise overridden by more specific contexts. [build] # Directory to change to before starting a build. # This is where we will look for package.json/.nvmrc/etc. base = "" # Directory that contains the deploy-ready HTML files and assets generated by # the build. This is relative to the base directory if one has been set, or the # root directory if a base has not been set. This sample publishes the # directory located at the absolute path "root/project/build-output" publish = "build/site" # Default build command. command = "npm i -g @antora/cli @antora/site-generator-default antora-site-generator-lunr && chmod 0755 ./build-site.sh && ./build-site.sh" - Log in to Netlify, create a webhook for the playbook project
- In GitHub create an account-level or organisation-level secret called
NETLIFY_HOOK_DOCS_PUBLIC
with the value set to the URL of the webhook created in step 1 - In GitHub add the secret to each content project that contains public docs
- In each content project create a GitHub action in
./.github/workflows/build-public.yml
that looks like this (we assume content root is always under./public
, edit to suit your setup):
name: Trigger netlify build for public docs | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'public/**' | |
jobs: | |
trigger-publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Invoke Netlify deployment hook | |
uses: distributhor/workflow-webhook@v1 | |
env: | |
webhook_url: ${{ secrets.NETLIFY_HOOK_DOCS_PUBLIC }}?trigger_title=content_update | |
webhook_secret: "Anything" |
Azure App Service / Azure Devops
- Create a connection in Azure Devops to the relevant Azure subscription
- In the playbook project add
./azure-pipelines.yml
as per the gist below (edit values for Azure subscription and website)This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characterstrigger: - master pool: vmImage: 'ubuntu-latest' variables: - group: Credentials jobs: - job: build steps: - script: | node --version sudo npm i -g @antora/cli@2.3 @antora/site-generator-default@2.3 sudo npm i -g antora-site-generator-lunr antora version displayName: 'Install antora' - script: | export GIT_CREDENTIALS='https://$(PAT):@github.com' DOCSEARCH_ENABLED=true DOCSEARCH_ENGINE=lunr NODE_PATH=" (Build.ArtifactStagingDirectory)' --generator antora-site-generator-lunr antora-playbook.ymldisplayName: 'Run antora' - publish: '$(Build.ArtifactStagingDirectory)' artifact: 'myartifactname' - job: publishWeb dependsOn: build steps: - checkout: none # no need to checkout any code because we only need the artifact - download: current artifact: 'myartifactname' - task: AzureRmWebAppDeployment@4 inputs: ConnectionType: 'AzureRM' azureSubscription: 'MyAzureSubscription' appType: 'webApp' WebAppName: 'mywebsitename' packageForLinux: '$(Pipeline.Workspace)/myartifactname/' - Connect the playbook project to Azure Devops and configure a pipeline based on the
./azure-pipelines.yml
file - Login to Azure Devops and create a Personal Access Token
- In GitHub create an account-level or organisation-level secret called
AZURE_DEVOPS_TOKEN
with the value set to the token created in the previous step - In GitHub add the secret to each content project that contains docs used in this project
- In each content project add a GitHub action in
./.github/workflows/build-azure.yml
that looks like the gist below (the version shown assumes content in the./staff
folder, edit to suit your setup )This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersname: Trigger Azure Build for Staff Docs on: push: branches: - master paths: - 'staff/**' jobs: trigger-build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: Azure/pipelines@v1 with: azure-devops-project-url: 'https://dev.azure.com/ORGNAME/PROJECTNAME' azure-pipeline-name: 'PIPELINE_NAME' azure-devops-token: '${{ secrets.AZURE_DEVOPS_TOKEN }}'