Skip to content

Commit

Permalink
add docker image name parameter to extract binaries script (#565)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #565

in order to leverage the extract binaries script in the github action, I refactored that code

Reviewed By: jrodal98

Differential Revision: D34115213

fbshipit-source-id: 6fb2b76ccdf2f294db8311a2e88492bad4c012b0
  • Loading branch information
leegross authored and facebook-github-bot committed Feb 11, 2022
1 parent b6aff54 commit 2d9f4cc
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions extract-docker-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ set -e
PROG_NAME=$0
usage() {
cat << EOF >&2
Usage: $PROG_NAME <emp_games|data_processing> [-t TAG]
Usage: $PROG_NAME <emp_games|data_processing> [-t TAG] [-d DOCKER_IMAGE_NAME]
package:
emp_games - extracts the binaries from fbpcs/emp-games docker image
data_processing - extracts the binaries from fbpcs/data-processing docker image
-t TAG: uses the image with the given tag (default: latest)
-d DOCKER_IMAGE_NAME: defines the image name to extract from
EOF
exit 1
}
Expand All @@ -27,22 +28,37 @@ fi
shift

TAG="latest"
while getopts "t:" o; do
while getopts "t:d:" o; do
case $o in
(t) TAG=$OPTARG;;
(*) usage
t) TAG=$OPTARG;;
d) DOCKER_IMAGE_NAME=$OPTARG;;
*) usage
esac
done
shift "$((OPTIND - 1))"

# ensure docker image name does not contain a : (since we apply that below)
if [[ "$DOCKER_IMAGE_NAME" == *":"* ]]; then
echo "Invalid docker image name. Should not include ':' and a tag."
exit 1
fi

# determine what docker image name and tag to use
if [ -z "$DOCKER_IMAGE_NAME" ]; then
case $PACKAGE in
emp_games) DOCKER_IMAGE_NAME="fbpcs/emp-games";;
data_processing) DOCKER_IMAGE_NAME="fbpcs/data-processing";;
esac
fi
DOCKER_IMAGE_PATH="${DOCKER_IMAGE_NAME}:${TAG}"

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Run from the root dir of so the binaries paths exist
cd "$SCRIPT_DIR" || exit
mkdir -p binaries_out

if [ "$PACKAGE" = "emp_games" ]; then
docker create -ti --name temp_container "fbpcs/emp-games:${TAG}"
docker create -ti --name temp_container "${DOCKER_IMAGE_PATH}"
docker cp temp_container:/usr/local/bin/lift_calculator "$SCRIPT_DIR/binaries_out/."
docker cp temp_container:/usr/local/bin/decoupled_attribution_calculator "$SCRIPT_DIR/binaries_out/."
docker cp temp_container:/usr/local/bin/decoupled_aggregation_calculator "$SCRIPT_DIR/binaries_out/."
Expand All @@ -51,7 +67,7 @@ docker rm -f temp_container
fi

if [ "$PACKAGE" = "data_processing" ]; then
docker create -ti --name temp_container "fbpcs/data-processing:${TAG}"
docker create -ti --name temp_container "${DOCKER_IMAGE_PATH}"
docker cp temp_container:/usr/local/bin/sharder "$SCRIPT_DIR/binaries_out/."
docker cp temp_container:/usr/local/bin/sharder_hashed_for_pid "$SCRIPT_DIR/binaries_out/."
docker cp temp_container:/usr/local/bin/pid_preparer "$SCRIPT_DIR/binaries_out/."
Expand Down

0 comments on commit 2d9f4cc

Please sign in to comment.