Skip to content
Open
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
59 changes: 59 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
FROM condaforge/miniforge3:latest

LABEL maintainer="Pychron Docker Builder"
LABEL description="Docker environment for AGESLDEO/pychron"

# 1. Build Stage

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv

# Install dependencies for gui and audio
RUN apt-get update && apt-get install -y \
git build-essential libgl1 libegl1 libxrandr2 libxss1 libxcursor1 \
libxcomposite1 libasound2t64 libxi6 libxtst6 libxkbcommon-x11-0 \
nano alsa-utils \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY . /app

# 2. Run Stage

# Create conda environment
# Install older versions of traits as a workaround for Color import errors
RUN mamba create -n pychron_env python=3.9 \
numpy \
cython \
"traits=6.3.2" \
"traitsui<8.0.0" \
"pyface<8.0.0" \
envisage \
apptools \
pyqt \
-c conda-forge -y && \
mamba clean -afy

# Install Pip dependencies with uv
SHELL ["conda", "run", "-n", "pychron_env", "/bin/bash", "-c"]

# Install chaco/enable explicitly for ARM64/Apple Silicon build issues
# Install requirements
RUN echo "Installing dependencies..." && \
uv pip install chaco enable --python $CONDA_PREFIX && \
if [ -f "docs/requirements.txt" ]; then \
uv pip install -r docs/requirements.txt --python $CONDA_PREFIX; \
fi && \
if [ -f "app_utils/requirements/pip_requirements.txt" ]; then \
uv pip install -r app_utils/requirements/pip_requirements.txt --python $CONDA_PREFIX; \
fi

COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

ENV PYCHRON_USE_LOGIN=0
ENV QT_X11_NO_MITSHM=1
ENV CONDA_DEFAULT_ENV=pychron_env

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["python", "launchers/launcher.py"]
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Default to :0 if DISPLAY isn't set as workaround for macos
DISPLAY ?= :0

.PHONY: up clean shell

up:
@echo "Checking for X11 display..."
@if [ -z "$(DISPLAY)" ]; then \
echo "Error: DISPLAY variable is empty."; \
echo "If on mac, make sure XQuartz is running and run 'export DISPLAY=:0'"; \
exit 1; \
fi
@echo "Configuring permissions for $(DISPLAY)..."
-xhost +local:docker
@echo "Starting Pychron..."
DISPLAY=$(DISPLAY) docker-compose up

clean:
docker-compose down
-xhost -local:docker

shell:
docker-compose run --rm pychron /bin/bash
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.8'
services:
pychron:
build: .
container_name: pychron_app
environment:
- DISPLAY=${DISPLAY_VAR}
- QT_X11_NO_MITSHM=1
- PYTHONPATH=/app # for launcher.py to find 'pychron' module
- ETS_QT4_IMPORTS=1 # fix legacy imports for traitsui.qt4
- ETS_TOOLKIT=qt4
volumes:
- ./data/Pychron:/root/Pychron
- ./data/logs:/root/.pychron
- /tmp/.X11-unix:/tmp/.X11-unix
stdin_open: true
tty: true
37 changes: 37 additions & 0 deletions docker-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
## Instructions

### Dependencies
1. Install [Docker Desktop](https://www.docker.com/products/docker-desktop/)

1. Install [Homebrew](https://brew.sh/)
```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

1. Install XQuartz
```bash
brew install --cask xquartz
```

XQuartz Settings > Security and check "Allow connections from network clients"
Quit and restart XQuartz

## Run Pychron
1. Run startup script

```bash
chmod +x run.sh
# run script
./run.sh
```

A login popup should appear.

If the startup script returns a build error, rebuild the docker image and rerun the startup script
```bash
# Rebuild image
docker-compose up --build
# rerun script
./run.sh
```

9 changes: 9 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e

# Activate the conda environment
source /opt/conda/etc/profile.d/conda.sh
conda activate pychron_env

# Execute the passed command
exec "$@"
29 changes: 29 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e

OS="$(uname -s)"

if [ "$OS" = "Darwin" ]; then
if ! pgrep -x "X11.bin" > /dev/null; then
echo "Starting XQuartz..."
open -a XQuartz
sleep 3
fi

[ -z "$DISPLAY" ] && export DISPLAY=:0

# add localhost to xquartz
xhost + 127.0.0.1 > /dev/null

# Use special DNS for mac
export DOCKER_DISPLAY="host.docker.internal:0"
else
[ -z "$DISPLAY" ] && export DISPLAY=:0
xhost +local:docker
export DOCKER_DISPLAY=$DISPLAY
fi

echo "Starting Pychron on $OS..."
export DISPLAY_VAR=$DOCKER_DISPLAY

docker-compose up --build