Skip to content

Commit

Permalink
Parameterize docker(-compose) commands
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Steiner <[email protected]>
  • Loading branch information
Michael Steiner committed Apr 25, 2024
1 parent aa18a19 commit 3d5f4ea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
41 changes: 23 additions & 18 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ PDO_VERSION ?= $$( if [ -d repository ]; then cd repository; bin/get_version; el
PDO_USER_UID ?= $(shell id -u)
PDO_GROUP_UID ?= $(shell id -g)

DOCKER_COMMAND ?= docker
DOCKER_COMPOSE_COMMAND ?= docker-comopse
# to work with upstream docker and docker compose plugin, redefine above
# as `DOCKER_COMPOSE_COMMAND=docker compose` in your `make.loc`

DOCKER_DIR = ${PDO_SOURCE_ROOT}/docker
DOCKER_USERNAME = $(LOGNAME)
DOCKER_BUILDARGS += --build-arg UID=$(PDO_USER_UID)
Expand All @@ -61,29 +66,29 @@ TIMESTAMP := $(shell /bin/date "+%Y%m%d%H%M%S")
all : $(addprefix build_,$(IMAGES))

rebuild_% : repository
docker build $(DOCKER_ARGS) \
$(DOCKER_COMMAND) build $(DOCKER_ARGS) \
--build-arg REBUILD=$(TIMESTAMP) \
--build-arg PDO_VERSION=$(PDO_VERSION) \
--tag pdo_$*:$(PDO_VERSION) \
--file '$(DOCKER_DIR)'/pdo_$*.dockerfile .

build_% : repository
docker build $(DOCKER_ARGS) \
$(DOCKER_COMMAND) build $(DOCKER_ARGS) \
--build-arg PDO_VERSION=$(PDO_VERSION) \
--tag pdo_$*:$(PDO_VERSION) \
--file '$(DOCKER_DIR)'/pdo_$*.dockerfile .

# overwrite above build rules for SGX-dependent images
rebuild_services_sgx : repository
docker build $(DOCKER_ARGS) \
$(DOCKER_COMMAND) build $(DOCKER_ARGS) \
--build-arg REBUILD=$(TIMESTAMP) \
--build-arg PDO_VERSION=$(PDO_VERSION) \
--build-arg SGX_MODE=HW \
--tag pdo_services_sgx:$(PDO_VERSION) \
--file $(DOCKER_DIR)/pdo_services.dockerfile .

build_services_sgx : $(IAS_CERTIFICATES) repository build_services_base
docker build $(DOCKER_ARGS) \
$(DOCKER_COMMAND) build $(DOCKER_ARGS) \
--build-arg PDO_VERSION=$(PDO_VERSION) \
--build-arg SGX_MODE=HW \
--tag pdo_services_sgx:$(PDO_VERSION) \
Expand All @@ -96,31 +101,31 @@ build_services_base: build_base
build_ccf: build_ccf_base

clean_% :
docker rmi -f pdo_$*:$(PDO_VERSION)
$(DOCKER_COMMAND) rmi -f pdo_$*:$(PDO_VERSION)

DOCKER_RUN_ARGS = -v $(DOCKER_DIR)/xfer/:/project/pdo/xfer
DOCKER_RUN_ARGS += --network host

run_ccf : build_ccf stop_ccf
docker run $(DOCKER_RUN_ARGS) --name ccf_container -P -d pdo_ccf:$(PDO_VERSION)
$(DOCKER_COMMAND) run $(DOCKER_RUN_ARGS) --name ccf_container -P -d pdo_ccf:$(PDO_VERSION)

run_services : build_base build_services_base build_services stop_services
docker run $(DOCKER_RUN_ARGS) --name services_container -P -d pdo_services:$(PDO_VERSION)
$(DOCKER_COMMAND) run $(DOCKER_RUN_ARGS) --name services_container -P -d pdo_services:$(PDO_VERSION)

run_client : build_base build_client stop_client
docker run $(DOCKER_RUN_ARGS) -it --name client_container pdo_client:$(PDO_VERSION) \
$(DOCKER_COMMAND) run $(DOCKER_RUN_ARGS) -it --name client_container pdo_client:$(PDO_VERSION) \
-c "stty cols $$(tput cols) rows $$(tput lines) && bash"

stop_all : stop_ccf stop_services stop_client

stop_ccf :
- docker rm -f ccf_container
- $(DOCKER_COMMAND) rm -f ccf_container

stop_services :
- docker rm -f services_container
- $(DOCKER_COMMAND) rm -f services_container

stop_client :
- docker rm -f client_container
- $(DOCKER_COMMAND) rm -f client_container

$(IAS_CERTIFICATES) : repository
# the script prepares the certificates from the source repo
Expand Down Expand Up @@ -169,13 +174,13 @@ SGX_DEVICE_PATH=$(shell if [ -e "/dev/isgx" ]; \
else echo "ERROR: NO SGX DEVICE FOUND"; \
fi)

DOCKER_COMPOSE_SGX := env SGX_DEVICE_PATH=${SGX_DEVICE_PATH} docker-compose
DOCKER_COMPOSE_SGX := env SGX_DEVICE_PATH=${SGX_DEVICE_PATH} $(DOCKER_COMPOSE_COMMAND)

build_test : repository build_services build_ccf build_client

test : clean_config clean_repository build_test stop_all
PDO_VERSION=$(PDO_VERSION) docker-compose $(TEST_FILES) up --abort-on-container-exit
PDO_VERSION=$(PDO_VERSION) docker-compose $(TEST_FILES) down
PDO_VERSION=$(PDO_VERSION) $(DOCKER_COMPOSE_COMMAND) $(TEST_FILES) up --abort-on-container-exit
PDO_VERSION=$(PDO_VERSION) $(DOCKER_COMPOSE_COMMAND) $(TEST_FILES) down

sgx_build_test : repository build_services_sgx build_ccf build_client

Expand All @@ -194,11 +199,11 @@ sgx_test : clean_config clean_repository sgx_build_test stop_all sgx_keys
# referenced images. Clean make sure that everything is cleaned up
# across the board.
# -----------------------------------------------------------------
_IMAGES_=$(shell docker images -a --filter=dangling=true -q)
_CONTAINERS_=$(shell docker ps --filter=status=exited --filter=status=created -q)
_IMAGES_=$(shell $(DOCKER_COMMAND) images -a --filter=dangling=true -q)
_CONTAINERS_=$(shell $(DOCKER_COMMAND) ps --filter=status=exited --filter=status=created -q)
clean_images : $(addprefix clean_,$(IMAGES))
if [ ! -z "$(_CONTAINERS_)" ]; then docker rm -f $(_CONTAINERS_); fi
if [ ! -z "$(_IMAGES_)" ]; then docker rmi -f $(_IMAGES_); fi
if [ ! -z "$(_CONTAINERS_)" ]; then $(DOCKER_COMMAND) rm -f $(_CONTAINERS_); fi
if [ ! -z "$(_IMAGES_)" ]; then $(DOCKER_COMMAND) rmi -f $(_IMAGES_); fi

clean_config :
rm -f '$(DOCKER_DIR)'/xfer/ccf/keys/*.pem '$(DOCKER_DIR)'/xfer/ccf/etc/*.toml
Expand Down
16 changes: 8 additions & 8 deletions docker/make.dev
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,31 @@ ifdef DOCKER_CLIENT_WITH_PDO_CONTRACTS
endif

run_ccf_dev : build_ccf
docker run $(DOCKER_DEV_ARGS) --name ccf_container_dev \
$(DOCKER_COMMAND) run $(DOCKER_DEV_ARGS) --name ccf_container_dev \
-P pdo_ccf:$(PDO_VERSION) -c "$(DOCKER_DEV_CMD)"

run_services_dev : build_base build_services_base build_services
docker run $(DOCKER_DEV_ARGS) --name services_container_dev \
$(DOCKER_COMMAND) run $(DOCKER_DEV_ARGS) --name services_container_dev \
-P pdo_services:$(PDO_VERSION) -c "$(DOCKER_DEV_CMD)"

run_client_dev : build_base build_client
docker run $(DOCKER_CLIENT_DEV_ARGS) $(DOCKER_DEV_ARGS) --name client_container_dev pdo_client:$(PDO_VERSION) \
$(DOCKER_COMMAND) run $(DOCKER_CLIENT_DEV_ARGS) $(DOCKER_DEV_ARGS) --name client_container_dev pdo_client:$(PDO_VERSION) \
-c "$(DOCKER_DEV_CMD)"

stop_all : stop_ccf_dev stop_services_dev stop_client_dev

stop_ccf_dev :
- docker rm -f ccf_container_dev
- $(DOCKER_COMMAND) rm -f ccf_container_dev

stop_services_dev :
- docker rm -f services_container_dev
- $(DOCKER_COMMAND) rm -f services_container_dev

stop_client_dev :
- docker rm -f client_container_dev
- $(DOCKER_COMMAND) rm -f client_container_dev

test_no_reset : clean_config build_test stop_all
PDO_VERSION=$(PDO_VERSION) docker-compose $(TEST_FILES) up --abort-on-container-exit
PDO_VERSION=$(PDO_VERSION) docker-compose $(TEST_FILES) down
PDO_VERSION=$(PDO_VERSION) $(DOCKER_COMPOSE_COMMAND) $(TEST_FILES) up --abort-on-container-exit
PDO_VERSION=$(PDO_VERSION) $(DOCKER_COMPOSE_COMMAND) $(TEST_FILES) down

.PHONY: test_no_reset
.PHONY: stop_ccf_dev stop_services_dev stop_client_dev
Expand Down

0 comments on commit 3d5f4ea

Please sign in to comment.