diff --git a/.github/workflows/detect-new-ib-gateway-ver.yml b/.github/workflows/detect-new-ib-gateway-ver.yml deleted file mode 100644 index cb22b64..0000000 --- a/.github/workflows/detect-new-ib-gateway-ver.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Detect new IB gateway version -on: - schedule: - - cron: '0 0 * * *' - workflow_dispatch: -jobs: - build: - runs-on: ubuntu-latest - timeout-minutes: 20 - env: - IMAGE_NAME: ib-gateway-docker - steps: - - uses: actions/checkout@master - - name: Setup python - uses: actions/setup-python@v5 - - name: detect new ib gateway version - id: detect-new-ibg-ver - run: | - ib-gateway-ver=$(python scripts/detect_ib_gateway_ver.py) >> "$GITHUB_OUTPUT" - cur-ib-gateway-ver=$(cat ib-gateway-ver) - if [ "$ib-gateway-ver" = "$cur-ib-gateway-ver" ]; then - echo "No dated IB gateway version" - else - echo "New IB gateway version($ib-gateway-ver)" - fi \ No newline at end of file diff --git a/.github/workflows/detect-new-ver.yml b/.github/workflows/detect-new-ver.yml new file mode 100644 index 0000000..cdf2a7b --- /dev/null +++ b/.github/workflows/detect-new-ver.yml @@ -0,0 +1,54 @@ +name: Detect new version +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + issues: write + env: + IMAGE_NAME: ib-gateway-docker + steps: + - uses: actions/checkout@master + - name: Setup python + uses: actions/setup-python@v5 + - name: detect new ib gateway version + id: check-update + run: | + ib-gateway-ver=$(python scripts/detect_ib_gateway_ver.py) >> "$GITHUB_OUTPUT" + python scripts/detect_ibc_ver.py + ibc-ver=${IBC_VER} >> "$GITHUB_OUTPUT" + ibc-asset-url=${IBC_ASSET_URL} >> "$GITHUB_OUTPUT" + cur-ib-gateway-ver=$(cat ib-gateway-ver) + cur-ibc-ver=$(cat ibc-ver) + if [ "$ib-gateway-ver" = "$cur-ib-gateway-ver" ]; then + echo "No dated IB gateway version" + has_update=false >> "$GITHUB_OUTPUT" + else + echo "New IB gateway version($ib-gateway-ver)" + has_update=true >> "$GITHUB_OUTPUT" + fi + - name: Update files with new version + if: steps.check-update.outputs.has_update == 'true' + run: | + cat README.template | envsubst > README.md + cat Dockerfile.template | envsubst > Dockerfile + - name: Create PR + if: ${{ steps.check-update.outputs.has_update == 'true' }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + branch='feat/update-to-${{ steps.check-update.outputs.ib-gateway-ver }}' + git config user.name github-actions + git config user.email github-actions@github.com + git pull + git checkout -b "$branch" origin/master + git add * + git commit -m 'Update to `${{ steps.check-update.outputs.ib-gateway-ver }}`' + git push --set-upstream origin "$branch" + + # gh pr create --base master --fill + \ No newline at end of file diff --git a/Dockerfile.temaplate b/Dockerfile.temaplate new file mode 100644 index 0000000..2537c9a --- /dev/null +++ b/Dockerfile.temaplate @@ -0,0 +1,68 @@ +FROM python:3.11-slim +# IBC Version : https://github.com/IbcAlpha/IBC/releases +ARG IBC_VER="3.18.0" +ARG IBC_ASSET_URL="https://github.com/IbcAlpha/IBC/releases/download/$IBC_VER-Update.1/IBCLinux-$IBC_VER.zip" + +# install dependencies +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y wget \ + unzip \ + xvfb \ + libxtst6 \ + libxrender1 \ + build-essential \ + net-tools \ + x11-utils \ + socat \ + expect \ + procps \ + xterm +RUN apt install -y openjdk-17-jre + +# set environment variables +ENV TWS_INSTALL_LOG=/root/Jts/tws_install.log \ + IBC_INI=/root/ibc/config.ini \ + IBC_PATH=/opt/ibc \ + javaPath=/opt/i4j_jres \ + TWS_PATH=/root/Jts \ + twsSettingsPath=/root/Jts \ + TWOFA_TIMEOUT_ACTION=restart + +# make dirs +RUN mkdir -p /tmp && mkdir -p ${IBC_PATH} && mkdir -p ${TWS_PATH} + +# download IB TWS +RUN wget -q -O /tmp/ibgw.sh https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/ibgateway-stable-standalone-linux-x64.sh +RUN chmod +x /tmp/ibgw.sh + +# download IBC +RUN wget -q -O /tmp/IBC.zip ${IBC_ASSET_URL} +RUN unzip /tmp/IBC.zip -d ${IBC_PATH} +RUN chmod +x ${IBC_PATH}/*.sh ${IBC_PATH}/*/*.sh + +# install TWS, write output to file so that we can parse the TWS version number later +RUN touch $TWS_INSTALL_LOG +COPY install_ibgw.exp /tmp/install_ibgw.exp +RUN chmod +x /tmp/install_ibgw.exp +RUN /tmp/install_ibgw.exp + +# remove downloaded files +RUN rm /tmp/ibgw.sh /tmp/IBC.zip + +# copy IBC/Jts configs +COPY ibc/config.ini ${IBC_INI} + +# copy cmd script +WORKDIR /root +COPY cmd.sh /root/cmd.sh +RUN chmod +x /root/cmd.sh + +# set display environment variable (must be set after TWS installation) +ENV DISPLAY=:0 + +ENV IBGW_PORT 4002 + +EXPOSE $IBGW_PORT + +ENTRYPOINT [ "sh", "/root/cmd.sh" ] diff --git a/README.template b/README.template index 87d47d5..656ad9f 100644 --- a/README.template +++ b/README.template @@ -10,9 +10,9 @@ It's just pure `IB Gateway` and don't include any VNC service (for security reas This docker image just installed: -- [IB Gateway](https://www.interactivebrokers.com/en/index.php?f=16457) (###IB_GATEWAY_VER###) +- [IB Gateway](https://www.interactivebrokers.com/en/index.php?f=16457) (${IB_GATEWAY_VER}) -- [IBC](https://github.com/IbcAlpha/IBC) (###IBC_VER###) +- [IBC](https://github.com/IbcAlpha/IBC) (${IBC_VER}) ## Pull the Docker image from Docker Hub diff --git a/ibc-ver b/ibc-ver new file mode 100644 index 0000000..ae56155 --- /dev/null +++ b/ibc-ver @@ -0,0 +1 @@ +3.18.0 \ No newline at end of file diff --git a/scripts/detect_ibc_ver.py b/scripts/detect_ibc_ver.py new file mode 100644 index 0000000..464483e --- /dev/null +++ b/scripts/detect_ibc_ver.py @@ -0,0 +1,16 @@ +import requests +import os + +if __name__ == "__main__": + url = "https://api.github.com/repos/IbcAlpha/IBC/releases" + response = requests.get(url) + data = response.json() + latest = data[0] + ver = latest["name"] + for asset in latest["assets"]: + if asset["name"].startswith("IBCLinux"): + asset_url = asset["browser_download_url"] + os.putenv("IBC_VER", ver) + os.putenv("IBC_ASSET_URL", asset_url) + print(ver) + print(asset_url)