Coder Social home page Coder Social logo

Comments (1)

sfc-gh-kbregula avatar sfc-gh-kbregula commented on May 10, 2024

Hello,

I recommend packing the component as a wheel package and then copying it to the Docker image.
Here is the documentation that describes how to build the wheel package.
https://docs.streamlit.io/library/components/publish#build-a-python-wheel (section: "Build a Python wheel")
Here is the documentation that describes how to build a Docker image.
https://docs.streamlit.io/knowledge-base/tutorials/deploy/docker
If you would like to build the wheel package and the docker image, you can also do it in one Dockerfile, but then I recommend using multistage build to limit the size of the final image.

An example Dockerfile might look like this, building a component in a separate stage and then copying the file into the final image.

# syntax=docker/dockerfile:1.4
FROM python:3.9-slim-bullseye as streamlit-app-component-build-image

SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"]

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
      curl \
    && curl -fsSL https://deb.nodesource.com/setup_18.x | bash -  \
    && apt-get install -y nodejs \
    && apt-get autoremove -yqq --purge \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

COPY ./examples/RadioButton/ /src/
WORKDIR /src/

# Build frontend
RUN cd /src/radio_button/frontend/ \
    && npm install \
    && npm run build

# Set RELEASE flag to True
RUN sed -i 's/_RELEASE = False/_RELEASE = True/' /src/radio_button/__init__.py

# Build wheel package
RUN python setup.py bdist_wheel --universal sdist

FROM python:3.9-slim-bullseye as streamlit-app-final-image

SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-c"]
WORKDIR /app

RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    software-properties-common \
    git \
    && rm -rf /var/lib/apt/lists/*

COPY ./app/ /app/

COPY --from=0 /src/dist/streamlit_radio_button-0.0.1-py2.py3-none-any.whl /component-whl/

RUN pip3 install streamlit /component-whl/*.whl

EXPOSE 8501

HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health

ENTRYPOINT ["streamlit", "run", "streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]

from component-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.