Skip to content
Snippets Groups Projects
Commit c8128575 authored by Christian Gumpert's avatar Christian Gumpert
Browse files

cleanup administrative scripts

parent 83280be0
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# configuration script to run at first boot via Openstack
# using the user_data and cloud-init.
echo "userdata running on hostname: $(uname -n)"
# install and setup CVMFS
yum-config-manager --add-repo http://cvmrepo.web.cern.ch/cvmrepo/yum/cvmfs/x86_64/
yum install -y --nogpgcheck cvmfs cvmfs-config-default
cat >> /etc/cvmfs/default.local << EOF
CVMFS_HTTP_PROXY='http://ca-proxy-meyrin.cern.ch:3128;http://ca-proxy.cern.ch:3128;http://ca01.cern.ch:3128|http://ca02.cern.ch:3128|http://ca03.cern.ch:3128|http://ca04.cern.ch:3128|http://ca05.cern.ch:3128|http://ca06.cern.ch:3128'
CVMFS_CACHE_BASE='/var/lib/cvmfs'
CVMFS_FORCE_SIGNING='yes'
CVMFS_REPOSITORIES='atlas-condb.cern.ch,atlas.cern.ch'
EOF
/usr/sbin/setenforce 0
cvmfs_config setup
cvmfs_config probe
# install gcc and g++
yum install -y gcc-4.4.7-16.el6.x86_64
yum install -y gcc-c++-4.4.7-16.el6.x86_64
# setup GitLab CI runner
yum-config-manager --add-repo http://linuxsoft.cern.ch/mirror/packages.gitlab.com/runner/gitlab-ci-multi-runner/el/6/x86_64/
yum install -y --nogpgcheck gitlab-ci-multi-runner
# set some missing links
ln -s /lib64/libuuid.so.1.3.0 /usr/lib64/libuuid.so
# set some environment variables
echo "export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase" >> /home/gitlab-runner/.bashrc
echo 'alias setupATLAS="source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh"' >> /home/gitlab-runner/.bashrc
#!/usr/bin/env python
#
# Helper script to setup a VM using the CERN opencloud service
# and initialise a GitLab CI Runner on it
#
# The shell profile needs to be configured according to
# http://clouddocs.web.cern.ch/clouddocs/tutorial/create_your_openstack_profile.html
import os
import tempfile
import shutil
import sys
import argparse
import logging
import subprocess
# Setup basic logging
logger = logging.getLogger('GLRunnerInit')
hdlr = logging.StreamHandler(sys.stdout)
frmt = logging.Formatter("%(name)s.%(funcName)s %(levelname)s %(message)s")
hdlr.setFormatter(frmt)
logger.addHandler(hdlr)
logger.setLevel(logging.INFO)
def main():
parser = argparse.ArgumentParser(description='Initialise a GitLab Runner',
epilog='Example',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('hostname', metavar='HOST',help='hostname of the created VM')
parser.add_argument('-f','--flavor',metavar='FLAVOR',default='m1.small',choices=['m1.tiny','m1.small','m1.medium','m1.large'],help='flavor of VM (check \'openstack flavor list\')')
parser.add_argument('-i','--image',metavar='IMAGE',default='8b082f2d-9728-4c3f-8440-cf110f03f745',help='boot image for VM (check \'openstack image list\')')
parser.add_argument('-k','--key',metavar='KEY',required=True,help='name of public-private key pair registered with openstack')
parser.add_argument('-n','--name',metavar='NAME',default='custom-runner',help='name of GitLab CI runner')
parser.add_argument('-t','--tags',metavar='TAGS',nargs='*',default=[],help='list of tags attached to the GitLab CI Runner')
parser.add_argument('-v','--debug',action="store_true",help="switch logging into DEBUG mode")
parser.add_argument('--token',metavar='TOKEN',required=True,help='token of GitLab project the runner should be associated to')
parser.add_argument('--url',metavar='URL',default='https://gitlab.cern.ch/ci',help='URL of GitLab instance where the GitLab project is hosted')
# Parse and handle initial arguments
args = parser.parse_args()
if args.debug:
logger.setLevel(logging.DEBUG)
logger.debug("parsed input values: " + str(args))
# make temporary copy of user data file
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir,'tmp_install_software.sh')
shutil.copy2('install_software.sh',temp_file)
# append command to create GitLab runner with correct arguments
tags = ','.join(args.tags)
gitlab_cmd = "gitlab-runner register -n -u {0} -r {1} --name {2} --executor shell --tag-list {3}".format(args.url,args.token,args.name,tags)
logger.debug("Using following command to register GitLab runner:\n{0}".format(gitlab_cmd))
try:
append_cmd = "echo '{0}' >> {1}".format(gitlab_cmd,temp_file)
logger.debug("Calling '{0}'".format(append_cmd))
output = subprocess.check_output(append_cmd,shell=True)
except subprocess.CalledProcessError:
logger.warning("Executing '{0}' failed".format(append_cmd))
sys.exit(1)
# create openstack VM
openstack_cmd = "openstack server create --key-name {0} --flavor {1} --image {2} --user-data {3} {4}".format(args.key,args.flavor,args.image,temp_file,args.hostname)
try:
logger.debug("Calling '{0}'".format(openstack_cmd))
output = subprocess.check_output(openstack_cmd,shell=True)
except subprocess.CalledProcessError:
logger.warning("Executing '{0}' failed".format(openstack_cmd))
# remove temporary user data file
os.system('rm {0}'.format(temp_file))
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment