Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
name: Docker Build and Publish

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Docker Image Build and Publish

on:
push:
push: # * Run for every push
branches: [ "*" ]
# Publish semver tags as releases.
tags: [ '*' ]
schedule: # Run on Tuesday's at noon
schedule: # Run on Tuesday's at 12:00
- cron: '0 12 * * 2'
workflow_dispatch: # Run manually

env:
# Use docker.io for Docker Hub if empty
Expand All @@ -38,10 +33,9 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

# Login against a Docker registry except on PR
# Login against a Docker registry
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
Expand Down Expand Up @@ -73,5 +67,5 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
#cache-from: type=gha
#cache-to: type=gha,mode=max
cache-from: type=gha
cache-to: type=gha,mode=max
11 changes: 8 additions & 3 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
name: Pre-Commit Checks

on:
push:
push: # Run for every push
branches: ["*"]
tags: ["*"]
workflow_dispatch: # Run manually

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout code
- uses: actions/setup-python@v3
- uses: actions/setup-python@v4
name: Setup Python
- uses: pre-commit/action@v3.0.0
with:
python-version: 3.9
- uses: pre-commit/action@v3.0.1
name: Run Pre-Commit Checks
13 changes: 0 additions & 13 deletions .github/workflows/tests.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# List available commands
default:
@just --list --justfile {{justfile()}}

# initialize the project
init:
@which pdm || echo "pdm not found, you'll need to install it: https://github.com/pdm-project/pdm"
@pdm install -G:all
@OSTYPE="" . .venv/bin/activate
@which pre-commit && pre-commit install && pre-commit autoupdate || true

# Build the project
build: init dcb

# Run the pre-commit checks
checks:
@pre-commit run --all-files || { echo "Checking fixes\n" ; pre-commit run --all-files; }
check: checks

# Run automated tests
test:
@pytest
tests: test
pytest: test

# Build docker image
dcb:
@docker compose build
11 changes: 7 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: check-json
- id: check-toml
- id: check-ast
- id: check-merge-conflict
Expand All @@ -12,15 +11,19 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.1
hooks:
- id: nbstripout
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.9
rev: v0.11.5
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
- repo: https://gitlab.com/bmares/check-json5
rev: v1.0.0
hooks:
- id: check-json5
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/ad-sdl/wei
FROM ghcr.io/ad-sdl/madsci

LABEL org.opencontainers.image.source=https://github.com/AD-SDL/camera_module
LABEL org.opencontainers.image.description="A module that implements a simple camera snapshot action"
Expand All @@ -13,14 +13,13 @@ RUN mkdir -p camera_module
COPY ./src camera_module/src
COPY ./README.md camera_module/README.md
COPY ./pyproject.toml camera_module/pyproject.toml
COPY ./tests camera_module/tests

RUN --mount=type=cache,target=/root/.cache \
pip install -e ./camera_module

CMD ["python", "-m", "camera_rest_node"]

# Add user to video group to access camera
RUN usermod -a -G video app
RUN usermod -a -G video madsci

#########################################
20 changes: 0 additions & 20 deletions Makefile

This file was deleted.

28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# camera_module

A simple module that supports taking snapshots with a camera or other video device.
Provides a simple MADSci node for integrating web cameras to capture images.

See `camera_node_template.node.info.yaml` for details on the capabilities of this node, and `camera_node_template.node.yaml` as a template for your own Camera Node definition file.

## Installation and Usage

Expand All @@ -9,36 +11,16 @@ A simple module that supports taking snapshots with a camera or other video devi
```bash
# Create a virtual environment named .venv
python -m venv .venv

# Activate the virtual environment on Linux or macOS
source .venv/bin/activate

# Alternatively, activate the virtual environment on Windows
# .venv\Scripts\activate

# Install the module and dependencies in the venv
pip install .

# Run the environment
python src/camera_rest_node.py --host 0.0.0.0 --port 2000
python -m camera_rest_node --host 127.0.0.1 --port 2000
```

### Docker

1. Install Docker for your platform of choice.
2. Run `make init` to create the `.env` file, or copy `example.env` to `.env`
3. Open the `.env` file and ensure that all values are set and correct.
1. Check that the `USER_ID` and `GROUP_ID` are correct, as these ensure correct file permissions (in most cases, they should match your user's UID and GID)
2. Check that the `WEI_DATA_DIR` and `REDIS_DIR` directories exist and have the appropriate permissions
3. The `DEVICE` variable can be used to determine which camera device is used by the module

```bash
# Build and run just the module
docker compose up --build

# Run the module, but detach so you can keep working in the same terminal
docker compose up --build -d

# Run the module alongside a simple workcell (for testing)
docker compose --profile wei up --build -d
```
You can use the `Dockerfile` and Docker Compose File (`compose.yaml`) as part of a docker (compose) setup. Note that you can set the container user's id and group id by setting the `USER_ID` and `GROUP_ID` variables in the container's environment.
60 changes: 11 additions & 49 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,19 @@ name: camera_module
services:
camera_module:
container_name: camera_module
image: ${IMAGE}
image: ghcr.io/ad-sdl/camera_module
environment:
- USER_ID=${USER_ID:-1000}
- GROUP_ID=${GROUP_ID:-1000}
- DEFINITION=${DEFINITION:-camera_module/definitions/camera_template.node.yaml}
build:
context: .
dockerfile: Dockerfile
tags:
- ${IMAGE}:latest
- ${IMAGE}:dev
command: python -m camera_rest_node --port 2000
privileged: true
env_file: .env
volumes:
- ${DEVICE}:/dev/video0
# - ./src:/home/app/camera_module/src
# - ./tests:/home/app/camera_module/tests
ports:
- 2000:2000

#####################
# WEI Core Services #
#####################
wei_server:
image: ghcr.io/ad-sdl/wei
container_name: wei_server
ports:
- 8000:8000
env_file: .env
environment:
- PYTHONUNBUFFERED=1 # Fix weird bug with empty logging
- ghcr.io/ad-sdl/camera_module:latest
- ghcr.io/ad-sdl/camera_module:dev
command: python camera_module/src/camera_rest_node.py --definition definitions/camera_node_template.node.yaml
volumes:
- ${WORKCELLS_DIR}:/workcell_defs
command: python3 -m wei.server --workcell /workcell_defs/${WORKCELL_FILENAME}
depends_on:
- wei_redis
profiles: [wei]
wei_engine:
image: ghcr.io/ad-sdl/wei
container_name: wei_engine
volumes:
- ${WORKCELLS_DIR}:/workcell_defs
env_file: .env
environment:
- PYTHONUNBUFFERED=1 # Fix weird bug with empty logging
command: python3 -m wei.engine --workcell /workcell_defs/${WORKCELL_FILENAME}
depends_on:
- wei_redis
- wei_server
profiles: [wei]
wei_redis:
image: redis
container_name: wei_redis
ports:
- 6379:6379
command: redis-server --save 60 1 --loglevel warning
profiles: [wei]
- ./definitions:/home/madsci/definitions
privileged: true
network_mode: host
Loading