Skip to content

Commit

Permalink
ci: detect ibc version
Browse files Browse the repository at this point in the history
  • Loading branch information
manhinhang committed Apr 16, 2024
1 parent 55e282d commit 6833c2b
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 27 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/detect-new-ib-gateway-ver.yml

This file was deleted.

54 changes: 54 additions & 0 deletions .github/workflows/detect-new-ver.yml
Original file line number Diff line number Diff line change
@@ -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 [email protected]
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
68 changes: 68 additions & 0 deletions Dockerfile.temaplate
Original file line number Diff line number Diff line change
@@ -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" ]
4 changes: 2 additions & 2 deletions README.template
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions ibc-ver
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.18.0
16 changes: 16 additions & 0 deletions scripts/detect_ibc_ver.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 6833c2b

Please sign in to comment.