forked from rcbops/jenkins-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkins-chef-cookbooks-package
executable file
·118 lines (99 loc) · 4.37 KB
/
jenkins-chef-cookbooks-package
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
# force a local default so this can be run on command line
GIT_BRANCH=${GIT_BRANCH:-master}
GIT_CLONE_URL=${GIT_CLONE_URL:-git://github.com/rcbops/chef-cookbooks.git}
TAR_PKG_DIR_NAME=${TAR_PKG_DIR_NAME:-chef-cookbooks}
GIT_TAG=${GIT_TAG:-unset}
WORKSPACE_CREATED=0
NOCLEAN=${NOCLEAN:=0}
if [[ -z ${WORKSPACE} ]]; then
export WORKSPACE=$(mktemp -d)
echo "using WORKSPACE ${WORKSPACE}"
WORKSPACE_CREATED=1
else
rm -rf ${WORKSPACE}
mkdir -p ${WORKSPACE}
fi
cd ${WORKSPACE}
echo "******************************************************************"
echo "cloning ${GIT_CLONE_URL}"
echo "******************************************************************"
# Clone the upstream repo
if ! ( git clone ${GIT_CLONE_URL} ${WORKSPACE}/git-checkout ); then
echo "Unable to clone git repo: ${GIT_CLONE_URL}"
exit 1
fi
cd ${WORKSPACE}/git-checkout
echo "******************************************************************"
echo "checking out ${GIT_TAG}"
echo "******************************************************************"
# Change to tag
if ! ( git checkout ${GIT_TAG} ); then
echo "Unable to checkout branch: ${GIT_TAG}"
exit 1
fi
echo "******************************************************************"
echo "submodule init"
echo "******************************************************************"
# Pull in submodules
if ! ( git submodule init ); then
echo "Unable to init submodules"
exit 1
fi
echo "******************************************************************"
echo "submodule update"
echo "******************************************************************"
if ! ( git submodule update ); then
echo "Unable to update submodules"
exit 1
fi
echo "******************************************************************"
echo "cleaning up after git"
echo "******************************************************************"
# Remove .git files/directories
find ${WORKSPACE}/git-checkout -name ".git*" -exec rm -rf {} \; 2>/dev/null
# Back out of the working root
cd ${WORKSPACE}
echo "******************************************************************"
echo "creating the tarball"
echo "******************************************************************"
mv ${WORKSPACE}/git-checkout ${WORKSPACE}/${TAR_PKG_DIR_NAME}-${GIT_TAG}
DIST_FILENAME=${WORKSPACE}/${TAR_PKG_DIR_NAME}-${GIT_TAG}".tgz"
# Tar up the archive
tar zcvf ${DIST_FILENAME} ${TAR_PKG_DIR_NAME}-${GIT_TAG}
echo "******************************************************************"
echo "calculate md5 for tarball"
echo "******************************************************************"
TAR_PKG_MD5=`md5sum ${TAR_PKG_DIR_NAME}-${GIT_TAG}.tgz | awk '{ print $1 }'`
echo "******************************************************************"
echo "update the manifest"
echo "******************************************************************"
# grab the current manifest
~/jenkins-build/scripts/cf-upload.sh get "PROD-cookbooks" "CURRENT.manifest" > ${WORKSPACE}/CURRENT.manifest
# Update Manifest
~/jenkins-build/scripts/manifest.py ${WORKSPACE}/CURRENT.manifest ${GIT_TAG} "http://8a8313241d245d72fc52-b3448c2b169a7d986fbb3d4c6b88e559.r9.cf1.rackcdn.com/${TAR_PKG_DIR_NAME}-${GIT_TAG}.tgz" ${TAR_PKG_MD5}
MANIFEST_LENGTH=$(wc -l "${WORKSPACE}/CURRENT.manifest" | awk '{print $1}')
if [[ ${MANIFEST_LENGTH} = 0 ]]; then
echo "DANGER! We have an empty manifest file. Giving up!"
exit 1;
fi
# Upload
echo "******************************************************************"
echo "upload here"
echo "******************************************************************"
# upload manifest
~/jenkins-build/scripts/cf-upload.sh put "${WORKSPACE}/CURRENT.manifest" "PROD-cookbooks" "CURRENT.manifest"
# upload tarball
~/jenkins-build/scripts/cf-upload.sh put "${WORKSPACE}/${TAR_PKG_DIR_NAME}-${GIT_TAG}.tgz" "PROD-cookbooks" "${TAR_PKG_DIR_NAME}-${GIT_TAG}.tgz"
echo "******************************************************************"
echo "items are located here: ${WORKSPACE}"
echo "MANIFEST: http://8a8313241d245d72fc52-b3448c2b169a7d986fbb3d4c6b88e559.r9.cf1.rackcdn.com/CURRENT.manifest"
echo "TARBALL: http://8a8313241d245d72fc52-b3448c2b169a7d986fbb3d4c6b88e559.r9.cf1.rackcdn.com/${TAR_PKG_DIR_NAME}-${GIT_TAG}.tgz"
echo "******************************************************************"
if [[ $NOCLEAN = 1 ]]; then
exit 0
fi
if [[ $WORKSPACE_CREATED = 1 ]]; then
echo "deleting the workspace"
rm -rf ${WORKSPACE}
fi