aynic.os 1 year ago
parent 8a7a545a6c
commit c9821467de
  1. 3
      .env.dist
  2. 4
      Makefile
  3. 10
      make/apps/build.mk
  4. 6
      make/apps/clean.mk
  5. 4
      make/apps/install.mk
  6. 8
      make/apps/php/cache.mk
  7. 5
      make/apps/php/clean.mk
  8. 1
      make/apps/php/install.mk
  9. 8
      make/apps/php/test.mk
  10. 16
      make/def.mk
  11. 11
      make/env.mk
  12. 5
      make/help.mk

@ -1 +1,2 @@
APP_DOMAIN=myos.dist.localhost
APP=myos
ENV=dist

@ -1,11 +1,9 @@
APP_TYPE := infra
include make/include.mk
##
# APP
app-build: build-rm myos-base
$(call install-parameters,,*,build)
app-build: myos-base install-build-parameters
$(call make,docker-compose-build up)
$(call make,docker-compose-exec ARGS='rm -Rf /root/.npm /log-buffer/*' SERVICE=logagent)
$(call make,docker-commit)

@ -13,7 +13,7 @@ build@%: myos-base
$(eval DRYRUN_IGNORE := false)
$(eval docker_images += $(foreach service,$(SERVICES),$(if $(shell docker images -q $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) 2>/dev/null),$(service))))
$(eval build_app := $(or $(filter $(DOCKER_BUILD_CACHE),false),$(filter-out $(docker_images),$(SERVICES))))
$(if $(build_app),$(call make,app-build),$(if $(filter $(VERBOSE),true),$(foreach service,$(SERVICES),echo "docker image $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) has id $(shell docker images -q $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) 2>/dev/null)" &&) true))
$(if $(build_app),$(call make,build-init app-build),$(if $(filter $(VERBOSE),true),$(foreach service,$(SERVICES),echo "docker image $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) has id $(shell docker images -q $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) 2>/dev/null)" &&) true))
# target build-env: Build .env file in docker $(SERVICE) to deploy
.PHONY: build-env
@ -21,10 +21,10 @@ build-env: SERVICE ?= $(DOCKER_SERVICE)
build-env: bootstrap
$(call docker-compose-exec,$(SERVICE),rm -f .env && make .env ENV=$(ENV) && echo BUILD=true >> .env && echo BUILD_DATE='"\'"'$(shell date "+%d/%m/%Y %H:%M:%S %z" 2>/dev/null)'"\'"' >> .env && echo BUILD_STATUS='"\'"'$(shell git status -uno --porcelain 2>/dev/null)'"\'"' >> .env && echo DOCKER=false >> .env && $(foreach var,$(BUILD_APP_VARS),$(if $($(var)),sed -i '/^$(var)=/d' .env && echo $(var)='$($(var))' >> .env &&)) true)
# target build-rm: Empty build directory
.PHONY: build-rm
build-rm:
$(call exec,rm -rf build && mkdir -p build)
# target build-init: Empty build directory
.PHONY: build-init
build-init:
$(ECHO) rm -rf build && $(ECHO) mkdir -p build
# target build-$(SHARED): Create shared folder in docker $(SERVICE) to deploy
.PHONY: build-$(SHARED)

@ -2,13 +2,9 @@
# CLEAN
.PHONY: clean app-clean
clean: app-clean docker-compose-down clean-env ## Clean application and docker images
clean: app-clean docker-compose-down .env-clean ## Clean application and docker images
# target clean@%: Clean deployed application and docker images
.PHONY: clean@%
clean@%:
$(call make,docker-compose-down DOCKER_COMPOSE_DOWN_OPTIONS='--rmi all -v')
.PHONY: clean-env
clean-env:
rm -i .env || true

@ -17,6 +17,10 @@ install-pgsql-database-%: myos-base
$(call exec,[ $$(PGPASSWORD=$* psql -h postgres -U $* -d $* -c "\d" 2>/dev/null |wc -l) -eq 0 ] && [ -f "${APP_DIR}/$*.pgsql.gz" ] && gzip -cd "${APP_DIR}/$*.pgsql.gz" |PGPASSWORD="postgres" psql -h postgres -U postgres -d $* || true)
$(call exec,[ $$(PGPASSWORD=$* psql -h postgres -U $* -d $* -c "\d" 2>/dev/null |wc -l) -eq 0 ] && [ -f "${APP_DIR}/$*.pgsql" ] && PGPASSWORD="postgres" psql -h postgres -U postgres -c "ALTER ROLE $* WITH SUPERUSER" && PGPASSWORD="postgres" pg_restore -h postgres --no-owner --role=$* -U postgres -d $* ${APP_DIR}/$*.pgsql && PGPASSWORD="postgres" psql -h postgres -U postgres -c "ALTER ROLE $* WITH NOSUPERUSER" || true)
.PHONY: install-build-parameters
install-build-parameters:
$(call install-parameters,,*,build)
.PHONY: install-parameters
install-parameters:
$(call install-parameters)

@ -3,20 +3,14 @@
## Clear symfony cache
.PHONY: cache-clear
cache-clear: cache-clear-dev cache-clear-prod
cache-clear: cache-clear-$(SYMFONY_ENV)
.PHONY: cache-clear-%
cache-clear-%: bootstrap ## Clear symfony cache
$(call docker-compose-exec,$(DOCKER_SERVICE),app/console cache:clear --env=$*)
.PHONY: cache-rm
cache-rm: bootstrap
$(call docker-compose-exec,$(DOCKER_SERVICE),rm -Rf app/cache/* app/logs/*)
$(if $(filter $(ENV),$(ENV_DEPLOY)),$(call docker-compose-exec,$(DOCKER_SERVICE),chown www-data app/cache/ app/logs/))
.PHONY: cache-warmup
cache-warmup: cache-warmup-$(SYMFONY_ENV)
$(if $(filter $(ENV),$(ENV_DEPLOY)),$(call docker-compose-exec,$(DOCKER_SERVICE),chown -R www-data app/cache/ app/logs/))
.PHONY: cache-warmup-%
cache-warmup-%: bootstrap

@ -1,12 +1,11 @@
##
# CLEAN
.PHONY: clean-php-app
clean-php-app: bootstrap
.PHONY: app-symfony-clean
app-symfony-clean: bootstrap
$(call docker-compose-exec,$(DOCKER_SERVICE),rm -rf app/bootstrap.php.cache)
$(call docker-compose-exec,$(DOCKER_SERVICE),rm -rf app/cache/* app/cach~)
$(call docker-compose-exec,$(DOCKER_SERVICE),rm -rf app/logs/*)
$(call docker-compose-exec,$(DOCKER_SERVICE),rm -rf var/cache/* var/cach~)
$(call docker-compose-exec,$(DOCKER_SERVICE),rm -rf var/logs/*)
$(call docker-compose-exec,$(DOCKER_SERVICE),rm -rf vendor/*)
$(call docker-compose-exec,$(DOCKER_SERVICE),rm -rf node_modules/*)

@ -8,7 +8,6 @@ install-assets: install-assets-$(SYMFONY_ENV)
install-assets-%: bootstrap
$(call docker-compose-exec,$(DOCKER_SERVICE),app/console assetic:dump --env=$*)
$(call docker-compose-exec,$(DOCKER_SERVICE),app/console assets:install --env=$*)
$(if $(filter $(ENV),$(ENV_DEPLOY)),$(call docker-compose-exec,$(DOCKER_SERVICE),chown -R www-data web/bundles/ web/css/ web/js/))
.PHONY: install-codecept
install-codecept: bootstrap install-phpunit vendor/codeception/codeception/codecept

@ -25,14 +25,6 @@ test-coverage-codeception-%: bootstrap install-codecept ## Run codeception tests
test-func: bootstrap install-phpunit ## Run functional tests
$(call docker-compose-exec,$(DOCKER_SERVICE),bin/phpunit --testsuite functional)
## Loop unit tests
.PHONY: test-loop
test-loop: bootstrap install-phpunit ## Loop unit tests
while true; \
do $(MAKE) test; \
read continue; \
done;
## Run search tests
.PHONY: test-search
test-search: bootstrap install-phpunit ## Run search tests

@ -4,13 +4,13 @@ dquote ?= "
quote ?= '
APP ?= $(if $(wildcard .git),$(notdir $(CURDIR)))
APP_DIR ?= $(if $(APP),$(CURDIR))
APP_DOMAIN ?= $(if ${DOMAIN},${ENV}.${DOMAIN},${ENV})
APP_HOST ?= $(if ${APP_DOMAIN},${APP}.${APP_DOMAIN},${APP})
APP_NAME ?= ${APP}
APP_PATH ?= /${APP_PATH_PREFIX}
APP_DOMAIN ?= $(if $(APP),$(ENV)$(addprefix .,$(DOMAIN)))
APP_HOST ?= $(if $(APP),$(APP)$(addprefix .,$(APP_DOMAIN)))
APP_NAME ?= $(APP)
APP_PATH ?= /$(APP_PATH_PREFIX)
APP_SCHEME ?= https
APP_URI ?= ${APP_HOST}${APP_PATH}
APP_URL ?= ${APP_SCHEME}://${APP_URI}
APP_URI ?= $(if $(APP),$(APP_HOST)$(APP_PATH))
APP_URL ?= $(if $(APP),$(APP_SCHEME)://$(APP_URI))
APPS ?= $(if $(MONOREPO),$(sort $(patsubst $(MONOREPO_DIR)/%/.git,%,$(wildcard $(MONOREPO_DIR)/*/.git))))
APPS_NAME ?= $(foreach app,$(APPS),$(or $(shell awk -F '=' '$$1 == "APP" {print $$2}' $(or $(wildcard $(MONOREPO_DIR)/$(app)/.env),$(wildcard $(MONOREPO_DIR)/$(app)/.env.$(ENV)),$(MONOREPO_DIR)/$(app)/.env.dist) 2>/dev/null),$(app)))
BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
@ -40,8 +40,10 @@ HOSTNAME ?= $(shell hostname 2>/dev/null |sed 's/\..*//')
MAKE_ARGS ?= $(foreach var,$(MAKE_VARS),$(if $($(var)),$(var)='$($(var))'))
MAKE_VARS ?= ENV
MAKE_SUBDIRS ?= $(if $(filter myos,$(MYOS)),monorepo,$(if $(SUBREPO),subrepo )$(if $(APP),apps $(foreach type,$(APP_TYPE),$(if $(wildcard $(MAKE_DIR)/apps/$(type)),apps/$(type)))))
MAKECMDVARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter command\ line,$(origin $(var))),$(var))))
MAKECMDARGS ?= $(foreach var,$(MAKECMDVARS),$(var)='$($(var))')
MAKECMDVARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter command\ line,$(origin $(var))),$(var))))
MAKEENVVARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter environment,$(origin $(var))),$(var))))
MAKEFILEVARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter file,$(origin $(var))),$(var))))
MAKETARGETS ?= $(filter-out $(.VARIABLES),$(shell $(MAKE) -qp 2>/dev/null |awk -F':' '/^[a-zA-Z0-9][^$$\#\/\t=]*:([^=]|$$)/ {print $$1}' |sort -u))
MONOREPO ?= $(if $(filter myos,$(MYOS)),$(notdir $(CURDIR)),$(if $(APP),$(notdir $(realpath $(CURDIR)/..))))
MONOREPO_DIR ?= $(if $(MONOREPO),$(if $(filter myos,$(MYOS)),$(realpath $(CURDIR)),$(if $(APP),$(realpath $(CURDIR)/..))))

@ -4,6 +4,10 @@
.env: .env.dist
$(call .env,,,$(wildcard ../$(PARAMETERS)/$(ENV)/$(APP)/.env .env.$(ENV)))
.PHONY: .env-clean
.env-clean:
rm -f .env || true
# include .env file
-include .env
@ -55,13 +59,14 @@ endef
# keep variables that exists in .env.dist
# keep variables that does not exist in .env
# read variables definition in a subshell with multiline support
# create a new environment (empty if $(ENV_RESET) is true)
# create a new environment (empty if $(ENV_RESET) is true) with
# $(env.args)
# read environment variables and keep only those existing in .env.dist
# add .env overrides variables definition
# add .env.dist variables definition
# remove empty lines or comments
# remove duplicate variables
# replace variabless in stdin with their value from the new environment
# replace variables in stdin with their value from the new environment
# remove residual empty lines or comments
# sort alphabetically
# add variables definition to the .env file
@ -75,7 +80,7 @@ define .env_update
|awk -F '=' 'ARGV[1] == FILENAME { A[$$1]; next } ($$1 in A)' $(env_dist) - 2>/dev/null \
|awk -F '=' 'ARGV[1] == FILENAME { A[$$1]; next } !($$1 in A)' $(env_file) - 2>/dev/null \
|(IFS=$$'\n'; \
env $(env_reset) \
env $(env_reset) $(env.args) \
$$(env |awk -F '=' 'NR == FNR { if($$1 !~ /^(#|$$)/) { A[$$1]; next } } ($$1 in A)' $(env_dist) - \
|cat - $(env_over) \
|cat - $(env_dist) \

@ -33,4 +33,7 @@ context:
.PHONY: context--%
context-%:
printf "${COLOR_BLUE}%-31s${COLOR_RESET} ${COLOR_GREEN}%s${COLOR_RESET}\n" $* "$($*)"
printf "${COLOR_BLUE}%-31s${COLOR_RESET}" $*
printf "${COLOR_GREEN}"
$(call PRINTF,$($*))
printf "${COLOR_RESET}"

Loading…
Cancel
Save