98 lines
4.0 KiB
YAML
98 lines
4.0 KiB
YAML
- name: Local documentation (DevDocs) limited to the languages of the contest
|
|
hosts: all
|
|
become: yes
|
|
vars:
|
|
# Documentation sets of the ICPC image: c, cpp, openjdk~25, python~3.11
|
|
# and kotlin~2.4. Kotlin is not a language of this contest.
|
|
contest_docs: [c, cpp, openjdk~25, python~3.11]
|
|
remove_docs: [kotlin~2.4]
|
|
image: localhost/devdocs:latest
|
|
|
|
tasks:
|
|
- name: Create the directory for offline contest help
|
|
file:
|
|
path: /usr/share/doc/acpc/help
|
|
state: directory
|
|
owner: root
|
|
group: root
|
|
mode: '0755'
|
|
|
|
- name: Install the approved offline help summaries
|
|
copy:
|
|
src: files/help/index.html
|
|
dest: /usr/share/doc/acpc/help/index.html
|
|
owner: root
|
|
group: root
|
|
mode: '0644'
|
|
|
|
- name: List the documentation sets of the DevDocs image
|
|
command: podman run --rm --entrypoint ls {{ image }} public/docs
|
|
register: docsets
|
|
changed_when: false
|
|
|
|
- name: Check that the contest languages are all there
|
|
assert:
|
|
that: item in docsets.stdout_lines
|
|
fail_msg: "DevDocs has no documentation for {{ item }}"
|
|
loop: "{{ contest_docs }}"
|
|
|
|
# DevDocs runs in a container created from the image at every boot, so
|
|
# the change is saved into the image (podman commit)
|
|
- name: Remove the other languages from the DevDocs image
|
|
when: remove_docs | intersect(docsets.stdout_lines) | length > 0
|
|
block:
|
|
- name: Stop the DevDocs service
|
|
systemd:
|
|
name: container-devdocs.service
|
|
state: stopped
|
|
|
|
- name: Start a container to change the image
|
|
shell: |
|
|
podman rm -f devdocs-build 2>/dev/null || true
|
|
podman run -d --name devdocs-build {{ image }}
|
|
|
|
- name: Remove the documentation sets and set the default list
|
|
shell: |
|
|
podman exec devdocs-build sh -c '
|
|
for slug in {{ remove_docs | join(" ") }}; do rm -rf "public/docs/$slug"; done
|
|
ruby -rjson -e "
|
|
f = %q{public/docs/docs.json}
|
|
data = JSON.parse(File.read(f))
|
|
data.reject! { |d| %w({{ remove_docs | join(" ") }}).include?(d[%q{slug}]) }
|
|
File.write(f, JSON.generate(data))"
|
|
sed -i "s|set :default_docs, %w(.*)|set :default_docs, %w({{ contest_docs | join(" ") }})|" lib/app.rb
|
|
grep -n "set :default_docs" lib/app.rb
|
|
# The compiled assets also hold the list of documentation sets
|
|
cd public/assets
|
|
ruby -rjson -e "
|
|
f = Dir[%q{docs-*.json}].first
|
|
data = JSON.parse(File.read(f))
|
|
data.reject! { |d| %w({{ remove_docs | join(" ") }}).include?(d[%q{slug}]) }
|
|
File.write(f, JSON.pretty_generate(data))
|
|
File.write(Dir[%q{docs-*.js}].reject { |x| x.end_with?(%q{.gz}) }.first, %q{app.DOCS=} + JSON.generate(data) + %q{;})"
|
|
# DevDocs warns when it is not served from devdocs.io (here https://devdocs/)
|
|
sed -i "s|production_host:\"devdocs.io\"|production_host:\"devdocs\"|" application-*.js
|
|
for f in docs-*.json docs-*.js application-*.js; do
|
|
case "$f" in *.gz) ;; *) gzip -kf "$f" ;; esac
|
|
done
|
|
grep -c kotlin docs-*.js docs-*.json | grep -v ".gz"'
|
|
|
|
|
|
- name: Save the change into the image
|
|
shell: |
|
|
podman stop devdocs-build
|
|
podman commit devdocs-build {{ image }}
|
|
podman rm -f devdocs-build
|
|
podman image prune -f
|
|
|
|
- name: Start the DevDocs service again
|
|
systemd:
|
|
name: container-devdocs.service
|
|
state: started
|
|
|
|
- name: Check the documentation sets of the image
|
|
command: podman run --rm --entrypoint ls {{ image }} public/docs
|
|
register: docsets_after
|
|
changed_when: false
|
|
failed_when: docsets_after.stdout_lines | difference(contest_docs + ['docs.json']) | length > 0
|