Skip to content

[draft] feat: dockerize #940

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Build a custom kasmweb image following guidelines from https://kasmweb.com/docs/latest/how_to/building_images.html
FROM kasmweb/ubuntu-jammy-desktop:1.16.0
USER root

ENV HOME=/home/kasm-default-profile
ENV STARTUPDIR=/dockerstartup
ENV INST_SCRIPTS=$STARTUPDIR/install
WORKDIR $HOME

######### Customize Container Here ###########

# Install dependencies for OpenAdapt

RUN curl -fsSL https://deb.nodesource.com/setup_21.x | bash
RUN apt-get update && \
apt-get install -y nodejs tesseract-ocr portaudio19-dev && \
apt-get clean

# Disable ssl and basic auth and enable sudo as this will be a developer container

ENV VNCOPTIONS=-disableBasicAuth
RUN sed -i '/ ssl:/a\ require_ssl: false' /etc/kasmvnc/kasmvnc.yaml
# https://github.com/kasmtech/workspaces-core-images/issues/2
RUN sed -i 's/-sslOnly//g' /dockerstartup/vnc_startup.sh
RUN echo 'kasm-user ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers

######### End Customizations ###########


RUN chown 1000:0 $HOME
RUN $STARTUPDIR/set_user_permission.sh $HOME

ENV HOME=/home/kasm-user
WORKDIR $HOME
RUN mkdir -p $HOME && chown -R 1000:0 $HOME

USER 1000


######### Customize Container Here ###########

WORKDIR $HOME

ENV PATH=$HOME/.local/bin:$PATH \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.5 python3 -

RUN git clone https://github.com/bard/OpenAdapt
WORKDIR $HOME/OpenAdapt
RUN poetry install

# replace torch and torchvision with cpu-only versions
RUN poetry source add --priority explicit pytorch_cpu https://download.pytorch.org/whl/cpu
RUN poetry add --source pytorch_cpu torch==2.0.1+cpu torchvision==0.15.2+cpu

# install prebuilt cpu-only detectron
RUN poetry source add --priority explicit torch_packages https://miropsota.github.io/torch_packages_builder
RUN poetry add --source torch_packages detectron2==0.6+2a420edpt2.0.1cpu

# for some reason, pyaudio either doesn't get installed, or it gets removed in the steps above
RUN poetry remove pyaudio && poetry add pyaudio

# restrict python compatibliity to accommodate pyside6.2
# RUN sed -i 's/python = ">=3.10,<3.12/python = ">=3.10,<3.11/' pyproject.toml
# install a pyside version compatible with system-installed qt
# RUN poetry add pyside6==6.2

RUN cd openadapt && poetry run alembic upgrade head
RUN cd openadapt/app/dashboard && npm install

######### End Customizations ###########

2 changes: 1 addition & 1 deletion openadapt/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from alembic import context
from openadapt.config import config
from openadapt.db import db
from openadapt.models import ForceFloat
from openadapt.decorators import ForceFloat

# This is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sqlalchemy as sa

from alembic import op
from openadapt.models import ForceFloat
from openadapt.decorators import ForceFloat

# revision identifiers, used by Alembic.
revision = "530f0663324e"
Expand Down
2 changes: 1 addition & 1 deletion openadapt/alembic/versions/607d1380b5ae_add_memorystat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sqlalchemy as sa

from alembic import op
from openadapt.models import ForceFloat
from openadapt.decorators import ForceFloat

# revision identifiers, used by Alembic.
revision = "607d1380b5ae"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('browser_event',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('recording_timestamp', openadapt.models.ForceFloat(precision=10, scale=2, asdecimal=False), nullable=True),
sa.Column('recording_timestamp', openadapt.decorators.ForceFloat(precision=10, scale=2, asdecimal=False), nullable=True),
sa.Column('recording_id', sa.Integer(), nullable=True),
sa.Column('message', sa.JSON(), nullable=True),
sa.Column('timestamp', openadapt.models.ForceFloat(precision=10, scale=2, asdecimal=False), nullable=True),
sa.Column('timestamp', openadapt.decorators.ForceFloat(precision=10, scale=2, asdecimal=False), nullable=True),
sa.ForeignKeyConstraint(['recording_id'], ['recording.id'], name=op.f('fk_browser_event_recording_id_recording')),
sa.PrimaryKeyConstraint('id', name=op.f('pk_browser_event'))
)
with op.batch_alter_table('action_event', schema=None) as batch_op:
batch_op.add_column(sa.Column('browser_event_timestamp', openadapt.models.ForceFloat(precision=10, scale=2, asdecimal=False), nullable=True))
batch_op.add_column(sa.Column('browser_event_timestamp', openadapt.decorators.ForceFloat(precision=10, scale=2, asdecimal=False), nullable=True))
batch_op.add_column(sa.Column('browser_event_id', sa.Integer(), nullable=True))
batch_op.create_foreign_key(batch_op.f('fk_action_event_browser_event_id_browser_event'), 'browser_event', ['browser_event_id'], ['id'])

Expand Down
4 changes: 2 additions & 2 deletions openadapt/alembic/versions/98c8851a5321_add_audio_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ def upgrade() -> None:
sa.Column("id", sa.Integer(), nullable=False),
sa.Column(
"timestamp",
openadapt.models.ForceFloat(precision=10, scale=2, asdecimal=False),
openadapt.decorators.ForceFloat(precision=10, scale=2, asdecimal=False),
nullable=True,
),
sa.Column("flac_data", sa.LargeBinary(), nullable=True),
sa.Column("transcribed_text", sa.String(), nullable=True),
sa.Column(
"recording_timestamp",
openadapt.models.ForceFloat(precision=10, scale=2, asdecimal=False),
openadapt.decorators.ForceFloat(precision=10, scale=2, asdecimal=False),
nullable=True,
),
sa.Column("recording_id", sa.Integer(), nullable=True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from alembic import op
import sqlalchemy as sa

from openadapt.models import ForceFloat
from openadapt.decorators import ForceFloat

# revision identifiers, used by Alembic.
revision = "d714cc86fce8"
Expand Down
19 changes: 19 additions & 0 deletions openadapt/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sqlalchemy as sa


# https://groups.google.com/g/sqlalchemy/c/wlr7sShU6-k
class ForceFloat(sa.TypeDecorator):
"""Custom SQLAlchemy type decorator for floating-point numbers."""

impl = sa.Numeric(10, 2, asdecimal=False)
cache_ok = True

def process_result_value(
self,
value: int | float | str | None,
dialect: str,
) -> float | None:
"""Convert the result value to float."""
if value is not None:
value = float(value)
return value
1 change: 1 addition & 0 deletions openadapt/error_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Any

from loguru import logger

from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QMessageBox, QPushButton
import git
Expand Down
19 changes: 1 addition & 18 deletions openadapt/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,11 @@
from openadapt.db import db
from openadapt.privacy.base import ScrubbingProvider, TextScrubbingMixin
from openadapt.privacy.providers import ScrubProvider
from openadapt.decorators import ForceFloat

EMPTY_VALS = [None, "", [], (), {}]


# https://groups.google.com/g/sqlalchemy/c/wlr7sShU6-k
class ForceFloat(sa.TypeDecorator):
"""Custom SQLAlchemy type decorator for floating-point numbers."""

impl = sa.Numeric(10, 2, asdecimal=False)
cache_ok = True

def process_result_value(
self,
value: int | float | str | None,
dialect: str,
) -> float | None:
"""Convert the result value to float."""
if value is not None:
value = float(value)
return value


class Recording(db.Base):
"""Class representing a recording in the database."""

Expand Down