This commit is contained in:
aynic.os
2021-06-09 03:41:47 +02:00
parent 15227453ec
commit 5e659fbfe0
9 changed files with 43 additions and 35 deletions
+16 -7
View File
@@ -32,6 +32,15 @@ else
DOCKER_RUN_VOLUME := -v /var/run/docker.sock:/var/run/docker.sock -v $(or $(MONOREPO_DIR),$(APP_DIR)):$(or $(WORKSPACE_DIR),$(MONOREPO_DIR),$(APP_DIR))
endif
# function env-run: Call env-exec with arg 1 in a subshell
define env-run
$(call env-exec,sh -c '$(or $(1),$(SHELL))')
endef
# function env-exec: Exec arg 1 in a new env
define env-exec
IFS=$$'\n'; env $(env_reset) $(env) $(1)
endef
ifeq ($(DOCKER), true)
DOCKER_SSH_AUTH := -e SSH_AUTH_SOCK=/tmp/ssh-agent/socket -v $(DOCKER_VOLUME_SSH):/tmp/ssh-agent
@@ -43,17 +52,17 @@ endef
ifeq ($(DRONE), true)
# function exec: Run new DOCKER_IMAGE docker with arg 1
define exec
$(call run,$(DOCKER_SSH_AUTH) $(DOCKER_IMAGE) sh -c '$(or $(1),$(SHELL))')
$(call run,$(DOCKER_IMAGE) sh -c '$(or $(1),$(SHELL))')
endef
else
# function exec: Exec arg 1 in docker DOCKER_NAME
define exec
$(ECHO) docker exec $(DOCKER_EXEC_OPTIONS) $(DOCKER_ENV) $(DOCKER_RUN_WORKDIR) $(DOCKER_NAME) sh -c '$(or $(1),$(SHELL))'
$(ECHO) docker exec $(DOCKER_ENV) $(DOCKER_EXEC_OPTIONS) $(DOCKER_RUN_WORKDIR) $(DOCKER_NAME) sh -c '$(or $(1),$(SHELL))'
endef
endif
# function run: Pass arg 1 to docker run
define run
$(ECHO) docker run $(DOCKER_RUN_OPTIONS) $(DOCKER_ENV) $(DOCKER_RUN_VOLUME) $(DOCKER_RUN_WORKDIR) $(1)
$(ECHO) docker run $(DOCKER_ENV) $(DOCKER_RUN_OPTIONS) $(DOCKER_RUN_VOLUME) $(DOCKER_RUN_WORKDIR) $(DOCKER_SSH_AUTH) $(1)
endef
else
@@ -63,13 +72,13 @@ SHELL := /bin/bash
define docker-run
$(ECHO) docker run $(DOCKER_RUN_OPTIONS) $(DOCKER_ENV) $(DOCKER_RUN_VOLUME) $(DOCKER_RUN_WORKDIR) $(or $(1),$(DOCKER_IMAGE):$(DOCKER_IMAGE_TAG)) $(2)
endef
# function exec: Call run with arg 1
# function exec: Call env-exec with arg 1 or SHELL
define exec
$(call run,sh -c '$(or $(1),$(SHELL))')
$(call env-exec,$(or $(1),$(SHELL)))
endef
# function run: Exec arg 1
# function run: Call env-run with arg 1
define run
IFS=$$'\n'; env $(env_reset) $(env) $(1)
$(call env-run,$(1))
endef
endif