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 19, 2024
1 parent 30da502 commit ae867a4
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: build docker

on:
workflow_dispatch:

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 }}
23 changes: 23 additions & 0 deletions deploy/standalone/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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

# 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"]
9 changes: 9 additions & 0 deletions deploy/standalone/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '2.0'
services:
api:
image: ghcr.io/datavisyn/visyn_core:standalone_docker
ports:
- 9000:9000
environment:
- VISYN_CORE__SECURITY__STORE__NO_SECURITY_STORE__ENABLE=true
- VISYN_CORE__SECURITY__STORE__NO_SECURITY_STORE__USER=anonymous
11 changes: 11 additions & 0 deletions visyn_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

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


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 ae867a4

Please sign in to comment.