Skip to content

Commit

Permalink
feat(api,robot-server): Add Dockerfile and docker-compose file (#7836)
Browse files Browse the repository at this point in the history
* docker file.

* docker-compose

* Controller will build simulating gpio object so no reason for the check.

* Update docker-compose.yml

Co-authored-by: Sam! Bonfante <[email protected]>

* Update docker-compose.yml

Co-authored-by: Sam! Bonfante <[email protected]>

* override config dir

* only copy files needed for the build.

* need manifest

* added readme.

* formatter

Co-authored-by: Sam! Bonfante <[email protected]>

closes #7674
  • Loading branch information
amitlissack authored May 27, 2021
1 parent 47f3385 commit f89a660
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 12 deletions.
38 changes: 38 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
./api-server
./app
./labware-library
./node_modules
./protocol-designer
./discovery-client
./coverage
./components
./app-shell
./update-server
./step-generation

.pytest_cache
.flake8
.idea
.pypy_cache
dist
build
yarn.lock
Pipfile.lock

__pycache__
*.pyc
*.pyo
*.pyd
.Python
env
pip-log.txt
pip-delete-this-directory.txt
.tox
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
*.log
.git
18 changes: 18 additions & 0 deletions .opentrons_config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"labware_database_file": "/config/opentrons.db",
"labware_calibration_offsets_dir_v2": "/config/labware/v2/offsets",
"labware_user_definitions_dir_v2": "/config/labware/v2/custom_definitions",
"feature_flags_file": "/config/feature_flags.json",
"robot_settings_file": "/config/robot_settings.json",
"deck_calibration_file": "/config/deck_calibration.json",
"log_dir": "/config/logs",
"api_log_file": "/config/logs/api.log",
"serial_log_file": "/config/logs/serial.log",
"wifi_keys_dir": "/config/user_storage/opentrons_data/network_keys",
"hardware_controller_lockfile": "/config/hardware.lock",
"pipette_config_overrides_dir": "/config/pipettes",
"tip_length_calibration_dir": "/config/tip_lengths",
"robot_calibration_dir": "/config/robot",
"pipette_calibration_dir": "/config/robot/pipettes",
"custom_tiprack_dir": "/config/tip_lengths/custom_tiprack_definitions"
}
17 changes: 17 additions & 0 deletions .opentrons_config/feature_flags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"shortFixedTrash": null,
"calibrateToBottom": null,
"deckCalibrationDots": null,
"useProtocolApi2": null,
"disableHomeOnBoot": null,
"useOldAspirationFunctions": null,
"enableDoorSafetySwitch": null,
"enableTipLengthCalibration": null,
"enableHttpProtocolSessions": null,
"enableFastProtocolUpload": null,
"enableProtocolEngine": null,
"disableLogAggregation": null,
"enableApi1BackCompat": null,
"useV1HttpApi": null,
"_version": 9
}
1 change: 1 addition & 0 deletions .opentrons_config/pipettes/P20SV202020070101.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "model": "p20_single_v2.0" }
1 change: 1 addition & 0 deletions .opentrons_config/pipettes/P3HMV202020041605.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "model": "p20_multi_v2.0" }
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Contributing Guide

Thanks for your interest in contributing to the Opentrons platform! This Contributing Guide is intended to ensure best practices for both internal Opentrons contributors as well as any external contributors. We want to make sure you’re set up to contribute effectively, no matter if you’re helping us out with bug reports, code, documentation, feature suggestions, or anything else. This guide covers:
Expand Down Expand Up @@ -150,6 +149,7 @@ Your computer will need the following tools installed to be able to develop with
```

**MacOS Big Sur Note:** due to this [known issue](https://github.com/pyenv/pyenv/issues/1737) we recommend using:

```shell
pyenv install 3.7.10
```
Expand Down
28 changes: 28 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Docker Guide
=======================
Included in this repo are the tools to run a containerized Opentrons robot stack in docker.

This includes the `robot-server` connected to the hardware emulation application. The emulation application includes the Smoothie and magnetic, temperature, and thermocycler modules.

## Requirements

- A clone of this repo.
- An installation [docker](https://docs.docker.com/get-docker/)
- An installation of [docker-compose](https://docs.docker.com/compose/install/)

## How to use

Start a terminal and change directory to the root of this repo.

1. Build
Enter `docker-compose build --force-rm` at the terminal.

2. Run
Enter `docker-compose up` at the terminal. _The build and run stages can be combined `docker-compose up --build`._

3. Start the Opentrons application. The docker container will appear as `dev`. Connect and run just as you would on a robot.

## Known Issues

- Pipettes cannot be changed at run time.
- Pipettes are fixed as `p20_multi_v2.0` on the left mount and `p20_single_v2.0` on the right.
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM ubuntu as base
RUN apt-get update && apt-get install -y python3 pip

FROM base as builder
COPY scripts scripts
COPY LICENSE LICENSE

COPY shared-data shared-data

COPY api/MANIFEST.in api/MANIFEST.in
COPY api/setup.py api/setup.py
COPY api/pypi-readme.rst api/pypi-readme.rst
COPY api/src/opentrons api/src/opentrons

COPY notify-server/setup.py notify-server/setup.py
COPY notify-server/README.rst notify-server/README.rst
COPY notify-server/notify_server notify-server/notify_server

COPY robot-server/setup.py robot-server/setup.py
COPY robot-server/robot_server robot-server/robot_server

RUN cd shared-data/python && python3 setup.py bdist_wheel -d /dist/
RUN cd api && python3 setup.py bdist_wheel -d /dist/
RUN cd notify-server && python3 setup.py bdist_wheel -d /dist/
RUN cd robot-server && python3 setup.py bdist_wheel -d /dist/

FROM base
COPY --from=builder /dist /dist
RUN pip install /dist/*
1 change: 0 additions & 1 deletion api/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include src/opentrons/package.json
graft src/opentrons/config
graft src/opentrons/resources
include src/opentrons/server/openapi.json
exclude pyproject.toml
17 changes: 8 additions & 9 deletions api/src/opentrons/hardware_control/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,16 @@ def disengage_axes(self, axes: List[str]):
self._smoothie_driver.disengage_axis(''.join(axes))

def set_lights(self, button: Optional[bool], rails: Optional[bool]):
if opentrons.config.IS_ROBOT:
if button is not None:
self.gpio_chardev.set_button_light(blue=button)
if rails is not None:
self.gpio_chardev.set_rail_lights(rails)
if button is not None:
self.gpio_chardev.set_button_light(blue=button)
if rails is not None:
self.gpio_chardev.set_rail_lights(rails)

def get_lights(self) -> Dict[str, bool]:
if not opentrons.config.IS_ROBOT:
return {}
return {'button': self.gpio_chardev.get_button_light()[2],
'rails': self.gpio_chardev.get_rail_lights()}
return {
'button': self.gpio_chardev.get_button_light()[2],
'rails': self.gpio_chardev.get_rail_lights()
}

def pause(self):
self._smoothie_driver.pause()
Expand Down
2 changes: 1 addition & 1 deletion api/src/opentrons/hardware_control/emulation/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def run_server(host: str, port: int, handler: ConnectionHandler) -> None:

async def run() -> None:
"""Run the module emulators."""
host = "127.0.0.1"
host = "0.0.0.0"

await asyncio.gather(
run_server(host=host,
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: '3'
services:
emulator:
build: .
command: python3 -m opentrons.hardware_control.emulation.app
ports:
- '9996:9996'
- '9997:9997'
- '9998:9998'
- '9999:9999'
robot-server:
build: .
command: uvicorn "robot_server:app" --host 0.0.0.0 --port 31950 --ws wsproto --reload
ports:
- '31950:31950'
environment:
- OT_API_CONFIG_DIR=/config
- OT_SMOOTHIE_EMULATOR_URI=socket://emulator:9996
- OT_THERMOCYCLER_EMULATOR_URI=socket://emulator:9997
- OT_TEMPERATURE_EMULATOR_URI=socket://emulator:9998
- OT_MAGNETIC_EMULATOR_URI=socket://emulator:9999
links:
- 'emulator'
depends_on:
- 'emulator'
volumes:
- .opentrons_config:/config:rw
4 changes: 4 additions & 0 deletions robot-server/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def get_version():
INSTALL_REQUIRES = [
'fastapi==0.54.1',
'python-multipart==0.0.5',
'uvicorn==0.11.3',
'python-dotenv',
'opentrons',
'wsproto==0.15.0',
'typing-extensions>=3.7.4.3',
]


Expand Down

0 comments on commit f89a660

Please sign in to comment.