docker attach
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
ANSIBLE_APP_LOAD ?= myos
|
||||
ANSIBLE_APP_NAME ?= myos
|
||||
ANSIBLE_APP_TYPE ?= myos
|
||||
ANSIBLE_ARGS ?= $(if $(filter-out 0,$(UID)),$(if $(shell sudo -l 2>/dev/null |grep 'NOPASSWD: ALL'),,--ask-become-pass))$(if $(DOCKER_RUN),$(if $(shell ssh-add -l >/dev/null 2>&1 || echo false), --ask-pass))
|
||||
ANSIBLE_AWS_ACCESS_KEY_ID ?= $(AWS_ACCESS_KEY_ID)
|
||||
ANSIBLE_AWS_DEFAULT_OUTPUT ?= $(AWS_DEFAULT_OUTPUT)
|
||||
@@ -36,22 +36,22 @@ ANSIBLE_USERNAME ?= $(USER)
|
||||
ANSIBLE_VERBOSE ?= $(if $(DEBUG),-vvvv,$(if $(VERBOSE),-v))
|
||||
CMDARGS += ansible ansible-playbook
|
||||
DOCKER_RUN_OPTIONS_ANSIBLE ?= -it $(if $(DOCKER_INTERNAL_DOCKER_HOST),--add-host=host.docker.internal:$(DOCKER_INTERNAL_DOCKER_HOST))
|
||||
ENV_VARS += ANSIBLE_APP_NAME ANSIBLE_APP_TYPE ANSIBLE_AWS_ACCESS_KEY_ID ANSIBLE_AWS_DEFAULT_OUTPUT ANSIBLE_AWS_DEFAULT_REGION ANSIBLE_AWS_SECRET_ACCESS_KEY ANSIBLE_CONFIG ANSIBLE_DISKS_NFS_DISK ANSIBLE_DISKS_NFS_OPTIONS ANSIBLE_DISKS_NFS_PATH ANSIBLE_DOCKER_IMAGE_TAG ANSIBLE_DOCKER_REGISTRY ANSIBLE_EXTRA_VARS ANSIBLE_GIT_DIRECTORY ANSIBLE_GIT_KEY_FILE ANSIBLE_GIT_REPOSITORY ANSIBLE_GIT_VERSION ANSIBLE_INVENTORY ANSIBLE_MYOS ANSIBLE_PLAYBOOK ANSIBLE_SSH_AUTHORIZED_KEYS ANSIBLE_SSH_BASTION_HOSTNAME ANSIBLE_SSH_BASTION_USERNAME ANSIBLE_SSH_PRIVATE_IP_RANGE ANSIBLE_SSH_PRIVATE_KEYS ANSIBLE_SSH_PUBLIC_HOSTS ANSIBLE_SSH_USERNAME ANSIBLE_USERNAME ANSIBLE_VERBOSE
|
||||
ENV_VARS += ANSIBLE_APP_LOAD ANSIBLE_APP_NAME ANSIBLE_AWS_ACCESS_KEY_ID ANSIBLE_AWS_DEFAULT_OUTPUT ANSIBLE_AWS_DEFAULT_REGION ANSIBLE_AWS_SECRET_ACCESS_KEY ANSIBLE_CONFIG ANSIBLE_DISKS_NFS_DISK ANSIBLE_DISKS_NFS_OPTIONS ANSIBLE_DISKS_NFS_PATH ANSIBLE_DOCKER_IMAGE_TAG ANSIBLE_DOCKER_REGISTRY ANSIBLE_EXTRA_VARS ANSIBLE_GIT_DIRECTORY ANSIBLE_GIT_KEY_FILE ANSIBLE_GIT_REPOSITORY ANSIBLE_GIT_VERSION ANSIBLE_INVENTORY ANSIBLE_MYOS ANSIBLE_PLAYBOOK ANSIBLE_SSH_AUTHORIZED_KEYS ANSIBLE_SSH_BASTION_HOSTNAME ANSIBLE_SSH_BASTION_USERNAME ANSIBLE_SSH_PRIVATE_IP_RANGE ANSIBLE_SSH_PRIVATE_KEYS ANSIBLE_SSH_PUBLIC_HOSTS ANSIBLE_SSH_USERNAME ANSIBLE_USERNAME ANSIBLE_VERBOSE
|
||||
|
||||
# function ansible: Call run ansible ANSIBLE_ARGS with arg 1
|
||||
define ansible
|
||||
$(call INFO,ansible,$(1))
|
||||
$(RUN) $(call $(if $(ANSIBLE_DOCKER_RUN),run,env-run),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(if $(ANSIBLE_DOCKER_RUN),-i $(ANSIBLE_INVENTORY)/.host.docker.internal) $(1),$(DOCKER_RUN_OPTIONS_ANSIBLE) $(DOCKER_REPOSITORY)/)
|
||||
$(call $(if $(ANSIBLE_DOCKER_RUN),run,env-exec),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(if $(ANSIBLE_DOCKER_RUN),-i $(ANSIBLE_INVENTORY)/.host.docker.internal) $(1),$(DOCKER_RUN_OPTIONS_ANSIBLE) $(DOCKER_REPOSITORY)/)
|
||||
endef
|
||||
# function ansible-playbook: Call run ansible-playbook ANSIBLE_ARGS with arg 1
|
||||
define ansible-playbook
|
||||
$(call INFO,ansible-playbook,$(1))
|
||||
$(RUN) $(call $(if $(ANSIBLE_DOCKER_RUN),run,env-run),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible$(if $(ANSIBLE_DOCKER_RUN),,-playbook) $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(if $(ANSIBLE_DOCKER_RUN),-i $(ANSIBLE_INVENTORY)/.host.docker.internal) $(1),$(DOCKER_RUN_OPTIONS_ANSIBLE) --entrypoint=ansible-playbook $(DOCKER_REPOSITORY)/)
|
||||
$(call $(if $(ANSIBLE_DOCKER_RUN),run,env-exec),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible$(if $(ANSIBLE_DOCKER_RUN),,-playbook) $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(if $(ANSIBLE_DOCKER_RUN),-i $(ANSIBLE_INVENTORY)/.host.docker.internal) $(1),$(DOCKER_RUN_OPTIONS_ANSIBLE) --entrypoint=ansible-playbook $(DOCKER_REPOSITORY)/)
|
||||
endef
|
||||
# function ansible-pull: Call run ansible-pull ANSIBLE_ARGS with arg 1
|
||||
define ansible-pull
|
||||
$(call INFO,ansible-pull,$(1))
|
||||
$(call $(if $(ANSIBLE_DOCKER_RUN),run,env-run),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible-pull $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1))
|
||||
$(call $(if $(ANSIBLE_DOCKER_RUN),run,env-exec),$(if $(ANSIBLE_DOCKER_RUN),,$(RUN) )ansible-pull $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1))
|
||||
endef
|
||||
# function ansible-user-add-groups: Call ansible to add user 1 in groups 2
|
||||
define ansible-user-add-groups
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
##
|
||||
# COMMON
|
||||
|
||||
# target attach: Exec ARGS in docker SERVICE
|
||||
# on local host
|
||||
.PHONY: attach
|
||||
attach: SERVICE ?= $(DOCKER_SERVICE)
|
||||
attach: ## Attach to docker SERVICE
|
||||
$(eval attach := $(COMPOSE_PROJECT_NAME)-$(SERVICE))
|
||||
$(if $(call docker-running,^$(attach)-1$), \
|
||||
$(call docker-attach,$(attach)-1) \
|
||||
, $(call docker-attach,$(attach)) \
|
||||
)
|
||||
|
||||
# target bootstrap: Configure system
|
||||
# on local host
|
||||
.PHONY: bootstrap app-bootstrap
|
||||
|
||||
+1
-1
@@ -226,7 +226,7 @@ docker-run-%: docker-build-%
|
||||
$(eval path := $(patsubst %/,%,$*))
|
||||
$(eval image := $(DOCKER_REPOSITORY)/$(lastword $(subst /, ,$(path)))$(if $(findstring :,$*),,:$(DOCKER_IMAGE_TAG)))
|
||||
$(eval image_id := $(shell docker images -q $(image) 2>/dev/null))
|
||||
$(call docker-run,$(RUN) $(command),$(if $(image_id),$(image),$(path)))
|
||||
$(call docker-run,$(command),$(if $(image_id),$(image),$(path)))
|
||||
|
||||
# target docker-tag: Call docker-tag for each SERVICES
|
||||
.PHONY: docker-tag
|
||||
|
||||
@@ -7,14 +7,14 @@ ifeq ($(SETUP_UFW),true)
|
||||
define ufw
|
||||
$(call INFO,ufw,$(1)$(comma))
|
||||
$(call app-bootstrap,ufw-docker)
|
||||
$(call app-exec,,ufw $(1))
|
||||
$(call app-exec,,$(if $(DOCKER_RUN),,$(SUDO)) ufw $(1))
|
||||
endef
|
||||
|
||||
# function ufw-docker: Exec command ufw-docker with args 1
|
||||
define ufw-docker
|
||||
$(call INFO,ufw-docker,$(1)$(comma))
|
||||
$(call app-bootstrap,ufw-docker)
|
||||
$(call app-exec,,ufw-docker $(1))
|
||||
$(call app-exec,,$(if $(DOCKER_RUN),,$(SUDO)) ufw-docker $(1))
|
||||
endef
|
||||
|
||||
endif
|
||||
|
||||
@@ -39,7 +39,7 @@ ssh-key:
|
||||
ifneq (,$(filter true,$(DRONE)))
|
||||
$(call exec,sh -c '[ ! -d $(SSH_DIR) ] && mkdir -p $(SSH_DIR) && chown $(UID) $(SSH_DIR) && chmod 0700 $(SSH_DIR) ||:')
|
||||
endif
|
||||
$(if $(SSH_KEY),$(eval export SSH_KEY ?= $(SSH_KEY)) $(call env-run,sh -c 'printf "$$SSH_KEY\n" > $(SSH_DIR)/$(COMPOSE_PROJECT_NAME)_id_rsa && chmod 0600 $(SSH_DIR)/$(COMPOSE_PROJECT_NAME)_id_rsa && chown $(UID) $(SSH_DIR)/$(COMPOSE_PROJECT_NAME)_id_rsa ||:'))
|
||||
$(if $(SSH_KEY),$(eval export SSH_KEY ?= $(SSH_KEY)) $(call env-exec,sh -c 'printf "$$SSH_KEY\n" > $(SSH_DIR)/$(COMPOSE_PROJECT_NAME)_id_rsa && chmod 0600 $(SSH_DIR)/$(COMPOSE_PROJECT_NAME)_id_rsa && chown $(UID) $(SSH_DIR)/$(COMPOSE_PROJECT_NAME)_id_rsa ||:'))
|
||||
|
||||
# target ssh-run: Call ssh-run make run SERVICE ARGS
|
||||
.PHONY: ssh-run
|
||||
|
||||
@@ -10,5 +10,5 @@ endif
|
||||
# function openstack: Call run openstack with arg 1
|
||||
define openstack
|
||||
$(call INFO,openstack,$(1))
|
||||
$(RUN) $(call run,openstack $(1),$(DOCKER_REPOSITORY)/)
|
||||
$(call run,openstack $(1),$(DOCKER_REPOSITORY)/)
|
||||
endef
|
||||
|
||||
@@ -86,12 +86,12 @@ endif
|
||||
## it needs SSH_PRIVATE_KEYS to get access without password to GIT_REPOSITORY
|
||||
## it needs AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY when deploying to AWS
|
||||
define packer
|
||||
$(RUN) $(call run,packer $(1),$(DOCKER_RUN_OPTIONS_PACKER) $(DOCKER_REPOSITORY)/)
|
||||
$(call run,packer $(1),$(DOCKER_RUN_OPTIONS_PACKER) $(DOCKER_REPOSITORY)/)
|
||||
endef
|
||||
# function packer-qemu: Call run qemu-system-% for PACKER_QEMU_ARCH
|
||||
define packer-qemu
|
||||
echo Running $(1)
|
||||
$(RUN) $(call run,$(if $(DOCKER_RUN),packer,qemu-system-$(PACKER_QEMU_ARCH)) $(PACKER_QEMU_ARGS) -m 512m -drive file=$(1)$(comma)format=raw -net nic$(comma)model=virtio -net user$(comma)hostfwd=tcp:$(PACKER_SSH_ADDRESS):$(PACKER_SSH_PORT)-:22 -vnc $(PACKER_VNC_ADDRESS):$(subst 590,,$(PACKER_VNC_PORT)),$(DOCKER_RUN_OPTIONS_PACKER) --entrypoint=qemu-system-$(PACKER_QEMU_ARCH) $(DOCKER_REPOSITORY)/)
|
||||
$(call run,$(if $(DOCKER_RUN),packer,qemu-system-$(PACKER_QEMU_ARCH)) $(PACKER_QEMU_ARGS) -m 512m -drive file=$(1)$(comma)format=raw -net nic$(comma)model=virtio -net user$(comma)hostfwd=tcp:$(PACKER_SSH_ADDRESS):$(PACKER_SSH_PORT)-:22 -vnc $(PACKER_VNC_ADDRESS):$(subst 590,,$(PACKER_VNC_PORT)),$(DOCKER_RUN_OPTIONS_PACKER) --entrypoint=qemu-system-$(PACKER_QEMU_ARCH) $(DOCKER_REPOSITORY)/)
|
||||
endef
|
||||
|
||||
# function packer-build: Call packer build with arg 1, Add build infos to file PACKER_ISO_INFO
|
||||
|
||||
Reference in New Issue
Block a user