Skip to content

Commit

Permalink
update Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
manhinhang committed Apr 21, 2024
1 parent d04d94e commit 060a9df
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 139 deletions.
104 changes: 40 additions & 64 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,46 +1,19 @@
FROM debian:bookworm-slim as dependencies

# install dependencies
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y \
xvfb \
libxtst6 \
libxrender1 \
x11-utils \
socat \
procps \
xterm


FROM eclipse-temurin:21 as ibgw
FROM debian:bookworm-slim as downloader
# 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/3.18.0-Update.1/IBCLinux-3.18.0.zip"
ARG IB_GATEWAY_MAJOR="10"
ARG IB_GATEWAY_MINOR="19"

USER root
# set environment variables
ENV IBC_INI=/root/ibc/config.ini \
IBC_PATH=/opt/ibc

# install dependencies
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y wget \
unzip \
build-essential \
net-tools \
expect

# set environment variables
ENV TWS_INSTALL_LOG=/root/Jts/tws_install.log \
IBC_INI=/root/ibc/config.ini \
IBC_PATH=/opt/ibc \
TWS_PATH=/root/Jts \
IB_GATEWAY_MAJOR=${IB_GATEWAY_MAJOR} \
IB_GATEWAY_MINOR=${IB_GATEWAY_MINOR}

unzip
# make dirs
RUN mkdir -p /tmp && mkdir -p ${IBC_PATH} && mkdir -p ${TWS_PATH}
RUN mkdir -p /tmp

# download IB TWS
RUN wget -q -O /tmp/ibgw.sh https://download2.interactivebrokers.com/installers/ibgateway/stable-standalone/ibgateway-stable-standalone-linux-x64.sh
Expand All @@ -51,45 +24,48 @@ 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
RUN /tmp/ibgw.sh -q -dir /root/Jts/ibgateway/${IB_GATEWAY_MAJOR}${IB_GATEWAY_MINOR}

# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink \
--add-modules java.base \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

# copy IBC/Jts configs
COPY ibc/config.ini ${IBC_INI}

FROM debian:bookworm-slim
ARG IB_GATEWAY_MAJOR="10"
ARG IB_GATEWAY_MINOR="19"

USER root
# install dependencies
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y \
xvfb \
libxtst6 \
libxrender1 \
net-tools \
x11-utils \
socat \
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 \
TWS_PATH=/root/Jts \
TWOFA_TIMEOUT_ACTION=restart \
IB_GATEWAY_MAJOR=${IB_GATEWAY_MAJOR} \
IB_GATEWAY_MINOR=${IB_GATEWAY_MINOR}

ENV TWS_INSTALL_LOG=/root/Jts/tws_install.log
ENV IBC_INI=/root/ibc/config.ini
ENV IBC_PATH=/opt/ibc
ENV TWS_PATH=/root/Jts
ENV TWOFA_TIMEOUT_ACTION=restart
# ENV JAVA_HOME=/opt/java/openjdk
# ENV PATH "${JAVA_HOME}/bin:${PATH}"
# make dirs
RUN mkdir -p /tmp && mkdir -p ${IBC_PATH} && mkdir -p ${TWS_PATH}

RUN mkdir -p /opt/ibc
RUN mkdir -p /root/Jts
RUN mkdir -p /root/ibc
# download IB TWS
COPY --from=downloader /tmp/ibgw.sh /tmp/ibgw.sh

# COPY --from=ibgw /javaruntime $JAVA_HOME
COPY --from=dependencies / /
COPY --from=ibgw /opt/ibc /opt/ibc
COPY --from=ibgw /root/Jts /root/Jts
COPY --from=ibgw /root/ibc /root/ibc
RUN /tmp/ibgw.sh -q -dir /root/Jts/ibgateway/${IB_GATEWAY_MAJOR}${IB_GATEWAY_MINOR}
# remove downloaded files
RUN rm /tmp/ibgw.sh

RUN apt install -y openjdk-17-jre
COPY --from=downloader /opt/ibc /opt/ibc
COPY --from=downloader /root/ibc /root/ibc

# install healthcheck tool
ADD healthcheck/healthcheck/build/distributions/healthcheck.tar /
Expand All @@ -107,4 +83,4 @@ ENV IBGW_PORT 4002

EXPOSE $IBGW_PORT

ENTRYPOINT [ "sh", "/root/start.sh" ]
ENTRYPOINT [ "sh", "/root/start.sh" ]
114 changes: 39 additions & 75 deletions Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,108 +1,72 @@
FROM ubuntu:24.04 as dependencies
FROM debian:bookworm-slim as downloader
# IBC Version : https://github.com/IbcAlpha/IBC/releases
ARG IBC_VER="###IBC_VER###"
ARG IBC_ASSET_URL="###IBC_ASSET_URL###"

# set environment variables
ENV IBC_INI=/root/ibc/config.ini \
IBC_PATH=/opt/ibc

# install dependencies
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y \
xvfb \
libxtst6 \
libxrender1 \
x11-utils \
socat \
procps \
xterm
&& apt-get install -y wget \
unzip
# make dirs
RUN mkdir -p /tmp

# 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

FROM eclipse-temurin:21 as ibgw
# IBC Version : https://github.com/IbcAlpha/IBC/releases
ARG IBC_VER="###IBC_VER###"
ARG IBC_ASSET_URL="###IBC_ASSET_URL###"
# 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

# copy IBC/Jts configs
COPY ibc/config.ini ${IBC_INI}

FROM debian:bookworm-slim
ARG IB_GATEWAY_MAJOR="###IB_GATEWAY_MAJOR###"
ARG IB_GATEWAY_MINOR="###IB_GATEWAY_MINOR###"

USER root

# install dependencies
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y wget \
unzip \
build-essential \
&& apt-get install -y \
xvfb \
libxtst6 \
libxrender1 \
net-tools \
expect
x11-utils \
socat \
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 \
TWS_PATH=/root/Jts \
TWOFA_TIMEOUT_ACTION=restart \
IB_GATEWAY_MAJOR=${IB_GATEWAY_MAJOR} \
IB_GATEWAY_MINOR=${IB_GATEWAY_MINOR}

# 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
COPY --from=downloader /tmp/ibgw.sh /tmp/ibgw.sh

# install TWS, write output to file so that we can parse the TWS version number later
RUN touch $TWS_INSTALL_LOG
RUN /tmp/ibgw.sh -q -dir /root/Jts/ibgateway/${IB_GATEWAY_MAJOR}${IB_GATEWAY_MINOR}

# remove downloaded files
RUN rm /tmp/ibgw.sh /tmp/IBC.zip

# Create a custom Java runtime
RUN $JAVA_HOME/bin/jlink \
--add-modules java.base \
--strip-debug \
--no-man-pages \
--no-header-files \
--compress=2 \
--output /javaruntime

# copy IBC/Jts configs
COPY ibc/config.ini ${IBC_INI}
RUN rm /tmp/ibgw.sh

FROM ubuntu:24.04

USER root

ENV TWS_INSTALL_LOG=/root/Jts/tws_install.log
ENV IBC_INI=/root/ibc/config.ini
ENV IBC_PATH=/opt/ibc
ENV TWS_PATH=/root/Jts
ENV TWOFA_TIMEOUT_ACTION=restart
ENV JAVA_HOME=/opt/java/openjdk
ENV PATH "${JAVA_HOME}/bin:${PATH}"

# RUN apt-get update \
# && apt-get upgrade -y \
# && apt-get install -y \
# xvfb \
# libxtst6 \
# libxrender1 \
# net-tools \
# x11-utils \
# socat \
# procps \
# xterm

RUN mkdir -p /opt/ibc
RUN mkdir -p /root/Jts
RUN mkdir -p /root/ibc

COPY --from=ibgw /javaruntime $JAVA_HOME
COPY --from=dependencies / /
COPY --from=ibgw /opt/ibc /opt/ibc
COPY --from=ibgw /root/Jts /root/Jts
COPY --from=ibgw /root/ibc /root/ibc
COPY --from=downloader /opt/ibc /opt/ibc
COPY --from=downloader /root/ibc /root/ibc

# install healthcheck tool
ADD healthcheck/healthcheck/build/distributions/healthcheck.tar /
Expand All @@ -120,4 +84,4 @@ ENV IBGW_PORT 4002

EXPOSE $IBGW_PORT

ENTRYPOINT [ "sh", "/root/start.sh" ]
ENTRYPOINT [ "sh", "/root/start.sh" ]

0 comments on commit 060a9df

Please sign in to comment.