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
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.
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:
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.
I ended up putting the following tools in my container
If you want to use this container in your own environment, please follow these steps to build the docker image
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
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
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
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!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.