Skip to content

Commit

Permalink
chore(push): add ssh_key option for identity file when using push-ot3…
Browse files Browse the repository at this point in the history
… to push code to the Flex (#13521)
  • Loading branch information
vegano1 authored Sep 12, 2023
1 parent 1ac6958 commit 803bf9c
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 108 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ ssh-keygen # note the path you save the key to
make -C robot-server install-key br_ssh_pubkey=/path/to/pubkey host=${some_other_ip_address}
```

and subsequently, when you do `make term`, add the `br_ssh_key=/path/to/key` option:
and subsequently, when you do `make term`, add the `ssh_key=/path/to/key` option:

```shell
make term br_ssh_key=/path/to/privkey
make term ssh_key=/path/to/privkey
```

If you create the key as `~/.ssh/robot_key` and `~/.ssh/robot_key.pub` then `make term` and `make install-key` will work without arguments.
Expand Down
25 changes: 13 additions & 12 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ test_opts ?=
pypi_username ?=
pypi_password ?=

# Host key location for buildroot robot
br_ssh_key ?= $(default_ssh_key)
# Other SSH args for buildroot robots
# Host key location for robot
ssh_key ?= $(default_ssh_key)
# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)
# Helper to safely bundle ssh options
ssh_helper = $(if $(ssh_key),-i $(ssh_key)) $(ssh_opts)

twine_auth_args := --username $(pypi_username) --password $(pypi_password)
twine_repository_url ?= $(pypi_test_upload_url)
Expand Down Expand Up @@ -171,24 +173,23 @@ local-shell:

.PHONY: push-no-restart
push-no-restart: wheel
$(call push-python-package,$(host),$(br_ssh_key),$(ssh_opts),$(wheel_file))
$(call push-python-package,$(host),$(ssh_key),$(ssh_opts),$(wheel_file))

.PHONY: push
push: push-no-restart
$(call restart-service,$(host),$(br_ssh_key),$(ssh_opts),"jupyter-notebook opentrons-robot-server")
$(call restart-service,$(host),$(ssh_key),$(ssh_opts),"jupyter-notebook opentrons-robot-server")

.PHONY: push-no-restart-ot3
push-no-restart-ot3: sdist
echo $(sdist_file)
$(call push-python-sdist,$(host),,$(ssh_opts),$(sdist_file),/opt/opentrons-robot-server,opentrons,src,,$(version_file))
ssh $(ssh_opts) root@$(host) "mount -o remount,rw / && mkdir -p /usr/local/bin"
scp $(ssh_opts) ./src/opentrons/hardware_control/scripts/ot3repl root@$(host):/usr/local/bin/ot3repl
scp $(ssh_opts) ./src/opentrons/hardware_control/scripts/ot3gripper root@$(host):/usr/local/bin/ot3gripper
ssh $(ssh_opts) root@$(host) "mount -o remount,ro /"
$(call push-python-sdist,$(host),$(ssh_key),$(ssh_opts),$(sdist_file),/opt/opentrons-robot-server,opentrons,src,,$(version_file))
ssh $(ssh_helper) root@$(host) "mount -o remount,rw / && mkdir -p /usr/local/bin"
scp $(ssh_helper) ./src/opentrons/hardware_control/scripts/{ot3repl,ot3gripper} root@$(host):/usr/local/bin/
ssh $(ssh_helper) root@$(host) "mount -o remount,ro /"

.PHONY: push-ot3
push-ot3: push-no-restart-ot3
$(call restart-server,$(host),,$(ssh_opts),"opentrons-robot-server")
$(call restart-server,$(host),$(host),$(ssh_opts),"opentrons-robot-server")

.PHONY: simulate
simulate:
Expand All @@ -206,7 +207,7 @@ deploy: wheel
# User must currently specify host, e.g.: `make term host=169.254.202.176`
.PHONY: term
term:
ssh -i $(br_ssh_key) $(ssh_opts) root@$(host)
ssh $(ssh_helper) root@$(host)

.PHONY: plot-session
plot-session:
Expand Down
6 changes: 3 additions & 3 deletions app-shell-odd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ dist-ot3: package-deps
.PHONY: push-ot3
push-ot3: dist-ot3
tar -zcvf opentrons-robot-app.tar.gz -C ./dist/linux-arm64-unpacked/ ./
scp -r $(ssh_opts) ./opentrons-robot-app.tar.gz root@$(host):
ssh $(ssh_opts) root@$(host) "mount -o remount,rw / && systemctl stop opentrons-robot-app && rm -rf /opt/opentrons-app && mkdir -p /opt/opentrons-app"
ssh $(ssh_opts) root@$(host) "tar -xvf opentrons-robot-app.tar.gz -C /opt/opentrons-app/ && mount -o remount,ro / && systemctl start opentrons-robot-app && rm -rf opentrons-robot-app.tar.gz"
scp $(if $(ssh_key),-i $(ssh_key)) $(ssh_opts) -r ./opentrons-robot-app.tar.gz root@$(host):
ssh $(if $(ssh_key),-i $(ssh_key)) $(ssh_opts) root@$(host) "mount -o remount,rw / && systemctl stop opentrons-robot-app && rm -rf /opt/opentrons-app && mkdir -p /opt/opentrons-app"
ssh $(if $(ssh_key),-i $(ssh_key)) $(ssh_opts) root@$(host) "tar -xvf opentrons-robot-app.tar.gz -C /opt/opentrons-app/ && mount -o remount,ro / && systemctl start opentrons-robot-app && rm -rf opentrons-robot-app.tar.gz"
rm -rf opentrons-robot-app.tar.gz

# development
Expand Down
2 changes: 1 addition & 1 deletion app-shell/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dist_files = $(if $(filter $(1),robot-stack),"dist/**/Opentrons-*","dist/**/Open
update_files := "dist/@(alpha|beta|latest)*.@(yml|json)"
publish_dir := dist/publish

# Other SSH args for buildroot robots
# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)

# TODO(mc, 2018-03-27): move all this to some sort of envfile
Expand Down
48 changes: 25 additions & 23 deletions hardware-testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ tests ?= tests
cov_opts ?= --cov=hardware_testing --cov-report term-missing:skip-covered --cov-report xml:coverage.xml
test_opts ?=

# Host key location for buildroot robot
br_ssh_key ?= $(default_ssh_key)
# Other SSH args for buildroot robots
# Host key location for robot
ssh_key ?= $(default_ssh_key)
# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)
# Helper to safely bundle ssh options
ssh_helper = $(if $(ssh_key),-i $(ssh_key)) $(ssh_opts)

# Source discovery
# For the python sources
Expand Down Expand Up @@ -170,32 +172,32 @@ endef

.PHONY: push-plot-webpage-ot3
push-plot-webpage-ot3:
scp -r hardware_testing/tools/plot root@$(host):/data
$(call move-plot-webpage-ot3,$(host),$(br_ssh_key),$(ssh_opts))
scp $(ssh_helper) -r hardware_testing/tools/plot root@$(host):/data
$(call move-plot-webpage-ot3,$(host),$(ssh_key),$(ssh_opts))

.PHONY: push-description-ot3
push-description-ot3:
$(python) -c "from hardware_testing.data import create_git_description_file; create_git_description_file()"
scp ./.hardware-testing-description root@$(host):/data/.hardware-testing-description
scp $(ssh_helper) ./.hardware-testing-description root@$(host):/data/

.PHONY: restart
restart:
$(call restart-service,$(host),$(br_ssh_key),$(ssh_opts),"opentrons-robot-server")
$(call restart-service,$(host),$(ssh_key),$(ssh_opts),"opentrons-robot-server")

.PHONY: push-no-restart
push-no-restart: wheel
$(call push-python-package,$(host),$(br_ssh_key),$(ssh_opts),$(wheel_file))
$(call push-python-package,$(host),$(ssh_key),$(ssh_opts),$(wheel_file))

.PHONY: push
push: push-no-restart restart

.PHONY: restart-ot3
restart-ot3:
$(call restart-server,$(host),,$(ssh_opts),"opentrons-robot-server")
$(call restart-server,$(host),$(ssh_key),$(ssh_opts),"opentrons-robot-server")

.PHONY: push-no-restart-ot3
push-no-restart-ot3: sdist Pipfile.lock
$(call push-python-sdist,$(host),,$(ssh_opts),$(sdist_file),/opt/opentrons-robot-server,"hardware_testing",,,$(version_file))
$(call push-python-sdist,$(host),$(ssh_key),$(ssh_opts),$(sdist_file),/opt/opentrons-robot-server,"hardware_testing",,,$(version_file))

.PHONY: push-ot3
push-ot3: push-no-restart-ot3 push-plot-webpage-ot3 push-description-ot3
Expand All @@ -205,7 +207,7 @@ push-all: clean wheel push-no-restart push-plot-webpage

.PHONY: term
term:
ssh -i $(br_ssh_key) $(ssh_opts) root@$(host)
ssh $(ssh_helper) root@$(host)

.PHONY: list-ports
list-ports:
Expand All @@ -221,7 +223,7 @@ push-all-and-term: push-all term
.PHONY: pull-data-ot3
pull-data-ot3:
mkdir -p "./.pulled-data"
scp -r "root@$(host):/data/testing_data/$(test)" "./.pulled-data"
scp $(ssh_helper) -r "root@$(host):/data/testing_data/$(test)" "./.pulled-data"

define delete-test-data-cmd
ssh -i $(2) $(3) root@$(1) \
Expand All @@ -230,14 +232,14 @@ endef

.PHONY: delete-data-ot3
delete-data-ot3:
$(call delete-test-data-cmd,$(host),$(br_ssh_key),$(ssh_opts),$(test))
$(call delete-test-data-cmd,$(host),$(ssh_key),$(ssh_opts),$(test))

define push-and-update-fw
scp $(2) root@$(1):/tmp
ssh root@$(1) \
"function cleanup () { (rm -rf /tmp/$(2) || true) && mount -o remount,ro / ; } ;\
scp -i $(2) $(3) $(4) root@$(1):/tmp/
ssh -i $(2) $(3) root@$(1) \
"function cleanup () { (rm -rf /tmp/$(4) || true) && mount -o remount,ro / ; } ;\
mount -o remount,rw / &&\
(unzip -o /tmp/$(2) -d /usr/lib/firmware || cleanup) &&\
(unzip -o /tmp/$(4) -d /usr/lib/firmware || cleanup) &&\
python3 -m json.tool /usr/lib/firmware/opentrons-firmware.json &&\
cleanup"
endef
Expand All @@ -248,7 +250,7 @@ sync-sw-ot3: push-ot3

.PHONY: sync-fw-ot3
sync-fw-ot3:
$(call push-and-update-fw,$(host),$(zip))
$(call push-and-update-fw,$(host),$(ssh_key),$(ssh_opts),$(zip))

.PHONY: sync-ot3
sync-ot3: sync-sw-ot3 sync-fw-ot3
Expand All @@ -258,10 +260,10 @@ push-ot3-gravimetric:
$(MAKE) apply-patches-gravimetric
-$(MAKE) sync-sw-ot3
$(MAKE) remove-patches-gravimetric
scp -r -O hardware_testing/labware/opentrons_flex_96_tiprack_50ul_adp/ root@$(host):/data/labware/v2/custom_definitions/custom_beta/
scp -r -O hardware_testing/labware/opentrons_flex_96_tiprack_200ul_adp/ root@$(host):/data/labware/v2/custom_definitions/custom_beta/
scp -r -O hardware_testing/labware/opentrons_flex_96_tiprack_1000ul_adp/ root@$(host):/data/labware/v2/custom_definitions/custom_beta/
scp -r -O hardware_testing/labware/radwag_pipette_calibration_vial/ root@$(host):/data/labware/v2/custom_definitions/custom_beta/
scp $(ssh_helper) -r -O hardware_testing/labware/opentrons_flex_96_tiprack_50ul_adp/ root@$(host):/data/labware/v2/custom_definitions/custom_beta/
scp $(ssh_helper) -r -O hardware_testing/labware/opentrons_flex_96_tiprack_200ul_adp/ root@$(host):/data/labware/v2/custom_definitions/custom_beta/
scp $(ssh_helper) -r -O hardware_testing/labware/opentrons_flex_96_tiprack_1000ul_adp/ root@$(host):/data/labware/v2/custom_definitions/custom_beta/
scp $(ssh_helper) -r -O hardware_testing/labware/radwag_pipette_calibration_vial/ root@$(host):/data/labware/v2/custom_definitions/custom_beta/

.PHONY: apply-patches-gravimetric
apply-patches-gravimetric:
Expand All @@ -283,7 +285,7 @@ update-patches-gravimetric:

.PHONY: push-photometric-ot2
push-photometric-ot2:
scp -r -O photometric-ot2/photometric_ot2 root@$(host):/data/user_storage
scp $(ssh_helper) -r -O photometric-ot2/photometric_ot2 root@$(host):/data/user_storage

.PHONY: get-latest-tag
get-latest-tag:
Expand Down
16 changes: 9 additions & 7 deletions hardware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ test_opts ?=
pypi_username ?=
pypi_password ?=

# Host key location for buildroot robot
br_ssh_key ?= $(default_ssh_key)
# Other SSH args for buildroot robots
# Host key location for robot
ssh_key ?= $(default_ssh_key)
# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)
# Helper to safely bundle ssh options
ssh_helper = $(if $(ssh_key),-i $(ssh_key)) $(ssh_opts)

twine_auth_args := --username $(pypi_username) --password $(pypi_password)
twine_repository_url ?= $(pypi_test_upload_url)
Expand Down Expand Up @@ -121,19 +123,19 @@ dev:

.PHONY: push-no-restart
push-no-restart: wheel
$(call push-python-package,$(host),$(br_ssh_key),$(ssh_opts),$(wheel_file))
$(call push-python-package,$(host),$(ssh_key),$(ssh_opts),$(wheel_file))

.PHONY: push
push: push-no-restart
$(call restart-service,$(host),$(br_ssh_key),$(ssh_opts),"jupyter-notebook opentrons-robot-server")
$(call restart-service,$(host),$(ssh_key),$(ssh_opts),"jupyter-notebook opentrons-robot-server")

.PHONY: push-no-restart-ot3
push-no-restart-ot3: sdist Pipfile.lock
$(call push-python-sdist,$(host),,$(ssh_opts),$(sdist_file),/opt/opentrons-robot-server,"opentrons_hardware",,,$(version_file))
$(call push-python-sdist,$(host),$(ssh_key),$(ssh_opts),$(sdist_file),/opt/opentrons-robot-server,"opentrons_hardware",,,$(version_file))

.PHONY: push-ot3
push-ot3: push-no-restart-ot3
$(call restart-server,$(host),,$(ssh_opts),"opentrons-robot-server")
$(call restart-server,$(host),$(ssh_key),$(ssh_opts),"opentrons-robot-server")


# Launch the emulator application.
Expand Down
20 changes: 10 additions & 10 deletions notify-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ tests ?= tests
cov_opts ?= --cov=$(SRC_PATH) --cov-report term-missing:skip-covered --cov-report xml:coverage.xml
test_opts ?=

# Host key location for buildroot robot
br_ssh_key ?= $(default_ssh_key)
# Host key location for robot
ssh_key ?= $(default_ssh_key)
# Pubkey location for buildroot robot to install with install-key
br_ssh_pubkey ?= $(br_ssh_key).pub
# Other SSH args for buildroot robots
br_ssh_pubkey ?= $(ssh_key).pub
# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)

# Source discovery
Expand Down Expand Up @@ -128,19 +128,19 @@ local-shell:

.PHONY: push
push: wheel
$(call push-python-package,$(host),$(br_ssh_key),$(ssh_opts),$(wheel_file))
$(call push-systemd-unit,$(host),$(br_ssh_key),$(ssh_opts),./opentrons-notify-server.service)
$(call restart-service,$(host),$(br_ssh_key),$(ssh_opts),opentrons-notify-server)
$(call push-python-package,$(host),$(ssh_key),$(ssh_opts),$(wheel_file))
$(call push-systemd-unit,$(host),$(ssh_key),$(ssh_opts),./opentrons-notify-server.service)
$(call restart-service,$(host),$(ssh_key),$(ssh_opts),opentrons-notify-server)


.PHONY: push-no-restart-ot3
push-no-restart-ot3: sdist
$(call push-python-sdist,$(host),,$(ssh_opts),$(sdist_file),"/opt/opentrons-robot-server","notify_server",,,$(version_file))
$(call push-python-sdist,$(host),$(ssh_key),$(ssh_opts),$(sdist_file),"/opt/opentrons-robot-server","notify_server",,,$(version_file))


.PHONY: push-ot3
push-ot3: push-no-restart-ot3
$(call restart-server,$(host),,$(ssh_opts),"opentrons-notify-server")
$(call restart-server,$(host),$(ssh_key),$(ssh_opts),"opentrons-notify-server")


.PHONY: install-key
Expand All @@ -152,4 +152,4 @@ install-key:
# User must currently specify host, e.g.: `make term host=169.254.202.176`
.PHONY: term
term:
ssh -i $(br_ssh_key) $(ssh_opts) root@$(host)
ssh $(if $(ssh_key),-i $(ssh_key)) $(ssh_opts) root@$(host)
22 changes: 11 additions & 11 deletions robot-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ tests ?= tests
cov_opts ?= --cov=$(SRC_PATH) --cov-report term-missing:skip-covered --cov-report xml:coverage.xml
test_opts ?=

# Host key location for buildroot robot
br_ssh_key ?= $(default_ssh_key)
# Pubkey location for buildroot robot to install with install-key
br_ssh_pubkey ?= $(br_ssh_key).pub
# Other SSH args for buildroot robots
# Host key location for robot
ssh_key ?= $(default_ssh_key)
# Pubkey location for robot to install with install-key
ssh_pubkey ?= $(ssh_key).pub
# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)

# Source discovery
Expand Down Expand Up @@ -150,19 +150,19 @@ local-shell:

.PHONY: push
push: wheel
$(call push-python-package,$(host),$(br_ssh_key),$(ssh_opts),$(wheel_file))
$(call push-systemd-unit,$(host),$(br_ssh_key),$(ssh_opts),./opentrons-robot-server.service)
$(call restart-service,$(host),$(br_ssh_key),$(ssh_opts),opentrons-robot-server)
$(call push-python-package,$(host),$(ssh_key),$(ssh_opts),$(wheel_file))
$(call push-systemd-unit,$(host),$(ssh_key),$(ssh_opts),./opentrons-robot-server.service)
$(call restart-service,$(host),$(ssh_key),$(ssh_opts),opentrons-robot-server)

.PHONY: push-ot3
push-ot3: sdist
$(call push-python-sdist,$(host),,$(ssh_opts),$(sdist_file),"/opt/opentrons-robot-server","robot_server",,,$(version_file))
$(call push-python-sdist,$(host),$(ssh_key),$(ssh_opts),$(sdist_file),"/opt/opentrons-robot-server","robot_server",,,$(version_file))

.PHONY: install-key
install-key:
curl -X POST $(host):31950/server/ssh_keys\
-H "Content-Type: application/json"\
-d "{\"key\":\"$(shell cat $(br_ssh_pubkey))\"}"
-d "{\"key\":\"$(shell cat $(ssh_pubkey))\"}"

.PHONY: restart
restart:
Expand Down Expand Up @@ -194,7 +194,7 @@ change-left:
# User must currently specify host, e.g.: `make term host=169.254.202.176`
.PHONY: term
term:
ssh -i $(br_ssh_key) $(ssh_opts) root@$(host)
ssh -i $(ssh_key) $(ssh_opts) root@$(host)


.PHONY: docs
Expand Down
2 changes: 1 addition & 1 deletion scripts/push.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# utilities for pushing things to robots in a reusable fashion

find_robot=$(shell yarn run -s discovery find -i 169.254)
default_ssh_key := ~/.ssh/robot_key
default_ssh_key :=
default_ssh_opts := -o stricthostkeychecking=no -o userknownhostsfile=/dev/null
version_dict=$(shell ssh $(call id-file-arg,$(2)) $(3) root@$(1) cat /etc/VERSION.json)
is-ot3=$(findstring OT-3, $(version_dict))
Expand Down
14 changes: 7 additions & 7 deletions server-utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ tests ?= tests
cov_opts ?= --cov=$(SRC_PATH) --cov-report term-missing:skip-covered --cov-report xml:coverage.xml
test_opts ?=

# Host key location for buildroot robot
br_ssh_key ?= $(default_ssh_key)
# Host key location for robot
ssh_key ?= $(default_ssh_key)
# Pubkey location for buildroot robot to install with install-key
br_ssh_pubkey ?= $(br_ssh_key).pub
# Other SSH args for buildroot robots
br_ssh_pubkey ?= $(ssh_key).pub
# Other SSH args for robot
ssh_opts ?= $(default_ssh_opts)

# Source discovery
Expand Down Expand Up @@ -111,9 +111,9 @@ local-shell:

.PHONY: push
push: wheel
$(call push-python-package,$(host),$(br_ssh_key),$(ssh_opts),$(wheel_file))
$(call push-python-package,$(host),$(ssh_key),$(ssh_opts),$(wheel_file))

.PHONY: push-ot3
push-ot3: sdist
$(call push-python-sdist,$(host),,$(ssh_opts),$(sdist_file),"/opt/opentrons-system-server","server_utils",,,$(version_file))
$(call push-python-sdist,$(host),,$(ssh_opts),$(sdist_file),"/opt/opentrons-robot-server","server_utils")
$(call push-python-sdist,$(host),$(ssh_key),$(ssh_opts),$(sdist_file),"/opt/opentrons-system-server","server_utils",,,$(version_file))
$(call push-python-sdist,$(host),$(ssh_key),$(ssh_opts),$(sdist_file),"/opt/opentrons-robot-server","server_utils")
Loading

0 comments on commit 803bf9c

Please sign in to comment.