#!/bin/bash # Copyright (c) 2012-2014 Hewlett-Packard Development Company, L.P. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # # See the License for the specific language governing permissions and # limitations under the License. # dib-lint: disable=setpipefail if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then set -x fi set -eu # We need a copy of the devstack repo to query for the list of image # files to cached by the source-repositories element (see # 55-cache-devstack-repos) # # This script is a hack to use the source-repositories repo cache to # get early access to the devstack checkout (rather than doing a whole # separate clone of the devstack tree). In essence, this script knows # the path of the devstack in the source-repositories cache and # creates/updates it. To get the gist of where this comes from, see # dib's # elements/source-repositories/extra-data.d/98-source-repositories # # This could be removed if we could ever source and call the # clone/update functions asynchronously from the source-repositories # dib element. function get_devstack_from_cache { local REPONAME=devstack local REPOTYPE=git local REPOPATH=/opt/git/openstack-dev/devstack local REPOLOCATION=git://git.openstack.org/openstack-dev/devstack.git local REPOREF=master local REPO_DEST=$TMP_MOUNT_PATH$REPOPATH local REPO_SUB_DIRECTORY=$(dirname $REPO_DEST) sudo mkdir -p $REPO_SUB_DIRECTORY # build the same cache name as source-repositories CACHE_NAME=$(echo "${REPOTYPE}_${REPOLOCATION}" | sha1sum | awk '{ print $1 }' ) CACHE_NAME=${REPONAME//[^A-Za-z0-9]/_}_${CACHE_NAME} CACHE_PATH=${CACHE_BASE}/$CACHE_NAME # clone repo if not in cache if [ ! -e "$CACHE_PATH" ] ; then echo "early-source-repo: Caching $REPONAME from $REPOLOCATION in $CACHE_PATH" git clone $REPOLOCATION $CACHE_PATH.tmp mv ${CACHE_PATH}{.tmp,} fi # update cached repo if [ -z "$DIB_OFFLINE" ] ; then echo "early-source-repo: Updating cache of $REPOLOCATION in $CACHE_PATH with ref $REPOREF" # note, we could update *all* refs here (+refs/*:refs/* and # create a really full mirror. but that brings in a lot of # change refs from gerrit which traditionally we haven't used. # Also, we only really care about refs/remotes/* as the # devstack caching script goes through these branches to # decide what to checkout. We keep refs/heads/* for # historical reasons...) git --git-dir=$CACHE_PATH/.git fetch --prune --update-head-ok \ $REPOLOCATION \ +refs/heads/*:refs/heads/* +refs/remotes/*:refs/remotes/* fi # clone the updated repo to our destination sudo git clone $CACHE_PATH $REPO_DEST } # in case source-repositories hasn't run yet, make the cache CACHE_BASE=$DIB_IMAGE_CACHE/source-repositories mkdir -p $CACHE_BASE get_devstack_from_cache