Documentation as Code

Introduction

With nowadays virtualization technologies, low latency communications, CPU Power and The Cloud, the Infrastructure paradigm is being changed from the static old-fashion way of managing servers to a new standard automation way of deploying services.

Sysadmins are becoming SysDevs and the widely famous DevOps term is starting to be defined by itself. Of course, the old-fashion way is still there though – and always from my humble point of view – any company with growth objectives will need to start changing the way of doing things in less than five years and start to automate their infrastructure.

Definition – Still a new concept?

When typing “Infrastructure as Code” in any Search Provider, about 350K results will be returned including a Wikipedia entry. New books are being published about this subject and it is clear that there is a new tendency when deploying new servers and services.

There are several approaches when talking about code development techniques and documentation like Wikis, Git Markdown, documentation along with the source, etc.

But what about doing it altogether? What about doing Documentation as Code?

I was surprised when at the time of writing this post; there is almost nothing on the Internet when searching for “Documentation as Code”. Search providers return almost 14K useless results. You will find that there is not even an entry in the Wikipedia. The Cherryleaf.com blog includes a couple of interesting links and describes it as being able to store the documentation with the code. To me, it is correct but I think we can go one step forward. Let’s hold the reins of this and let’s complete the definition.

Documentation as Codeis the way of automating documentation along with the written code. It can be when deploying new Infrastructure elements, new services or just a new piece of software or script. Automated Documentation will be able to be exported and shared using external tools like Wikis, Content Management, Git or others.

The Idea

Bash Example

Let’s suppose that we want to create a bash script. Our documentation will be together with our script code. The difference is that it will be able to be exported with a flag given. This flag will also allow the exporting of the document in markdown and even in HTML or PDF.

Final Step

From here, we can use tools like Pandoc or AsciiDoctor inside our scripts to automatically convert and post our documentation to a Wiki, GitHub, Content Management, etc. Another approach is keeping the markdown format and using Jekyll to automatically creating amazing documentation portals.

Conclusion

Documentation As Code is still a raw concept and I’m sure that it will start to emerge in a few months. To me, it is a procedure together with tools to get the best documentation and revision control along with the code. The way of creating documentation must be simple and the result must be useful. The scripts shown here are just ideas and I’m sure that once you read this, a lot of new ones will strike your head.

Download the Eclipse Vert.x cheat sheet, this cheat sheet provides step by step details to let you create your apps the way you want to.