Skip to content

Commit 5ab966d

Browse files
committed
gendocs: generate image ENV var documentation
gendocs.py is a rudimentary Python script that operates on the output of a cekit build (including a dry-run) and generates AsciiDoc Environment-variable documentation for the image. gendocs.sh is a harness to invoke gendocs.py for every image and version we care about: it switches to different git branches and tags, collects the image descriptors and runs gendocs.py. Add a GitHub workflow to invoke gendocs.sh and upload the results to GitHub Pages. Trigger on pushes to the ubi8 or ubi9 branches, or a tag matching the pattern for releases. Signed-off-by: Jonathan Dowland <[email protected]>
1 parent c8f342b commit 5ab966d

File tree

4 files changed

+203
-0
lines changed

4 files changed

+203
-0
lines changed

.github/workflows/gendocs.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Generate docs for OpenJDK images
2+
on:
3+
push:
4+
branches:
5+
- 'ubi8'
6+
- 'ubi9'
7+
- 'gendocs'
8+
tags:
9+
- 'ubi?-openjdk-containers*'
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
concurrency:
17+
group: "pages"
18+
cancel-in-progress: false
19+
20+
jobs:
21+
gendocs:
22+
name: Generate documentation
23+
runs-on: ubuntu-20.04
24+
strategy:
25+
fail-fast: false
26+
steps:
27+
- uses: actions/checkout@v2
28+
with:
29+
fetch-depth: 0 # all branches and tags
30+
31+
- name: Install CEKit
32+
uses: cekit/[email protected]
33+
34+
- name: Setup required packages for docs
35+
run: |
36+
sudo apt-get update
37+
sudo apt-get install -y asciidoctor
38+
39+
- name: Generate docs
40+
run: |
41+
./gendocs.sh
42+
43+
- name: Setup Pages
44+
uses: actions/configure-pages@v3
45+
46+
- name: Upload artifact
47+
uses: actions/upload-pages-artifact@v1
48+
with:
49+
path: 'docs'
50+
51+
- name: Deploy to GitHub Pages
52+
id: deployment
53+
uses: actions/deploy-pages@v2

docs/README.adoc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Red Hat UBI OpenJDK container images
2+
3+
This is auto-generated documentation for the
4+
link:https://www.redhat.com/en/blog/introducing-red-hat-universal-base-image[Red
5+
Hat Universal Base Image] (UBI) OpenJDK container images.
6+
7+
* link:https://github.com/jboss-container-images/openjdk[container image source repository]
8+
9+
Container images are available from the
10+
link:https://catalog.redhat.com/software/containers/explore[Red Hat Ecosystem
11+
Catalog].
12+
13+
The documentation lists the environment variables that are available for
14+
configuring the behavior of the images.
15+
16+
Documentation is available for the development branches (UBI8, UBI9) and all
17+
tagged releases.

gendocs.py

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env python3
2+
3+
# read in all the module YAML files specified for an image, in order, to
4+
# produce a comprehensive list of configuration environment variables,
5+
# then write them out to something useful
6+
7+
import yaml
8+
import sys
9+
10+
def getvars():
11+
y = yaml.safe_load(open("target/image.yaml","r"))
12+
es = {}
13+
14+
for mobj in y['modules']['install']:
15+
mname = mobj['name']
16+
mf = open("target/image/modules/{}/module.yaml".format(mname))
17+
my = yaml.safe_load(mf)
18+
for h in my['envs']:
19+
es[h['name']] = h
20+
21+
es2 = list(es.values())
22+
es2.sort(key=(lambda h: h['name']))
23+
return es2
24+
25+
def adocpreamble(title):
26+
print("= {}".format(title))
27+
print("Jonathan Dowland <[email protected]>")
28+
print(":toc:")
29+
print()
30+
31+
def adoctable(es,ty,test, field):
32+
print("== {} variables".format(ty))
33+
print(".Table {} variables".format(ty))
34+
print("|===")
35+
print("|Name |{}{} |Description".format(field[0].upper(),field[1:]))
36+
for h in es:
37+
if test(h):
38+
print("|{}".format(h['name']))
39+
print("|`{}`".format(h.get(field,'-')))
40+
print("|{}".format(h.get('description','-')))
41+
print("|===")
42+
print()
43+
44+
def main(title):
45+
es = getvars()
46+
adocpreamble(title)
47+
adoctable(es,"Informational",lambda h: 'value' in h, 'value')
48+
adoctable(es,"Configuration",lambda h: 'value' not in h, 'example')
49+
50+
if __name__ == "__main__":
51+
main(sys.argv[1])

gendocs.sh

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# This script arranges to call gendocs.py for each image descriptor we
5+
# wish to generate documentation for, by switching to the relevant git
6+
# branches and tags and enumerating the image descriptors.
7+
# It is expected that this script is invoked via GitHub Actions.
8+
9+
engine=${engine-podman}
10+
11+
die()
12+
{
13+
echo "$@"
14+
exit 1
15+
}
16+
17+
addToIndex()
18+
{
19+
echo -e "$@" >> "$workdir/README.adoc"
20+
}
21+
22+
# generate docs for a single image
23+
genImageDocs()
24+
{
25+
ref="$1" # e.g. ubi8
26+
input="$2" # e.g. ubi8-openjdk-11.yaml
27+
28+
name="$(awk '-F"' '/name: &name/ { print $2 }' "$input")"
29+
output="docs/$ref/${input/yaml/adoc}"
30+
31+
mkdir -p "$(dirname "$output")"
32+
cekit --descriptor "$input" build --dry-run "$engine"
33+
python3 "$workdir/gendocs.py" "$name" > "$output"
34+
asciidoctor "$output"
35+
36+
addToIndex "* link:$ref/${name/\//-}.html[$name]"
37+
}
38+
39+
# moves to the git ref, enumerates all images, calls
40+
# genImageDocs for each
41+
handleRef()
42+
{
43+
ref="$1"
44+
git checkout "$ref"
45+
for y in ubi?-*yaml; do
46+
genImageDocs "$ref" "$y"
47+
done
48+
}
49+
50+
##############################################################################
51+
52+
for dep in cekit python3 asciidoctor; do
53+
if ! which "$dep" >/dev/null; then
54+
die "$dep is required to execute this script"
55+
fi
56+
done
57+
58+
# This ensures the directory won't be purged when we switch refs
59+
mkdir -p docs
60+
touch docs/index.html
61+
62+
# backup files from this ref we need prior to switching git refs
63+
# (we don't bother with cleaning up workdir, GHA will do that for us)
64+
workdir="$(mktemp -td gendocs.XXXXXX)"
65+
cp ./gendocs.py "$workdir/gendocs.py"
66+
cp ./docs/README.adoc "$workdir/README.adoc"
67+
68+
# documentation for development branches
69+
addToIndex "\n== Development branches ==\n"
70+
for branch in ubi8 ubi9; do
71+
addToIndex "\n=== $branch ===\n"
72+
handleRef "$branch" "$branch"
73+
done
74+
75+
# documentation for tagged releases
76+
addToIndex "\n== Released images =="
77+
for tag in $(git tag -l 'ubi?-openjdk-containers*' | sort -r); do
78+
addToIndex "\n=== $tag ===\n"
79+
handleRef "$tag"
80+
done
81+
82+
asciidoctor "$workdir/README.adoc" -o docs/index.html

0 commit comments

Comments
 (0)