Benefits and an example of implementing Docs-As-Code
In development teams, it is common and natural that the focus is on coding, testing, and deploying software. However, writing documentation is just as crucial because it is fundamental to effectively and efficiently communicate how the code works, its architecture and how to use it. Some types of documentation may also serve as a reference for future work, and for others, it may be to maintain the code.
Traditionally, documentation is stored in a separate document management system, but this creates a disconnect between the developers' work and the documentation and because of this, we should turn towards the concept of "Docs-As-Code" or "DaC" for short. This approach involves treating documentation like code, including using the same version control systems, and using the same development tools and processes as they do for code.
Benefits of implementing Docs-As-Code
The benefits of implementing DaC in a development team include the following:
Implementing Docs-As-Code in a development team
To implement DaC in a development team, it is important to focus on the following areas:
Common pitfalls when implementing Docs-As-Code
There are several common pitfalls to watch out for when implementing DaC:
领英推荐
Example - Markdown with MkDocs published to both GitHub pages and Confluence
In this example, we have a simple flow, where the code repository serves as the source of truth. When new documentation is added, the first GibHub workflow compiles the MkDocs and publishes this to GitHub pages. The second workflow takes the same Markdown files from the source and publishes those to Confluence using md2cf by Giacomo Gaino .
MkDocs has a direct implementation of how to publish the documentation to GitHub Pages. The YAML file for my implementation looks like the following:
name: build n' deploy MkDocs to GitHub page
on:
? push:
? ? branches:
? ? ? - main
? ? paths:
? ? ? - "docs/**"
? ? ? - mkdocs.yml
jobs:
? deploy:
? ? runs-on: ubuntu-latest
? ? steps:
? ? ? - uses: actions/checkout@v2
? ? ? - uses: actions/setup-python@v2
? ? ? ? with:
? ? ? ? ? python-version: 3.x
? ? ? - name: install mkdocs
? ? ? ? run: pip install mkdocs
? ? ? - name: deploy mkdocs
? ? ? ? run: mkdocs gh-deploy --force --clean --verboses
To implement md2cf we need to be aware of how this translates the folder structure to Confluence Pages.
It is important to note that folders are created as empty pages, which can be modified through some built-in behaviours.
The YAML file for the md2cf implementation to a cloud Confluence instance looks like the following:
name: Publish md files to Confluence
on:
? push:
? ? branches:
? ? ? - main
? ? paths:
? ? ? - "docs/**"
jobs:
? deploy:
? ? runs-on: ubuntu-latest
? steps:
? ? - name: Checkout Source
? ? ? uses: actions/checkout@v3
? ? - name: Setup Python-pip
? ? ? shell: bash
? ? ? run: |
? ? ? ? sudo apt-get update > /dev/null
? ? ? ? sudo apt-get install python3-pip -y
? ? - name: Install md2cf
? ? ? shell: bash
? ? ? run: |
? ? ? ? sudo pip install md2cf --upgrade
? ? - name: Deploy using md2cf
? ? ? shell: bash
? ? ? run: |
? ? ? ? md2cf --host ${{ vars.CONFLUENCE_HOST }} --username ${{ secrets.CONFLUENCE_USERNAME }} --password ${{ secrets.CONFLUENCE_PASSWORD }} \
? ? ? ? ? ./docs \
? ? ? ? ? --space ${{ vars.CONFLUENCE_SPACE }} \
? ? ? ? ? --parent-title 'Docs-As-Code from GitHub' \
? ? ? ? ? --only-changed \
? ? ? ? ? --strip-top-header
The implementation is rather simple, but that doesn't change the importance of DaC!?
You can find the full source code here: https://github.com/petermefrandsen/Docs-As-Code/
Final Thoughts
By implementing Docs-As-Code, development teams can improve collaboration, ensure consistent and reliable documentation and increase discoverability. Teams should focus on choosing the right tooling, establishing clear guidelines, integrating documentation into the development process and encouraging collaboration to successfully implement Docs-As-Code.
DevOps, SRE, Platfoms, DevEx | Chapter Lead @ Vestas
2 年Tommy Frichot, Anders Keis Hansen ?, Thomas Langton, Sekar Anandan, Nicklas Frahm ??