Skip to content

Commit

Permalink
Merge pull request #1 from AD-SDL/clean_make
Browse files Browse the repository at this point in the history
Remove Makefile
  • Loading branch information
LuckierDodge authored Feb 22, 2024
2 parents 8210522 + 762f87e commit fc148cc
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 643 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,6 @@ cython_debug/

# Ruff
.ruff_cache

# Outputs
experiment_output.jpg
27 changes: 0 additions & 27 deletions Dockerfile-jupyter

This file was deleted.

29 changes: 0 additions & 29 deletions Makefile

This file was deleted.

28 changes: 10 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,25 @@ This is a template Workcell repository for the [Workcell Execution Interface](ht

## Dependencies

- This template uses GNU make and a handful of makefiles for configuration and as a command runner. You can run `make help` for a complete list of supported `make` commands and a brief description of what they do.
- You'll need [docker installed](https://docs.docker.com/engine/install/)
- Make sure to follow the [post installation steps](https://docs.docker.com/engine/install/linux-postinstall/) to enable non-root user access
- Make sure on Linux to follow the [post installation steps](https://docs.docker.com/engine/install/linux-postinstall/) to enable non-root user access
- You'll need Python 3.8 or greater installed to run the Example Application.

## Configuration

As much as possible, this workcell is designed to be configured declaratively. This is done with:

- Build rules and targets defined in the `Makefile` and included makefiles in the `make/` subdirectory.
- A `.env` file, generated by `make` based on configuration declared in `make/config.mk`
- A `.env` file, which you can create by copying `example.env` (`cp example.env .env` on Linux).
- The `compose.yaml` docker compose file, which defines a "stack" of containers that control your workcell
- Note: whenever you see `${SOME_VARIABLE_NAME}` in the compose file, this value is being taken from the `.env` generated by `make`
- The `Dockerfile` in `example_app/`, which allows you to customize your experiment applications container (e.g. you can add any software or python packages that your code depends on in here)
- Note: whenever you see `${SOME_VARIABLE_NAME}` in the compose file, this value is being taken from the `.env`
- The Workcell Config in `workcell_defs/example_workcell.yaml`, which allows you to define WEI specific configuration for your workcell

## Building, Running, and Managing your Workcell and Experiment Application
## Building, Running, and Managing your Workcell

Here are some common commands you can use to manage this workcell:
- `docker compose up` to start your workcell (`docker compose up -d` starts it in the background)
- `docker compose down` to stop a workcell
- `docker compose logs -f` to view the output

- `make build`: build the workcell, incorporating any changes as needed
- `make start`: start just the containers, but don't run the experiment application
- `make run`: run your experiment application (run `make start` first)
- `make exec`: opens a terminal inside your application container
- `make stop`: stops the workcell and any currently running applications
## Experiment Application

For a complete list of supported commands, you can run `make` or `make help`.

## Using Diaspora

To use Diaspora for logging events, you can change `USE_DIASPORA` to `true` in the `Makefile` or run `make <subcommand> USE_DIASPORA=true`
See `example_app/README.md` for info on installing and running the example application using your workcell.
67 changes: 1 addition & 66 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
name: example_workcell
include: ['wei.compose.yaml']
services:
############
# Your app #
############
example_app:
container_name: ${APP_NAME}
build:
context: ./example_app
dockerfile: ${DOCKERFILE}
volumes:
- ./example_app:/home/app/example_app # Mount your app code, so you can edit it without rebuilding the image
- ${WEI_DATA_DIR}:/home/app/.wei # Mount the wei data directory
- diaspora_config:/home/app/.diaspora
command: python example_app/example_app.py
env_file:
- .env
profiles: [example_app]

###########
# Modules #
###########
Expand All @@ -38,52 +22,3 @@ services:
command: python webcam_module/src/webcam_rest_node.py --port 2001
env_file:
- .env

#####################
# WEI Core Services #
#####################
wei_server:
image: ghcr.io/ad-sdl/wei
container_name: wei_server
ports:
- 8000:8000
volumes:
- ${WORKCELLS_DIR}:/workcell_defs
- ${WEI_DATA_DIR}:/home/app/.wei
- diaspora_config:/home/app/.diaspora
command: python3 -m wei.server --workcell /workcell_defs/${WORKCELL_FILENAME} --use_diaspora ${USE_DIASPORA}
env_file:
- .env
depends_on:
- wei_redis
wei_engine:
image: ghcr.io/ad-sdl/wei
container_name: wei_engine
volumes:
- ${WORKCELLS_DIR}:/workcell_defs
- ${WEI_DATA_DIR}:/home/app/.wei
env_file:
- .env
command: python3 -m wei.engine --workcell /workcell_defs/${WORKCELL_FILENAME} --use_diaspora ${USE_DIASPORA}
environment:
- PYTHONUNBUFFERED=1 # Fix weird bug with empty logging
depends_on:
- wei_redis
- wei_server
- sleep_node
- webcam_node
wei_redis:
image: redis
container_name: wei_redis
ports:
- 6379:6379
volumes:
- ${REDIS_DIR}:/data
command: redis-server --save 60 1 --loglevel warning

################
# Data Storage #
################
volumes:
diaspora_config:
driver: local
8 changes: 8 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copy this file and rename to `.env` to set environment variables for docker-compose
USER_ID=
GROUP_ID=
PROJECT_DIR=~/workspace/wei_template_workcell
WEI_DATA_DIR=~/.wei
REDIS_DIR=~/.wei/redis
WORKCELL_FILENAME=example_workcell.yaml
WORKCELLS_DIR=${PROJECT_DIR}/workcell_defs
12 changes: 0 additions & 12 deletions example_app/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions example_app/Makefile

This file was deleted.

10 changes: 10 additions & 0 deletions example_app/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Example App

In the `example_app` directory:

```
python -m venv .venv
source .venv/bin/activate
pip install -e .
# After starting the workcell:
python example_app.py
```
10 changes: 5 additions & 5 deletions example_app/example_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Runs an example of a WEI workflow"""
"""Example experiment application that uses the WEI client to run a workflow."""

import json
from pathlib import Path
Expand All @@ -9,12 +9,12 @@

def main() -> None:
"""Runs an example WEI workflow"""
# This defines the Experiment object that will communicate with the WEI server
exp = ExperimentClient("localhost", "8000", "Example_Program")

# The path to the Workflow definition yaml file
wf_path = Path(__file__).parent / "workflows" / "example_workflow.yaml"

# This defines the Experiment object that will communicate with the WEI server
exp = ExperimentClient("wei_server", "8000", "Example_Program")

# This runs the workflow
flow_info = exp.start_run(
wf_path.resolve(),
Expand All @@ -28,7 +28,7 @@ def main() -> None:
# The below line can be used to fetch the result and save it in our local directory
exp.get_file(
flow_info["hist"]["Take Picture"]["action_msg"],
"/home/app/.wei/experiment_output.jpg",
"experiment_output.jpg",
)


Expand Down
4 changes: 1 addition & 3 deletions example_app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ version = "1.0.0"
description = "A simple example WEI application that waits for a set amount of time, then takes a picture with a webcam."
authors = [{name = "Ryan D. Lewis", email="[email protected]"}]
dependencies = [
# "fastapi>=0.103",
# "uvicorn>=0.14.0",
# "ad_sdl.wei",
"ad_sdl.wei",
]
requires-python = ">=3.8.1"
readme = "README.md"
Expand Down
18 changes: 13 additions & 5 deletions example_app/workflows/example_workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ modules:
flowdef:
#This defines a step in the workflow. Each step represents an action on a single module
#This is a human legible name for the step
- name: Sleep workcell for t seconds
# - name: Sleep workcell for t seconds
#This defines which module the action will run on, in this case, a test node that simply sleeps for t seconds
module: sleeper
# module: sleeper
#This tells the module which action in its library to run, in this case grabbing a wellplate from one of the storage tower
action: sleep
# action: sleep
#These arguments specify the parameters for the action above, in this case, which tower the arm will pull a plate from.
# args:
# t: "payload.wait_time"
#This represents checks that will take place before the system runs, in this case, there are none specified
# checks: null
#This is a place for additional notes
# comment: Sleep for 5 seconds before we take a picture

- name: Sleep workcell for t seconds
module: sleeper
action: sleep
args:
t: "payload.wait_time"
#This represents checks that will take place before the system runs, in this case, there are none specified
checks: null
#This is a place for additional notes
comment: Sleep for 5 seconds before we take a picture

- name: Take Picture
Expand Down
Loading

0 comments on commit fc148cc

Please sign in to comment.