auto install app
This commit is contained in:
@@ -77,6 +77,7 @@ define compose-file
|
||||
$(eval suffix := $(or $(3),$(COMPOSE_FILE_SUFFIX)))
|
||||
$(eval extension := $(or $(4),yml yaml))
|
||||
$(eval COMPOSE_FILE += $(wildcard $(foreach e,$(extension),$(foreach n,$(name),$(foreach p,$(path),$(p)/$(n).$(e) $(p)/$(n).$(ENV).$(e) $(p)/$(ENV)/$(n).$(e) $(p)/$(ENV)/$(n).$(ENV).$(e) $(foreach s,$(suffix),$(p)/$(n).$(s).$(e) $(p)/$(n).$(s).$(ENV).$(e)))))))
|
||||
$(call debug,COMPOSE_FILE)
|
||||
endef
|
||||
# function docker-build: Build docker image
|
||||
define docker-build
|
||||
|
||||
@@ -22,7 +22,6 @@ APP_SCHEME ?= http
|
||||
APP_UPSTREAM_REPOSITORY ?= $(or $(shell git config --get remote.upstream.url 2>/dev/null),$(GIT_UPSTREAM_REPOSITORY))
|
||||
APP_URI ?= $(patsubst %,%/$(APP_PATH),$(APP_HOST))
|
||||
APP_URL ?= $(patsubst %,$(APP_SCHEME)://%,$(APP_URI))
|
||||
APP_VERSION ?= $(VERSION)
|
||||
CONTEXT += APP APPS BRANCH DOMAIN VERSION RELEASE
|
||||
CONTEXT_DEBUG += APP_DIR APP_URL APP_REPOSITORY APP_UPSTREAM_REPOSITORY ENV_DEPLOY
|
||||
ENV_DEPLOY ?= $(patsubst origin/%,%,$(shell git rev-parse --symbolic --remotes=origin 2>/dev/null |sed '/origin\/HEAD/d'))
|
||||
|
||||
+11
-7
@@ -4,7 +4,9 @@
|
||||
# target $(APP): Call app-update
|
||||
.PHONY: $(APP)
|
||||
$(APP): APP_DIR := $(RELATIVE)$(APP)
|
||||
$(APP): myos-user
|
||||
$(APP) $(APP_DIR):
|
||||
echo APP: $(APP)
|
||||
echo APP_DIR: $(APP_DIR)
|
||||
$(call app-update)
|
||||
|
||||
# target app-%: Call app-$(command) for APP in APP_DIR
|
||||
@@ -13,12 +15,14 @@ $(APP): myos-user
|
||||
## it includes apps/$(app)/*.mk file and hydrates APP_* variables
|
||||
## ex: APP_REPOSITORY_URL is set with value from variable $(APP)_REPOSITORY_URL
|
||||
.PHONY: app-%
|
||||
app-%:
|
||||
app-%: APP_DIR := $(RELATIVE)$(APP)
|
||||
app-%: $(APP_DIR)
|
||||
$(eval APP_REPOSITORY_URL :=)
|
||||
$(eval COMPOSE_FILE :=)
|
||||
$(eval STACK :=)
|
||||
$(eval app := $(subst -$(lastword $(subst -, ,$*)),,$*))
|
||||
$(eval command := $(lastword $(subst -, ,$*)))
|
||||
$(eval include $(wildcard apps/def.mk apps/$(app).mk apps/$(app)/*.mk))
|
||||
$(eval include $(wildcard $(foreach stack_dir,$(STACK_DIR),$(stack_dir)/$(app).mk $(stack_dir)/$(app)/*.mk)))
|
||||
$(foreach var,$(filter $(call UPPERCASE,$(app))_%,$(MAKE_FILE_VARS)), \
|
||||
$(if $(filter $(subst $(call UPPERCASE,$(app))_,APP_,$(var)),$(MAKE_FILE_VARS)), \
|
||||
$(eval $(subst $(call UPPERCASE,$(app))_,APP_,$(var)) := $($(var))) \
|
||||
@@ -36,7 +40,7 @@ app-%:
|
||||
) \
|
||||
) \
|
||||
, \
|
||||
$(if $($(call UPPERCASE,$(APP))_REPOSITORY_URL), \
|
||||
$(if $(APP_REPOSITORY_URL), \
|
||||
$(call app-install) \
|
||||
$(call app-bootstrap) \
|
||||
,$(call WARNING,Unable to find app,$(app),in dir,$(RELATIVE)$(app)) \
|
||||
@@ -110,17 +114,17 @@ endif
|
||||
|
||||
# target update-remote-%: fetch git remote %
|
||||
.PHONY: update-remote-%
|
||||
update-remote-%: myos-user
|
||||
update-remote-%:
|
||||
$(RUN) git fetch --prune --tags $*
|
||||
|
||||
# target update-remotes: fetch all git remotes
|
||||
.PHONY: update-remotes
|
||||
update-remotes: myos-user
|
||||
update-remotes:
|
||||
$(RUN) git fetch --all --prune --tags
|
||||
|
||||
# target update-upstream: fetch git remote upstream
|
||||
.PHONY: update-upstream
|
||||
update-upstream: myos-user .git/refs/remotes/upstream/master
|
||||
update-upstream: .git/refs/remotes/upstream/master
|
||||
$(RUN) git fetch --prune --tags upstream
|
||||
|
||||
# target .git/refs/remotes/upstream/master: add git upstream APP_UPSTREAM_REPOSITORY
|
||||
|
||||
+2
-3
@@ -23,10 +23,9 @@ define app-bootstrap
|
||||
$(eval COMPOSE_SERVICE_NAME := $(or $(DOCKER_COMPOSE_SERVICE_NAME),$(subst _,-,$(COMPOSE_PROJECT_NAME))))
|
||||
$(eval DOCKER_BUILD_DIR := $(APP_DIR))
|
||||
$(call compose-file,$(APP_DIR) $(APP_DIR)/$(or $(APP_DOCKER_DIR),$(DOCKER_DIR)),docker-compose)
|
||||
$(call compose-file,apps apps/$(APP),$(APP))
|
||||
$(eval APP_COMPOSE_FILE ?= $(COMPOSE_FILE))
|
||||
$(foreach stackz,$(or $(DOCKER_STACK),$(STACK)),$(call docker-stack,$(stackz)))
|
||||
$(call compose-file,$(MYOS_STACK),$(MYOS_STACK_FILE))
|
||||
$(eval APP_COMPOSE_FILE ?= $(COMPOSE_FILE))
|
||||
$(call docker-stack,$(APP))
|
||||
$(call .env,$(APP_DIR)/.env,$(APP_DIR)/.env.dist $(APP_DIR)/.env.example $(APP_DIR)/.env.sample)
|
||||
endef
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ MYOS_STACK ?= $(foreach stack_dir,$(STACK_DIR),$(MYOS)/$(st
|
||||
MYOS_STACK_FILE ?= networks volumes
|
||||
RESU_DOCKER_REPOSITORY ?= $(subst -,/,$(USER_COMPOSE_PROJECT_NAME))
|
||||
STACK ?= $(APP)
|
||||
STACK_DIR ?= ../stack
|
||||
STACK_DIR ?= ../mystack
|
||||
USER_COMPOSE_PROJECT_NAME ?= $(subst .,-,$(RESU))
|
||||
USER_COMPOSE_SERVICE_NAME ?= $(USER_COMPOSE_PROJECT_NAME)
|
||||
USER_DOCKER_IMAGE ?= $(USER_DOCKER_REPOSITORY):${DOCKER_IMAGE_TAG}
|
||||
|
||||
@@ -20,6 +20,7 @@ CMD_APT_REMOVE ?= $(if $(shell type -p apt-get),apt-get -fy rem
|
||||
COLOR_BLUE ?= \033[01;34m
|
||||
COLOR_BROWN ?= \033[33m
|
||||
COLOR_CYAN ?= \033[36m
|
||||
COLOR_DEBUG ?= $(COLOR_BLUE)
|
||||
COLOR_DGRAY ?= \033[30m
|
||||
COLOR_ERROR ?= $(COLOR_RED)
|
||||
COLOR_GRAY ?= \033[37m
|
||||
@@ -146,6 +147,14 @@ endif
|
||||
# include .env files
|
||||
include $(wildcard $(ENV_FILE))
|
||||
|
||||
DEBUG_FD := 2
|
||||
# macro debug: print variable content when DEBUG
|
||||
debug = $(if $(DEBUG), \
|
||||
printf '${COLOR_INFO}$(APP)${COLOR_RESET}[${COLOR_VALUE}$(MAKELEVEL)${COLOR_RESET}]$(if $@, ${COLOR_VALUE}$@${COLOR_RESET}):${COLOR_RESET} ' >&$(DEBUG_FD) \
|
||||
$(foreach variable,$(1),&& printf '${COLOR_DEBUG}$(variable):${COLOR_RESET} ${COLOR_VALUE}$($(variable))${COLOR_RESET}, ' >&$(DEBUG_FD)) \
|
||||
&& printf '\n' >&$(DEBUG_FD) \
|
||||
)
|
||||
|
||||
ERROR_FD := 2
|
||||
# macro ERROR: print colorized warning
|
||||
ERROR = \
|
||||
|
||||
Reference in New Issue
Block a user