OPENSHIFT

Hugo Blog on OpenShift

#go , #hugo , #blog , #asciidoc , #asciidoctor

  1. Create a Dockerfile that adds all the dependencies your environment needs. A lot of the work is in this Dockerfile. I used asciidocs, so I needed an implementation of either asciidoc or asciidoctor, the two options that Hugo provides integration with. I chose asciidoctor.

$ cat Dockerfile
FROM centos:centos7

COPY . /opt/blog

RUN cd /opt \
  && curl -O -J -L https://github.com/gohugoio/hugo/releases/download/v0.40.3/hugo_0.40.3_Linux-64bit.tar.gz \
  && tar -xf hugo_0.40.3_Linux-64bit.tar.gz \
  && rm hugo_0.40.3_Linux-64bit.tar.gz \
  && yum -y install ruby \
  && yum clean all \
  && rm -rf /var/cache/yum \
  && gem install asciidoctor --no-user-install

EXPOSE 1313

WORKDIR /opt/blog

CMD ["/opt/hugo","server","--bind","0.0.0.0"]
  1. Create a project in openshift if needed.

    $ oc new-project my-blog
  2. Provide authorization to build containers using root access, because we are building this image from the upstream centos distribution. You might have to request this from your system admin if you do not have access to execute this command. By default, there are three sa or serviceaccounts in each project: builder, deployer, and default. You will only need root to build the image, but it can deploy and run as anyone. This is better security practice. Best security practice would be to derive this image from a secured image on Red Hat’s repository. Perhaps we’ll do that later.

    $ oc adm policy add-scc-to-user anyuid -z builder -n my-blog

See notes here:

How build from GitHub:

  1. Generate a new build config

    $ oc new-build --strategy docker https://github.com/briantward/blog --name btw-blog-blue
  2. Create a new deployment from this build config

    $ oc new-app btw-blog-blue
  3. Edit your route to point to the new service

    $ oc edit route btw-blog
  4. Make changes, commit to GitHub, then start a new build from your latest changes:

    $ oc start-build btw-blog-blue

Update for trigger from GitHub. Find URL from buildConfig: "Webhook GitHub: URL: ". Add this URL to your WebHook in GitHub and make sure to choose content type "application/json". It defaults to "application/x-www-form-urlencoded" and OpenShift doesn’t like that format.

$ oc describe bc/btw-blog-blue