diff --git a/.env b/.env index d6b889c..e8bf873 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -CUR_IB_GATEWAY_VER=10.19.2l -CUR_IBC_VER=3.18.0 +CUR_IB_GATEWAY_VER=10.19.2o +CUR_IBC_VER=3.19.0 diff --git a/.github/workflows/deploy-dockerhub.yml b/.github/workflows/deploy.yml similarity index 51% rename from .github/workflows/deploy-dockerhub.yml rename to .github/workflows/deploy.yml index 870604c..2b56d9b 100644 --- a/.github/workflows/deploy-dockerhub.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy to docker hub +name: "Publish Docker" on: push: @@ -13,6 +13,19 @@ on: jobs: build: + strategy: + matrix: + include: + # Dockerhub + - images: manhinhang/ib-gateway-docker + username: DOCKERHUB_USERNAME + password: DOCKERHUB_PASSWORD + registry: '' + # Github + - images: ghcr.io/manhinhang/ib-gateway-docker + username: ${{ github.actor }} + password: GITHUB_TOKEN + registry: 'ghcr.io' runs-on: ubuntu-latest timeout-minutes: 20 steps: @@ -21,12 +34,13 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: manhinhang/ib-gateway-docker + images: ${{ matrix.images }} - name: Login to Docker Hub uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + registry: ${{ matrix.registry }} + username: ${{ matrix.registry == 'ghcr.io' && matrix.username || secrets[matrix.username] }} + password: ${{ secrets[matrix.password] }} - name: Build and push uses: docker/build-push-action@v5 with: diff --git a/.github/workflows/detect-new-ver.yml b/.github/workflows/detect-new-ver.yml index 867a14e..21275b6 100644 --- a/.github/workflows/detect-new-ver.yml +++ b/.github/workflows/detect-new-ver.yml @@ -14,8 +14,6 @@ jobs: IBC_VERSION_JSON_URL: "https://api.github.com/repos/IbcAlpha/IBC/releases" steps: - uses: actions/checkout@master - - name: Setup python - uses: actions/setup-python@v5 - name: detect new ib gateway version id: check-update run: | @@ -24,21 +22,25 @@ jobs: IBC_VER=$(curl ${IBC_VERSION_JSON_URL} | jq -r '.[0].name') source .env + HAS_UPDATE='false' if [ "$IB_GATEWAY_VER" = "$CUR_IB_GATEWAY_VER" ]; then - echo "No dated IB gateway version" + echo "No new IB gateway version available" echo has_update=false >> "$GITHUB_OUTPUT" else echo "New IB gateway version($IB_GATEWAY_VER)" echo has_update=true >> "$GITHUB_OUTPUT" + HAS_UPDATE='true' fi - - if [ "$IBC_VER" = "$CUR_IBC_VER" ]; then - echo "No dated IBC version" + if [ "$HAS_UPDATE" = 'false' ]; then + if [ "$IBC_VER" = "$CUR_IBC_VER" ]; then + echo "No new IBC version available" echo has_update=false >> "$GITHUB_OUTPUT" - else - echo "New IBC version($IBC_VER)" - echo has_update=true >> "$GITHUB_OUTPUT" + else + echo "New IBC version($IBC_VER) available" + echo has_update=true >> "$GITHUB_OUTPUT" + fi fi + echo "ib-gateway-ver=$IB_GATEWAY_VER" >> "$GITHUB_OUTPUT" echo "ibc-ver=$IBC_VER" >> "$GITHUB_OUTPUT" - name: Update files with new version diff --git a/Dockerfile b/Dockerfile index 155e1a7..4dbfe8b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -105,6 +105,7 @@ ENV DISPLAY=:0 ENV IBGW_PORT 4002 ENV JAVA_HEAP_SIZE 768 +ENV HEALTHCHECK_API_ENABLE=false EXPOSE $IBGW_PORT diff --git a/README.md b/README.md index 8770526..e1e0e70 100644 --- a/README.md +++ b/README.md @@ -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) (10.19.2l) +- [IB Gateway](https://www.interactivebrokers.com/en/index.php?f=16457) (10.19.2o) -- [IBC](https://github.com/IbcAlpha/IBC) (3.18.0) +- [IBC](https://github.com/IbcAlpha/IBC) (3.19.0) ## Pull the Docker image from Docker Hub @@ -26,7 +26,7 @@ docker run -d \ --env IB_ACCOUNT= \ #YOUR_USER_ID --env IB_PASSWORD= \ #YOUR_PASSWORD --env TRADING_MODE= \ #paper or live ---p 4002:4002 \ #brige IB gateway port to your local port 4002 +-p 4002:4002 \ #brige IB gateway port to your local port 4002 manhinhang/ib-gateway-docker ``` @@ -60,6 +60,8 @@ ib-gateway-docker Healthcheck via api call `http://localhost:8080/healthcheck` +Config `HEALTHCHECK_API_ENABLE=true` in environment variable to enable API + ```bash curl -f http://localhost:8080/healthcheck ``` @@ -76,6 +78,7 @@ services: - IB_ACCOUNT=$IB_ACCOUNT - IB_PASSWORD=$IB_PASSWORD - TRADING_MODE=$TRADING_MODE + - HEALTHCHECK_API_ENABLE=true healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/healthcheck"] interval: 60s diff --git a/start.sh b/start.sh index 7602fa0..44053d4 100755 --- a/start.sh +++ b/start.sh @@ -58,7 +58,12 @@ set_java_heap() { set_java_heap # start rest api for healthcheck -healthcheck-rest >&1 & +if [ "$HEALTHCHECK_API_ENABLE" = true ] ; then + echo "starting healthcheck api..." + healthcheck-rest >&1 & +else + echo "Skip starting healthcheck api" +fi echo "detect IB gateway version: $IBGW_VERSION" diff --git a/test/test_ib_gateway.py b/test/test_ib_gateway.py index d4d36b8..2b41dfb 100644 --- a/test/test_ib_gateway.py +++ b/test/test_ib_gateway.py @@ -23,7 +23,7 @@ def test_healthcheck(): assert subprocess.check_call(['docker', 'exec', docker_id, 'healthcheck']) == 0 subprocess.check_call(['docker', 'rm', '-f', docker_id]) -def test_healthcheck_rest(): +def test_healthcheck_api(): account = os.environ['IB_ACCOUNT'] password = os.environ['IB_PASSWORD'] trading_mode = os.environ['TRADING_MODE'] @@ -34,9 +34,32 @@ def test_healthcheck_rest(): '--env', 'IB_ACCOUNT={}'.format(account), '--env', 'IB_PASSWORD={}'.format(password), '--env', 'TRADING_MODE={}'.format(trading_mode), + '--env', 'HEALTHCHECK_API_ENABLE=true', '-p', '8080:8080', '-d', IMAGE_NAME]).decode().strip() time.sleep(30) response = requests.get("http://127.0.0.1:8080/healthcheck") assert response.ok subprocess.check_call(['docker', 'rm', '-f', docker_id]) + +def test_healthcheck_api_fail(): + account = 'test' + password = 'test' + trading_mode = os.environ['TRADING_MODE'] + + # run a container + docker_id = subprocess.check_output( + ['docker', 'run', + '--env', 'IB_ACCOUNT={}'.format(account), + '--env', 'IB_PASSWORD={}'.format(password), + '--env', 'TRADING_MODE={}'.format(trading_mode), + '--env', 'HEALTHCHECK_API_ENABLE=true', + '-p', '8080:8080', + '-d', IMAGE_NAME]).decode().strip() + time.sleep(30) + try: + response = requests.get("http://127.0.0.1:8080/healthcheck") + assert not response.ok + except requests.exceptions.ConnectionError: + pass + subprocess.check_call(['docker', 'rm', '-f', docker_id]) diff --git a/test/test_ib_gateway_fail.py b/test/test_ib_gateway_fail.py index 61b622e..af4a9b3 100644 --- a/test/test_ib_gateway_fail.py +++ b/test/test_ib_gateway_fail.py @@ -63,5 +63,8 @@ def test_healthcheck_fail(host): def test_healthcheck_rest_fail(host): time.sleep(30) - response = requests.get("http://127.0.0.1:8080/healthcheck") - assert not response.ok \ No newline at end of file + try: + response = requests.get("http://127.0.0.1:8080/healthcheck") + assert False + except requests.exceptions.ConnectionError: + pass