Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Asciidoctor on OpenShift

 

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

Share:

    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

    • Exploring Llama Stack with Python: Tool calling and agents

    • Enhance data security in OpenShift Data Foundation

    • AI meets containers: My first step into Podman AI Lab

    • Live migrating VMs with OpenShift Virtualization

    • Storage considerations for OpenShift Virtualization

    What’s up next?

     

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    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
    © 2025 Red Hat

    Red Hat legal and privacy links

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

    Report a website issue