I'm sure there are lots of ways to solve these problems, but a simple solution we use at TransFICC is to use a bootstrap script that wraps our build system. This is called everytime you want to run something via the build system (in our case Maven [we haven't buck'd up]), and ensures all build dependencies are present. I should note that we only use this for build dependencies, not run time dependencies.
bootstrap.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
JDK="jdk1.8.0_74" | |
EXPECTED_JDK_EXPLODED_SHA1="25d468495c8d44f71233cf240560b9d2c681d5e4" | |
NODE="node-v4.3.2-linux-x64" | |
EXPECTED_NODE_EXPLODED_SHA1="f1ecc0b12739e5ab1b4d03006f7f8b406fcaba07" | |
BUCK="buck-344c05b" | |
EXPECTED_BUCK_EXPLODED_SHA1="9bd0b11e2225d74f38d57c22dc404142e5d51ed0" | |
MAVEN="apache-maven-3.3.9" | |
EXPECTED_MAVEN_EXPLODED_SHA1="5b4c117854921b527ab6190615f9435da730ba05" | |
#Runtime Dependencies | |
PGSQL="pgsql-9.2.15" | |
EXPECTED_PGSQL_EXPLODED_SHA1="8fad03ec139bc05cd7d3b7976e93f32ea5bc93d8" | |
OPT_DIR=${ROOT_DIR}/opt | |
function fetch_artifact() { | |
local name=$1 | |
echo "Fetching dependency ${name} ..." | |
local namedVersion=$2 | |
curl -J --progress-bar -o ${OPT_DIR}/${version}.tar.gz http://thearts.internal.transficc.com/artifacts/${name}/${namedVersion}.tar.gz | |
} | |
function ensure_dependency_extracted_and_linked() { | |
local short_name=$1 | |
local name_version=$2 | |
local expectedSha1Hash=$3 | |
local fully_qualified_extracted_dir=${OPT_DIR}/${name_version} | |
local fully_qualified_linked_dir=${OPT_DIR}/${short_name} | |
local package_hash_file="$fully_qualified_extracted_dir.sha1" | |
local actual_sha1_hash="" | |
if [ -e "$package_hash_file" ]; then | |
actual_sha1_hash=$(cat ${package_hash_file}) | |
fi | |
if [ "$actual_sha1_hash" != "$expectedSha1Hash" ]; then | |
echo "Hashes don't match" | |
echo "actual: $actual_sha1_hash expected: $expectedSha1Hash" | |
rm -rf ${fully_qualified_linked_dir} | |
rm -rf ${fully_qualified_extracted_dir} | |
fetch_artifact ${short_name} ${name_version} | |
tar xzf "${OPT_DIR}/${name_version}.tar.gz" -C ${OPT_DIR}/ | |
ln -s ${fully_qualified_extracted_dir} ${fully_qualified_linked_dir} | |
local sha1hash=$(sha1sum ${OPT_DIR}/${name_version}.tar.gz | awk '{ print $1 }') | |
echo ${sha1hash} > "$fully_qualified_extracted_dir.sha1" | |
rm "${OPT_DIR}/${name_version}.tar.gz" | |
fi | |
} | |
function ensure_directory_exists() { | |
mkdir -p ${OPT_DIR} | |
} | |
function bootstrap() { | |
echo "Arguments: $@" | |
ensure_directory_exists | |
ensure_dependency_extracted_and_linked "jdk" ${JDK} ${EXPECTED_JDK_EXPLODED_SHA1} | |
ensure_dependency_extracted_and_linked "node" ${NODE} ${EXPECTED_NODE_EXPLODED_SHA1} | |
ensure_dependency_extracted_and_linked "buck" ${BUCK} ${EXPECTED_BUCK_EXPLODED_SHA1} | |
ensure_dependency_extracted_and_linked "maven" ${MAVEN} ${EXPECTED_MAVEN_EXPLODED_SHA1} | |
} | |
boostrap |
Our build dependencies are Java, Node (well, npm), Buck, and Maven. This script assumes the dependencies live at http://thearts.internal.transficc.com/artifacts/ (e.g. the jdk is located at http://thearts.internal.transficc.com/artifacts/jdk/jdk1.8.0_74.tar.gz and the directory contained inside the tar.gz is jdk1.8.0_74). The checksums check for a change of dependencies rather than ensuring they are downloaded correctly.
This script could be used as follows.
transficc.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
export ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
OPT_DIR=${ROOT_DIR}/opt | |
./bootstrap.sh | |
export JAVA_HOME=${OPT_DIR}/jdk | |
mvn $@ |
./transficc.sh compile
No comments:
Post a Comment