Enhancement and additions for webinar
[doc.git] / docs / guides / onap-developer / how-to-use-docs / include-documentation.rst
1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2
3
4 Setting Up
5 ==========
6 Some initial set up is required to connect a project with
7 the master document structure and enable automated publishing of
8 changes as summarized in the following diagram and description below 
9 below.
10
11 .. seqdiag::
12    :height: 700
13    :width: 1000
14
15    seqdiag {
16      RD [label = "Read The Docs",                color =lightgreen ];
17      DA [label = "Doc Project\nAuthor/Committer",   color=lightblue];
18      DR [label = "Doc Gerrit Repo" ,                     color=pink];
19      PR [label = "Other Project\nGerrit Repo",          color=pink ];
20      PA [label = "Other Project\nAuthor/Committer", color=lightblue];
21      
22      === One time setup doc project only ===
23      RD  ->   DA [label = "Acquire Account" ]; 
24      DA  ->   DR [label = "Create initial\n doc repository content"];
25      DA  <<-- DR [label = "Merge" ];
26      RD  <--  DA [label = "Connect gerrit.onap.org" ];
27      === For each project repository containing document source ===
28      PA  ->   DR [label = "Add project repo as\ngit submodule" ];
29      DR  ->   DA [label = "Review & Plan to\nIntegrate Content with\nTocTree Structure" ];
30      DR  <--  DA [label = "Vote +2/Merge" ];
31      PA  <--  DR [label = "Merge Notification" ];     
32      PA  ->   PR [label = "Create in project repo\ntop level directory and index.rst" ];
33      PR  ->   DA [label = "Add as Reviewer" ];
34      PR  <--  DA [label = "Approve and Integrate" ];
35      PA  <--  PR [label = "Merge" ];
36      }
37      
38      
39
40 Setup doc project
41 -----------------
42 These steps are performed only once for the doc project and include:
43
44 (1) creating in the doc repository an initial:
45         - sphinx master document index
46         - a directory structure aligned with the document structure
47         - tests performed in jenkins verify jobs
48         - sphinx configuration
49   
50 (2) establishing an account at readthedocs connected with the doc
51 doc project repo in gerrit.onap.org.
52
53
54 Setup project repositories(s)
55 -----------------------------
56 These steps are performed for each project repository that provides documentation. 
57
58 First let's set two variables that will be used in the subsequent steps.
59 Set reponame to the project repository you are setting up just as it appears in the
60 **Project Name** column of the Gerrit projects page.
61 Set lfid to your Linux Foundation identity that you use to login to gerrit or for git
62 clone requests over ssh.
63
64 .. code-block:: bash
65
66    reponame=
67    lfid=
68
69 The next step is to add a directory in the doc project where your project will be included as a 
70 submodule and at least one reference from the doc project to the documentation index in your repository.
71 The following sequence will do this over ssh.
72
73 .. caution::
74
75    If your access network restricts ssh, you will need to use equivalent git commands and
76    HTTP Passwords as described `here <http://wiki.onap.org/x/X4AP>`_.
77         
78 .. code-block:: bash
79
80    git clone ssh://$lfid@gerrit.onap.org:29418/doc
81    cd doc
82    mkdir -p `dirname docs/submodules/$reponame`
83    git submodule add https://gerrit.onap.org/r/$reponame docs/submodules/$reponame.git
84    git submodule init docs/submodules/$reponame.git
85    git submodule update docs/submodules/$reponame.git
86
87    echo "   $reponame <../submodules/$reponame.git/docs/index>" >> docs/release/repolist.rst
88    
89    git add .
90    git commit -s
91    git review
92    
93 .. caution::
94    Wait for the above change to be merged before any merge to the
95    project repository that you have just added as a submodule.
96    If the project repository added as submodule changes before the doc project merge, git may not
97    automatically update the submodule reference on changes and/or the verify job will
98    fail in the step below.
99
100
101 The last step is to create a docs directory in your repository with an index.rst file.
102 The following sequence will complete the minimum required over ssh.  As you have time
103 to convert or add new content you can update the index and add files under the docs folder.
104
105 .. hint::
106    If you have additional content, you can include it by editing the
107    index.rst file and/or adding other files before the git commit.
108    See `Templates and Examples`_ below and :ref:`converting-to-rst` for more information.
109    
110
111 .. code-block:: bash
112
113    git clone ssh://$lfid@gerrit.onap.org:29418/$reponame
114    cd $reponame
115    mkdir docs
116    echo ".. This work is licensed under a Creative Commons Attribution 4.0 International License.
117
118    TODO Add files to toctree and delete this header
119    ------------------------------------------------
120    .. toctree::
121       :maxdepth: 1
122       
123    " >  docs/index.rst
124    
125    git add .
126    git commit -s
127    git review
128    
129
130 The diagram below illustrates what is accomplished in the setup steps
131 above from the perspective of a file structure created for a local test,
132 a jenkins verify job, and/or published release documentation including:
133   - ONAP gerrit project repositories,
134   - doc project repository master document index.rst, templates, configuration, and other documents
135   - submodules directory where other project repositories and directories/files are referenced 
136   - file structure: directories (ellipses), files(boxes)
137   - references: directory/files (solid edges), git submodule (dotted edges), sphinx toctree (dashed edges)
138
139
140 .. graphviz::
141
142    
143    digraph docstructure {
144    size="8,12";
145    node [fontname = "helvetica"];
146    // Align gerrit repos and docs directories
147    {rank=same doc aaf aai reponame repoelipse vnfsdk vvp}
148    {rank=same confpy release templates masterindex submodules otherdocdocumentelipse}
149    {rank=same releasedocumentindex releaserepolist}
150
151    //Illustrate Gerrit Repos and provide URL/Link for complete repo list
152    gerrit [label="gerrit.onap.org/r", href="https://gerrit.onap.org/r/#/admin/projects/" ];
153    doc [href="https://gerrit.onap.org/r/gitweb?p=doc.git;a=tree"];
154    gerrit -> doc;
155    gerrit -> aaf;
156    gerrit -> aai;
157    gerrit -> reponame; 
158    gerrit -> repoelipse;
159              repoelipse [label=". . . ."];
160    gerrit -> vnfsdk;
161    gerrit -> vvp;
162
163    //Show example of local reponame instance of component info
164    reponame -> reponamedocsdir;
165    reponamesm -> reponamedocsdir;  
166                     reponamedocsdir [label="docs"];
167    reponamedocsdir -> repnamedocsdirindex; 
168                          repnamedocsdirindex [label="index.rst", shape=box];
169
170    //Show detail structure of a portion of doc/docs 
171    doc  -> docs;
172    docs -> confpy;                   
173            confpy [label="conf.py",shape=box];
174    docs -> masterindex; 
175            masterindex [label="Master\nindex.rst", shape=box];
176    docs -> release;
177    docs -> templates;                                
178    docs -> otherdocdocumentelipse;  
179            otherdocdocumentelipse [label="...other\ndocuments"];
180    docs -> submodules
181    
182    masterindex -> releasedocumentindex [style=dashed, label="sphinx\ntoctree\nreference"];
183    
184    //Show submodule linkage to docs directory
185    submodules -> reponamesm [style=dotted,label="git\nsubmodule\nreference"];  
186                  reponamesm [label="reponame.git"];
187
188    //Example Release document index that references component info provided in other project repo
189    release -> releasedocumentindex;   
190               releasedocumentindex [label="index.rst", shape=box];
191    releasedocumentindex -> releaserepolist [style=dashed, label="sphinx\ntoctree\nreference"];
192                            releaserepolist  [label="repolist.rst", shape=box];
193    release -> releaserepolist;
194    releaserepolist -> repnamedocsdirindex [style=dashed, label="sphinx\ntoctree\nreference"];
195  
196    }
197
198 Creating Restructured Text
199 ==========================
200
201 Templates and Examples
202 ----------------------
203 Some templates are available that capture the kinds of information
204 useful for different types of projects and provide simple examples of 
205 restructured text.
206 You can: browse the templates below; show source to look at the Restructured
207 Text and Sphinx directives used; and then copy the source either from a browser window
208 or by downloading the file in raw form from
209 the `gerrit doc repository <https://gerrit.onap.org/r/gitweb?p=doc.git;a=tree;f=docs/templates;/>`_.
210
211 .. toctree::
212    :maxdepth: 1
213    :glob:
214
215    ../../../templates/**/index
216
217 In addition to these simple templates and examples 
218 there are many open source projects (e.g. Open Daylight, Open Stack)
219 that are using Sphinx and Readthedocs where you may find examples to start with.
220 Working with project teams we will continue to enhance templates here and
221 capture frequently asked questions on the developer wiki question 
222 topic `documentation <https://wiki.onap.org/questions/topics/16384055/documentation>`_.
223
224 Each project should: decide what is relevant content; determine the
225 best way to create/maintain it in a CI/CD process; and work with the
226 documentation team to reference content from the master index and guides.
227 Consider options including filling in a template, 
228 identifying existing content that can be used as is or
229 easily converted, and use of Sphinx directives/extensions to automatically
230 generate restructured text from other source you already have.
231
232 Links and References
233 --------------------
234 It's pretty common to want to reference another location in the
235 ONAP documentation and it's pretty easy to do with
236 reStructuredText. This is a quick primer, more information is in the
237 `Sphinx section on Cross-referencing arbitrary locations
238 <http://www.sphinx-doc.org/en/stable/markup/inline.html#ref-role>`_.
239
240 Within a single document, you can reference another section simply by::
241
242    This is a reference to `The title of a section`_
243
244 Assuming that somewhere else in the same file there a is a section
245 title something like::
246
247    The title of a section
248    ^^^^^^^^^^^^^^^^^^^^^^
249
250 It's typically better to use ``:ref:`` syntax and labels to provide
251 links as they work across files and are resilient to sections being
252 renamed. First, you need to create a label something like::
253
254    .. _a-label:
255
256    The title of a section
257    ^^^^^^^^^^^^^^^^^^^^^^
258
259 .. note:: The underscore (_) before the label is required.
260
261 Then you can reference the section anywhere by simply doing::
262
263     This is a reference to :ref:`a-label`
264
265 or::
266
267     This is a reference to :ref:`a section I really liked <a-label>`
268
269 .. note:: When using ``:ref:``-style links, you don't need a trailing
270           underscore (_).
271
272 Because the labels have to be unique, it usually makes sense to prefix
273 the labels with the project name to help share the label space, e.g.,
274 ``sfc-user-guide`` instead of just ``user-guide``.
275
276 Testing
277 =======
278
279 One RST File
280 ------------
281 It is recommended that all rst content is validated by `doc8 <https://pypi.python.org/pypi/doc8>`_ standards.
282 To validate your rst files using doc8, install doc8.
283
284 .. code-block:: bash
285
286    sudo pip install doc8
287
288 doc8 can now be used to check the rst files. Execute as,
289
290 .. code-block:: bash
291
292    doc8 --ignore D000,D001 <file>
293
294
295
296 One Project
297 -----------
298 To test how the documentation renders in HTML, follow these steps:
299
300 Install virtual environment.
301
302 .. code-block:: bash
303
304    sudo pip install virtualenv
305    cd /local/repo/path/to/project
306
307 Download the doc repository.
308
309 .. code-block:: bash
310
311    git clone http://gerrit.onap.org/r/doc
312
313 Change directory to doc & install requirements.
314
315 .. code-block:: bash
316
317    cd doc
318    sudo pip install -r etc/requirements.txt
319
320 Move the conf.py file to your project folder where RST files have been kept:
321
322 .. code-block:: bash
323
324    mv doc/docs/conf.py <path-to-your-folder>/
325
326 Move the static files to your project folder:
327
328 .. code-block:: bash
329
330    mv docs/_static/ <path-to-your-folder>/
331
332 Build the documentation from within your project folder:
333
334 .. code-block:: bash
335
336    sphinx-build -b html <path-to-your-folder> <path-to-output-folder>
337
338 Your documentation shall be built as HTML inside the
339 specified output folder directory.
340
341 .. note:: Be sure to remove the `conf.py`, the static/ files and the output folder from the `<project>/docs/`. This is for testing only. Only commit the rst files and related content.
342
343
344 All Documentation
345 -----------------
346 To build the whole documentation under doc/, follow these steps:
347
348 Install virtual environment.
349
350 .. code-block:: bash
351
352    sudo pip install virtualenv
353    cd /local/repo/path/to/project
354
355 Download the DOC repository.
356
357 .. code-block:: bash
358
359    git clone http://gerrit.onap.org/r/doc
360
361 Change directory to docs & install requirements.
362
363 .. code-block:: bash
364
365    cd doc
366    sudo pip install -r etc/requirements.txt
367
368 Update submodules, build documentation using tox & then open using any browser.
369
370 .. code-block:: bash
371
372    cd doc
373    git submodule update --init
374    tox -edocs
375    firefox docs/_build/html/index.html
376
377 .. note:: Make sure to run `tox -edocs` and not just `tox`.
378
379
380