Commit 688de08a authored by odatskov's avatar odatskov
Browse files

Backing up some debugging of api gets

parent b61d1280
Pipeline #456651 passed with stage
in 1 minute and 52 seconds
url: docker://cern/cc7-base:latest
descriptor: CC7-Dockerhub
description: CentOS7 image maintained by CERN
maintainer: cern-cc7@cern.ch
url: gitlab-registry.cern.ch/linuxsupport/cc7-base:latest
descriptor: CC7-Linuxsupport
description: CentOS7 image maintained by linux support
maintainer: linuxsupport@cern.ch
url: docker.io/ubuntu:latest
description: Ubuntu image from dockerHub
maintainer: ubuntu@awesome.mail.com
all:
clean:
rm -rf cvmfs
#!/bin/bash
# Docker Hub provides API v2 based on HTTP requests: https://docs.docker.com/registry/spec/api/#pulling-an-image
# Get the manifest from the repo
# Fetch the layers
# Unpack the structure
# Adjust permissions on the files
# Run singularity exec tests
#####################################
########## Global ###################
CVMFS_PATH="cvmfs/unpacked.cern.ch"
#####################################
LOG() {
#####################################
TST=`date +"%F %T"`
if [ "$1" == "error" ]; then STAT="[Error]"; STATC='\e[1;31m[Error]\e[0m'; TXT=$2;
else STAT=""; STATC=""; TXT=$@; fi
echo -e "\e[1;30m$TST\e[0m $STATC $TXT"
}
#####################################
PARSE_ARGS() {
#####################################
if [ $# -eq 1 ]; then
if [ ! -f $1 ]; then LOG "error" "Not a valid file path: $1. Exiting.."; exit 1;
else REPO_FILES=( $1 ); fi
elif [ $# -eq 0 ]; then REPO_FILES=( `ls ../*/*.yaml` );
else LOG "error" "Usage: $0 <repo file>"; exit 1; fi
if [ ${#REPO_FILES[*]} -eq 1 ]; then LOG "Syncing file: ${REPO_FILES[*]}";
else LOG "Discovered ${#REPO_FILES[*]} files"; fi
}
#####################################
GET_TOKEN() {
#####################################
DOCKER_TOKEN=".docker.token"
if [ "$1" == "docker" ]; then
if [ -f "$DOCKER_TOKEN" ]; then echo "Token file already exists."; fi
# Fetch token for the entire registry (if we can):
AUTH_DOCKER="https://auth.docker.io/token"
#AUTH_DOCKER="https://auth.docker.io/token?service=registry.docker.io&scope=repository:pull"
curl -i X GET $AUTH_DOCKER >> $DOCKER_TOKEN
fi
}
#####################################
FETCH_IMAGE() {
#####################################
EXP_NAME=`echo $1 | sed -e "s%/..%%" | awk -F'/' '{print $1}'`
IMAGE_REPO=`grep "url:" $1 | awk '{print $2}'`
IMAGE_CVMFS=`echo $IMAGE_REPO | sed -e "s%docker:/%docker.io% ; s%:%/%"`
LOG "Fetching manifest from $IMAGE_REPO"
if [[ ! $(echo $IMAGE_REPO | grep "docker://") == "" || ! $(echo $IMAGE_REPO | grep "docker.io/") == "" ]]; then
LOG "DockerHub repo with CVMFS target: $CVMFS_PATH/$EXP_NAME/$IMAGE_CVMFS"
# If the docker token file exists check whether it is expired or will expire in the next 2 minutes
#GET_TOKEN "docker"
elif [ $(echo $IMAGE_REPO | grep "gitlab-registry.cern.ch/") ]; then
LOG "GitLab repo with CVMFS target: $CVMFS_PATH/$EXP_NAME/$IMAGE_CVMFS"
fi
#curl -X ""
}
#####################################
SINGULARITY_TEST() {
#####################################
# Make sure that Singularity is available before trying the test
SPATH=`which singularity 2>&1`
if [ ! $? -eq 0 ]; then LOG "error" "Singularity not found. Exiting.."; exit 1 ;
else LOG "Singularity version found: $(singularity --version)"; fi
}
#####################################
########## Main #####################
PARSE_ARGS $*
# Create a test "cvmfs" location
if [ ! -d $CVMFS_PATH ]; then mkdir -p $CVMFS_PATH; LOG "Created $CVMFS_PATH folder."; fi
# For each file in the list fetch and unpack the image
for file in ${REPO_FILES[*]}; do
FETCH_IMAGE $file
done
# Functionality test for each synced image
SINGULARITY_TEST
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment