9

How To Improve Your Software Documentation by Connecting Gitlab with Mkdocs

 4 years ago
source link: https://hackernoon.com/how-to-improve-your-software-documentation-by-connecting-gitlab-with-mkdocs-n82o316c
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How To Improve Your Software Documentation by Connecting Gitlab with Mkdocs

@hatembentayebhatem ben tayeb

Archlinux User | Devops engineer | Technical writer | Automation enthusiast | IaaC | CaaC | GitOps

Producing documentation may be painful and need a lot of time to write and operate. In this story, i will share with you, my way of generating docs using the devops approach. To make life easier, we will explore the art of automation 😃.

Let’s go folks šŸ˜™

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Create a Gitlab repo

This is straightforward, follow these steps:

0 reactions
heart.png
light.png
thumbs-down.png
money.png
  • Log in to your GitLab
  • Click new project
  • Give it a name:Ā auto_docs
  • Initialize it with aĀ README.mdĀ file
  • Make it public or private

Now clone the project by copying the URL and run this command :

0 reactions
heart.png
light.png
thumbs-down.png
money.png
$ git clone https://gitlab.com/auto_docs.git

Setting up the environment

I’m using a Linux environment but it is possible to reproduce the same steps on a Windows machine.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

In order to follow me, you need a set of tools that must be available on your machine … make sure to to haveĀ python3 installed, I have python 3.8 (latest).

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Creating a virtual environment

The easiest way to set up a virtual environment is to installĀ virtualenvĀ python package by executingĀ 

pip install virtualenv
Ā .
0 reactions
heart.png
light.png
thumbs-down.png
money.png

Navigate to your local GitLab repository and create a new virtual environment.

0 reactions
heart.png
light.png
thumbs-down.png
money.png
$ cd auto_docs/
$ virtualenv autodocs
$ source autodocs/bin/acivate

Installing Mkdocs Material

Make sure that the virtual environment is active.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Install the mkdocs material with this command :Ā pip install mkdocs-material.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

This package needs some dependencies to work .. install them by using a requirement.txt file, copy-paste the dependencies list to filenameĀ requirements.txt

0 reactions
heart.png
light.png
thumbs-down.png
money.png
Babel==2.8.0
click==7.1.1
future==0.18.2
gitdb==4.0.4
GitPython==3.1.1
htmlmin==0.1.12
Jinja2==2.11.2
joblib==0.14.1
jsmin==2.2.2
livereload==2.6.1
lunr==0.5.6
Markdown==3.2.1
MarkupSafe==1.1.1
mkdocs==1.1
mkdocs-awesome-pages-plugin==2.2.1
mkdocs-git-revision-date-localized-plugin==0.5.0
mkdocs-material==5.1.1
mkdocs-material-extensions==1.0b1
mkdocs-minify-plugin==0.3.0
nltk==3.5
Pygments==2.6.1
pymdown-extensions==7.0
pytz==2019.3
PyYAML==5.3.1
regex==2020.4.4
six==1.14.0
smmap==3.0.2
tornado==6.0.4
tqdm==4.45.0

Install them all with one command :Ā 

pip install -r requirements.txt

Now it’s time to create a new mkdocs project šŸ˜….
0 reactions
heart.png
light.png
thumbs-down.png
money.png

Run this command :Ā mkdocs new .Ā and verify that you have this structure :

0 reactions
heart.png
light.png
thumbs-down.png
money.png
|--auto_docs
    |--- docs
    |--- mkdocs.yml
  • TheĀ docsĀ folder contains the structure of your documentation, it contains subfolders and markdown files.
  • TheĀ mkdocs.ymlĀ file defines the configuration of the generated site.

Let's test the installation by running this command :Ā 

mkdocs serve
Ā . The site will be accessible onĀ http://locahost:8000Ā and you should see the initial look of the docs.
0 reactions
heart.png
light.png
thumbs-down.png
money.png

Setting up the CI/CD

let’s enable le CI/CD to automate the build and the deployment of the docs. Notice that GitLab offers a feature calledĀ gitlab pagesĀ that can serve for free a static resource (HTML, js, CSS). The repo path is converted to an URL to your docs.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Create the CI/CD file

Gitlab uses a YAML file — it holds the pipeline configuration.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

The CI file content:

0 reactions
heart.png
light.png
thumbs-down.png
money.png
stages :
  - build
pages:
  stage: build
  image:
  name: squidfunk/mkdocs-material
  entrypoint:
    - ""
  script:
    - mkdocs build
    - mv site public
  artifacts:
    paths:
      - public
  only:
    - master
  tags:
    - gitlab-org-docker

This pipeline uses a docker executor with an image that containsĀ mkdocsĀ already installed… mkdocs build the project and put the build assets on a folder calledĀ site … to be able to use GitLab pages you have to name your jobĀ pagesĀ and put the site assets into a new folder calledĀ public.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

For tags: check the runner's section underĀ settings → CI/CD →RunnersĀ and pick one of the shared runners that have a tagĀ GitLab-org-docker.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

All things were done šŸŽ‰ šŸŽ‰ 😸 !

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Oh ! just one thing … we forgot the virtual environment files .. they are big and not needed on the pipeline … they are for the local development only. The mkdocs image on the pipeline is already shipped with the necessary packages.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

So … create a new file calledĀ .gitignoreĀ and add these lines:

0 reactions
heart.png
light.png
thumbs-down.png
money.png
auto_docs/ 
requirements.txt

TheĀ auto_docsĀ folder has the same name as the virtual environment .. don't forget 😠! you will be punished by pushing +100Mi šŸ˜ and you will wait your whole life to complete the process haha 😢.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Now runĀ git add . && git commit -m "initial commit" a && git push … go to your GitLab repo and clickĀ CI/CD → pipelines,Ā click on the blue icon and visualize the logs .. once the job succeeded, navigate toĀ settings -> pagesĀ and click the link of your new documentation site (you have to wait for 10m~ to be accessible)

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Finally, I hope this was helpful! thanks for reading 😺 šŸ˜!

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Originally published on: https://hatembentayeb.hashnode.dev/deploying-a-dockerized-angular-app-with-github-actions-1

0 reactions
heart.png
light.png
thumbs-down.png
money.png
heart.pngheart.pngheart.pngheart.png
light.pnglight.pnglight.pnglight.png
boat.pngboat.pngboat.pngboat.png
money.pngmoney.pngmoney.pngmoney.png
Share this story
Read my stories

Archlinux User | Devops engineer | Technical writer | Automation enthusiast | IaaC | CaaC | GitOps

Join Hacker Noon

Create your free account to unlock your custom reading experience.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK