BookmarkSubscribeRSS Feed

Setting Up SAS Viya with GitLab CI/CD Pipelines: Step Three

Started 9 hours ago by
Modified 9 hours ago by
Views 52

Let's dive into crafting GitLab CI/CD pipelines tailored for SAS Viya. First, you established a GitLab Kubernetes runner. Next, you crafted a bespoke Docker image suited for your SAS Viya ecosystem and uploaded it to a secure, private GitLab container registry. Read this post to understand what a pipeline for SAS Viya looks like, what the different components are and how to put them all together.

 

Post Series

 

In this post series you will learn how to:

 

 

Video

 

Take a look at the following video, in which we demonstrate a GitLab CI/CD pipeline that runs a SAS program in SAS Viya.

 

 

GitLab CI/CD Pipeline

 
The pipeline is designed to submit a SAS program, which is stored in your Git repository, to SAS Viya for execution. This program's task is to load a table into memory within a caslib.

 

Begin by creating a .gitlab-ci.yml file in your repository's root directory:

 

default:
  image: $CI_REGISTRY/$GITLAB_USER_LOGIN/sasgitlabdevops/jass/gitlab-runner-sas:0.07

run-sas-program:
  stage: build
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"
    - echo "CI Registry $CI_REGISTRY"

    # test container folders
    - ls -la
    - ls -la /usr/local/bin

    # SAS Viya CLI
    - sas-viya plugins list

    # TLS Certificate location
    - export SSL_CERT_FILE=/usr/local/bin/gelenv_trustedcerts.pem
    - echo ${SSL_CERT_FILE}

    # SAS Viya CLI profile
    - sas-viya --profile dev profile set-endpoint $dev_endpoint
    - sas-viya --profile dev profile toggle-color on
    - sas-viya --profile dev profile set-output fulljson
    - sas-viya --profile dev profile show
    - sas-viya --profile dev auth login -user $dev_user -password $dev_passwd

    # SAS Viya CLI
    - echo Run a SAS program stored in Git
    - sas-viya --profile dev batch jobs submit-pgm --pgm-path 1.sas --context default  --watch-output --wait-log-list --results-dir ~/

 

Explanation

 

Image

 

default:
  image: $CI_REGISTRY/$GITLAB_USER_LOGIN/sasgitlabdevops/jass/gitlab-runner-sas:0.07

 

The configuration snippet you've provided is designed to pull a specific Docker image from your GitLab Container Registry for use in your CI/CD pipeline. This Docker image is the one you previously constructed for your SAS Viya environment.

 

Here's a breakdown of the image directive in your .gitlab-ci.yml file:

 

  • `default:` sets the default configuration for all jobs in the pipeline.
  • `image:` specifies the Docker image to use.
  • $CI_REGISTRY and $GITLAB_USER_LOGIN are placeholders for GitLab's predefined variables;
    • $CI_REGISTRY will become the URL of the GitLab registry, typically registry.gitlab.com.
    • $GITLAB_USER_LOGIN will be replaced with your GitLab username.

 

The complete image name, including the tag, will be resolved using these variables, ensuring that the correct image is used for the pipeline.

 

01_BT_800_GitLab_Docker_Image_from_Private_Registry-1024x309.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.

 

To learn more about building the Docker image, refer to the associated post.

 

Executor Pod

 

The pipeline runs. The Kubernetes runner initiates the execution. The runner creates a temporary Kubernetes executor pod from the pulled Docker image.

 

02_BT_800_GitLab_Kubernetes_Executor_Pod-1024x577.png

 

 

Stage, Job and Script

 

The basic bricks in a GitLab CI/CD pipeline are the stage, which contains jobs. The job contains scripts.

 

run-sas-program:
  stage: build
  script:
    - echo "Hello, $GITLAB_USER_LOGIN!"

 

Where:

 

  • run-sas-program job runs inside the build stage:
  • script: runs a series of shell scripts: printing variables, listing folders, etc.

 

SAS Viya CLI commands

 

  • List the plugins.
  • Initialize a variable needed by the SAS Viya CLI: the location of the SAS Viya TLS certificates. Recall from step two, we ‘baked in’ the certificate in the Docker image.
  • Create a SAS Viya profile using variables declared when we setup the GitLab runner.
  • Authenticate against SAS Viya (get an access token).
  • Submit a SAS program in batch.

 

    # SAS Viya CLI
    - sas-viya plugins list

    # TLS Certificate location
    - export SSL_CERT_FILE=/usr/local/bin/gelenv_trustedcerts.pem
    - echo ${SSL_CERT_FILE}

    # SAS Viya CLI profile
    - sas-viya --profile dev profile set-endpoint $dev_endpoint
    - sas-viya --profile dev profile toggle-color on
    - sas-viya --profile dev profile set-output fulljson
    - sas-viya --profile dev profile show
    - sas-viya --profile dev auth login -user $dev_user -password $dev_passwd
    - sas-viya --profile dev batch jobs submit-pgm --pgm-path 1.sas --context default --watch-output --wait-log-list --results-dir ~/ 

 

Notice the variables:

 

  • $dev_endpoint is the URL of our SAS Viya environment.
  • $dev_user is the SAS user executing the pipeline.
  • $dev_passwd is the credential for SAS Viya CLI authentication.

 

These are Project variables, defined under Settings > CI/CD > Variables in GitLab.

 

03_BT_800_GitLab_CI_CD_Variables-1024x504.png

 

From a security perspective you should mask sensitive variables, so that they can’t be printed by accident in a log.

 

04_BT_800_GitLab_CI_CD_Masked_Variables-1024x504.png

 

Finally, by using the SAS Viya CLI, you can submit the SAS program to be executed in SAS Viya.

 

 - sas-viya --profile dev batch jobs submit-pgm --pgm-path 1.sas --context default --watch-output --wait-log-list --results-dir ~/

 

05_BT_800_GitLab_CI_CD_Run_SAS_Program_Confirmation-1024x504.png

 

Ultimately, you should see the table successfully loaded in SAS Viya.

 

Conclusion

 

In conclusion, this post has walked you through setting up a GitLab CI/CD pipeline designed for SAS Viya, utilizing the Kubernetes runner established in the first step and a custom Docker image crafted in the second step. Looking ahead, we will delve into additional SAS Viya pipelines and various runner options. Thank you for following along!

 

Acknowledgements

 

Many thanks to Jan Kostrubiec @JanKostrubiec , Katarzyna Zuk @KatarzynaŻuk , Lars Arne Skår @larsarne , Neil Griffin

@Neil-Griffin , from whom I learned the most about DevOps with SAS Viya and GitLab.

 

Thank you for your time reading this post. If you liked the post, give it a thumbs up! Please comment and tell us what you think about having conversations with your data. If you wish to get more information, please write me an email.

 

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
9 hours ago
Updated by:
Contributors

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!

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