-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use Makefile for all tasks #17
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
LOCAL_IMAGE = acorn_docker:1.0 | ||
REMOTE_IMAGE = merlinran/acorn_docker | ||
|
||
.PHONY: list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
list: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is the first target in the file, |
||
@echo "Welcome! You may want to try one of the following:\n---"; \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One caveat is to always use tab instead of whitespaces in the rule body, or |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||
@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; \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's again plain shell. Start the container if it doesn't exist, then |
||
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 . | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to allow me building and pushing the image for |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is supposed to be run inside the container, but since you are on Linux, you can also |
||
|
||
.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 |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variables are similar to shell variables, you just need to reference them via
$(var)
, instead of$${var}
(${var}
in normal shell, but since we are running shell scripts withinMakefile
, we need to escape$
, similar to why we have to use\\
to represent\
in C string).