Skip to content

Commit

Permalink
Added docker log
Browse files Browse the repository at this point in the history
  • Loading branch information
jayhuynh committed May 10, 2023
1 parent 1224b6a commit 7905e9d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 3 deletions.
10 changes: 10 additions & 0 deletions scripts/build-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ cd $REPO_DIR/app

docker exec -t $(docker ps -a -q --filter ancestor="$APP_NAME" --format="{{.ID}}") bash -c 'pkill -SIGINT -f python3 && sleep 5' || true

echo "Wait for 10 seconds for the container to stop"
# wait for 10 seconds for the container to stop
sleep 10

docker exec -t $(docker ps -a -q --filter ancestor="$APP_NAME" --format="{{.ID}}") bash -c 'pkill -SIGINT -f python3 && sleep 5' || true
echo "Send SIGINT to all containers with image tag: $APP_NAME"

echo "Wait for 10 seconds for the container to stop"
# wait for 10 seconds for the container to stop
sleep 10

docker kill -s SIGINT $(docker ps -a -q --filter ancestor="$APP_NAME" --format="{{.ID}}") || true


Expand Down
21 changes: 18 additions & 3 deletions scripts/run-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,24 @@ docker run -d --rm --init -v $APP_NAME-volume:/mephisto/data \
-e APP_ENV=$APP_ENV \
$APP_NAME;

timeout 30m \
sh -c "while ! docker logs -f $(docker ps -q --filter ancestor=$APP_NAME --format="{{.ID}}")| grep -q '$M_TURK_PREVIEW_URL_PREFIX'; \
container_id=$(docker ps -q --filter ancestor=$APP_NAME --format="{{.ID}}");

if [ -z "$container_id" ]
then
echo "Container $APP_NAME failed to start";
exit 1;
fi

mkdir -p ~/logs/$APP_NAME/;

echo "Streaming logs from container $container_id to file ~/logs/$APP_NAME/$container_id-$(date +%s).log";
nohup docker logs -f $container_id > ~/logs/$APP_NAME/$container_id-$(date +%s).log &

echo "Waiting for MTurk preview URL: ";
timeout 1800 \
sh -c "while ! docker logs -f $container_id| grep -q '$M_TURK_PREVIEW_URL_PREFIX'; \
do sleep 1; done";


docker logs $(docker ps -q --filter ancestor=$APP_NAME --format="{{.ID}}");
echo "MTurk preview URL: ";
docker logs $container_id;
37 changes: 37 additions & 0 deletions scripts/sync-volumes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
# Arg 1: $SYNC_INTERVAL, default 60 seconds
# Arg 2: $S3_BUCKET_NAME, default s3://mephisto-data
# Arg 3: $LOCAL_DIR, default current directory

SYNC_INTERVAL=${1:-60}
LOCAL_DIR=${2:-.}
S3_BUCKET_NAME=${3:-s3://mephisto-data}
AWS_ACCESS_KEY_ID=${4:-""}
AWS_SECRET_ACCESS_KEY=${5:-""}

trap "echo '[$(date)] Exit syncing script!'; exit;" SIGINT SIGTERM

if [ -z "$AWS_ACCESS_KEY_ID" ]
then
echo "AWS_ACCESS_KEY_ID not set";
exit 1;
fi

if [ -z "$AWS_SECRET_ACCESS_KEY" ]
then
echo "AWS_SECRET_ACCESS_KEY not set";
exit 1;
fi

export AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY

while true; do
echo "[$(date)] Syncing $LOCAL_DIR to $S3_BUCKET_NAME!"
aws s3 sync $LOCAL_DIR $S3_BUCKET_NAME

echo "[$(date)] Sync complete!"
sleep $SYNC_INTERVAL
done

# echo when interrupted

0 comments on commit 7905e9d

Please sign in to comment.