Skip to content

Commit

Permalink
Make docker image runnable via a config file. (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurva authored Feb 26, 2024
1 parent 1900e02 commit e92ed59
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 23 deletions.
37 changes: 24 additions & 13 deletions build/simple/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,35 @@
# See the License for the specific language governing permissions and
# limitations under the License.

if [[ $GCS_INPUT_DIR != "" ]]; then
export INPUT_DIR=$GCS_INPUT_DIR
else
export INPUT_DIR=/input/
fi

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

echo "DC_API_KEY=$DC_API_KEY"
echo "INPUT_DIR=$INPUT_DIR"
echo "OUTPUT_DIR=$INPUT_DIR"
if [[ $CONFIG_FILE != "" ]]; then
echo "DC_API_KEY=$DC_API_KEY"
echo "CONFIG_FILE=$CONFIG_FILE"
echo "OUTPUT_DIR=$OUTPUT_DIR"

python3 -m stats.main \
--mode=maindc \
--input_dir=$INPUT_DIR \
--output_dir=$OUTPUT_DIR
python3 -m stats.main \
--mode=maindc \
--config_file=$CONFIG_FILE \
--output_dir=$OUTPUT_DIR
else
if [[ $GCS_INPUT_DIR != "" ]]; then
export INPUT_DIR=$GCS_INPUT_DIR
else
export INPUT_DIR=/input/
fi

echo "DC_API_KEY=$DC_API_KEY"
echo "INPUT_DIR=$INPUT_DIR"
echo "OUTPUT_DIR=$OUTPUT_DIR"

python3 -m stats.main \
--mode=maindc \
--input_dir=$INPUT_DIR \
--output_dir=$OUTPUT_DIR
fi

10 changes: 7 additions & 3 deletions tools/simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
`run_simple.sh` is an example script illustrating how the simple import docker image
can be run locally.

In the `env.list` file, specify the `DC_API_KEY`.
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.
* In the `env.list` file, specify the `DC_API_KEY`.
* 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.
2 changes: 2 additions & 0 deletions tools/simple/env.list
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ INPUT_DIR=
OUTPUT_DIR=
GCS_INPUT_DIR=
GCS_OUTPUT_DIR=
CONFIG_FILE=
GOOGLE_CLOUD_PROJECT=
22 changes: 15 additions & 7 deletions tools/simple/run_simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ set -o allexport
source env.list
set +o allexport

docker run -it \
--env-file env.list \
-v $INPUT_DIR:/input \
-v $OUTPUT_DIR:/output \
-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
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
fi

0 comments on commit e92ed59

Please sign in to comment.