Maintaining Open Source Singularity Since 2017
Using Singularity Container Services Registry for CI/CD Workflows
By Adam Hughes
Introduction
CI/CD Workflow Example Overview
.gitlab-ci.yml file:.gitlab-ci.yml file:mkdir demo
touch .gitlab-ci.yml
.gitlab-ci.yml file. The cache segment determines which directory retains its content across stages. This directory serves as our workspace:cache:
- paths:
- example
stages:
- prepare
- test
- build
- singularity-prepare
- build-image-and-push
prepare:
stage: prepare
image: alpine:3.18.0
script:
- rm -rf example
- apk update && apk add git
- git clone https://github.com/golang/example
test:
stage: test
image: golang:1.20-alpine
script:
- ls -la
- cd example/hello && go test
build:
stage: build
image: golang:1.20-alpine
script:
- cd example/hello && go build
$SINGULARITY_TOKEN with the token as its value. Follow these steps:
singularity-prepare:
stage: singularity-prepare
image: almalinux:9
script:
- dnf install -y epel-release && dnf install -y singularity-ce
- echo $SINGULARITY_TOKEN>/tmp/token && singularity remote login --tokenfile /tmp/token && rm /tmp/token
- singularity remote get-login-password > example/dockerlogin
The final stage assembles the OCI image using Docker, auto-calculates the image’s tag, and ultimately pushes the image to SCS:
build-image-and-push:
stage: build-image-and-push
image: docker:latest
services:
- docker:dind
before_script:
- cat example/dockerlogin | docker login -u "USERNAME" --password-stdin registry.sylabs.io
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag="latest"
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag=":$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- docker build --pull -t "registry.sylabs.io/USERNAME/hello:${tag}" .
- docker push "registry.sylabs.io/USERNAME/hello:${tag}"
after_script:
- rm example/dockerlogin
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile
Join Our Mailing List
Recent Posts
Related Posts
Ensuring Singularity Enterprise Continuity: Crafting a Disaster Recovery Plan
In the dynamic world of IT operations, disaster recovery procedures stand as the secret weapon, quietly ensuring the resilience and continuity of businesses. Whether it's a natural disaster, a cyberattack, or a hardware failure, having a robust disaster recovery plan...
Remote Building with OCI Registries
This blog post will demonstrate how to use a definition file in a remote build that references an Open Container Initiative (OCI) image stored in Singularity Enterprise and Singularity Container Services.First, create an account in Singularity Container Service. To do...
SingularityCE and PRO 4.1: Embracing Compatibility with Dockerfiles
Introduction In the ever-evolving landscape of containerization, where innovation thrives and technological boundaries are pushed, adaptability is key. The ability to seamlessly integrate diverse technologies not only fosters a collaborative ecosystem but also...