-
-
Notifications
You must be signed in to change notification settings - Fork 355
/
Copy pathdeploy_production.sh
executable file
·84 lines (69 loc) · 2.58 KB
/
deploy_production.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
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
#!/bin/bash
#
# Deploys the current Spoon website to the website server.
# To test the site locally before deploying run `jekyll serve`
# in the website branch.
#
# Copied in the config of job "website deployer" on Jenkins
REPO="https://github.com/INRIA/spoon.git"
DIR=temp-spoon-clone
DIR_WEBSITE=${DIR}/doc/
USER_SERVER="spoon-bot"
WEBSITE_SERVER="${USER_SERVER}@scm.gforge.inria.fr"
SOURCE="_site/"
HOST_DESTINATION="/home/groups/spoon/"
FOLDER_DESTINATION="htdocs"
DESTINATION="${HOST_DESTINATION}${FOLDER_DESTINATION}/"
# Delete any existing previous temps spoon clone.
rm -rf $DIR
# Clone the current repo into temp folder.
git clone $REPO $DIR
# Move working directory into temp folder.
cd $DIR_WEBSITE
cp ../README.md doc_homepage.md
# Generate the website.
LATESTVERSION=`curl -s "http://search.maven.org/solrsearch/select?q=g:%22fr.inria.gforge.spoon%22+AND+a:%22spoon-core%22&core=gav" | jq -r '.response.docs | map(select(.v | match("^[0-9.]+$")) | .v )| .[0]'`
sed -i -e "s/^spoon_release: .*/spoon_release: $LATESTVERSION/" _config.yml
SNAPSHOTVERSION=`xmlstarlet sel -t -v /_:project/_:version ../pom.xml`
sed -i -e "s/^spoon_snapshot: .*/spoon_snapshot: \"$SNAPSHOTVERSION\"/" _config.yml
jekyll build
if [ "$?" -ne 0 ]; then
echo "Jekyll cannot build your site!"
exit 1
fi
# moving repositories before backup
ssh $WEBSITE_SERVER "mv ${DESTINATION}/repositories ${HOST_DESTINATION}"
# Back up the old website and create the folder for the new one.
TIMESTAMP=$(date +%s)
BACKUP_DESTINATION="${HOST_DESTINATION}${FOLDER_DESTINATION}-${TIMESTAMP}"
ssh $WEBSITE_SERVER "mv ${DESTINATION} ${BACKUP_DESTINATION}"
if [ "$?" -ne 0 ]; then
echo "Error when you tried to back up the old website!"
exit 1
fi
ssh $WEBSITE_SERVER "mkdir -p ${DESTINATION}"
if [ "$?" -ne 0 ]; then
echo "Error when you tried to create the folder of the new website!"
exit 1
fi
# Copy the website on the server.
scp -r $SOURCE* $WEBSITE_SERVER:$DESTINATION
if [ "$?" -ne 0 ]; then
echo "Error when you tried to copy the new version on the server!"
exit 1
fi
# moving repositories before backup
ssh $WEBSITE_SERVER "mv ${HOST_DESTINATION}/repositories ${DESTINATION}"
# Remove backups older than 3 days.
ssh $WEBSITE_SERVER "find ${HOST_DESTINATION}${FOLDER_DESTINATION}-* -mtime +3 -type d -exec rm -rf {} \;"
# Come back at the root of the temp project.
cd ..
# Generate maven site and deploy it.
# coming back into the main folder with pom.xml
mvn site site:deploy
if [ "$?" -ne 0 ]; then
echo "Error when you tried to build or deploy maven site!"
exit 1
fi
# Delete our temp folder.
cd .. && rm -rf $DIR