From 541629ae9eacfe52568334ede8a3e94a2fd3200d Mon Sep 17 00:00:00 2001 From: Merlin Ran Date: Thu, 9 Dec 2021 12:38:24 -0500 Subject: [PATCH] use Makefile for all tasks --- .github/workflows/test.yaml | 2 +- Makefile | 64 +++++++++++++++++++++++++++++++++++++ SIMULATION.md | 14 ++++---- attach_docker_server.sh | 1 - attach_docker_vehicle.sh | 1 - kill-docker.sh | 4 --- run_docker_server.sh | 3 -- run_docker_simulation.sh | 2 -- run_docker_test.sh | 2 -- run_docker_vehicle.sh | 3 -- stop_docker_simulation.sh | 1 - 11 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 Makefile delete mode 100755 attach_docker_server.sh delete mode 100755 attach_docker_vehicle.sh delete mode 100755 kill-docker.sh delete mode 100755 run_docker_server.sh delete mode 100755 run_docker_simulation.sh delete mode 100755 run_docker_test.sh delete mode 100755 run_docker_vehicle.sh delete mode 100755 stop_docker_simulation.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 47a3a49..3b9fca9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,7 +9,7 @@ concurrency: jobs: test: runs-on: ubuntu-latest - # To create and push new image: docker buildx build -t merlinran/acorn_docker --platform linux/amd64,linux/arm64 --push . + # To create and push new image: make push-image container: docker://merlinran/acorn_docker:latest strategy: fail-fast: true diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a64d637 --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +LOCAL_IMAGE = acorn_docker:1.0 +REMOTE_IMAGE = merlinran/acorn_docker + +.PHONY: list +list: + @echo "Welcome! You may want to try one of the following:\n---"; \ + grep "^.PHONY:" Makefile | grep "#" | cut -d ":" -f 2- | sed "s/\w*#/\t#/g" | sed "s/^/make/" + +.PHONY: simulation # Run the vehicle and server containers in simulation mode. +simulation: docker-image + @DOCKER_COMPOSE_FILE=docker-compose-simulation.yml make restart-docker-compose &&\ + echo "Please visit http://localhost" + +.PHONY: attach-vehicle # Attach to the shell of the vehicle container. It creates the container if it doesn't exist. +attach-vehicle: + @test -z `docker ps -f "name=acorn_vehicle" -q` && make docker-vehicle; \ + docker exec -it acorn_vehicle /bin/sh + +.PHONY: attach-server # Attach to the shell of the server container. It creates the container if it doesn't exist. +attach-server: + @test -z `docker ps -f "name=acorn_server" -q` && make docker-server; \ + docker exec -it acorn_server /bin/sh + +.PHONY: stop # Stop both the vehicle and server containers. +stop: + @docker-compose -f docker-compose-simulation.yml down --remove-orphans + +.PHONY: docker-test # Start the vehicle container in test mode and run the tests in it. +docker-test: docker-image + @docker-compose -f docker-compose-test.yml up --remove-orphans -d && \ + docker exec -it acorn_vehicle make test + +.PHONY: push-image # Build and push image to Docker Hub to be used by CI. +push-image: docker-image +ifeq ($(shell uname -m),arm64) + docker buildx build -t $(REMOTE_IMAGE) --platform linux/amd64,linux/arm64 --push . +else + docker build -t $(REMOTE_IMAGE) . && docker push $(REMOTE_IMAGE) +endif + +.PHONY: test # Run tests on Linux (if the Python dependencies are installed) or inside Docker. Otherwise, you probably want to try `make docker-test` instead. +test: + coverage run -m pytest --log-cli-level DEBUG && coverage report --skip-covered --skip-empty + +.PHONY: docker-vehicle +docker-vehicle: docker-image + @DOCKER_COMPOSE_FILE=docker-compose-vehicle.yml make restart-docker-compose + +.PHONY: docker-server +docker-server: docker-image + @DOCKER_COMPOSE_FILE=docker-compose-server.yml make restart-docker-compose + +.PHONY: restart-docker-compose +restart-docker-compose: + @docker-compose -f $${DOCKER_COMPOSE_FILE} down --remove-orphans; \ + docker-compose -f $${DOCKER_COMPOSE_FILE} up -d + +.PHONY: docker-image +docker-image: Dockerfile + @find Dockerfile -newermt "`docker images $(LOCAL_IMAGE) --format "{{.CreatedAt}}"`" || \ + docker build -t $(LOCAL_IMAGE) . + +Dockerfile: vehicle/requirements.txt server/requirements.txt + @docker build --no-cache -t $(LOCAL_IMAGE) . # Force rebuilding image if requirements files have been changed diff --git a/SIMULATION.md b/SIMULATION.md index 1f8b064..c25aaf2 100644 --- a/SIMULATION.md +++ b/SIMULATION.md @@ -2,9 +2,9 @@ ## Running the code in simulation -It is now possible to run a simulated robot in Docker on -your computer. Our launch scripts are designed to run in linux, but if -you examine run_docker_simulation.sh you will see the commands needed. +It is now possible to run a simulated robot in Docker on your computer. Our +launch scripts are only tested on Linux and macOS, but if you examine Makefile +you will see the commands needed. This is early stages alpha quality and at this time only rough notes follow. @@ -25,7 +25,7 @@ Clone this git repo and change in to the directory. ``` git clone https://github.com/Twisted-Fields/acorn-precision-farming-rover.git cd acorn-precision-farming-rover -./run_docker_simulation.sh +make simulation ``` The docker container will now (hopefully) build and launch. This will take @@ -41,7 +41,7 @@ development. Connect to the vehicle container: ``` -./attach_docker_vehicle.sh +make attach-vehicle ``` Multiple processes are running in separate tmux windows. The vehicle has a main process and a separate motor process. @@ -72,7 +72,7 @@ Ctrl+D to exit the docker container without stopping it. The server is configured the same way, but with more tmux windows operating. Attach to the server docker container with: ``` -./attach_docker_server.sh +make attach-server ``` And explore the tmux windows there. @@ -86,7 +86,7 @@ robot status. If you are done, exit any tmux windows and docker containers and then stop simulation with: ``` -./stop_docker_simulation.sh +make stop ``` Want to play around a little more before stopping the simulation? One thing to diff --git a/attach_docker_server.sh b/attach_docker_server.sh deleted file mode 100755 index 5c18f92..0000000 --- a/attach_docker_server.sh +++ /dev/null @@ -1 +0,0 @@ -docker exec -it acorn_server /bin/sh diff --git a/attach_docker_vehicle.sh b/attach_docker_vehicle.sh deleted file mode 100755 index 7169a7d..0000000 --- a/attach_docker_vehicle.sh +++ /dev/null @@ -1 +0,0 @@ -docker exec -it acorn_vehicle /bin/sh diff --git a/kill-docker.sh b/kill-docker.sh deleted file mode 100755 index f62eba6..0000000 --- a/kill-docker.sh +++ /dev/null @@ -1,4 +0,0 @@ -docker kill acorn_server -docker rm acorn_server -docker kill acorn_vehicle -docker rm acorn_vehicle diff --git a/run_docker_server.sh b/run_docker_server.sh deleted file mode 100755 index d433755..0000000 --- a/run_docker_server.sh +++ /dev/null @@ -1,3 +0,0 @@ -docker kill acorn_server -docker rm acorn_server -docker-compose -f docker-compose-server.yml up --remove-orphans -d diff --git a/run_docker_simulation.sh b/run_docker_simulation.sh deleted file mode 100755 index bd224ea..0000000 --- a/run_docker_simulation.sh +++ /dev/null @@ -1,2 +0,0 @@ -docker-compose -f docker-compose-simulation.yml down --remove-orphans -docker-compose -f docker-compose-simulation.yml up -d diff --git a/run_docker_test.sh b/run_docker_test.sh deleted file mode 100755 index fb0daa6..0000000 --- a/run_docker_test.sh +++ /dev/null @@ -1,2 +0,0 @@ -docker-compose -f docker-compose-test.yml up --remove-orphans -d -docker exec -it acorn_vehicle sh -c 'coverage run -m pytest --log-cli-level DEBUG && coverage report --skip-covered --skip-empty' diff --git a/run_docker_vehicle.sh b/run_docker_vehicle.sh deleted file mode 100755 index e76f62a..0000000 --- a/run_docker_vehicle.sh +++ /dev/null @@ -1,3 +0,0 @@ -docker kill acorn_vehicle -docker rm acorn_vehicle -docker-compose -f docker-compose-vehicle.yml up --remove-orphans -d diff --git a/stop_docker_simulation.sh b/stop_docker_simulation.sh deleted file mode 100755 index 88f4259..0000000 --- a/stop_docker_simulation.sh +++ /dev/null @@ -1 +0,0 @@ -docker-compose -f docker-compose-simulation.yml down --remove-orphans