Skip to content

Commit

Permalink
Simplify env variables to be the same for both local and GCS paths. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurva authored Feb 27, 2024
1 parent e92ed59 commit c9dbfec
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 28 deletions.
11 changes: 3 additions & 8 deletions build/simple/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if [[ $GCS_OUTPUT_DIR != "" ]]; then
export OUTPUT_DIR=$GCS_OUTPUT_DIR
else
if [ "$OUTPUT_DIR" = "" ]; then
export OUTPUT_DIR=/output/
fi

if [[ $CONFIG_FILE != "" ]]; then
if [ "$CONFIG_FILE" != "" ]; then
echo "DC_API_KEY=$DC_API_KEY"
echo "CONFIG_FILE=$CONFIG_FILE"
echo "OUTPUT_DIR=$OUTPUT_DIR"
Expand All @@ -29,9 +27,7 @@ if [[ $CONFIG_FILE != "" ]]; then
--config_file=$CONFIG_FILE \
--output_dir=$OUTPUT_DIR
else
if [[ $GCS_INPUT_DIR != "" ]]; then
export INPUT_DIR=$GCS_INPUT_DIR
else
if [ "$INPUT_DIR" = "" ]; then
export INPUT_DIR=/input/
fi

Expand All @@ -44,4 +40,3 @@ else
--input_dir=$INPUT_DIR \
--output_dir=$OUTPUT_DIR
fi

6 changes: 3 additions & 3 deletions tools/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ can be run locally.
* If using GCS:
* Run `gcloud beta auth application-default login`.
* Specify your cloud project via the `GOOGLE_CLOUD_PROJECT` variable.
* If using config file and output dirs, specify `CONFIG_FILE` and `GCS_OUTPUT_DIR` (or `OUTPUT_DIR`) respectively.
* If using local input and output dirs, specify `INPUT_DIR` and `OUTPUT_DIR` respectively.
* If using GCS input and output dirs, specify `GCS_INPUT_DIR` and `GCS_OUTPUT_DIR` respectively.
* If using config file and output dir, specify `CONFIG_FILE` and `OUTPUT_DIR` respectively.
* If using input dir and output dir, specify `INPUT_DIR` and `OUTPUT_DIR` respectively.
* Note that `CONFIG_FILE`, `INPUT_DIR` and `OUTPUT_DIR` can be GCS paths or local file system paths.
4 changes: 1 addition & 3 deletions tools/simple/env.list
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
DC_API_KEY=
CONFIG_FILE=
INPUT_DIR=
OUTPUT_DIR=
GCS_INPUT_DIR=
GCS_OUTPUT_DIR=
CONFIG_FILE=
GOOGLE_CLOUD_PROJECT=
33 changes: 19 additions & 14 deletions tools/simple/run_simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@ set -o allexport
source env.list
set +o allexport

if [[ $CONFIG_FILE != "" ]]; then
docker run -it \
--env-file env.list \
-e GOOGLE_APPLICATION_CREDENTIALS=/gcp/creds.json \
-v $HOME/.config/gcloud/application_default_credentials.json:/gcp/creds.json:ro \
-e CONFIG_FILE=/config.json \
-v $CONFIG_FILE:/config.json:ro \
gcr.io/datcom-ci/datacommons-simple:latest
else
docker run -it \
--env-file env.list \
-e GOOGLE_APPLICATION_CREDENTIALS=/gcp/creds.json \
-v $HOME/.config/gcloud/application_default_credentials.json:/gcp/creds.json:ro \
gcr.io/datcom-ci/datacommons-simple:latest
ARGS=""

if [ "$CONFIG_FILE" != "" && "$CONFIG_FILE" != "gs://"* ]; then
ARGS+="-e CONFIG_FILE=/config.json -v $CONFIG_FILE:/config.json "
fi

if [[ "$INPUT_DIR" != "" && "$INPUT_DIR" != "gs://"* ]]; then
ARGS+="-e INPUT_DIR=/input -v $INPUT_DIR:/input "
fi

if [[ "$OUTPUT_DIR" != "" && "$OUTPUT_DIR" != "gs://"* ]]; then
ARGS+="-e OUTPUT_DIR=/output -v $OUTPUT_DIR:/output "
fi

docker run -it \
--env-file env.list \
-e GOOGLE_APPLICATION_CREDENTIALS=/gcp/creds.json \
-v $HOME/.config/gcloud/application_default_credentials.json:/gcp/creds.json:ro \
$ARGS \
gcr.io/datcom-ci/datacommons-simple:latest

0 comments on commit c9dbfec

Please sign in to comment.