BookmarkSubscribeRSS Feed

SAS administration command-line interface in a container: Part 1 Docker

Started ‎07-22-2020 by
Modified ‎08-18-2020 by
Views 4,399

In this post we will create a container image that contains the SAS administration command line interface.  We will build a container image to show how this can be done and then run some Viya tasks using the container. Initially, the container will be run using Docker. A follow up post takes the container and run it in a Viya 4 kubernetes cluster to do some more advanced processing.

 

Why?

 

Having the sas-admin command-line interface, and other administration tools in a container has a number of benefits. We get all the benefits of containerization for our administration clients:

 

  • standardized packaging: the container will include the sas-admin cli, all the plug-ins and any related software.
  • better version control: we can have multiple versions of the cli and the plugins all running on the same system. We can tag different versions different ways so that it is clear what version is being used.
  • consistency in runtime environment: When the cli is runs from the container the environment will always be the same. No need to worry about interactions with other software or missing pieces that are required.
  • scalability: as we will see later when we start run on Kubernetes we can execute many container based cli processes sequentially or in parallel in a cluster.

 

A containerized cli could be used to automate:

  • initialization of a new Viya environment
  • export and import of content between Viya environments
  • loading and unloading of data
  • testing of functionality and performance.

 

I am sure you can think of many more. Let's see how we do it. Firstly, a really quick review of some docker terminology. Docker images are the basis of containers.  An image typically contains a union of layered file systems stacked on top of each other. A container is a runtime instance of a docker image. A  Dockerfile is used to build a docker image. In this post we will step through the process:

 

  1. Create a Dockerfile that defines our container image
  2. Build the container image from the contents of the DockerFile
  3. Run the container and perform some processing in Viya

 

Create a DockerFile

 

The docker file we will use to create our own custom Docker image for the sas-admin cli is shown below. This file contains all the commands you would normally execute manually in order to build a Docker image. When you build an image docker reads the instructions from a docker file.  They key instructions in the file are:

 

The FROM instruction usually starts the dockerfile and defines the base image on which your new image is built. Most of the time you will start from an existing docker image and build on top of it. Here we start from the Centos:7 image.

 

The RUN instruction will execute commands in a new layer on top of the current image and commit the results. The first block of RUN commands layers the required software on top of the base image. Included in this we install pyviyatools from github.

 

The ADD and COPY commands are similar and are used to copy files/directories into a Docker image. The main difference is ADD allows the source to be a URL. The adds add the sas-admin executable the COPY includes a script that will run when the image is built to install all the available sas-admin plugins. You can see the script in a prior post on keeping the cli current. This sets the user that is used when running the container.  

 

GN_containers_admincli_01_new.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

Build the container image

 

With the DockerFile defined use the build command, passing the filename to build the image. The -t tags the image with the name provided.

 

docker build . -f sasadmincli.Dockerfile -t sasadmincli:v01

 

The first time the build is run it will take some time, subsequent builds will be quicker as docker caches the layers. As the build process runs the result of each step will be displayed (partial output below)  

 

containers_admincli_02.png

 

Using the sas-admin cli container image

 

Now we can use docker container run to run the sas-admin cli. Firstly, as a test lets just look at the plug-ins that are available. This will prove that our container works and can run a sas-admin cli command.

 

 
docker container run -it sasadmincli:v01 ./sas-admin plugins list

 

containers_admincli_03.png

 

The sas-admin cli requires two prerequisites to run, a profile which defines what Viya system to access, and it requires that the user authenticate. You can create a profile and authenticate using the sas-admin cli. The process creates two files one containing the endpoint you want to connect to, and another containing an authentication token.

 

When running the container, instead of having to authenticate with every execution we will share the token and profile from the host into the container. We will use a docker volume to mount the profile (config.json) and the credentials file (credentials.json) from the host machine to the location that the cli expects them to be located in the container (the users home-directory). With that information made available we can use the container to run  sas-admin cli commands. As an example this one list all the groups defined in the system.

 

The docker run command below uses the following parameters.

  • -it runs in an interactive terminal
  • -v mounts a directory or a file
  • -e sets an environment variable in the container (the variable tells the CLI what profile to use)
  • sasadmincli:v01 is the container image
 
docker container run -it \
-v /home/cloud-user/.sas/config.json:/home/sas/.sas/config.json \
-v /home/cloud-user/.sas/credentials.json:/home/sas/.sas/credentials.json \
-e SAS_CLI_PROFILE=gelcorp sasadmincli:v01 ./sas-admin --output text identities list-groups
 
 

In addition to single commands we can use the container to execute whole scripts that do more complex processing.  For example, to execute a script that loads data to CAS and sets authorization on the loaded data the docker run is  modified to share the script from, for an nfs mount, into the container.

 

docker container run -it \
-v /shared/gelcontent:/gelcontent \
-v /home/cloud-user/.sas/config.json:/home/sas/.sas/config.json \
-v /home/cloud-user/.sas/credentials.json:/home/sas/.sas/credentials.json \
sasadmincli:v01 sh /gelcontent/gelcorp/initenv/scripts/01-load_data.sh
 

 

At this point the image is running in Docker on my local machine. To make it available generally it needs to be pushed to a Docker registry. A Docker registry is a storage and content delivery system, holding named Docker images, available in different tagged versions. To push our sas-admincli image  to the registry tag the image with a tag that includes the registry name and use the docker image push command.

 
REGISTRY_NAME=myregistry.test.com
IMAGE_TAG=$REGISTRY_NAME/admin-toolkit/sasadmincli:v01
docker tag sasadmincli:v01 $IMAGE_TAG
docker image push $IMAGE_TAG

 

Now to use the image you can use the docker pull command.

 

docker pull myregistry.test.com/admin-toolkit/sasadmincli:v01
docker tag myregistry.test.com/admin-toolkit/sasadmincli:v01 sasadmincli:v01
docker container run -it sasadmincli:v01 ./sas-admin plugins list

 

In this post we have looked at how to build and run a container that will perform sas-admin cli processing. In my next post I will take this approach a few steps further, the additional steps will really show the power of using an administration container as we start to use the functionality with Viya 2020 on a Kubernetes cluster.

 

Search for more content from our group: SAS Global Enablement & Learning.

Comments

Hi Gerry,

 

You mention this is functionality with Viya 2020 - so SAS Viya 4.0? Please confirm.

Is this also available in SAS Viya 3.x?

 

Thanks,
Michelle

Hi Michelle,

 

Yes Viya 4, that is correct.

 

The technique in this post of building the image and running the CLI in a container will work for Viya 3.x or Viya 4. 

Hope that helps.

Gerry

Thanks Gerry - this helps!

Hi Gerry,

 

for Viya4 will the sas-admin tool be available for download without signing in & accepting the agreement as per the current one for Viya3.x ? I see in your code above the tool (in the ADD line) is directly available rather than being extracted from a .tgz (albeit from an internal SAS location I presume?)

 

I see an update has been made this month to the current CLI (now v1.3.6) - are the updates to this published elsewhere in a similar way to Hot Fixes?

 

regards

 

Alan

Hi Alan,

 

I believe there are plans to make the Viya 4 cli available in more convenient ways (as a SAS provided container and possibly from common package managers). When/if that happens I will update this post to reflect the changes. Incidentally, the Viya 4 cli will be sas-viya not sas-admin.

 

I don't think we publish the actual changes that are made anywhere. I think that would be very useful. I will request that feature be added.

 

Gerry

 

Version history
Last update:
‎08-18-2020 03:58 PM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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