forked from redhat-cip/software-factory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish_image.sh
executable file
·48 lines (42 loc) · 1.68 KB
/
publish_image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# publish code borrowed from publish_docs script
set -e
[ -n "$DEBUG" ] && set -x
. ./role_configrc
trap "rm -f /tmp/swift_description-*" EXIT
function publish {
SRC=$1
IMG=$(basename $SRC)
IMG_NAME=$2
cd $(dirname $SRC)
echo "[+] Check if $IMG have changed"
TMP_FILE=$(mktemp /tmp/swift_description-${IMG_NAME}-XXXXXX)
curl -o ${TMP_FILE} ${SWIFT_SF_URL}/${IMG_NAME}.description
diff ${TMP_FILE} ${IMG_NAME}.description 2> /dev/null && return
rm -f ${TMP_FILE}
echo "[+] Upstream is out dated"
if [ ! -f "${IMG_NAME}.tgz" ]; then
rm -f "${IMG_NAME}.tgz"
fi
echo "[+] Creating edeploy file of ${SRC}"
(cd $IMG; sudo tar -c -p --use-compress-program=pigz --numeric-owner --xattrs --selinux -f ../${IMG_NAME}.tgz .)
for hot in $(ls ${HOT_TEMPLATES}/*.hot); do
sudo cp $hot $(basename $hot | sed "s/\.hot/-${SF_VER}.hot/")
done
echo "[+] Creating manifest"
OBJ="$(/bin/ls ${IMG_NAME}.{tgz,description,img.qcow2,hot} 2> /dev/null || true)"
sha256sum $OBJ | sudo tee ${IMG_NAME}.digest
for OBJECT in $OBJ ${IMG_NAME}.digest; do
[ -f ${OBJECT} ] || continue
echo "[+] Uploading ${OBJECT} to ${SWIFT_BASE_URL}/v1/AUTH_${SWIFT_ACCOUNT}/${SWIFT_IMAGE_CONTAINER}/"
SWIFT_PATH="/v1/AUTH_${SWIFT_ACCOUNT}/${SWIFT_IMAGE_CONTAINER}/${OBJECT}"
set +x
TEMPURL=`swift tempurl PUT 120 ${SWIFT_PATH} ${TEMP_URL_KEY}`
set -x
curl -f -i -X PUT --upload-file "$OBJECT" "${SWIFT_BASE_URL}${TEMPURL}"
done
}
echo "=== Publish image ${IMAGE_PATH} ==="
publish ${IMAGE_PATH} softwarefactory-${SF_VER}
echo "=== Publish cache ${CACHE_PATH} ==="
publish ${CACHE_PATH} sf-centos7