#!/bin/bash
WORK_DIR=$PWD
TEMP_DIR=$PWD$1

SRC_DOCKER_FILE="/data/chum_to_databricks/extractor/docker_images/Dockerfile"
LIB_FILES="/usr/lib/x86_64-linux-gnu/libstdc++.so.6"

DOCKER_CONTEXT="$TEMP_DIR/docker_temp_dir"
TMP_BUILD_FILES_DIR="$DOCKER_CONTEXT/build_files/"
TMP_LIB_DIR="$DOCKER_CONTEXT/libraries/"

BAZEL_BIN_FILES="/bazel-bin/data/chum_to_databricks/extractor/*"

echo $WORK_DIR$SRC_DOCKER_FILE
echo $TMP_BUILD_FILES_DIR
echo $TMP_LIB_DIR

if [ ! -d $DOCKER_CONTEXT ]; then
  mkdir $DOCKER_CONTEXT
fi

mkdir $TMP_BUILD_FILES_DIR
mkdir $TMP_LIB_DIR

cp $WORK_DIR$SRC_DOCKER_FILE $DOCKER_CONTEXT

cp -a -L $WORK_DIR$BAZEL_BIN_FILES $TMP_BUILD_FILES_DIR
cp $LIB_FILES $TMP_LIB_DIR

docker build -t protobuf_extractor_image $DOCKER_CONTEXT --no-cache
