-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathcompile
executable file
·54 lines (42 loc) · 1.72 KB
/
compile
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
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir> <env-dir>
set -euo pipefail
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
AWS_CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
BUILD_DIR=$1
BUILDPACK_DIR="$(dirname $(dirname $0))"
INSTALL_DIR="/app/.awscli"
TMP_DIR=$(mktemp -d)
echo "-----> Downloading AWS CLI"
curl --silent --show-error --fail -o "${TMP_DIR}/awscliv2.zip" "${AWS_CLI_URL}" |& indent
unzip -qq -d "${TMP_DIR}" "${TMP_DIR}/awscliv2.zip" |& indent
echo "-----> Installing AWS CLI"
mkdir -p "${BUILD_DIR}/.awscli"
# The AWS installer creates symlinks that use absolute paths, as such the install
# location must match the location from which the CLI is eventually run.
# At runtime the app will be run from /app, however at build time $BUILD_DIR is
# typically a path under /tmp (unless a Heroku CI build, in which case it's /app).
# In order to make all cases work, we have to create a symlink from /app to $BUILD_DIR,
# so that we can use `/app` paths for the installer, so that the symlinks it creates
# will use /app paths. A symlink is used instead of file copying to improve build times.
if [[ "${BUILD_DIR}" != /app ]]; then
mkdir -p /app
ln -nsf "${BUILD_DIR}/.awscli" "${INSTALL_DIR}"
fi
"${TMP_DIR}/aws/install" --install-dir "${INSTALL_DIR}/aws-cli" --bin-dir "${INSTALL_DIR}/bin" |& indent
/app/.awscli/bin/aws --version |& indent
mkdir -p "${BUILD_DIR}/.profile.d"
cat > "${BUILD_DIR}/.profile.d/awscli.sh" <<'PROFILE'
export PATH="/app/.awscli/bin:${PATH}"
PROFILE
cat > "${BUILDPACK_DIR}/export" <<'EXPORT'
export PATH="/app/.awscli/bin:${PATH}"
EXPORT
rm -rf "${TMP_DIR}"
echo "-----> Successfully installed AWS CLI"