-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.sh
executable file
·92 lines (73 loc) · 2.83 KB
/
build.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
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
function usage {
echo "Usage:"
echo " $0 -f <packageFilename> -b <buildNumber> [-g <gitRevision>] [-r <projectRootDir>]"
echo " -f <packageFilename> file name of the archive that will be created"
echo " -b <buildNumber> build number"
echo " -g <gitRevision> git revision"
echo " -r <projectRootDir> Path to the project dir. Defaults to current working directory."
echo ""
exit $1
}
PROJECTROOTDIR=$PWD
########## get argument-values
while getopts 'f:b:g:d:r:' OPTION ; do
case "${OPTION}" in
f) FILENAME="${OPTARG}";;
b) BUILD_NUMBER="${OPTARG}";;
g) GIT_REVISION="${OPTARG}";;
r) PROJECTROOTDIR="${OPTARG}";;
\?) echo; usage 1;;
esac
done
if [ -z ${FILENAME} ] ; then echo "ERROR: No file name given (-f)"; usage 1 ; fi
if [ -z ${BUILD_NUMBER} ] ; then echo "ERROR: No build number given (-b)"; usage 1 ; fi
cd ${PROJECTROOTDIR} || { echo "Changing directory failed"; exit 1; }
if [ ! -f 'composer.json' ] ; then echo "Could not find composer.json"; exit 1 ; fi
if [ ! -f 'bin/composer.phar' ] ; then echo "Could not find composer.phar"; exit 1 ; fi
if type "hhvm" &> /dev/null; then
PHP_COMMAND=hhvm
echo "Using HHVM for composer..."
else
PHP_COMMAND=php
fi
# Run composer
$PHP_COMMAND bin/composer.phar install --verbose --no-ansi --no-interaction --prefer-source || { echo "Composer failed"; exit 1; }
# Some basic checks
if [ ! -f 'pub/index.php' ] ; then echo "Could not find pub/index.php"; exit 1 ; fi
# Prepare for production
touch .maintenance.flag
#php bin/magento setup:di:compile
#php bin/magento setup:static-content:deploy
# Write file: build.txt
echo "${BUILD_NUMBER}" > build.txt
# Write file: version.txt
echo "Build: ${BUILD_NUMBER}" > pub/version.txt
echo "Build time: `date +%c`" >> pub/version.txt
if [ ! -z ${GIT_REVISION} ] ; then echo "Revision: ${GIT_REVISION}" >> pub/version.txt ; fi
# Create package
if [ ! -d "artifacts/" ] ; then mkdir artifacts/ ; fi
tmpfile=$(mktemp)
# Backwards compatibility in case tar_excludes.txt doesn't exist
if [ ! -f "config/tar_excludes.txt" ] ; then
touch config/tar_excludes.txt
fi
BASEPACKAGE="artifacts/${FILENAME}"
echo "Creating base package '${BASEPACKAGE}'"
tar -vczf "${BASEPACKAGE}" \
--exclude=./var/log \
--exclude=./pub/media \
--exclude=./artifacts \
--exclude=./tmp \
--exclude-from="config/tar_excludes.txt" . > $tmpfile || { echo "Creating archive failed"; exit 1; }
EXTRAPACKAGE=${BASEPACKAGE/.tar.gz/.extra.tar.gz}
echo "Creating extra package '${EXTRAPACKAGE}' with the remaining files"
tar -czf "${EXTRAPACKAGE}" \
--exclude=./var/log \
--exclude=./pub/media \
--exclude=./artifacts \
--exclude=./tmp \
--exclude-from="$tmpfile" . || { echo "Creating extra archive failed"; exit 1; }
rm "$tmpfile"
cd artifacts
md5sum * > MD5SUMS