From eb244a1d8d01e1ad93c5dc349656aa4170397f90 Mon Sep 17 00:00:00 2001 From: Chavithra Date: Wed, 19 Oct 2022 18:00:59 +0200 Subject: [PATCH] Docker : building + publishing (#2904) * fixed integrated test test_stocks_ba.openbb * fixed integrated test test_stocks_dd.openbb * improved and centralised the check * fix lint * Docker : update ci + build files * Docker : update build and CD * Docker : update CD * Docker : test * Docker : test CD * Docker : test CD * Docker : rename `build.sh` * Docker : tests CD * Docker : test CD * Docker : update CD + build * Docker : fix CD * Docker : fix CD * Docker : build * Docker : test CD * Docker : CD * Docker : CD * Docker : test * Docker : test CD * Docker : test CD * Docker : test CD * Docker : test CD * Docker : test CD * Docker : test CD * Docker : test CD * Docker : test CD * Docker : build + CD * Docker : test CD * Docker : test CD * Docker : test CD * Docker : test CD * Docker : build * Docker : test CD * Docker : build + cd * Moving `scripts` * Checkout `helper_funcs.py` from main * Docker : remove test file with alpine * fixing readme errors * fixing missed readme errors * Docker : build * Logging : handle docker app name * Docker : test CD * Docker : cd * Doc * Doc * Doc : linting * Doc * Docker * Doc * Fixing `terminal_controller` * Linting * Doc : fixing links * Version 1.9.1 * Docker : fix name * Doc : add volumes in command Co-authored-by: hjoaquim Co-authored-by: James Simmons Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> --- .github/workflows/docker.yml | 34 ++-- DOCKER_ADVANCED.md | 63 ------ README.md | 74 +++---- build/pyinstaller/.env | 4 +- docker/build.sh | 25 +++ docker/compose.env | 14 +- docker/docker-compose.yaml | 33 +--- docker/entry-point.sh | 5 - docker/openbbterminal-poetry-deps.dockerfile | 12 -- docker/openbbterminal-poetry.dockerfile | 9 - docker/poetry-deps.dockerfile | 12 ++ docker/poetry.dockerfile | 11 ++ ...al-python.dockerfile => python.dockerfile} | 21 +- openbb_terminal/DOCKER_README.md | 183 ++++++++++++++++++ openbb_terminal/README.md | 50 ----- .../core/log/generation/settings_logger.py | 3 +- openbb_terminal/feature_flags.py | 3 - openbb_terminal/helper_funcs.py | 1 - .../miscellaneous/scripts}/README.md | 78 +++++--- openbb_terminal/terminal_controller.py | 22 +-- openbb_terminal/terminal_helper.py | 14 +- pyproject.toml | 2 +- scripts/test_stocks.openbb | 9 - 23 files changed, 391 insertions(+), 291 deletions(-) delete mode 100644 DOCKER_ADVANCED.md create mode 100644 docker/build.sh delete mode 100644 docker/entry-point.sh delete mode 100644 docker/openbbterminal-poetry-deps.dockerfile delete mode 100644 docker/openbbterminal-poetry.dockerfile create mode 100644 docker/poetry-deps.dockerfile create mode 100644 docker/poetry.dockerfile rename docker/{openbbterminal-python.dockerfile => python.dockerfile} (52%) create mode 100644 openbb_terminal/DOCKER_README.md rename {scripts => openbb_terminal/miscellaneous/scripts}/README.md (57%) delete mode 100644 scripts/test_stocks.openbb diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 107b6c2f597..32ec09366cc 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -6,23 +6,25 @@ jobs: publish-image: runs-on: ubuntu-latest env: - OWNER: openbb-finance - IMAGE: openbbterminal-poetry + OPENBBTERMINAL_DOCKER_GITHUB_REPOSITORY: ${{ github.repository }} steps: - - uses: actions/checkout@v2 + - name: Checkout Code + uses: actions/checkout@v3 - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Build the Docker image - run: | - source docker/compose.env - docker-compose -f docker/docker-compose.yaml build - docker tag `docker images -q ghcr.io/$OWNER/$IMAGE` ghcr.io/$OWNER/$IMAGE:$OPENBBTERMINAL_DOCKER_POETRY_VERSION - docker run ghcr.io/$OWNER/$IMAGE:$OPENBBTERMINAL_DOCKER_POETRY_VERSION - docker push ghcr.io/$OWNER/$IMAGE:$OPENBBTERMINAL_DOCKER_POETRY_VERSION + - name: Building the Docker image + run: | + source docker/compose.env + source docker/build.sh + echo "OPENBBTERMINAL_DOCKER_POETRY_IMAGE=$OPENBBTERMINAL_DOCKER_POETRY_IMAGE" >> $GITHUB_ENV + + - name: Publishing the Docker image + run: | + docker push "${OPENBBTERMINAL_DOCKER_POETRY_IMAGE}" diff --git a/DOCKER_ADVANCED.md b/DOCKER_ADVANCED.md deleted file mode 100644 index 893e8784f7d..00000000000 --- a/DOCKER_ADVANCED.md +++ /dev/null @@ -1,63 +0,0 @@ -# Docker Advanced Settings - -## Display - -In order to display plots in the docker container, we need to configure the XServer on the host machine. -Without this configuration the interactive charts will not be displayed. - -### X-Server on macOS - -Users familiar with Docker and X-Server can set the `DISPLAY` variable in the file [setenv](/docker/setenv) described above. If you use this approach remember to add `:0` at the end of your inet address. E.g. `DISPLAY=192.168.1.155:0`. - -For help setting up the X-Server continue reading: - -#### Setting up X Quartz/X11 - -On macOS the X11 client of choice is [XQuartz](https://www.xquartz.org/). On Windows it's [Xming](http://www.straightrunning.com/XmingNotes/). XQuartz will be used as an example further on. - -0. Install X Quartz from -1. With X Quartz open: go to Preferences -> Security and make sure both options are enabled. - ![Screen Shot 2021-09-08 at 12 21 48 PM](https://user-images.githubusercontent.com/18151143/132548605-235d774b-9aa6-4a45-afcf-58fb775d376a.png) - -#### Adding the display for Docker - -From the command prompt or terminal, run the following to add your local configuration to the list of allowed access control: - -```bash -IP=$(ifconfig | grep inet | grep -v -e "127.0.0.1" | awk '$1=="inet" {print $2}') -xhost + $IP -``` - -Now we can run the docker container, adding the display to the environment: - -```bach -docker run -it --rm --env-file=path/to/setenv -e DISPLAY=$IP:0 ghcr.io/openbb-finance/openbbterminal-poetry:latest -``` - -This container will be able to display all the same plots as the terminal interface. - -### X-Server on Linux Desktop - -X-Server is default in Linux distribution. There is no need to install any clients. - -#### Local docker container - -We can use IPC socket to connect Desktop. - -Add this setting to your `.env` file. - -```bash -OPENBB_BACKEND=Qt5Agg -``` - -And run the following commands. - -```bash -xhost +local: -docker run -it --rm --name openbb --env-file=./.env -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix ghcr.io/openbb-finance/openbbterminal-poetry:latest -xhost -local: -``` - -If you're using remote docker host, you can connect with "ssh -X ". - -Then run the previous docker command. diff --git a/README.md b/README.md index 9ad4f890855..b6c46164445 100644 --- a/README.md +++ b/README.md @@ -66,44 +66,48 @@

Table of Contents

    -
  1. About The Project
  2. -
  3. Installation
  4. -
  5. Contributing
  6. -
  7. License
  8. -
  9. Disclaimer
  10. -
  11. Contacts
  12. +
  13. About The Project
  14. +
  15. Installation
  16. +
  17. Contributing
  18. +
  19. License
  20. +
  21. Disclaimer
  22. +
  23. Contacts
  24. +
  25. Star History
  26. +
  27. Contributors
-## About The Project +## 1. About The Project **How it started:** -OpenBB Terminal is an awesome stock and crypto market terminal that has been developed for fun, while I saw my GME -shares tanking. But hey, I like the stock 💎🙌. +OpenBBTerminal is an awesome stock and crypto market terminal that has been developed for fun, while I saw my GME shares tanking. But hey, I like the stock 💎🙌. **How it's going:** -OpenBB Terminal provides a modern Python-based integrated environment for investment research, that allows +OpenBBTerminal provides a Python-based integrated environment for investment research, that allows an average joe retail trader to leverage state-of-the-art Data Science and Machine Learning technologies. -As a modern Python-based environment, OpenBBTerminal opens access to numerous Python data libraries in Data Science +As a Python-based environment, OpenBBTerminal opens access to numerous Python data libraries in Data Science (Pandas, Numpy, Scipy, Jupyter), Machine Learning (Pytorch, Sklearn, Flair), and Data Acquisition (Beautiful Soup, and numerous third-party APIs). -## Installation +## 2. Installation -If you wish to install the Terminal, there are currently four options: +If you wish to install the OpenBBTerminal, there are currently four options: -- [Using the Installer](https://openbb-finance.github.io/OpenBBTerminal/#accessing-the-openbb-terminal) (recommended if you just want to use the terminal) -- [Using Python](openbb_terminal/README.md#anaconda--python) (recommended if you want to develop new features) -- [Using Docker](openbb_terminal/README.md#Docker-Installation) (alternative option to the installer if preferred) +|**Option**|**Use case**| +|:-|:-| +|[Installer for Mac or Windows](https://openbb-finance.github.io/OpenBBTerminal/#accessing-the-openbb-terminal)|Recommended way if you just want to use the terminal.| +|[Git clone](openbb_terminal/README.md#anaconda--python)|Best way if you want to contribute to the project : by adding code or documentation.| +|[Pypi.org](openbb_terminal/SDK_README)|Best way if you want to use the SDK.| +|[Using Docker](openbb_terminal/DOCKER_README.md)|An alternative way.| -## Contributing +## 3. Contributing -There are 3 main ways of contributing to this project. (Hopefully you have starred the project by now ⭐️) +There are three main ways of contributing to this project. (Hopefully you have starred the project by now ⭐️) -**Become a Contributor** +**BECOME A CONTRIBUTOR** 1. Fork the Project 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) @@ -115,33 +119,37 @@ There are 3 main ways of contributing to this project. (Hopefully you have starr You can read more details about adding a feature in our [CONTRIBUTING GUIDELINES](/CONTRIBUTING.md). -**Raise an issue or Request a feature** +**RAISE AN ISSUE OR REQUEST A FEATURE** - Raise an issue by opening a [bug ticket](https://github.com/OpenBB-finance/OpenBBTerminal/issues). - Request a new feature through a [feature request ticket](https://github.com/OpenBB-finance/OpenBBTerminal/issues). -**Join us** +**JOIN US** Join [our Discord](https://openbb.co/discord) and provide us any feedback on The OpenBB Terminal. -## License +## 4. License Distributed under the MIT License. See [LICENSE](https://github.com/OpenBB-finance/OpenBBTerminal/blob/main/LICENSE) for more information. -## Disclaimer +## 5. Disclaimer -"A few things I am not. I am not a cat. I am not an institutional investor, nor am I a hedge fund. I do not have -clients and I do not provide personalized investment advice for fees or commissions." DFV +*"A few things I am not. I am not a cat. I am not an institutional investor, nor am I a hedge fund. I do not have +clients and I do not provide personalized investment advice for fees or commissions."* DFV +```text Trading in financial instruments involves high risks including the risk of losing some, or all, of your investment -amount, and may not be suitable for all investors. Before deciding to trade in a financial instrument you should be fully -informed of the risks and costs associated with trading the financial markets, carefully consider your investment -objectives, level of experience, and risk appetite, and seek professional advice where needed. The data contained in the OpenBB terminal -is not necessarily accurate. OpenBB and any provider of the data contained in this website will not accept liability for -any loss or damage as a result of your trading, or your reliance on the information displayed. +amount, and may not be suitable for all investors. -## Contacts +Before deciding to trade in a financial instrument you should be fully informed of the risks and costs associated with trading the financial markets, carefully consider your investment objectives, level of experience, and risk appetite, and seek professional advice where needed. + +The data contained in the OpenBBTerminal is not necessarily accurate. + +OpenBB and any provider of the data contained in this website will not accept liability for any loss or damage as a result of your trading, or your reliance on the information displayed. +``` + +## 6. Contacts If you have any questions about the terminal or anything OpenBB, feel free to email us at support@openbb.co @@ -153,11 +161,11 @@ Feel free to share loss porn, memes or any questions at: - Discord: [openbb.co/discord](https://openbb.co/discord) - Reddit: [openbb.co/reddit](https://openbb.co/reddit) -## Star History +## 7. Star History [![Star History Chart](https://api.star-history.com/svg?repos=openbb-finance/OpenBBTerminal&type=Date)](https://star-history.com/#openbb-finance/OpenBBTerminal&Date) -## Contributors +## 8. Contributors diff --git a/build/pyinstaller/.env b/build/pyinstaller/.env index 4c7c2c49eb2..4033d71e90c 100644 --- a/build/pyinstaller/.env +++ b/build/pyinstaller/.env @@ -1,5 +1,5 @@ -OPENBB_PACKAGED_APPLICATION=true -OPENBB_LOGGING_COMMIT_HASH='sha:c9884228' +OPENBB_LOGGING_APP_NAME=gst_packaged +OPENBB_LOGGING_COMMIT_HASH=sha:c9884228 OPENBB_ENABLE_PREDICT=false OPENBB_ENABLE_CHECK_API=true OPENBB_ENABLE_THOUGHTS_DAY=false diff --git a/docker/build.sh b/docker/build.sh new file mode 100644 index 00000000000..5f45187ef11 --- /dev/null +++ b/docker/build.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +echo "Building docker releases" + +# SET DEFAULT PARAMETERS IF EMPTY +OPENBBTERMINAL_DOCKER_REGISTRY="${OPENBBTERMINAL_DOCKER_REGISTRY:-ghcr.io}" +OPENBBTERMINAL_DOCKER_GITHUB_REPOSITORY="${OPENBBTERMINAL_DOCKER_GITHUB_REPOSITORY:-openbb-finance}" +OPENBBTERMINAL_DOCKER_RELEASE_VERSION="${OPENBBTERMINAL_DOCKER_RELEASE_VERSION:-0.0.1}" +# SET IMAGES NAMES +OPENBBTERMINAL_DOCKER_PYTHON_IMAGE=${OPENBBTERMINAL_DOCKER_REGISTRY,,}/${OPENBBTERMINAL_DOCKER_GITHUB_REPOSITORY,,}/python:${OPENBBTERMINAL_DOCKER_RELEASE_VERSION,,} +OPENBBTERMINAL_DOCKER_POETRY_DEPS_IMAGE=${OPENBBTERMINAL_DOCKER_REGISTRY,,}/${OPENBBTERMINAL_DOCKER_GITHUB_REPOSITORY,,}/poetry-deps:${OPENBBTERMINAL_DOCKER_RELEASE_VERSION,,} +OPENBBTERMINAL_DOCKER_POETRY_IMAGE=${OPENBBTERMINAL_DOCKER_REGISTRY,,}/${OPENBBTERMINAL_DOCKER_GITHUB_REPOSITORY,,}/poetry:${OPENBBTERMINAL_DOCKER_RELEASE_VERSION,,} + +# DISPLAY PARAMETERS +echo "OPENBBTERMINAL_DOCKER_REGISTRY = $OPENBBTERMINAL_DOCKER_REGISTRY" +echo "OPENBBTERMINAL_DOCKER_GITHUB_REPOSITORY = $OPENBBTERMINAL_DOCKER_GITHUB_REPOSITORY" +echo "OPENBBTERMINAL_DOCKER_RELEASE_VERSION = $OPENBBTERMINAL_DOCKER_RELEASE_VERSION" +# DISPLAY IMAGES NAMES +echo "OPENBBTERMINAL_DOCKER_PYTHON_IMAGE = $OPENBBTERMINAL_DOCKER_PYTHON_IMAGE" +echo "OPENBBTERMINAL_DOCKER_POETRY_DEPS_IMAGE = $OPENBBTERMINAL_DOCKER_POETRY_DEPS_IMAGE" +echo "OPENBBTERMINAL_DOCKER_POETRY_IMAGE = $OPENBBTERMINAL_DOCKER_POETRY_IMAGE" + +docker build -f docker/python.dockerfile -t ${OPENBBTERMINAL_DOCKER_PYTHON_IMAGE} . +docker build -f docker/poetry-deps.dockerfile -t ${OPENBBTERMINAL_DOCKER_POETRY_DEPS_IMAGE} --build-arg OPENBBTERMINAL_DOCKER_PYTHON_IMAGE=${OPENBBTERMINAL_DOCKER_PYTHON_IMAGE} . +docker build -f docker/poetry.dockerfile -t "${OPENBBTERMINAL_DOCKER_POETRY_IMAGE}" --build-arg OPENBBTERMINAL_DOCKER_POETRY_DEPS_IMAGE=${OPENBBTERMINAL_DOCKER_POETRY_DEPS_IMAGE} . diff --git a/docker/compose.env b/docker/compose.env index e3ce49cafba..70bd0953c5a 100644 --- a/docker/compose.env +++ b/docker/compose.env @@ -1,12 +1,2 @@ -OPENBBTERMINAL_DOCKER_IMAGE_PREFIX="ghcr.io/openbb-finance" -OPENBBTERMINAL_DOCKER_PYTHON_VERSION="1.8.0" -OPENBBTERMINAL_DOCKER_POETRY_DEPS_VERSION="1.8.0" -OPENBBTERMINAL_DOCKER_POETRY_VERSION="1.8.0" -DOCKER_DEFAULT_PLATFORM=linux/amd64 - -export OPENBBTERMINAL_DOCKER_IMAGE_PREFIX -export OPENBBTERMINAL_DOCKER_PYTHON_VERSION -export OPENBBTERMINAL_DOCKER_DEPS_VERSION -export OPENBBTERMINAL_DOCKER_POETRY_DEPS_VERSION -export OPENBBTERMINAL_DOCKER_OPENBBTERMINAL_VERSION -export OPENBBTERMINAL_DOCKER_POETRY_VERSION +OPENBBTERMINAL_DOCKER_REGISTRY="ghcr.io" +OPENBBTERMINAL_DOCKER_RELEASE_VERSION="1.9.1" \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index e669f75b19f..7e5b25adc08 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -1,27 +1,12 @@ version: '3.8' services: - openbbterminal-python: + poetry: + environment: + DISPLAY: host.docker.internal:0.0 + volumes: + - ~/OpenBBUserData:/home/python/OpenBBUserData + - ~/.openbb_terminal:/home/python/.openbb_terminal platform: linux/amd64 - build: - context: .. - dockerfile: docker/openbbterminal-python.dockerfile - image: "${OPENBBTERMINAL_DOCKER_IMAGE_PREFIX}/openbbterminal-python:${OPENBBTERMINAL_DOCKER_PYTHON_VERSION}" - openbbterminal-poetry-deps: - platform: linux/amd64 - build: - context: .. - dockerfile: docker/openbbterminal-poetry-deps.dockerfile - args: - OPENBBTERMINAL_DOCKER_IMAGE_PREFIX: ${OPENBBTERMINAL_DOCKER_IMAGE_PREFIX} - OPENBBTERMINAL_DOCKER_PYTHON_VERSION: ${OPENBBTERMINAL_DOCKER_PYTHON_VERSION} - image: "${OPENBBTERMINAL_DOCKER_IMAGE_PREFIX}/openbbterminal-poetry-deps:${OPENBBTERMINAL_DOCKER_POETRY_DEPS_VERSION}" - openbbterminal-poetry: - platform: linux/amd64 - build: - context: .. - dockerfile: docker/openbbterminal-poetry.dockerfile - args: - OPENBBTERMINAL_DOCKER_IMAGE_PREFIX: ${OPENBBTERMINAL_DOCKER_IMAGE_PREFIX} - OPENBBTERMINAL_DOCKER_POETRY_DEPS_VERSION: ${OPENBBTERMINAL_DOCKER_POETRY_DEPS_VERSION} - image: "${OPENBBTERMINAL_DOCKER_IMAGE_PREFIX}/openbbterminal-poetry:${OPENBBTERMINAL_DOCKER_POETRY_VERSION}" - tty: true + image: ghcr.io/openbb-finance/openbbterminal/poetry:1.9.1 + stdin_open: true # docker run -i + tty: true # docker run -t \ No newline at end of file diff --git a/docker/entry-point.sh b/docker/entry-point.sh deleted file mode 100644 index 76b8b343be3..00000000000 --- a/docker/entry-point.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -# stty erase ^h -# poetry run python terminal.py -python terminal.py diff --git a/docker/openbbterminal-poetry-deps.dockerfile b/docker/openbbterminal-poetry-deps.dockerfile deleted file mode 100644 index 84ee9325ff2..00000000000 --- a/docker/openbbterminal-poetry-deps.dockerfile +++ /dev/null @@ -1,12 +0,0 @@ -ARG OPENBBTERMINAL_DOCKER_IMAGE_PREFIX="ghcr.io/openbb-finance" -ARG OPENBBTERMINAL_DOCKER_PYTHON_VERSION="1.0.0" -FROM ${OPENBBTERMINAL_DOCKER_IMAGE_PREFIX}/openbbterminal-python:${OPENBBTERMINAL_DOCKER_PYTHON_VERSION} - -LABEL org.opencontainers.image.source https://github.com/OpenBB-finance/OpenBBTerminal - -COPY --chown=python:python pyproject.toml poetry.lock /home/python/ - -RUN mkdir /home/python/openbb_terminal && \ - touch openbb_terminal/__init__.py && \ - chown python:python /home/python/openbb_terminal /home/python/openbb_terminal/__init__.py && \ - poetry install diff --git a/docker/openbbterminal-poetry.dockerfile b/docker/openbbterminal-poetry.dockerfile deleted file mode 100644 index f65f53257c9..00000000000 --- a/docker/openbbterminal-poetry.dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -ARG OPENBBTERMINAL_DOCKER_IMAGE_PREFIX="ghcr.io/openbb-finance" -ARG OPENBBTERMINAL_DOCKER_POETRY_DEPS_VERSION="1.2.0" -FROM ${OPENBBTERMINAL_DOCKER_IMAGE_PREFIX}/openbbterminal-poetry-deps:${OPENBBTERMINAL_DOCKER_POETRY_DEPS_VERSION} - -LABEL org.opencontainers.image.source https://github.com/OpenBB-finance/OpenBBTerminal - -COPY --chown=python:python . . - -CMD ["bash", "docker/entry-point-poetry.sh"] diff --git a/docker/poetry-deps.dockerfile b/docker/poetry-deps.dockerfile new file mode 100644 index 00000000000..7099d7a8c7b --- /dev/null +++ b/docker/poetry-deps.dockerfile @@ -0,0 +1,12 @@ +ARG OPENBBTERMINAL_DOCKER_PYTHON_IMAGE="ghcr.io/openbb-finance/openbbterminal-python:1.0.0" + +FROM ${OPENBBTERMINAL_DOCKER_PYTHON_IMAGE} + +LABEL org.opencontainers.image.source https://github.com/OpenBB-finance/OpenBBTerminal + +COPY --chown=python:python pyproject.toml poetry.lock /home/python/ + +RUN mkdir /home/python/openbb_terminal +RUN touch openbb_terminal/__init__.py +RUN chown python:python /home/python/openbb_terminal /home/python/openbb_terminal/__init__.py +RUN poetry install diff --git a/docker/poetry.dockerfile b/docker/poetry.dockerfile new file mode 100644 index 00000000000..ca3c0d45604 --- /dev/null +++ b/docker/poetry.dockerfile @@ -0,0 +1,11 @@ +ARG OPENBBTERMINAL_DOCKER_POETRY_DEPS_IMAGE="ghcr.io/openbb-finance/openbbterminal-poetry-deps:1.0.0" + +FROM ${OPENBBTERMINAL_DOCKER_POETRY_DEPS_IMAGE} + +LABEL org.opencontainers.image.source https://github.com/OpenBB-finance/OpenBBTerminal + +COPY --chown=python:python . . + +RUN echo "OPENBB_LOGGING_APP_NAME=gst_docker" > .env + +CMD ["bash", "docker/entry-point-poetry.sh"] diff --git a/docker/openbbterminal-python.dockerfile b/docker/python.dockerfile similarity index 52% rename from docker/openbbterminal-python.dockerfile rename to docker/python.dockerfile index 78ca12c5976..1436dda7519 100644 --- a/docker/openbbterminal-python.dockerfile +++ b/docker/python.dockerfile @@ -1,8 +1,9 @@ -FROM python:3.9-slim-buster +FROM python:3.9-slim-bullseye LABEL org.opencontainers.image.source https://github.com/OpenBB-finance/OpenBBTerminal -RUN apt-get update && apt-get -y install --no-install-recommends \ +RUN apt-get update +RUN apt-get -y install --no-install-recommends \ gcc \ g++ \ make \ @@ -21,13 +22,13 @@ RUN apt-get update && apt-get -y install --no-install-recommends \ libgl1-mesa-glx \ libpng16-16 \ procps \ - python3-tk && \ - curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh && \ - bash nodesource_setup.sh && \ - apt-get install -y nodejs && \ - apt-get -y autoremove && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + python3-tk +RUN curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh +RUN bash nodesource_setup.sh +RUN apt-get install -y nodejs +RUN apt-get -y autoremove +RUN apt-get clean +RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN useradd --create-home --shell /bin/bash python @@ -36,4 +37,4 @@ WORKDIR /home/python ENV PATH="/home/python/.local/bin:${PATH}" -RUN pip install "poetry==1.1.13" +RUN pip install "poetry==1.1.15" diff --git a/openbb_terminal/DOCKER_README.md b/openbb_terminal/DOCKER_README.md new file mode 100644 index 00000000000..a2710e8ed47 --- /dev/null +++ b/openbb_terminal/DOCKER_README.md @@ -0,0 +1,183 @@ +# OpenBBTerminal with Docker + +Here are the steps to get OpenBBTerminal using the Docker containers that we provide: + +1. Installing `Docker` and `Docker Compose` +2. Pulling and running `OpenBBTerminal Docker Container` +3. Configuring your X-server to show plots + +Each of this steps need to be followed to have a working version of OpenBBTerminal. + +We will detail these steps in the rest of this document. + +## 1. Installing `Docker` and `Docker Compose` + +**INSTALL DOCKER** + +Installing Docker Desktop is the easiest way for most people: + +It has a `Graphical User Interface` and comes with `Docke Compose` in it. + +You can find `Docker Desktop` installation file for your `OS` here: + +[Download Docker Desktop](https://www.docker.com/products/docker-desktop) + +**START DOCKER** + +Once you have `Docker` installed and running, you can use the following command to check the state: + +```bash +docker info +``` + +It should output a text like this one: + +```text +Client: + Context: default + Debug Mode: false + +Server: + Containers: 14 + Running: 2 + Paused: 1 + Stopped: 10 +... +``` + +If you see a message like the following, it most likely means you need to start `Docker`. + +Open the docker desktop app in this case. + +```text +Server: +ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. +Is the docker daemon running? +``` + +## 2. Pulling and running `OpenBBTerminal Docker Container` + +**DOCKER COMPOSE** + +Here are the commands to use `Docker Compose` to pull and run the `OpenBBTerminal Docker Container`: + +```bash +curl -o docker-compose.yaml https://raw.githubusercontent.com/OpenBB-finance/OpenBBTerminal/main/docker/docker-compose.yaml + +docker compose run poetry +``` + +The command line with `curl` is downloading this file : [`docker-compose.yaml`](https://raw.githubusercontent.com/OpenBB-finance/OpenBBTerminal/main/docker/docker-compose.yaml). + +The `docker-compose.yaml` file is a configuration file telling `Docker Compose`: + +- where to find `OpenBBTerminal Docker Container` +- how to run this container. + +The second command runs `Docker Compose` on the service `poetry` defined in this `docker-compose.yaml` file. + +This second command must be run in the same folder in which `docker-compose.yaml` file is. + +**DOCKER** + +If you don't have `Docker Compose` you can also use `Docker` directly to run the `OpenBBTerminal Docker Container`. + +Here is the commands to run: + +```bash +docker pull ghcr.io/openbb-finance/openbbterminal/poetry:X.Y.Z + +docker run -v ~/.openbb_terminal/:/home/python/.openbb_terminal -v ~/OpenBBUserData:/home/python/OpenBBUserData -it --rm ghcr.io/openbb-finance/openbbterminal/poetry:X.Y.Z +``` + +Be sure to replace `X.Y.Z` with the version you want to pull and run. + +Note for windows: + +```text + Ignore this message if you are using Powershell or a more evolved interpreters. + If you are using the builtin Windows interpreter. + Replace `~` by `%USERPROFILE%` in the command above. +``` + +## 3. Configuring your X-server to show plots + +In order to display plots in the docker container, we need to configure the XServer on the host machine. +Without this configuration the interactive charts will not be displayed. + +### On Windows + +Download and install : [VcXsrv](https://sourceforge.net/projects/vcxsrv/) + +When running the program is important to check "Disable access control" + +Run `Docker Compose` like this: + +```bash +curl -o docker-compose.yaml https://raw.githubusercontent.com/OpenBB-finance/OpenBBTerminal/main/docker/docker-compose.yaml + +docker compose run poetry +``` + +Or run `Docker` directly: + +```bash +docker run -v ~/.openbb_terminal:/home/python/.openbb_terminal -v ~/OpenBBUserData:/home/python/OpenBBUserData -it --rm --env DISPLAY=host.docker.internal:0.0 ghcr.io/openbb-finance/openbbterminal/poetry:X.Y.Z +``` + +### X-Server on macOS + +Users familiar with Docker and X-Server can set the `DISPLAY` variable in the file [setenv](/docker/setenv) described above. If you use this approach remember to add `:0` at the end of your inet address. E.g. `DISPLAY=192.168.1.155:0`. + +For help setting up the X-Server continue reading: + +#### Setting up X Quartz/X11 + +On macOS the X11 client of choice is [XQuartz](https://www.xquartz.org/). On Windows it's [Xming](http://www.straightrunning.com/XmingNotes/). XQuartz will be used as an example further on. + +0. Install X Quartz from +1. With X Quartz open: go to Preferences -> Security and make sure both options are enabled. + ![Screen Shot 2021-09-08 at 12 21 48 PM](https://user-images.githubusercontent.com/18151143/132548605-235d774b-9aa6-4a45-afcf-58fb775d376a.png) + +#### Adding the display for Docker + +From the command prompt or terminal, run the following to add your local configuration to the list of allowed access control: + +```bash +IP=$(ifconfig | grep inet | grep -v -e "127.0.0.1" | awk '$1=="inet" {print $2}') +xhost + $IP +``` + +Now we can run the docker container, adding the display to the environment: + +```bach +docker run -v ~/.openbb_terminal/:/home/python/.openbb_terminal -v ~/OpenBBUserData:/home/python/OpenBBUserData -it --rm --env-file=path/to/setenv --env DISPLAY=$IP:0 ghcr.io/openbb-finance/openbbterminal/poetry:X.Y.Z +``` + +This container will be able to display all the same plots as the terminal interface. + +### X-Server on Linux Desktop + +X-Server is default in Linux distribution. There is no need to install any clients. + +#### Local docker container + +We can use IPC socket to connect Desktop. + +Add this setting to your `.env` file. + +```bash +OPENBB_BACKEND=Qt5Agg +``` + +And run the following commands. + +```bash +xhost +local: +docker run -it --rm --name openbb --env-file=./.env -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix ghcr.io/openbb-finance/openbbterminal/poetry:X.Y.Z +xhost -local: +``` + +If you're using remote docker host, you can connect with "ssh -X ". + +Then run the previous docker command. diff --git a/openbb_terminal/README.md b/openbb_terminal/README.md index c238f351a09..edb01e8764d 100644 --- a/openbb_terminal/README.md +++ b/openbb_terminal/README.md @@ -249,56 +249,6 @@ If you `stashed` your changes previously, you can un-stash them with: git stash pop ``` -## Docker Installation - -1. Make sure docker desktop is installed. Install links can be found [here](https://www.docker.com/products/docker-desktop). - To confirm that your docker desktop is downloaded and running, open a command prompt or terminal and enter - `docker info`. If you get the following you are not running the docker desktop: - - ```text - Server: - ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. - Is the docker daemon running? - ``` - - Open the docker desktop app in this case. - -2. Download the latest docker image. - - ```bash - docker pull ghcr.io/openbb-finance/openbbterminal-poetry:latest - ``` - - Upon running this the first time, you should see the various layers downloading (note the random series of letters - numbers will vary). The first time this is run, it will take a few minutes. Subsequent updates will be much faster, - as the changes will be in the MB instead of GB. - - ![Screen Shot 2021-09-08 at 10 41 08 AM](https://user-images.githubusercontent.com/18151143/132531075-7d7f7e71-4fcb-435c-9bb3-466d7077eba4.png) - - Once the download is complete, confirm that the image has been created by doing `docker images`. You should see - something similar to - - ```text - REPOSITORY TAG IMAGE ID CREATED SIZE - ghcr.io/openbb-finance/openbbterminal-poetry latest b1409a304750 42 hours ago 2.29GB - ``` - -3. Run a container - - To launch the container you need to run the following command: - - `docker run -v ~/.openbb_terminal/:/home/python/.openbb_terminal -v ~/OpenBBUserData:/home/python/OpenBBUserData -it --rm ghcr.io/openbb-finance/openbbterminal-poetry:1.6.0` - - **NOTE FOR WINDOWS** - - Replace `~` by `%USERPROFILE%` in the command above. - This applies if you are using the builtin Windows interpreter. - You won't have to do this inside Powershell or more evolved interpreters. - - At this point, you should be able to use the majority of the features using Docker. To read more on how to configure - your X-server to show plots, hop over to the - [Advanced Docker Setup](/DOCKER_ADVANCED.md). - ## Local Installation of GST on Raspberry Pi 1. Running raspbian lite(headless) or desktop (both 64bit) we should first start off with an update/upgrade. diff --git a/openbb_terminal/core/log/generation/settings_logger.py b/openbb_terminal/core/log/generation/settings_logger.py index 42db57d77a9..46221e64114 100644 --- a/openbb_terminal/core/log/generation/settings_logger.py +++ b/openbb_terminal/core/log/generation/settings_logger.py @@ -10,6 +10,7 @@ from types import FunctionType, ModuleType # IMPORTATION INTERNAL import openbb_terminal.feature_flags as obbff from openbb_terminal import config_terminal as cfg +from openbb_terminal.terminal_helper import is_packaged_application from openbb_terminal.core.log.generation.path_tracking_file_handler import ( PathTrackingFileHandler, ) @@ -57,7 +58,7 @@ def log_settings() -> None: settings_dict["watermark"] = "True" if obbff.USE_WATERMARK else "False" settings_dict["autoscaling"] = "True" if obbff.USE_PLOT_AUTOSCALING else "False" settings_dict["dt"] = "True" if obbff.USE_DATETIME else "False" - settings_dict["packaged"] = "True" if obbff.PACKAGED_APPLICATION else "False" + settings_dict["packaged"] = "True" if is_packaged_application() else "False" settings_dict["python"] = str(platform.python_version()) settings_dict["os"] = str(platform.system()) diff --git a/openbb_terminal/feature_flags.py b/openbb_terminal/feature_flags.py index 571e8225b23..6e3339cf13f 100644 --- a/openbb_terminal/feature_flags.py +++ b/openbb_terminal/feature_flags.py @@ -87,9 +87,6 @@ LOG_COLLECTION = bool(strtobool(os.getenv("OPENBB_LOG_COLLECT", "True"))) # Provide export folder path. If empty that means default. EXPORT_FOLDER_PATH = str(os.getenv("OPENBB_EXPORT_FOLDER_PATH", "")) -# Set a flag if the application is running from a packaged bundle -PACKAGED_APPLICATION = strtobool(os.getenv("OPENBB_PACKAGED_APPLICATION", "False")) - # Toolbar hint TOOLBAR_HINT = strtobool(os.getenv("OPENBB_TOOLBAR_HINT", "True")) diff --git a/openbb_terminal/helper_funcs.py b/openbb_terminal/helper_funcs.py index e88ec9df08a..2352116b507 100644 --- a/openbb_terminal/helper_funcs.py +++ b/openbb_terminal/helper_funcs.py @@ -1149,7 +1149,6 @@ def replace_user_timezone(user_tz: str) -> None: """ if is_timezone_valid(user_tz): dotenv.set_key(USER_ENV_FILE, "OPENBB_TIMEZONE", user_tz) - os.environ["OPENBB_TIMEZONE"] = user_tz console.print("Timezone successfully updated", "\n") else: console.print("Timezone selected is not valid", "\n") diff --git a/scripts/README.md b/openbb_terminal/miscellaneous/scripts/README.md similarity index 57% rename from scripts/README.md rename to openbb_terminal/miscellaneous/scripts/README.md index 9e9c099f1a5..8598bfaa2a0 100644 --- a/scripts/README.md +++ b/openbb_terminal/miscellaneous/scripts/README.md @@ -1,4 +1,4 @@ -# 1. OpenBB Terminal : `Integration Testing` +# OpenBB Terminal : `Integration Testing` This document is part of the `OpenBB Terminal` library documentation. @@ -9,20 +9,30 @@ It aims to provide necessary information in order to: - Identify errors noted from `integration tests` ## 1.1. Why having integration tests ? -The purpose of integration tests is to provide standard usage examples that can be programmatically run to make sure that a specific functionality of the terminal and the process to utilize that functionality is working properly. -# 2. How to build integration tests ? +The purpose of integration tests is to provide standard usage examples that can be programmatically run +to make sure that a specific functionality of the terminal and the process to utilize that functionality +is working properly. -Integration tests themselves are the same as manually running a certain series of steps. As a result, writing tests is easy because the integration test script is just the total list of steps necessary to use a command, command with specific argument, or series of commands. +## 2. How to build integration tests ? -When you contribute a new feature to the Terminal, it's important that integration tests are added for this particular feature. It is a part of the Checklist for the PR to be approved. +Integration tests themselves are the same as manually running a certain series of steps. As a result, +writing tests is easy because the integration test script is just the total list of steps necessary to +use a command, command with specific argument, or series of commands. -All the `integration tests` should be insides the `scripts` folder. The naming convention for scripts should be `test__.openbb` if you are testing a specific command or `test_.openbb` if you are testing the entire menu. However, it is encouraged to create as specific of integration tests as possible to identify errors more precisely. Additionally, all tests must end with the `exit` command. +When you contribute a new feature to the Terminal, it's important that integration tests are added for +this particular feature. It is a part of the Checklist for the PR to be approved. + +All the `integration tests` should be insides the `scripts` folder. The naming convention for scripts +should be `test__.openbb` if you are testing a specific command or `test_.openbb` +if you are testing the entire menu. However, it is encouraged to create as specific of integration tests +as possible to identify errors more precisely. Additionally, all tests must end with the `exit` command. ### Examples + Testing a specific command and it's arguments: -``` +```zsh script: test_alt_covid.openbb - - - - - - - - - - alternative @@ -42,7 +52,8 @@ exit ``` Testing an entire menu -``` + +```zsh test_stocks_options.openbb - - - - - - - - - - stocks @@ -77,49 +88,63 @@ exit ### Conda Terminal -After navigating to the location of the OpenBBTerminal repo, one can run integration tests in a few different ways using the wildcare expression `*`. +After navigating to the location of the OpenBBTerminal repo, one can run integration tests in a +few different ways using the wildcard expression. -* Run all integration tests: - ``` +- Run all integration tests: + + ```zsh python terminal.py scripts/*.openbb -t ``` -* Run some integration tests: - ``` +- Run some integration tests: + + ```zsh python terminal.py scripts/test_stocks_*.openbb -t ``` + *This specific example runs all of the stocks integration tests. One can use this same format for different tests.* -* Run one integration tests: - ``` +- Run one integration tests: + + ```zsh python terminal.py scripts/test_alt_covid.openbb -t ``` ### Installer Terminal -Integration tests can also be used on installers, which is a packaged version of the conda terminal. More information on how to build an installer can be found [here](/build/README.md). +Integration tests can also be used on installers, which is a packaged version of the conda terminal. +More information on how to build an installer can be found [here](/build/README.md). -* Run all integration tests: - ``` +- Run all integration tests: + + ```zsh /Full/Path/To/OpenBB\ Terminal/.OpenBB/OpenBBTerminal /Full/Path/To/OpenBBTerminal/OpenBBTerminal/scripts/*.openbb -t ``` -* Run some integration tests: - ``` +- Run some integration tests: + + ```zsh /Full/Path/To/OpenBB\ Terminal/.OpenBB/OpenBBTerminal /Full/Path/To/OpenBBTerminal/OpenBBTerminal/scripts/test_stocks_*.openbb -t ``` -* Run one integration tests: - ``` +- Run one integration tests: + + ```zsh /Full/Path/To/OpenBB\ Terminal/.OpenBB/OpenBBTerminal /Full/Path/To/OpenBBTerminal/OpenBBTerminal/scripts/test_alt_covid.openbb -t ``` -The `-t` argument runs the integration tests in 'test' mode. It is effectively a 'quiet' mode where one doesn't see the terminal in action. If one were to remove this argument, then the terminal and subsequent steps will be seen running in real time. +The `-t` argument runs the integration tests in 'test' mode. It is effectively a 'quiet' mode where one +doesn't see the terminal in action. If one were to remove this argument, then the terminal and subsequent +steps will be seen running in real time. ## 4. Errors -If the `-t` argument is given, errors that occur during an integration test are shown after all the selected tests have run. The specific script that has some type of failure occurring, the reason why it failed, and a summary of all the integration tests that were run is printed. An example is as followed: -``` +If the `-t` argument is given, errors that occur during an integration test are shown after all the +selected tests have run. The specific script that has some type of failure occurring, the reason why +it failed, and a summary of all the integration tests that were run is printed. An example is as followed: + +```zsh /scripts/test_stocks_ba.openbb: Implement enable_gui in a subclass /scripts/test_stocks_disc.openbb: No tables found @@ -131,6 +156,7 @@ If the `-t` argument is given, errors that occur during an integration test are Summary: Successes: 55 Failures: 4 ``` -If the `-t` argument is not given, then the reason why a specific failure occurs within an integration test is printed inline while the test is being run. +If the `-t` argument is not given, then the reason why a specific failure occurs within an integration +test is printed inline while the test is being run. If there is an error, one can identify the command and or series of steps that causes it fairly easily. diff --git a/openbb_terminal/terminal_controller.py b/openbb_terminal/terminal_controller.py index cee62c615d7..a775a85a19d 100644 --- a/openbb_terminal/terminal_controller.py +++ b/openbb_terminal/terminal_controller.py @@ -19,7 +19,7 @@ from prompt_toolkit.formatted_text import HTML import pandas as pd from openbb_terminal import feature_flags as obbff - +from openbb_terminal.terminal_helper import is_packaged_application from openbb_terminal.core.config.paths import ( HOME_DIRECTORY, MISCELLANEOUS_DIRECTORY, @@ -138,7 +138,7 @@ class TerminalController(BaseController): mt.add_cmd("about") mt.add_cmd("support") mt.add_cmd("survey") - if not obbff.PACKAGED_APPLICATION: + if not is_packaged_application(): mt.add_cmd("update") mt.add_cmd("wiki") mt.add_cmd("record") @@ -326,7 +326,7 @@ class TerminalController(BaseController): def call_update(self, _): """Process update command""" - if not obbff.PACKAGED_APPLICATION: + if not is_packaged_application(): self.update_success = not update_terminal() else: console.print( @@ -400,7 +400,7 @@ class TerminalController(BaseController): def call_dashboards(self, _): """Process dashboards command""" - if not obbff.PACKAGED_APPLICATION: + if not is_packaged_application(): from openbb_terminal.dashboards.dashboards_controller import ( DashboardsController, ) @@ -594,14 +594,11 @@ class TerminalController(BaseController): # pylint: disable=global-statement -def terminal(jobs_cmds: List[str] = None, appName: str = "gst", test_mode=False): +def terminal(jobs_cmds: List[str] = None, test_mode=False): """Terminal Menu""" - # TODO: HELP WANTED! Refactor the appName setting if a more elegant solution comes up - if obbff.PACKAGED_APPLICATION: - appName = "gst_packaged" if not test_mode: - setup_logging(appName) + setup_logging() logger.info("START") log_all_settings() @@ -815,14 +812,13 @@ def run_scripts( file_cmds = [" ".join(file_cmds)] if not test_mode: - terminal(file_cmds, appName="openbb_script") - # TODO: Add way to track how many commands are tested + terminal(file_cmds, test_mode=True) else: if verbose: - terminal(file_cmds, appName="openbb_script", test_mode=True) + terminal(file_cmds, test_mode=True) else: with suppress_stdout(): - terminal(file_cmds, appName="openbb_script", test_mode=True) + terminal(file_cmds, test_mode=True) else: console.print(f"File '{path}' doesn't exist. Launching base terminal.\n") if not test_mode: diff --git a/openbb_terminal/terminal_helper.py b/openbb_terminal/terminal_helper.py index dacc7a8d261..148d99e13fa 100644 --- a/openbb_terminal/terminal_helper.py +++ b/openbb_terminal/terminal_helper.py @@ -16,6 +16,7 @@ import requests import matplotlib.pyplot as plt # IMPORTATION INTERNAL +from openbb_terminal import config_terminal as cfg from openbb_terminal import feature_flags as obbff from openbb_terminal import thought_of_the_day as thought from openbb_terminal.rich_config import console @@ -174,12 +175,23 @@ def hide_splashscreen(): logger.info(e) +def is_packaged_application() -> bool: + """Tell whether or not it is a packaged version (Windows or Mac installer). + + + Returns: + bool: If the application is packaged + """ + + return cfg.LOGGING_APP_NAME == "gst_packaged" + + def bootup(): if sys.platform == "win32": # Enable VT100 Escape Sequence for WINDOWS 10 Ver. 1607 os.system("") # nosec # Hide splashscreen loader of the packaged app - if obbff.PACKAGED_APPLICATION: + if is_packaged_application(): hide_splashscreen() try: diff --git a/pyproject.toml b/pyproject.toml index 6edea9f0e2b..2b2df189d65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "OpenBBTerminal" -version = "1.9.0" +version = "1.9.1" description = "" authors = ["Didier Rodrigues Lopes"] packages = [ diff --git a/scripts/test_stocks.openbb b/scripts/test_stocks.openbb deleted file mode 100644 index 66f1a7d247d..00000000000 --- a/scripts/test_stocks.openbb +++ /dev/null @@ -1,9 +0,0 @@ -stocks -search apple -load aapl -s 2022-10-01 -tob -tob -e EDGX -candle -codes -news -exit