BookmarkSubscribeRSS Feed

SAS Administration CLI - using Alpine as a base Docker image

Started ‎08-28-2020 by
Modified ‎08-28-2020 by
Views 2,106

Introduction

 

I was inspired by this article about containerizing the sas administration command-line interface (CLI), written by Gerry Nelson. In his article, he explains the reasons why you would want to containerize the command-line interface.  One of the reasons he mentions is that when you have the CLI containerized, you can automate the export and import of content between Viya environments. And that’s exactly what I set out to do. I wanted to build a container that would contain the tools I needed to export and import my content between Viya environments.

 

But I wanted to keep the container as small as possible. That's why I ended up selecting alpine as my base image

 

Why Alpine

 

Alpine is the official base image that Docker is using in their image library when they switched from Ubuntu in 2016. And as Alpine put it themselves on their website.

 

Small. Simple. Secure.

Alpine Linux is a security-oriented, lightweight Linux distribution based on musl libc and busybox.

 

Size

 

One of the biggest drivers of using Alpine as a base image is its size. The current size of the Alpine base image is about 5.57 MB. If you compare that to the size of a centos 8 image which is about 217 MB, then the difference between the two of them is huge. The centos 8 base image is about 40 times bigger than the Alpine base image.

 

So why does the size of the image matter? Well it matters because:

 

  • Startup time of your application is much faster. When the image is pulled fresh from the repository, an Alpine based image will be up and running much faster than a centos image because it needs to pull less MB.
  • If you host a container registry on the cloud and you pay for data that goes out of your cloud environment, then all of a sudden, the number of bytes transferred becomes interesting.
  • If you want to make updates to your application, it's easier if the size of the image is small. You just download the latest version of your image, make your updates and then push it back to the registry. If you have an image that is quite large then this whole process will take more time.

Secure

 

It’s built with security in mind. It has a smaller base set of packages. Which means that there are less things included in the base image that could have vulnerabilities. Non-essential packages are not installed by default.

 

Building the container

 

I ended up putting the following tools in my container

 

  • sas-administration-cli:  to transfer content between my Viya environments by creating packages
  • sas-model-repository-cli: to query SAS Model Manager
  • curl: to interact with some of the Viya REST API’s
  • jQuery: to process the responses from the Viya REST API, like for example to filter out an ID

If you want to use this container in your own environment, please follow these steps to build the docker image

 

  1. Download the sas administration cli from here
  2. Download the sas-model-repository from here
  3. Create a directory called sas-admin-container
  4. Move the tgz files you downloaded in step 1 and 2 into this directory
  5. Create the Dockerfile in this directory based on the content
  6. Run the following command to build the image: docker build . -t sas-admin-container

Dockerfile

FROM alpine

RUN apk update \
    && apk add libpq jq curl \
    && apk --no-cache add ca-certificates wget \
    && wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub \
    && wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk \
    && apk add glibc-2.30-r0.apk \
    && rm glibc-2.30-r0.apk

COPY sas-*.tgz /tmp/

RUN mkdir -p /tmp/utilities \
    && tar -xvf /tmp/sas-admin-cli-1.2.11-linux-amd64.tgz -C /tmp/utilities \
    && mv /tmp/utilities/bin/sas-admin /usr/local/bin \
    && rm -Rf /tmp/utilities \
    && tar -xvf /tmp/sas-mmmodelpublish-cli-1.1.6-linux.tgz -C /usr/local/bin \
    && tar -xvf /tmp/sas-mmmodelrepository-cli-1.1.6-linux.tgz -C /usr/local/bin \
    && chmod +x /usr/local/bin/sas* \
    && rm -f /tmp/sas-*

RUN addgroup -S sas --gid 1001 && adduser -S sas -G sas --uid 1000

USER sas

 

Start the container

 

You should now have an image available that contains the list of tools that was mentioned previously. To start the container, run this command

 

docker run --name sas-tools -d -it sas-admin-container

 

This will start the container. Once started you can access the container via the following command

 

docker exec -it sas-tools /bin/sh

 

Using the sas-admin-cli

 

To use the sas-admin cli we need to configure some environment variables and then logon to the Viya environment via a command.

export VIYA_SERVER_URL=<hostname>
export VIYA_USER=<username>
export VIYA_PASSWORD=<password>
export SAS_SERVICES_ENDPOINT=http://$VIYA_SERVER_URL

sas-admin auth login -u $VIYA_USER -p $VIYA_PASSWORD

 

Now that we are connected to the VIya environment we can install some plugins we can use to import / export packages.

 

sas-admin plugins enable-default-repo
sas-admin plugins install --repo SAS transfer
sas-admin plugins install --repo SAS folders​

 

Conclusion

 

There you have it. We have just created a container that uses Alpine as a base image and contains the sas-admin and the sas-model-repository command line interface and some other tools that can be of use to move content between environments. The result is a container that is smaller than the centos 8 base image. I’m interested in hearing your thoughts about your experiences with automating the export and import of content between Viya environments. Do you have any tools that you use which I didn't add to the container?

 

Let me know in the comments!

Version history
Last update:
‎08-28-2020 04:57 AM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags