Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker Deployment #11

Merged
merged 13 commits into from
Nov 4, 2024
Next Next commit
restructure project to be Python module,
add Dockerfile
  • Loading branch information
ytausch committed Oct 31, 2024
commit f58dd3f1a6526b07a0e14d92dc7e5014b2d7bc61
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
"codespaces": {
"openFiles": [
"README.md",
"app.py"
"conda_metadata_app/pages/main_page.py"
]
},
"vscode": {
@@ -19,7 +19,7 @@
},
"updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y <packages.txt; [ -f requirements.txt ] && pip3 install --user -r requirements.txt; pip3 install --user streamlit; echo '✅ Packages installed and Requirements met'",
"postAttachCommand": {
"server": "streamlit run app.py --server.enableCORS false --server.enableXsrfProtection false"
"server": "streamlit run app_proxy.py --server.enableCORS false --server.enableXsrfProtection false"
},
"portsAttributes": {
"8501": {
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Dockerfile
.pixi/
.github/
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ghcr.io/prefix-dev/pixi:0.31.0 AS build

RUN apt update
RUN apt install -y git

COPY . /app
WORKDIR /app

RUN ./docker/install.sh

FROM ubuntu:24.04 AS production

COPY --from=build /app/.pixi/envs/default /app/.pixi/envs/default
COPY --from=build /app/app_proxy.py /app
COPY --from=build /app/app_config.toml /app
COPY --from=build --chmod=0555 /entrypoint.sh /

WORKDIR /app
EXPOSE 8080
CMD ["/entrypoint.sh"]
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -12,6 +12,9 @@ Use `pixi run dev` to run the app in development mode, and `pixi run deploy` to

If you modified the configuration schema (see below), use `pixi run schema` to update the schema.

### Dependencies
Please note that this project defines dependencies in both a pixi project file (`pixi.toml`) and

## Custom Configuration

Refer to the [Configuration Documentation](docs/configuration.md) for more information on how to customize the app.
8 changes: 8 additions & 0 deletions app_proxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
This workaround is needed because streamlit does not support an app from a module.
https://github.com/streamlit/streamlit/issues/662#issuecomment-553356419
"""

import runpy

runpy.run_module("conda_metadata_app.app", run_name="__main__", alter_sys=True)
Empty file added conda_metadata_app/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions conda_metadata_app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from pathlib import Path

import streamlit as st

"""
If deploying a streamlit app as a Python module, we cannot use
the automatic pages/ subpages. Instead, we need to define the
pages manually.
"""

pages_dir = Path(__file__).parent / "pages"

main_page = st.Page(
pages_dir / "main_page.py",
title="app",
)

search_by_file_path_page = st.Page(
pages_dir / "search_by_file_path_page.py",
title="Search By File Path",
)

pg = st.navigation([main_page, search_by_file_path_page])
pg.run()
File renamed without changes.
Empty file.
7 changes: 3 additions & 4 deletions app.py → conda_metadata_app/pages/main_page.py
Original file line number Diff line number Diff line change
@@ -16,8 +16,9 @@
from rattler.platform import PlatformLiteral
from requests.auth import HTTPBasicAuth

from app_config import AppConfig, Channel, PackageDiscoveryChoice, ArchSubdirDiscoveryChoice, ArchSubdirList, \
ArtifactDiscoveryChoice, MetadataRetrieval, Secret
from conda_metadata_app.app_config import (AppConfig, Channel, PackageDiscoveryChoice, ArchSubdirDiscoveryChoice,
ArchSubdirList, ArtifactDiscoveryChoice, MetadataRetrieval, Secret)
from conda_metadata_app.version_order import VersionOrder

if not os.environ.get("CACHE_DIR"):
from conda_oci_mirror import defaults
@@ -36,8 +37,6 @@
from streamlit.logger import get_logger
from xml.etree import ElementTree as ET

from version_order import VersionOrder


yaml = YAML(typ="safe")
yaml.allow_duplicate_keys = True
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
import streamlit as st
from streamlit_searchbox import st_searchbox

from app import app_config
from conda_metadata_app.app_config import AppConfig


@st.cache_resource(ttl="15m", max_entries=100)
@@ -49,7 +49,7 @@ def find_artifacts_by_path(path):
initial_sidebar_state="collapsed",
)

if not app_config().enable_filepath_search:
if not AppConfig().enable_filepath_search:
st.error("File path search is disabled in the app configuration.")
st.stop()

File renamed without changes.
11 changes: 11 additions & 0 deletions docker/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -eux

pixi run -e build build-wheel
pixi install -e default
pixi run -e default postinstall-production
echo "#!/bin/sh" > /entrypoint.sh
pixi shell-hook -e default >> /entrypoint.sh

echo 'streamlit run --server.headless=true --global.developmentMode=false --browser.gatherUsageStats=false --server.port=8080 app_proxy.py' >> /entrypoint.sh
21 changes: 16 additions & 5 deletions pixi.toml
Original file line number Diff line number Diff line change
@@ -4,23 +4,33 @@ version = "0.1.0"
description = "A streamlit app to query metadata from conda packages"
authors = ["jaimergp <jaimergp@users.noreply.github.com>"]
channels = ["conda-forge"]
platforms = ["linux-64", "win-64", "osx-arm64", "osx-64"]
platforms = ["linux-64", "win-64", "osx-arm64", "osx-64", "linux-aarch64"]

[tasks]
dev = "streamlit run --server.runOnSave=true app.py"
deploy = "streamlit run --server.headless=true --global.developmentMode=false app.py"
dev = "streamlit run --server.runOnSave=true app_proxy.py"
deploy = "streamlit run --server.headless=true --global.developmentMode=false app_proxy.py"
schema = "python app_config.py"
postinstall-production = "pip install --no-deps --disable-pip-version-check dist/conda_metadata_app-*.whl"

[dependencies]
python = "3.12.*"
pip = "23.3.2.*"
pydantic-settings = ">=2.4.0,<3"
pydantic = ">=2.8.2,<3"
typing-extensions = ">=4.12.2,<5"
zstandard = ">=0.23.0,<0.24"
py-rattler = ">=0.7.0,<0.8"
setuptools = "*"

[host-dependencies]
pip = "*"

[feature.build.dependencies]
python-build = "*"
hatchling = "*"
[feature.build.tasks]
postinstall = "pip install --no-build-isolation --no-deps --disable-pip-version-check -e ."
build-wheel = "python -m build --no-isolation --wheel ."

[feature.dev.dependencies]
pixi-pycharm = ">=0.0.6,<0.0.7"

@@ -31,5 +41,6 @@ streamlit = ">=1.38.0,<2"
streamlit-searchbox = "==0.1.16"

[environments]
default = {}
default = [] # includes default feature
build = ["build"]
dev = { features = ["dev"], no-default-feature = true }
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "conda-metadata-app"
description = "A streamlit app to query metadata from conda packages"
version = "0.1.0"
authors = [{ name = "jaimergp", email = "jaimergp@users.noreply.github.com" }]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.12",
]
requires-python = ">=3.12"

[project.urls]
repository = "https://github.com/Quansight-Labs/conda-metadata-app"