Skip to content

Commit

Permalink
Safety improvements (jonathanong#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
ridem committed Jun 22, 2021
1 parent d549ddc commit 25e435c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Run the following from the heroku command line:
heroku buildpacks:add --index 1 https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
```

You can set a custom download URL by setting the variable `FFMPEG_DOWNLOAD_URL`.

Note: This buildpack should be added before the main language buildpack (by using `--index 1`),
since the application process types are calculated from the last buildpack in the list if no
`Procfile` is specified.
55 changes: 45 additions & 10 deletions bin/compile
Original file line number Diff line number Diff line change
@@ -1,24 +1,59 @@
#!/bin/sh
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir> <env-dir>

indent() {
sed -u 's/^/ /'
header() {
echo "" || true
echo "-----> $*" || true
}

echo "-----> Install ffmpeg"
BUILD_DIR=$1
VENDOR_DIR="vendor"
DOWNLOAD_URL="https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz"
output() {
while IFS= read -r LINE; do
# do not indent headers that are being piped through the output
if [[ "$LINE" =~ ^-----\>.* ]]; then
echo "$LINE" || true
else
echo " $LINE" || true
fi
done
}

echo "DOWNLOAD_URL = " $DOWNLOAD_URL | indent
header "Installing ffmpeg"

BUILD_DIR=${1:-}
VENDOR_DIR="vendor"
FFMPEG_ARCHIVE_NAME="ffmpeg.tar.xz"

cd $BUILD_DIR
mkdir -p $VENDOR_DIR
cd $VENDOR_DIR
mkdir -p ffmpeg
cd ffmpeg
curl -L --silent $DOWNLOAD_URL | tar xJ --strip-components=1

echo "exporting PATH" | indent
if [[ -z $FFMPEG_DOWNLOAD_URL ]]; then
echo "Variable FFMPEG_DOWNLOAD_URL isn't set, using default value" | output
FFMPEG_DOWNLOAD_URL="https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz"
fi

echo "Downloading $FFMPEG_DOWNLOAD_URL" | output

code=$(curl "$FFMPEG_DOWNLOAD_URL" -L --silent --fail --retry 5 --retry-max-time 15 -o ./$FFMPEG_ARCHIVE_NAME --write-out "%{http_code}")

if [ "$code" != "200" ]; then
echo "Unable to download ffmpeg: $code" | output && exit 1
fi

echo "Unpacking the archive" | output

tar xJf "./$FFMPEG_ARCHIVE_NAME" --strip-components=1

if [ "$?" != "0" ]; then
echo "Failed to unpack" | output && exit 1
fi

rm $FFMPEG_ARCHIVE_NAME

PROFILE_PATH="$BUILD_DIR/.profile.d/ffmpeg.sh"
mkdir -p $(dirname $PROFILE_PATH)
echo 'export PATH="$PATH:${HOME}/vendor/ffmpeg"' >> $PROFILE_PATH

echo "Installation successful" | output

0 comments on commit 25e435c

Please sign in to comment.