Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Asciidoctor on OpenShift

<p>&nbsp;</p> <quillbot-extension-portal></quillbot-extension-portal>

May 12, 2015
Samuel Mendenhall
Related topics:
DevOpsKubernetes
Related products:
Red Hat OpenShift Container Platform

    Asciidoctor encompasses and builds an ecosystem around Asciidoc for writing documentation, and well, writing anything.   If you want to host your own blog, documentation site, book, ect.., Asciidoctor would be an excellent choice.  If you want to do that in OpenShift, that is what I'm going to help you with.

    Getting Started

    Create a Sinatra ruby gear or on the command line.

    rhc app create mydocs sinatra ruby-2.0

    The current sinatra-example is geared for ruby 1.9 current, https://github.com/openshift/. It could be modified to work with 2.0 but I will focus on 1.9 here.

    rhc app create mydocs ruby-1.9 --from-code https://github.com/openshift/sinatra-example.git

    You may or may not need to clone the project, it should auto-clone it unless there was a timeout.

    rhc git-clone mydocs
    cd mydocs
    

    Set your environment up so the bundler won't install dev dependencies.

    rhc env set BUNDLE_WITHOUT=development -a mydocs

    This gives us a base Sinatra project to work with. Now let's add Asciidoctor to the mix.

    Configure Ruby for Asciidoctor

    Add the Asciidoctor gem and development gems to bundler and bundle. Your Gemfile should look like:

    source 'https://rubygems.org'
    
    gem 'sinatra'
    gem 'asciidoctor'
    
    group :development do
        gem 'guard'
        gem 'guard-shell'
        gem 'guard-livereload'
    end

    Now Install those new gems, this will also trigger a new bundle install when you push since the Gemfile.lock will change.

    bundle install

    Write an Asciidoc file

    Create a folder for your Asciidoc files, let's call it adocs.

    mkdir adocs

    Create an adocs/index.adoc, open it up and paste in:

    = Introduction
    :linkcss:
    :toc: left
    
    Welcome to my documentation!
    
    == Heading 1
    
    === Sub Heading 1
    
    == Heading 2
    
    === Sub Heading 1
    
    === Sub Heading 2
    

    Development and LiveReload

    Create a Guardfile in the project root. The :safe => :unsafe is for the injection of asciidoctor.css into the html. This Guardfile will watch for changes to the index.adoc and compile it to the public dir.

    require 'asciidoctor'
    
    guard 'shell' do
      watch(/^adocs/index.adoc$/) {|m|
      Asciidoctor.convert_file(m[0], :to_dir => "public", :safe => :unsafe)
    }
    end
    
    guard 'livereload' do
      watch(%r{^public/.+.(css|js|html)$})
    end
    

    Add public/index.html and public/asciidoctor.css to .gitignore as Asciidoctor will be invoked on push.  The benefit to this setup is your generated html will not pollute git, it will be generated on push.

    echo "public/index.html" >> .gitignore
    echo "public/asciidoctor.css" >> .gitignore
    

    Install the LiveReload browser extension then guard start http://asciidoctor.org/docs/editing-asciidoc-with-live-preview/

    guard start

    Click on the Live Reload icon in the browser, in the Guard console you should see:

    [1] guard(main)> 13:30:31 - INFO - Browser connected.

    Now you can live edit the index.adoc and see updates in the browser. You will need to navigate to the file in your browser. In my case I went to the url: file:///Users/smendenh/Projects/mydocs/public/index.html

    Production

    Add a .openshift/action_hooks/build file which will be responsible for invoking Asciidoctor to generate the html.

    mkdir -p .openshift/action_hooks
    vim .openshift/action_hooks/build
    
    #!/bin/bash
    
    pushd $OPENSHIFT_REPO_DIR > /dev/null
    bundle install --path ./vendor/bundle --without development
    bundle exec ruby -C${OPENSHIFT_REPO_DIR} -rasciidoctor -e "Asciidoctor.convert_file('adocs/index.adoc', :to_dir => 'public', :safe => :unsafe)"
    popd > /dev/null
    

    Test it out!

    Edit the adocs/index.adoc file, change anything.

    git commit -a -m "Simple update"
    git push
    

    Wait for the push to finish then hit the openshift url for your gear in the browser and see your changes.

    Other ideas for Asciidoctor on OpenShift

    You can use Asciidoctor in many languages, be it Java, Ruby, Javascript, ect...   Hooking in Asciidoctor to the Sinatra gear was simple and straight forward, the documentation on the Asciidoctor.org site was a fantastic help.  There is around a 30 second delay in git push, that is minor, but if you wanted an even faster means of hosting an Asciidoctor based OpenShift gear you could use the Nginx gear and push the generated html.  I've done that, and it is incredibly fast to push to and update.

    Last updated: May 29, 2023

    Recent Posts

    • Red Hat Enterprise Linux 10.2 and 9.8: Top features for developers

    • What GPU kernels mean for your distributed inference

    • Debugging image mode with Red Hat OpenShift 4.20: A practical guide

    • EvalHub: Because "looks good to me" isn't a benchmark

    • SQL Server HA on RHEL: Meet Pacemaker HA Agent v2 (tech preview)

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.