Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Cross-platform Makefile #1660

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 74 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# Check if this is Windows
ifneq (,$(findstring WINDOWS,$(PATH)))
WINDOWS := True
endif

# Set shell to cmd on windows
ifdef WINDOWS
SHELL := C:/Windows/System32/cmd.exe
endif

# Don't use sudo on windows
SUDO := "sudo"
ifdef WINDOWS
SUDO :=
endif

# set home dir to user's home on windows running MINGW
ifdef MSYSTEM
HOME := $(subst \,/,$(HOME))
endif

# Get the root dir of this file
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

# Define the full path to this file
THIS_FILE := $(lastword $(MAKEFILE_LIST))

# Set docker-compose file selector for windows
ifneq (,$(findstring WINDOWS,$(PATH)))
DC_CONFIG=$(ROOT_DIR)/docker-compose-windows.yml
else
DC_CONFIG=$(ROOT_DIR)/docker-compose.yml
endif

# Find or create a home for sensitive environment variables
# Check my secret place
CREDS=$(HOME)/.bash/.credentials
ifneq ("$(wildcard $(CREDS))","")
CREDENTIALS := $(CREDS)
else
# Check a normal place
CREDS=$(HOME)/.credentials
ifneq ("$(wildcard $(CREDS))","")
CREDENTIALS := $(CREDS)
else
$(info $(shell "mkdir" $(CREDS)))
endif
endif

# To use arguments with make execute: make -- <command> <args>
ARGS = $(filter-out $@,$(MAKECMDGOALS))
MAKEFLAGS += --silent

Expand All @@ -9,68 +59,69 @@ list:
#############################

list-strategies:
sudo docker-compose exec server zenbot list-strategies $(ARGS)
docker-compose exec server zenbot list-strategies $(ARGS)

list-selectors:
sudo docker-compose exec server zenbot list-selectors $(ARGS)
docker-compose exec server zenbot list-selectors $(ARGS)

backfill:
sudo docker-compose exec server zenbot backfill $(ARGS)
docker-compose exec server zenbot backfill $(ARGS)

sim:
sudo docker-compose exec server zenbot sim $(ARGS)
docker-compose exec server zenbot sim $(ARGS)

trade:
sudo docker-compose exec server zenbot trade $(ARGS)
docker-compose exec server zenbot trade $(ARGS)

paper:
sudo docker-compose exec server zenbot trade --paper $(ARGS)
docker-compose exec server zenbot trade --paper $(ARGS)

balance:
sudo docker-compose exec server zenbot balance $(ARGS)
docker-compose exec server zenbot balance $(ARGS)

buy:
sudo docker-compose exec server zenbot buy $(ARGS)
docker-compose exec server zenbot buy $(ARGS)

sell:
sudo docker-compose exec server zenbot sell $(ARGS)
docker-compose exec server zenbot sell $(ARGS)

zenbot:
sudo docker-compose exec server zenbot $(ARGS)
docker-compose exec server zenbot $(ARGS)

#############################
# Docker machine states
#############################

up:
sudo docker-compose up -d
$(SUDO) docker-compose --file=$(DC_CONFIG) up

start:
sudo docker-compose start
docker-compose start

stop:
sudo docker-compose stop
docker-compose stop

state:
sudo docker-compose ps
docker-compose ps

rebuild:
sudo docker-compose stop
sudo docker-compose pull
sudo docker-compose rm --force server
sudo docker-compose rm --force mongodb
sudo docker-compose rm --force adminmongo
sudo docker-compose build --no-cache
sudo docker-compose up -d --force-recreate
$(SUDO) docker-compose stop
$(SUDO) docker-compose pull
$(SUDO) docker-compose rm --force server
$(SUDO) docker-compose rm --force mongodb
-$(SUDO) docker-compose rm --force adminmongo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you asking about line 112?
That makes the command optional and prevents the target from stopping if it fails. If the user is using adminmongo, the command executes, otherwise the container doesn't exist so the target will report that the command failed and move on.

$(SUDO) docker-compose build --no-cache
$(SUDO) docker-compose --file=$(DC_CONFIG) up -d --force-recreate


shell:
sudo docker-compose exec server /bin/sh
docker-compose exec server /bin/sh

shellw:
docker exec -it -u root $$(docker-compose ps -q server) /bin/sh

logs:
sudo docker-compose logs $(ARGS)
docker-compose logs $(ARGS)

#############################
# Argument fix workaround
Expand Down