Skip to content

Commit

Permalink
feat: standalone docker mode
Browse files Browse the repository at this point in the history
  • Loading branch information
puehringer committed Feb 16, 2024
1 parent 30da502 commit 08397dd
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: build docker

on:
workflow_dispatch:
push:

jobs:
build-docker:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Set up node version
uses: actions/setup-node@v4
with:
node-version: '20.9'
- name: Install dependencies
run: yarn install --no-immutable --inline-builds
shell: bash
- name: Webpack build
run: yarn run webpack:prod
shell: bash
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/datavisyn/visyn_core
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./deploy/standalone/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
26 changes: 26 additions & 0 deletions deploy/standalone/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This Dockerfile is used as standalone container for simple deployments, it will be built automatically by GH Actions in the build.yml
FROM python:3.10-buster

# Copy everything from our backend to our app folder # need to copy backend because we have to install the python packages
COPY visyn_core/ /app/visyn_core/
COPY Makefile MANIFEST.in README.md setup.py setup.cfg package.json requirements.txt requirements_dev.txt /app/

# define target folder
WORKDIR /app/

# Install some build tools and finally python dependencies (numpy is required to build opentsne)
RUN make install

# Override the setttings.py to use include the bundled frontend
ENV VISYN_CORE__BUNDLES_DIR /app/bundles
# Disable the login and always use a anonymous user
ENV VISYN_CORE__SECURITY__STORE__NO_SECURITY_STORE__ENABLE true
ENV VISYN_CORE__SECURITY__STORE__NO_SECURITY_STORE__USER anonymous

# copy the pre-built front-end --> comment for development because we mount the volume anyway
COPY bundles/ /app/bundles/

# expose default port
EXPOSE 9000

CMD ["uvicorn", "visyn_core.server.main:app", "--host", "0.0.0.0", "--port", "9000"]
11 changes: 11 additions & 0 deletions visyn_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

from .plugin.model import AVisynPlugin, RegHelper
from . import manager


class VisynPlugin(AVisynPlugin):

Check failure on line 8 in visyn_core/__init__.py

View workflow job for this annotation

GitHub Actions / build / Python

Ruff (I001)

visyn_core/__init__.py:1:1: I001 Import block is un-sorted or un-formatted
Expand All @@ -21,6 +23,15 @@ def init_app(self, app: FastAPI):

app.include_router(create_settings_router())

@app.on_event("startup")
async def startup():
# Add the / path at the very end to match all other routes before
bundles_dir = manager.settings.visyn_core.bundles_dir
if bundles_dir:
# Mount the bundles directory as static files to enable the frontend (required in standalone Dockerfile mode)
_log.info(f"Mounting bundles dir: {bundles_dir}")
app.mount("/", StaticFiles(directory=bundles_dir, html=True), name="bundles")

def register(self, registry: RegHelper):
# phovea_server
registry.append(
Expand Down
5 changes: 5 additions & 0 deletions visyn_core/settings/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ class VisynCoreSettings(BaseModel):
```
"""

bundles_dir: str | None = None
"""
Directory where the bundles are stored. If set, a StaticFiles route at / is added to the application.
"""

disable: DisableSettings = DisableSettings()
enabled_plugins: list[str] = []

Expand Down

0 comments on commit 08397dd

Please sign in to comment.