Skip to content

Commit 52dc753

Browse files
authored
Merge pull request #386 from jmtd/gendocs
gendocs: generate image ENV var documentation
2 parents c8f342b + 5c87528 commit 52dc753

File tree

4 files changed

+211
-0
lines changed

4 files changed

+211
-0
lines changed

.github/workflows/gendocs.yml

Lines changed: 53 additions & 0 deletions
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

Lines changed: 17 additions & 0 deletions
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

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
# Usage:
8+
# ./gendocs.py name-of-image > output-asciidoc-file
9+
#
10+
# This script reads target/image.yaml, which is produced by a cekit
11+
# build (including --dry-run)
12+
13+
import yaml
14+
import sys
15+
16+
def getvars():
17+
y = yaml.safe_load(open("target/image.yaml","r"))
18+
es = {}
19+
20+
for mobj in y['modules']['install']:
21+
mname = mobj['name']
22+
mf = open("target/image/modules/{}/module.yaml".format(mname))
23+
my = yaml.safe_load(mf)
24+
for h in my['envs']:
25+
es[h['name']] = h
26+
27+
es2 = list(es.values())
28+
es2.sort(key=(lambda h: h['name']))
29+
return es2
30+
31+
def adocpreamble(title):
32+
print("= {}".format(title))
33+
print("Jonathan Dowland <[email protected]>")
34+
print(":toc:")
35+
print()
36+
37+
def adoctable(es,ty,test, field):
38+
print("== {} variables".format(ty))
39+
print(".Table {} variables".format(ty))
40+
print("|===")
41+
print("|Name |{}{} |Description".format(field[0].upper(),field[1:]))
42+
for h in es:
43+
if test(h):
44+
print("|{}".format(h['name']))
45+
print("|`{}`".format(h.get(field,'-')))
46+
print("|{}".format(h.get('description','-')))
47+
print("|===")
48+
print()
49+
50+
def main(title):
51+
es = getvars()
52+
adocpreamble(title)
53+
adoctable(es,"Informational",lambda h: 'value' in h, 'value')
54+
adoctable(es,"Configuration",lambda h: 'value' not in h, 'example')
55+
56+
if __name__ == "__main__":
57+
main(sys.argv[1])

gendocs.sh

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

0 commit comments

Comments
 (0)