Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -528,19 +528,26 @@ jobs:
gcloud compute scp "${source_file}" "${REMOTE_TARGET}:${dest_file}" "${SCP_FLAGS[@]}"
}

SOURCE_ARCHIVE="$RUNNER_TEMP/ibkr-gateway-source.tar.gz"
REMOTE_ARCHIVE="/tmp/ibkr-gateway-${TARGET_NAME}-${GITHUB_SHA}.tar.gz"
git archive --format=tar.gz --output="${SOURCE_ARCHIVE}" HEAD
log_step "Uploading source archive to ${REMOTE_ARCHIVE}"
copy_remote_file "${SOURCE_ARCHIVE}" "${REMOTE_ARCHIVE}"

REMOTE_SYNC_COMMAND=$(cat <<EOF
set -euo pipefail
echo "[\$(date -u +%FT%TZ)] Syncing repository contents"
case '${DEPLOY_PATH}' in
''|'/'|'/home'|'/opt')
Comment on lines +539 to +540

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Normalize deploy path before deleting it

When DEPLOY_PATH is misconfigured with an equivalent form such as /opt/ or /home/, it bypasses this exact-match guard and the next line runs sudo rm -rf on that directory, deleting the VM's /opt or /home contents before recreating the deploy directory. Since this change adds the destructive removal step, normalize the path or reject slash/dot variants before allowing the delete.

Useful? React with 👍 / 👎.

echo "Refusing unsafe DEPLOY_PATH: '${DEPLOY_PATH}'" >&2
exit 1
;;
esac
echo "[\$(date -u +%FT%TZ)] Syncing source archive"
sudo rm -rf '${DEPLOY_PATH}'
sudo mkdir -p '${DEPLOY_PATH}'
sudo chown -R '${GCE_USER}':'${GCE_USER}' '${DEPLOY_PATH}'
if [ -d '${DEPLOY_PATH}/.git' ]; then
cd '${DEPLOY_PATH}'
git fetch --all
git reset --hard origin/main
else
rm -rf '${DEPLOY_PATH}'
git clone 'https://github.com/${{ github.repository }}.git' '${DEPLOY_PATH}'
fi
tar -xzf '${REMOTE_ARCHIVE}' -C '${DEPLOY_PATH}'
rm -f '${REMOTE_ARCHIVE}'
EOF
)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ sudo bash ./scripts/install_gateway_health_watcher.sh

> Manual `workflow_dispatch` defaults to `keepalive`. If you really need to rebuild the image, choose `deploy_mode=full` when dispatching it.

The deploy workflow uploads a source archive from the GitHub runner to the VM. The VM does not need GitHub credentials or a checked-out private repository to receive updates.

### Multiple Gateway Sessions on One VM

The default deployment remains one container named `ib-gateway` exposing live/paper API ports `4001`/`4002`. To run another IBKR username on the same VM, use a separate deploy directory or `COMPOSE_PROJECT_NAME`, and give that instance unique container and host ports:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_workflow_shared_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ grep -Fq 'Scheduled keepalive mode: skip docker build' "$workflow_file"
grep -Fq 'reset_instance_and_wait_for_ssh()' "$workflow_file"
grep -Fq 'run_remote_ssh()' "$workflow_file"
grep -Fq 'copy_remote_file()' "$workflow_file"
grep -Fq 'git archive --format=tar.gz' "$workflow_file"
grep -Fq 'tar -xzf' "$workflow_file"
grep -Fq 'gcloud compute instances reset "${GCE_INSTANCE_NAME}"' "$workflow_file"
grep -Fq 'run_remote_ssh "Repository sync" "${REMOTE_SYNC_COMMAND}"' "$workflow_file"
grep -Fq 'copy_remote_file "${ENV_FILE}" "${DEPLOY_PATH}/.env"' "$workflow_file"
Expand Down