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

Brings latest work on VirtualFlyBrain/virtual-fly-brain branch into the Metacell/virtual-fly-brain branch #147

Open
wants to merge 20 commits into
base: development
Choose a base branch
from
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
75 changes: 75 additions & 0 deletions .github/workflows/docker_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build and Push VFB Containers

on:
push:
branches: [ "main", "master", "development" ]
pull_request:
branches: [ "main", "master", "development" ]
# Allow manual trigger
workflow_dispatch:

env:
REGISTRY: docker.io
BACKEND_IMAGE_NAME: virtualflybrain/vfb-backend
FRONTEND_IMAGE_NAME: virtualflybrain/vfb-frontend

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Log in to DockerHub
uses: docker/login-action@v3
with:
registry: docker.io
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
logout: true

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.BACKEND_IMAGE_NAME }}
${{ env.FRONTEND_IMAGE_NAME }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=sha
type=raw,value=latest,enable={{is_default_branch}}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Backend image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.backend
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.BACKEND_IMAGE_NAME }}:latest,${{ env.BACKEND_IMAGE_NAME }}:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.BACKEND_IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.BACKEND_IMAGE_NAME }}:buildcache,mode=max

- name: Build and push Frontend image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.frontend
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.FRONTEND_IMAGE_NAME }}:latest,${{ env.FRONTEND_IMAGE_NAME }}:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.FRONTEND_IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.FRONTEND_IMAGE_NAME }}:buildcache,mode=max
55 changes: 55 additions & 0 deletions Dockerfile.backend
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Use Python base image
FROM python:3.9-slim

# Set working directory
WORKDIR /app

# Install git, build tools, and OpenGL dependencies
RUN apt-get update && apt-get install -y \
git \
build-essential \
libgl1-mesa-glx \
libgl1-mesa-dev \
xvfb \
libglu1-mesa \
libosmesa6 \
freeglut3-dev \
&& rm -rf /var/lib/apt/lists/*

# Set up virtual display for OpenGL
ENV DISPLAY=:99

# Copy backend files first
COPY applications/virtual-fly-brain/backend/virtual_fly_brain /app/virtual_fly_brain
COPY applications/virtual-fly-brain/backend/setup.py /app/
COPY applications/virtual-fly-brain/backend/requirements.txt /app/
COPY applications/virtual-fly-brain/backend/test-requirements.txt /app/

# Copy and install VFBquery
COPY applications/virtual-fly-brain/backend/virtual_fly_brain/libs/VFBquery /app/VFBquery
RUN cd /app/VFBquery && pip install -e .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt -r test-requirements.txt

# Add virtual_fly_brain to PYTHONPATH
ENV PYTHONPATH=/app:/app/virtual_fly_brain:${PYTHONPATH} \
PYTHONUNBUFFERED=1

# Create and set up volume directories
RUN mkdir -p /app/data /app/cache
VOLUME ["/app/data", "/app/cache"]

# Expose port
EXPOSE 8080

# Create startup script
RUN echo '#!/bin/bash\n\
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &\n\
sleep 1\n\
cd /app/virtual_fly_brain\n\
python __main__.py' > /start.sh && \
chmod +x /start.sh

# Command to run the application
CMD ["/start.sh"]
54 changes: 54 additions & 0 deletions Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Use Node.js base image
FROM node:16-bullseye-slim

# Set working directory
WORKDIR /app

# Install required tools
RUN apt-get update && \
apt-get install -y \
git \
&& rm -rf /var/lib/apt/lists/*

# Copy package files
COPY applications/virtual-fly-brain/client/package.json ./
COPY applications/virtual-fly-brain/client/yarn.lock ./

# Set up global dependencies
RUN npm install -g eslint \
&& yarn config set ignore-engines true

# Set up basic eslint config to avoid build errors
RUN echo '{"extends": ["react-app","eslint:recommended"],"rules":{"no-unused-vars":"warn"}}' > .eslintrc.json

# Install dependencies with legacy peer deps to handle version conflicts
RUN yarn install --legacy-peer-deps

# Copy all configuration files
COPY applications/virtual-fly-brain/client/.* ./
COPY applications/virtual-fly-brain/client/tsconfig.json ./
COPY applications/virtual-fly-brain/client/webpack.config*.js ./

# Copy source files
COPY applications/virtual-fly-brain/client/src ./src
COPY applications/virtual-fly-brain/client/public ./public

# Modify package.json scripts
RUN sed -i 's/"start": ".*"/"start": "webpack serve --config webpack.config.dev.js --mode development"/' package.json

# Build the application with NODE_ENV set to production
RUN NODE_ENV=production yarn build

# Create and set up volume directories
RUN mkdir -p /app/build /app/node_modules
VOLUME ["/app/build", "/app/node_modules"]

# Expose port
EXPOSE 3000

# Set environment variable to disable eslint during runtime
ENV DISABLE_ESLINT_PLUGIN=true \
NODE_ENV=production

# Command to run the application
CMD ["yarn", "start"]
17 changes: 12 additions & 5 deletions applications/virtual-fly-brain/client/.babelrc
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
"@babel/preset-env",
"@babel/preset-react"
],
"env": {
"production":{
"presets": ["minify"]
"production": {
// Remove the minify preset and add individual minification plugins
"plugins": [
"babel-plugin-transform-remove-console", // Remove console logs
"babel-plugin-minify-dead-code-elimination", // Remove dead code
"babel-plugin-minify-constant-folding", // Fold constants
"babel-plugin-transform-remove-debugger" // Remove debugger statements
]
}
},
"plugins": [
"@babel/transform-regenerator",
"@babel/plugin-proposal-class-properties",
"@babel/transform-runtime",
[
"module-resolver", {
"module-resolver",
{
"root": ["./src"]
}
]
Expand Down
2 changes: 1 addition & 1 deletion applications/virtual-fly-brain/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@
"@babel/preset-env": "^7.8.3",
"@babel/preset-react": "^7.8.3",
"@babel/runtime": "^7.8.3",
"babel-loader": "^8.2.3",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"awesome-typescript-loader": "^5.2.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.0.6",
"babel-plugin-module-resolver": "^4.0.0",
"babel-preset-minify": "^0.5.1",
"clean-webpack-plugin": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ const MainLayout = ({ bottomNav, setBottomNav }) => {
if ( openTemplate) {
templateLoaded(id, openTemplate);
templateRef = window.location.href.replace(id + ",", "")
}else {
getInstanceByID(id, false, true, false, false)
}
setModalOpen(false)
}
Expand Down Expand Up @@ -230,8 +228,8 @@ const MainLayout = ({ bottomNav, setBottomNav }) => {
The image you requested is aligned to another template. Click Okay
to open in a new tab or Cancel to just view the image metadata.
</Typography>
<Button variant="contained" color={primaryBg} onClick={() => handleModalClose(misalignedTemplate, true )} target="_blank" href={window.location.origin + "/?id=" + misalignedTemplate}>Okay</Button>
<Button variant="outlined" color={secondaryBtnColor} onClick={() => handleModalClose(misalignedTemplate, false )}>Cancel</Button>
<Button variant="contained" color={"primary"} onClick={() => handleModalClose(misalignedTemplate, true )} target="_blank" href={window.location.origin + "/?id=" + misalignedTemplate}>Okay</Button>
<Button variant="outlined" color={"secondary"} onClick={() => handleModalClose(misalignedTemplate, false )}>Cancel</Button>
</Box>
</Modal>
<Box
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
requests>=2.31.0
pandas>=2.1.0
numpy>=1.24.0