Scott's Weblog The weblog of an IT pro focusing on cloud computing, Kubernetes, Linux, containers, and networking

Validating RAML Files Using Docker

Back in July of this year I introduced Polyglot, a project whose only purpose is to provide a means for me to learn more about software development and programming (areas where am I sorely lacking real knowledge). In the limited spare time I’ve had to work on Polyglot in the ensuing months, I’ve been building out an API specification using RAML, and in this post I’ll share how I use Docker and a Docker image to validate my RAML files.

Since I was (am) using Visual Studio Code as my primary text editor/development environment these days, I started out by looking for a RAML extension that would provide some sort of linting/validation functionality. I found an extension to do RAML syntax highlighting, which seemed like a reasonable first step.

After a bit more research, I found that there was a raml-cli NPM package that one could use to validate RAML files from the command line. I was a bit leery of installing an NPM package on my system, so I thought, “Why not use a Docker container for this?” It will keep my system clean of excess/unnecessary packages and dependencies, and it will provide some practice with building Docker containers.

A bit of work later I had this Dockerfile (which you can find in my “dockerfiles” GitHub repository):

FROM node:6.14.3-alpine

LABEL maintainer "Scott Lowe <scott.lowe@scottlowe.org>"

RUN apk add --no-cache git && \
    rm -rf /var/cache/apk/*

RUN npm install -qg raml-cli && \
    npm cache clean

RUN mkdir -p /data
VOLUME /data
WORKDIR /data

ENTRYPOINT ["raml"]

CMD ["--help"]

Feeding this to docker build results in an image of about 196MB in size, which isn’t too shabby (I’d like to continue to try to shave this down even further). With this image, I can now easily validate RAML files:

docker run --rm -v $(pwd):/data raml-cli:0.1 validate orders-api.raml

And, of course, I could make this even easier with a Bash alias:

alias raml-cli="docker run --rm -v $(pwd):/data raml-cli:0.1"

Using the alias means I can now simply run raml-cli validate <filename.raml>. This makes it very easy for me to validate the RAML specifications I’m writing.

In the event others may find this helpful, the Dockerfile is on GitHub in my “dockerfiles” repository, and I’ve pushed the Docker image to Docker Hub for anyone to pull down.

Metadata and Navigation

Be social and share this post!