This commit is contained in:
aynic.os 2021-06-06 16:29:54 +02:00
parent 85ffdb7096
commit 3a9ddae015
26 changed files with 183 additions and 158 deletions

View File

@ -3,27 +3,13 @@ include make/include.mk
## ##
# APP # APP
.PHONY: app-bootstrap app-bootstrap: setup-sysctl setup-nfsd
app-bootstrap: setup-sysctl
ifeq ($(SETUP_NFSD),true)
ifeq ($(HOST_SYSTEM),DARWIN)
$(call setup-nfsd-osx)
endif
endif
.PHONY: app-build app-build: base install-build-parameters
app-build: myos-base install-build-parameters $(call make,docker-compose-build docker-compose-up)
$(call make,docker-compose-build up) $(foreach service,$(or $(SERVICE),$(SERVICES)),$(call make,app-build-$(service)))
$(call make,docker-compose-exec ARGS='rm -Rf /root/.npm /log-buffer/*' SERVICE=logagent)
$(call make,docker-commit) $(call make,docker-commit)
.PHONY: app-install app-install: base node
app-install: base node up
.PHONY: app-start
app-start: base-ssh-add app-start: base-ssh-add
.PHONY: app-tests
app-tests:
echo ENV: $(env)
echo DOCKER_ENV: $(DOCKER_ENV)

View File

@ -1,3 +1,4 @@
# target ansible: Fire docker-build-ansible, Call ansible ANSIBLE_ARGS ARGS or ansible-run target
.PHONY: ansible .PHONY: ansible
ansible: docker-build-ansible ansible: docker-build-ansible
ifneq ($(ARGS),) ifneq ($(ARGS),)
@ -6,21 +7,26 @@ else
$(call make,ansible-run) $(call make,ansible-run)
endif endif
# target ansible-playbook: Call ansible-playbook ANSIBLE_ARGS ARGS
.PHONY: ansible-playbook .PHONY: ansible-playbook
ansible-playbook: ansible-playbook:
$(call ansible-playbook,$(ANSIBLE_ARGS) $(ARGS)) $(call ansible-playbook,$(ANSIBLE_ARGS) $(ARGS))
# target ansible-pull: Call ansible-pull ANSIBLE_GIT_REPOSITORY ANSIBLE_PLAYBOOK
.PHONY: ansible-pull .PHONY: ansible-pull
ansible-pull: ansible-pull:
$(call ansible-pull,--url $(ANSIBLE_GIT_REPOSITORY) $(if $(ANSIBLE_GIT_KEY_FILE),--key-file $(ANSIBLE_GIT_KEY_FILE)) $(if $(ANSIBLE_GIT_VERSION),--checkout $(ANSIBLE_GIT_VERSION)) $(if $(ANSIBLE_GIT_DIRECTORY),--directory $(ANSIBLE_GIT_DIRECTORY)) $(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) $(if $(ANSIBLE_EXTRA_VARS),--extra-vars '$(ANSIBLE_EXTRA_VARS)') $(if $(findstring true,$(FORCE)),--force) $(if $(findstring true,$(DRYRUN)),--check) --full $(if $(ANSIBLE_INVENTORY),--inventory $(ANSIBLE_INVENTORY)) $(ANSIBLE_PLAYBOOK)) $(call ansible-pull,--url $(ANSIBLE_GIT_REPOSITORY) $(if $(ANSIBLE_GIT_KEY_FILE),--key-file $(ANSIBLE_GIT_KEY_FILE)) $(if $(ANSIBLE_GIT_VERSION),--checkout $(ANSIBLE_GIT_VERSION)) $(if $(ANSIBLE_GIT_DIRECTORY),--directory $(ANSIBLE_GIT_DIRECTORY)) $(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) $(if $(ANSIBLE_EXTRA_VARS),--extra-vars '$(ANSIBLE_EXTRA_VARS)') $(if $(findstring true,$(FORCE)),--force) $(if $(findstring true,$(DRYRUN)),--check) --full $(if $(ANSIBLE_INVENTORY),--inventory $(ANSIBLE_INVENTORY)) $(ANSIBLE_PLAYBOOK))
# target ansible-pull@%: Fire get-PrivateIpAddress-% for SERVER_NAME, Call ssh-exec make ansible-pull DOCKER_IMAGE_TAG
.PHONY: ansible-pull@% .PHONY: ansible-pull@%
ansible-pull@%: aws-ec2-get-PrivateIpAddress-$(SERVER_NAME) ansible-pull@%: get-PrivateIpAddress-$(SERVER_NAME)
$(call ssh-exec,$(AWS_INSTANCE_IP),make ansible-pull ANSIBLE_DOCKER_IMAGE_TAG=$(ANSIBLE_DOCKER_IMAGE_TAG) ANSIBLE_TAGS=$(ANSIBLE_TAGS) FORCE=$(FORCE)) $(call ssh-exec,$(AWS_INSTANCE_IP),make ansible-pull ANSIBLE_DOCKER_IMAGE_TAG=$(ANSIBLE_DOCKER_IMAGE_TAG) ANSIBLE_TAGS=$(ANSIBLE_TAGS) FORCE=$(FORCE))
# target ansible-run: Fire base-ssh-add docker-build-ansible ansible-run-localhost
.PHONY: ansible-run .PHONY: ansible-run
ansible-run: base-ssh-add docker-build-ansible ansible-run-localhost ansible-run: base-ssh-add docker-build-ansible ansible-run-localhost
# target ansible-run-%: Call ansible-playbook ANSIBLE_PLAYBOOK
.PHONY: ansible-run-% .PHONY: ansible-run-%
ansible-run-%: ansible-run-%:
$(call ansible-playbook,$(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) $(if $(ANSIBLE_EXTRA_VARS),--extra-vars '$(patsubst target=localhost,target=$*,$(ANSIBLE_EXTRA_VARS))') $(if $(findstring true,$(DRYRUN)),--check) $(if $(ANSIBLE_INVENTORY),--inventory $(ANSIBLE_INVENTORY)) $(ANSIBLE_PLAYBOOK)) $(call ansible-playbook,$(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) $(if $(ANSIBLE_EXTRA_VARS),--extra-vars '$(patsubst target=localhost,target=$*,$(ANSIBLE_EXTRA_VARS))') $(if $(findstring true,$(DRYRUN)),--check) $(if $(ANSIBLE_INVENTORY),--inventory $(ANSIBLE_INVENTORY)) $(ANSIBLE_PLAYBOOK))

View File

@ -38,12 +38,15 @@ define ansible-pull
IFS=$$'\n'; $(ECHO) env $(foreach var,$(ENV_VARS),$(if $($(var)),$(var)='$($(var))')) $(shell printenv |awk -F '=' 'NR == FNR { if($$1 !~ /^(\#|$$)/) { A[$$1]; next } } ($$1 in A)' .env.dist - 2>/dev/null) $$(cat $(ENV_FILE) 2>/dev/null |awk -F "=" '$$1 ~! /^\(#|$$\)/') ansible-pull $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1) IFS=$$'\n'; $(ECHO) env $(foreach var,$(ENV_VARS),$(if $($(var)),$(var)='$($(var))')) $(shell printenv |awk -F '=' 'NR == FNR { if($$1 !~ /^(\#|$$)/) { A[$$1]; next } } ($$1 in A)' .env.dist - 2>/dev/null) $$(cat $(ENV_FILE) 2>/dev/null |awk -F "=" '$$1 ~! /^\(#|$$\)/') ansible-pull $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1)
endef endef
else else
# function ansible: Call run ansible ANSIBLE_ARGS with arg 1
define ansible define ansible
$(call run,ansible $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1)) $(call run,ansible $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1))
endef endef
# function ansible-playbook: Call run ansible-playbook ANSIBLE_ARGS with arg 1
define ansible-playbook define ansible-playbook
$(call run,ansible-playbook $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1)) $(call run,ansible-playbook $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1))
endef endef
# function ansible-pull: Call run ansible-pull ANSIBLE_ARGS with arg 1
define ansible-pull define ansible-pull
$(call run,ansible-pull $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1)) $(call run,ansible-pull $(ANSIBLE_ARGS) $(ANSIBLE_VERBOSE) $(1))
endef endef

View File

@ -1,9 +1,11 @@
# target aws: Fire docker-build-aws, Call aws ARGS
.PHONY: aws .PHONY: aws
aws: docker-build-aws aws: docker-build-aws
$(call aws,$(ARGS)) $(call aws,$(ARGS))
.PHONY: aws-codedeploy # target aws-deploy: Call aws deploy create-deployment with application-name CODEDEPLOY_APP_NAME
aws-codedeploy: .PHONY: aws-deploy
aws-deploy:
$(call aws,deploy create-deployment \ $(call aws,deploy create-deployment \
--application-name $(CODEDEPLOY_APP_NAME) \ --application-name $(CODEDEPLOY_APP_NAME) \
--deployment-config-name $(CODEDEPLOY_DEPLOYMENT_CONFIG) \ --deployment-config-name $(CODEDEPLOY_DEPLOYMENT_CONFIG) \
@ -11,16 +13,19 @@ aws-codedeploy:
--description "$(CODEDEPLOY_DESCRIPTION)" \ --description "$(CODEDEPLOY_DESCRIPTION)" \
--github-location repository=$(CODEDEPLOY_GITHUB_REPO)$(comma)commitId=$(CODEDEPLOY_GITHUB_COMMIT_ID)) --github-location repository=$(CODEDEPLOY_GITHUB_REPO)$(comma)commitId=$(CODEDEPLOY_GITHUB_COMMIT_ID))
.PHONY: aws-role-create-import-image # target aws-docker-login: Fire aws-ecr-get-login
aws-role-create-import-image: aws-iam-create-role-$(AWS_VM_IMPORT_ROLE_NAME) aws-iam-put-role-policy-$(AWS_VM_IMPORT_ROLE_NAME) .PHONY: aws-docker-login
aws-docker-login: aws-ecr-get-login
.PHONY: aws-ecr-login # target aws-ecr-get-login: Exec 'Call aws ecr get-login'
aws-ecr-login: .PHONY: aws-ecr-get-login
aws-ecr-get-login:
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval docker_login := $(shell $(call aws,ecr get-login --no-include-email --region $(AWS_DEFAULT_REGION)))) $(eval docker_login := $(shell $(call aws,ecr get-login --no-include-email --region $(AWS_DEFAULT_REGION))))
$(eval DRYRUN_IGNORE := FALSE) $(eval DRYRUN_IGNORE := FALSE)
$(ECHO) $(docker_login) $(ECHO) $(docker_login)
# target aws-iam-create-role-%: Call aws iam create-role with role-name % and role-policy file aws/policies/%-trust.json
.PHONY: aws-iam-create-role-% .PHONY: aws-iam-create-role-%
aws-iam-create-role-%: base docker-build-aws aws-iam-create-role-%: base docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
@ -28,6 +33,7 @@ aws-iam-create-role-%: base docker-build-aws
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
$(call aws,iam create-role --role-name $* --assume-role-policy-document '$(json)') $(call aws,iam create-role --role-name $* --assume-role-policy-document '$(json)')
# target aws-iam-put-role-policy-%: Call aws iam put-role-policy with policy-name % and policy-document file aws/policies/%.json
.PHONY: aws-iam-put-role-policy-% .PHONY: aws-iam-put-role-policy-%
aws-iam-put-role-policy-%: base docker-build-aws aws-iam-put-role-policy-%: base docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
@ -35,116 +41,140 @@ aws-iam-put-role-policy-%: base docker-build-aws
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
$(call aws,iam put-role-policy --role-name $* --policy-name $* --policy-document '$(json)') $(call aws,iam put-role-policy --role-name $* --policy-name $* --policy-document '$(json)')
# target aws-role-create-import-image: Fire aws-iam-create-role-% aws-iam-put-role-policy-% for AWS_VM_IMPORT_ROLE_NAME
.PHONY: aws-role-create-import-image
aws-role-create-import-image: aws-iam-create-role-$(AWS_VM_IMPORT_ROLE_NAME) aws-iam-put-role-policy-$(AWS_VM_IMPORT_ROLE_NAME)
# target aws-s3-check-upload: Fire aws-s3api-get-head-object-etag, Eval upload=false if remote s3 file already exists
.PHONY: aws-s3-check-upload .PHONY: aws-s3-check-upload
aws-s3-check-upload: docker-build-aws aws-s3api-head-object-query-etag aws-s3-check-upload: docker-build-aws aws-s3api-get-head-object-etag
$(eval upload := true) $(eval upload := true)
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(if $(AWS_S3_KEY_ETAG),$(if $(filter $(AWS_S3_KEY_ETAG),"$(shell cat $(PACKER_ISO_INFO) |awk '$$1 == "etag:" {print $$2}' 2>/dev/null)"),$(eval upload := false))) $(if $(AWS_S3_KEY_ETAG),$(if $(filter $(AWS_S3_KEY_ETAG),"$(shell cat $(PACKER_ISO_INFO) |awk '$$1 == "etag:" {print $$2}' 2>/dev/null)"),$(eval upload := false)))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
# target aws-s3-cp: Fire aws-s3-check-upload, Call aws s3 cp PACKER_ISO_FILE s3://AWS_S3_BUCKET/AWS_S3_KEY, Call aws-s3-etag-save target
.PHONY: aws-s3-cp .PHONY: aws-s3-cp
aws-s3-cp: docker-build-aws $(PACKER_ISO_FILE) aws-s3-check-upload aws-s3-cp: docker-build-aws $(PACKER_ISO_FILE) aws-s3-check-upload
$(if $(filter $(upload),true),$(call aws,s3 cp $(PACKER_ISO_FILE) s3://$(AWS_S3_BUCKET)/$(AWS_S3_KEY)) $(call make,aws-s3-etag-save)) $(if $(filter $(upload),true),$(call aws,s3 cp $(PACKER_ISO_FILE) s3://$(AWS_S3_BUCKET)/$(AWS_S3_KEY)) $(call make,aws-s3-etag-save))
# target aws-s3-etag-save: Fire aws-s3api-get-head-object-etag, Add line 'etag: AWS_S3_KEY_TAG' to file PACKER_ISO_INFO
.PHONY: aws-s3-etag-save .PHONY: aws-s3-etag-save
aws-s3-etag-save: docker-build-aws aws-s3api-head-object-query-etag aws-s3-etag-save: docker-build-aws aws-s3api-get-head-object-etag
echo "etag: $(AWS_S3_KEY_ETAG)" >> $(PACKER_ISO_INFO) echo "etag: $(AWS_S3_KEY_ETAG)" >> $(PACKER_ISO_INFO)
.PHONY: aws-s3api-head-object-query-etag # target aws-s3api-get-head-object-etag: Eval AWS_S3_KEY_ETAG, Echo 'ETag: AWS_S3_KEY_ETAG'
aws-s3api-head-object-query-etag: docker-build-aws .PHONY: aws-s3api-get-head-object-etag
aws-s3api-get-head-object-etag: docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_S3_KEY_ETAG := $(shell $(call aws,s3api head-object --bucket $(AWS_S3_BUCKET) --key $(AWS_S3_KEY) --output text --query ETag) |grep -v 'operation: Not Found' 2>/dev/null)) $(eval AWS_S3_KEY_ETAG := $(shell $(call aws,s3api head-object --bucket $(AWS_S3_BUCKET) --key $(AWS_S3_KEY) --output text --query ETag) |grep -v 'operation: Not Found' 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo ETag: $(AWS_S3_KEY_ETAG) echo ETag: $(AWS_S3_KEY_ETAG)
.PHONY: aws-s3api-head-object-query-lastmodified # target aws-s3api-get-head-object-lastmodified: Eval AWS_S3_KEY_DATE, Echo 'LastModified: AWS_S3_KEY_DATE'
aws-s3api-head-object-query-lastmodified: docker-build-aws .PHONY: aws-s3api-get-head-object-lastmodified
aws-s3api-get-head-object-lastmodified: docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_S3_KEY_DATE := $(shell $(call aws,s3api head-object --bucket $(AWS_S3_BUCKET) --key $(AWS_S3_KEY) --output text --query LastModified) |grep -v 'operation: Not Found' 2>/dev/null)) $(eval AWS_S3_KEY_DATE := $(shell $(call aws,s3api head-object --bucket $(AWS_S3_BUCKET) --key $(AWS_S3_KEY) --output text --query LastModified) |grep -v 'operation: Not Found' 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo LastModified: $(AWS_S3_KEY_DATE) echo LastModified: $(AWS_S3_KEY_DATE)
# target aws-ec2-import-snapshot: Call aws ec2 import-snapshot with S3Bucket AWS_S3_BUCKET and S3Key AWS_S3_KEY
.PHONY: aws-ec2-import-snapshot .PHONY: aws-ec2-import-snapshot
aws-ec2-import-snapshot: base docker-build-aws aws-s3api-head-object-query-etag aws-s3api-head-object-query-lastmodified aws-ec2-import-snapshot: base docker-build-aws aws-s3api-get-head-object-etag aws-s3api-get-head-object-lastmodified
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval json := $(shell $(call exec,envsubst < aws/import-snapshot.json))) $(eval json := $(shell $(call exec,envsubst < aws/import-snapshot.json)))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
$(eval AWS_TASK_ID := $(shell $(call aws,ec2 import-snapshot --description '$(AWS_SNAP_DESCRIPTION)' --output text --query ImportTaskId --disk-container '$(json)'))) $(eval AWS_TASK_ID := $(shell $(call aws,ec2 import-snapshot --description '$(AWS_SNAP_DESCRIPTION)' --output text --query ImportTaskId --disk-container '$(json)')))
echo ImportTaskId: $(AWS_TASK_ID) echo ImportTaskId: $(AWS_TASK_ID)
.PHONY: aws-ec2-describe-import-snapshot-task-% # target aws-ec2-describe-import-snapshot-tasks-%: Call aws ec2 describe-import-snapshot-tasks with import-task-id %
aws-ec2-describe-import-snapshot-task-%: docker-build-aws .PHONY: aws-ec2-describe-import-snapshot-tasks-%
aws-ec2-describe-import-snapshot-tasks-%: docker-build-aws
$(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $*) $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $*)
# target aws-ec2-describe-import-snapshot-tasks: Call aws ec2 describe-import-snapshots-tasks
.PHONY: aws-ec2-describe-import-snapshot-tasks .PHONY: aws-ec2-describe-import-snapshot-tasks
aws-ec2-describe-import-snapshot-tasks: docker-build-aws aws-ec2-describe-import-snapshot-tasks: docker-build-aws
$(call aws,ec2 describe-import-snapshot-tasks) $(call aws,ec2 describe-import-snapshot-tasks)
.PHONY: aws-ec2-describe-instance-PrivateIpAddress # target aws-ec2-describe-instances-PrivateIpAddress: Call aws ec2 describe-instances, Print list of PrivateIpAddress
aws-ec2-describe-instance-PrivateIpAddress: docker-build-aws .PHONY: aws-ec2-describe-instances-PrivateIpAddress
aws-ec2-describe-instances-PrivateIpAddress: docker-build-aws
$(call aws,ec2 describe-instances --no-paginate --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value$(comma)PrivateIpAddress]' --output text) |sed '$$!N;s/\r\n/ /' |awk 'BEGIN {printf "%-24s%s\r\n"$(comma)"PrivateIpAddress"$(comma)"Name"}; $$1 != "None" {printf "%-24s%s\n"$(comma)$$1$(comma)$$2}' $(call aws,ec2 describe-instances --no-paginate --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value$(comma)PrivateIpAddress]' --output text) |sed '$$!N;s/\r\n/ /' |awk 'BEGIN {printf "%-24s%s\r\n"$(comma)"PrivateIpAddress"$(comma)"Name"}; $$1 != "None" {printf "%-24s%s\n"$(comma)$$1$(comma)$$2}'
.PHONY: aws-ec2-describe-instance-PrivateIpAddress-% # target aws-ec2-describe-instances-PrivateIpAddress-%: Call aws ec2 describe-instances, Print list of PrivateIpAddress for Name matching %
aws-ec2-describe-instance-PrivateIpAddress-%: docker-build-aws .PHONY: aws-ec2-describe-instances-PrivateIpAddress-%
aws-ec2-describe-instances-PrivateIpAddress-%: docker-build-aws
$(call aws,ec2 describe-instances --no-paginate --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value$(comma)PrivateIpAddress]' --output text) |sed '$$!N;s/\r\n/ /' |awk 'BEGIN {printf "%-24s%s\r\n"$(comma)"PrivateIpAddress"$(comma)"Name"}; $$1 != "None" && $$2 ~ /$*/ {printf "%-24s%s\n"$(comma)$$1$(comma)$$2}' $(call aws,ec2 describe-instances --no-paginate --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value$(comma)PrivateIpAddress]' --output text) |sed '$$!N;s/\r\n/ /' |awk 'BEGIN {printf "%-24s%s\r\n"$(comma)"PrivateIpAddress"$(comma)"Name"}; $$1 != "None" && $$2 ~ /$*/ {printf "%-24s%s\n"$(comma)$$1$(comma)$$2}'
.PHONY: aws-ec2-get-PrivateIpAddress # target aws-ec2-get-instances-PrivateIpAddress: Eval AWS_INSTANCE_IP, Echo 'PrivateIpAddress: AWS_INSTANCE_IP'
aws-ec2-get-PrivateIpAddress: docker-build-aws .PHONY: aws-ec2-get-instances-PrivateIpAddress
aws-ec2-get-instances-PrivateIpAddress: docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_INSTANCE_IP := $(shell $(call aws,ec2 describe-instances --no-paginate --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text) 2>/dev/null)) $(eval AWS_INSTANCE_IP := $(shell $(call aws,ec2 describe-instances --no-paginate --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text) 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo PrivateIpAddress: $(AWS_INSTANCE_IP) echo PrivateIpAddress: $(AWS_INSTANCE_IP)
.PHONY: aws-ec2-get-PrivateIpAddress-% # target aws-ec2-get-instances-PrivateIpAddress-%: Eval AWS_INSTANCE_IP with Name matching %, Echo 'PrivateIpAddress: AWS_INSTANCE_IP'
aws-ec2-get-PrivateIpAddress-%: .PHONY: aws-ec2-get-instances-PrivateIpAddress-%
aws-ec2-get-instances-PrivateIpAddress-%:
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_INSTANCE_IP := $(shell $(call aws,ec2 describe-instances --no-paginate --filter 'Name=tag:Name$(comma)Values=$**' --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text) 2>/dev/null)) $(eval AWS_INSTANCE_IP := $(shell $(call aws,ec2 describe-instances --no-paginate --filter 'Name=tag:Name$(comma)Values=$**' --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text) 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo PrivateIpAddress: $(AWS_INSTANCE_IP) echo PrivateIpAddress: $(AWS_INSTANCE_IP)
.PHONY: aws-ec2-get-snap-id-import-snapshot-task # target aws-ec2-get-import-snapshot-tasks-id: Fire aws-ec2-get-import-snapshot-tasks-id-% for AWS_TASK_ID
aws-ec2-get-snap-id-import-snapshot-task: aws-ec2-get-snap-id-import-snapshot-task-$(AWS_TASK_ID) .PHONY: aws-ec2-get-import-snapshot-tasks-id
aws-ec2-get-import-snapshot-tasks-id: aws-ec2-get-import-snapshot-tasks-id-$(AWS_TASK_ID)
.PHONY: aws-ec2-get-snap-id-import-snapshot-task-% # target aws-ec2-get-import-snapshot-tasks-id-%: Eval AWS_SNAP_IP with import-task-ids %, Echo 'SnapshotId: AWS_SNAP_IP'
aws-ec2-get-snap-id-import-snapshot-task-%: docker-build-aws .PHONY: aws-ec2-get-import-snapshot-tasks-id-%
aws-ec2-get-import-snapshot-tasks-id-%: docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_SNAP_ID := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.SnapshotId) 2>/dev/null)) $(eval AWS_SNAP_ID := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.SnapshotId) 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo SnapshotId: $(AWS_SNAP_ID) echo SnapshotId: $(AWS_SNAP_ID)
.PHONY: aws-ec2-get-snap-message-import-snapshot-task-% # target aws-ec2-get-import-snapshot-tasks-message-%: Eval AWS_SNAP_MESSAGE with import-task-ids %, Echo 'StatusMessage: AWS_SNAP_MESSAGE'
aws-ec2-get-snap-message-import-snapshot-task-%: docker-build-aws .PHONY: aws-ec2-get-import-snapshot-tasks-message-%
aws-ec2-get-import-snapshot-tasks-message-%: docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_SNAP_MESSAGE := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.StatusMessage) 2>/dev/null)) $(eval AWS_SNAP_MESSAGE := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.StatusMessage) 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo StatusMessage: $(AWS_SNAP_MESSAGE) echo StatusMessage: $(AWS_SNAP_MESSAGE)
.PHONY: aws-ec2-get-snap-progress-import-snapshot-task-% # target aws-ec2-get-import-snapshot-tasks-progress-%: Eval AWS_SNAP_PROGRESS with import-task-ids %, Echo 'Progress: AWS_SNAP_PROGRESS'
aws-ec2-get-snap-progress-import-snapshot-task-%: docker-build-aws .PHONY: aws-ec2-get-import-snapshot-tasks-progress-%
aws-ec2-get-import-snapshot-tasks-progress-%: docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_SNAP_PROGRESS := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.Progress) 2>/dev/null)) $(eval AWS_SNAP_PROGRESS := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.Progress) 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo Progress: $(AWS_SNAP_PROGRESS) echo Progress: $(AWS_SNAP_PROGRESS)
.PHONY: aws-ec2-get-snap-size-import-snapshot-task-% # target aws-ec2-get-import-snapshot-tasks-size-%: Eval AWS_SNAP_SIZE with import-task-ids %, Echo 'DiskImageSize: AWS_SNAP_SIZE'
aws-ec2-get-snap-size-import-snapshot-task-%: docker-build-aws .PHONY: aws-ec2-get-import-snapshot-tasks-size-%
aws-ec2-get-import-snapshot-tasks-size-%: docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_SNAP_SIZE := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.DiskImageSize) 2>/dev/null)) $(eval AWS_SNAP_SIZE := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.DiskImageSize) 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo DiskImageSize: $(AWS_SNAP_SIZE) echo DiskImageSize: $(AWS_SNAP_SIZE)
.PHONY: aws-ec2-get-snap-status-import-snapshot-task-% # target aws-ec2-get-import-snapshot-tasks-status-%: Eval AWS_SNAP_STATUS with import-task-ids %, Echo 'Status: AWS_SNAP_STATUS'
aws-ec2-get-snap-status-import-snapshot-task-%: docker-build-aws .PHONY: aws-ec2-get-import-snapshot-tasks-status-%
aws-ec2-get-import-snapshot-tasks-status-%: docker-build-aws
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval AWS_SNAP_STATUS := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.Status) 2>/dev/null)) $(eval AWS_SNAP_STATUS := $(shell $(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.Status) 2>/dev/null))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
echo Status: $(AWS_SNAP_STATUS) echo Status: $(AWS_SNAP_STATUS)
.PHONY: aws-ec2-wait-snap-completed-import-snapshot-task # target aws-ec2-wait-import-snapshot-tasks-status-completed: Fire aws-ec2-wait-import-snapshot-tasks-status-completed-% for AWS_TASK_ID
aws-ec2-wait-snap-completed-import-snapshot-task: aws-ec2-wait-snap-completed-import-snapshot-task-$(AWS_TASK_ID) .PHONY: aws-ec2-wait-import-snapshot-tasks-status-completed
aws-ec2-wait-import-snapshot-tasks-status-completed: aws-ec2-wait-import-snapshot-tasks-status-completed-$(AWS_TASK_ID)
.PHONY: aws-ec2-wait-snap-completed-import-snapshot-task-% # target aws-ec2-wait-import-snapshot-tasks-status-completed-%: Wait SnapshotTaskDetail.Status=completed for import-task-ids %
aws-ec2-wait-snap-completed-import-snapshot-task-%: docker-build-aws .PHONY: aws-ec2-wait-import-snapshot-tasks-status-completed-%
aws-ec2-wait-import-snapshot-tasks-status-completed-%: docker-build-aws
while [ `$(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.Status)` != "completed$$(printf '\r')" ]; \ while [ `$(call aws,ec2 describe-import-snapshot-tasks --import-task-ids $* --output text --query ImportSnapshotTasks[0].SnapshotTaskDetail.Status)` != "completed$$(printf '\r')" ]; \
do \ do \
count=$$(( $${count:-0}+1 )); \ count=$$(( $${count:-0}+1 )); \
@ -152,19 +182,22 @@ aws-ec2-wait-snap-completed-import-snapshot-task-%: docker-build-aws
sleep 10; \ sleep 10; \
done done
.PHONY: aws-ec2-wait-snapshot-% # target aws-ec2-wait-snapshot-completed-%: Call ec2 wait snapshot-completed with shapshot-ids %
aws-ec2-wait-snapshot-%: docker-build-aws .PHONY: aws-ec2-wait-snapshot-completed-%
aws-ec2-wait-snapshot-completed-%: docker-build-aws
$(call aws,ec2 wait snapshot-completed --snapshot-ids $* --output text) $(call aws,ec2 wait snapshot-completed --snapshot-ids $* --output text)
# target aws-ec2-register-image: Fire aws-ec2-get-import-snapshot-tasks-id, Eval AWS_AMI_ID with Name AWS_AMI_NAME, Echo 'ImageId: AWS_AMI_ID'
.PHONY: aws-ec2-register-image .PHONY: aws-ec2-register-image
aws-ec2-register-image: base docker-build-aws aws-ec2-get-snap-id-import-snapshot-task aws-ec2-register-image: base docker-build-aws aws-ec2-get-import-snapshot-tasks-id
$(eval DRYRUN_IGNORE := true) $(eval DRYRUN_IGNORE := true)
$(eval json := $(shell $(call exec,envsubst < aws/register-image-device-mappings.json))) $(eval json := $(shell $(call exec,envsubst < aws/register-image-device-mappings.json)))
$(eval DRYRUN_IGNORE := false) $(eval DRYRUN_IGNORE := false)
$(eval AWS_AMI_ID := $(shell $(call aws,ec2 register-image --name '$(AWS_AMI_NAME)' --description '$(AWS_AMI_DESCRIPTION)' --architecture x86_64 --root-device-name /dev/sda1 --virtualization-type hvm --block-device-mappings '$(json)') 2>/dev/null)) $(eval AWS_AMI_ID := $(shell $(call aws,ec2 register-image --name '$(AWS_AMI_NAME)' --description '$(AWS_AMI_DESCRIPTION)' --architecture x86_64 --root-device-name /dev/sda1 --virtualization-type hvm --block-device-mappings '$(json)') 2>/dev/null))
echo ImageId: $(AWS_AMI_ID) echo ImageId: $(AWS_AMI_ID)
# target aws-ami: Fire aws-s3-cp aws-ec2-import-snapshot, Call aws-ec2-wait-import-snapshot-tasks-status-completed target, Call aws-ec2-register-image target
.PHONY: aws-ami .PHONY: aws-ami
aws-ami: aws-s3-cp aws-ec2-import-snapshot aws-ami: aws-s3-cp aws-ec2-import-snapshot
$(call make,aws-ec2-wait-snap-completed-import-snapshot-task,,AWS_TASK_ID) $(call make,aws-ec2-wait-import-snapshot-tasks-status-completed,,AWS_TASK_ID)
$(call make,aws-ec2-register-image,,AWS_TASK_ID) $(call make,aws-ec2-register-image,,AWS_TASK_ID)

View File

@ -17,6 +17,7 @@ define aws
$(call run,$(DOCKER_SSH_AUTH) -v $$HOME/.aws:/root/.aws:ro anigeo/awscli:latest $(1)) $(call run,$(DOCKER_SSH_AUTH) -v $$HOME/.aws:/root/.aws:ro anigeo/awscli:latest $(1))
endef endef
else else
# function aws: Call run aws with arg 1
define aws define aws
$(call run,aws $(1)) $(call run,aws $(1))
endef endef

View File

@ -33,9 +33,6 @@ build: docker-compose-build ## Build application docker images
# on local host # on local host
.PHONY: build@% app-build .PHONY: build@% app-build
build@%: myos-base build@%: myos-base
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(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 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)))) $(eval build_app := $(or $(filter $(DOCKER_BUILD_CACHE),false),$(filter-out $(docker_images),$(SERVICES))))
$(if $(build_app), \ $(if $(build_app), \
@ -75,7 +72,7 @@ connect@%: SERVICE ?= $(DOCKER_SERVICE)
connect@%: connect@%:
$(call make,ssh-connect,$(MYOS),APP SERVICE) $(call make,ssh-connect,$(MYOS),APP SERVICE)
# target deploy: Fire deploy@ENV # target deploy: Fire deploy@% for ENV
.PHONY: deploy .PHONY: deploy
deploy: deploy@$(ENV) ## Deploy application dockers deploy: deploy@$(ENV) ## Deploy application dockers
@ -84,7 +81,7 @@ deploy: deploy@$(ENV) ## Deploy application dockers
.PHONY: down .PHONY: down
down: docker-compose-down ## Remove application dockers down: docker-compose-down ## Remove application dockers
# target exec: Exec command in docker SERVICE # target exec: Exec ARGS in docker SERVICE
# on local host # on local host
.PHONY: exec .PHONY: exec
exec: ## Exec command in docker SERVICE exec: ## Exec command in docker SERVICE
@ -94,7 +91,7 @@ else
$(call make,docker-compose-exec,,ARGS) $(call make,docker-compose-exec,,ARGS)
endif endif
# target exec@%: Exec command in docker SERVICE of % ENV # target exec@%: Exec ARGS in docker SERVICE of % ENV
# on all remote hosts # on all remote hosts
.PHONY: exec@% .PHONY: exec@%
exec@%: SERVICE ?= $(DOCKER_SERVICE) exec@%: SERVICE ?= $(DOCKER_SERVICE)
@ -104,7 +101,7 @@ exec@%:
# target install app-install: Install application # target install app-install: Install application
# on local host # on local host
.PHONY: install app-install .PHONY: install app-install
install: app-install ## Install application install: update-app app-install ## Install application
# target logs: Display application dockers logs # target logs: Display application dockers logs
# on local host # on local host
@ -132,7 +129,7 @@ rebuild@%:
.PHONY: recreate .PHONY: recreate
recreate: docker-compose-recreate app-start ## Recreate application dockers recreate: docker-compose-recreate app-start ## Recreate application dockers
# target reinstall: Fire clean and call install target # target reinstall: Fire clean, Call .env target, Call install target
# on local host # on local host
.PHONY: reinstall .PHONY: reinstall
reinstall: clean ## Reinstall application reinstall: clean ## Reinstall application
@ -148,7 +145,7 @@ release: release-create ## Create release VERSION
.PHONY: restart .PHONY: restart
restart: docker-compose-restart app-start ## Restart application restart: docker-compose-restart app-start ## Restart application
# target run: Run command in a new docker SERVICE # target run: Run command ARGS in a new docker SERVICE
# on local host # on local host
.PHONY: run .PHONY: run
run: ## Run a command in a new docker run: ## Run a command in a new docker
@ -158,7 +155,7 @@ else
$(call make,docker-compose-run,,ARGS) $(call make,docker-compose-run,,ARGS)
endif endif
# target run@%: Run command in a new docker SERVICE of % ENV # target run@%: Run command ARGS in a new docker SERVICE of % ENV
# on all remote hosts # on all remote hosts
.PHONY: run@% .PHONY: run@%
run@%: SERVICE ?= $(DOCKER_SERVICE) run@%: SERVICE ?= $(DOCKER_SERVICE)
@ -182,7 +179,7 @@ ssh@%:
stack: stack:
$(foreach stackz,$(STACK),$(call docker-stack,$(stackz))) $(foreach stackz,$(STACK),$(call docker-stack,$(stackz)))
# target stack-%: Call docker-compose-% target on a given stack # target stack-%: Call docker-compose-% target on STACK
## it splits % on dashes and extracts stack from the beginning and command from ## it splits % on dashes and extracts stack from the beginning and command from
## the last part of % ## the last part of %
## ex: stack-base-up will fire the docker-compose-up target in the base stack ## ex: stack-base-up will fire the docker-compose-up target in the base stack
@ -194,9 +191,9 @@ stack-%:
$(if $(filter $(command),$(filter-out %-%,$(patsubst docker-compose-%,%,$(filter docker-compose-%,$(MAKE_TARGETS))))), \ $(if $(filter $(command),$(filter-out %-%,$(patsubst docker-compose-%,%,$(filter docker-compose-%,$(MAKE_TARGETS))))), \
$(call make,docker-compose-$(command) STACK="$(stack)" $(if $(filter node,$(stack)),COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME_NODE)),,ARGS COMPOSE_IGNORE_ORPHANS SERVICE))) $(call make,docker-compose-$(command) STACK="$(stack)" $(if $(filter node,$(stack)),COMPOSE_PROJECT_NAME=$(COMPOSE_PROJECT_NAME_NODE)),,ARGS COMPOSE_IGNORE_ORPHANS SERVICE)))
# target start: Start application dockers # target start app-start: Start application dockers
# on local host # on local host
.PHONY: start .PHONY: start app-start
start: docker-compose-start ## Start application dockers start: docker-compose-start ## Start application dockers
# target stop: Stop application dockers # target stop: Stop application dockers

View File

@ -2,6 +2,8 @@ APP_DIR ?= $(CURDIR)
APP_DOMAIN ?= $(ENV)$(addprefix .,$(DOMAIN)) APP_DOMAIN ?= $(ENV)$(addprefix .,$(DOMAIN))
APP_HOST ?= $(APP)$(addprefix .,$(APP_DOMAIN)) APP_HOST ?= $(APP)$(addprefix .,$(APP_DOMAIN))
APP_PARAMETERS_REPOSITORY ?= $(GIT_PARAMETERS_REPOSITORY) APP_PARAMETERS_REPOSITORY ?= $(GIT_PARAMETERS_REPOSITORY)
APP_PARENT ?= $(MONOREPO)
APP_PARENT_DIR ?= $(MONOREPO_DIR)
APP_PATH ?= /$(APP_PATH_PREFIX) APP_PATH ?= /$(APP_PATH_PREFIX)
APP_REPOSITORY ?= $(GIT_REPOSITORY) APP_REPOSITORY ?= $(GIT_REPOSITORY)
APP_SCHEME ?= https APP_SCHEME ?= https
@ -9,9 +11,10 @@ APP_UPSTREAM_REPOSITORY ?= $(or $(shell git config --get remote.upstream
APP_URI ?= $(APP_HOST)$(APP_PATH) APP_URI ?= $(APP_HOST)$(APP_PATH)
APP_URL ?= $(APP_SCHEME)://$(APP_URI) APP_URL ?= $(APP_SCHEME)://$(APP_URI)
BUILD_ENV_VARS ?= APP BRANCH COMMIT DEPLOY_HOOK_URL ENV VERSION BUILD_ENV_VARS ?= APP BRANCH COMMIT DEPLOY_HOOK_URL ENV VERSION
CONTEXT_DEBUG += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL APP_REPOSITORY APP_UPSTREAM_REPOSITORY APP_PARAMETERS_REPOSITORY CONSUL_HTTP_TOKEN CONTEXT_DEBUG += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL APP_REPOSITORY APP_UPSTREAM_REPOSITORY APP_PARAMETERS_REPOSITORY CONSUL_HTTP_TOKEN SERVICES
ENV_DEPLOY ?= $(shell ls .git/refs/heads/) ENV_DEPLOY ?= $(shell ls .git/refs/heads/)
ENV_VARS += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL CONSUL_HTTP_TOKEN $(if $(filter true,$(MOUNT_NFS)),NFS_CONFIG) ENV_VARS += APP_DIR APP_DOMAIN APP_HOST APP_PATH APP_URL CONSUL_HTTP_TOKEN $(if $(filter true,$(MOUNT_NFS)),NFS_CONFIG)
MOUNT_NFS ?= false MOUNT_NFS ?= false
NFS_CONFIG ?= addr=$(NFS_HOST),actimeo=3,intr,noacl,noatime,nocto,nodiratime,nolock,soft,rsize=32768,wsize=32768,tcp,rw,vers=3 NFS_CONFIG ?= addr=$(NFS_HOST),actimeo=3,intr,noacl,noatime,nocto,nodiratime,nolock,soft,rsize=32768,wsize=32768,tcp,rw,vers=3
NFS_HOST ?= host.docker.internal NFS_HOST ?= host.docker.internal
SERVICES ?= $(eval DRYRUN_IGNORE := true) $(shell $(call docker-compose,--log-level critical config --services)) $(eval DRYRUN_IGNORE := false)

View File

@ -1,7 +1,7 @@
## ##
# DOCKER # DOCKER
# target docker-build: Fire docker-images-myos and call docker-build-% target for each DOCKER_IMAGES # target docker-build: Fire docker-images-myos, Call docker-build-% target for each DOCKER_IMAGES
.PHONY: docker-build .PHONY: docker-build
docker-build: docker-images-myos docker-build: docker-images-myos
$(foreach image,$(or $(SERVICE),$(DOCKER_IMAGES)),$(call make,docker-build-$(image))) $(foreach image,$(or $(SERVICE),$(DOCKER_IMAGES)),$(call make,docker-build-$(image)))
@ -17,25 +17,16 @@ docker-build-%:
# target docker-commit: Call docker-commit for each SERVICES # target docker-commit: Call docker-commit for each SERVICES
.PHONY: docker-commit .PHONY: docker-commit
docker-commit: docker-commit:
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-commit,$(service))) $(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-commit,$(service)))
# target docker-commit-%: Call docker-commit with tag % for each SERVICES # target docker-commit-%: Call docker-commit with tag % for each SERVICES
.PHONY: docker-commit-% .PHONY: docker-commit-%
docker-commit-%: docker-commit-%:
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-commit,$(service),,,$*)) $(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-commit,$(service),,,$*))
# target docker-compose-build: Fire docker-images-myos and call docker-compose build SERVICE # target docker-compose-build: Fire docker-images-myos, Call docker-compose build SERVICE
.PHONY: docker-compose-build .PHONY: docker-compose-build
docker-compose-build: docker-images-myos docker-compose-build: docker-images-myos
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(call docker-compose,build $(if $(filter $(DOCKER_BUILD_NO_CACHE),true),--pull --no-cache) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE))) $(call docker-compose,build $(if $(filter $(DOCKER_BUILD_NO_CACHE),true),--pull --no-cache) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-config: Call docker-compose config # target docker-compose-config: Call docker-compose config
@ -52,9 +43,6 @@ docker-compose-connect:
# target docker-compose-down: Call docker-compose rm SERVICE or docker-compose down # target docker-compose-down: Call docker-compose rm SERVICE or docker-compose down
.PHONY: docker-compose-down .PHONY: docker-compose-down
docker-compose-down: docker-compose-down:
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(if $(filter $(SERVICE),$(SERVICES)),$(call docker-compose,rm -fs $(SERVICE)),$(call docker-compose,down $(DOCKER_COMPOSE_DOWN_OPTIONS))) $(if $(filter $(SERVICE),$(SERVICES)),$(call docker-compose,rm -fs $(SERVICE)),$(call docker-compose,down $(DOCKER_COMPOSE_DOWN_OPTIONS)))
# target docker-compose-exec: Call docker-compose-exec SERVICE ARGS # target docker-compose-exec: Call docker-compose-exec SERVICE ARGS
@ -66,9 +54,6 @@ docker-compose-exec:
# target docker-compose-logs: Call docker-compose logs SERVICE # target docker-compose-logs: Call docker-compose logs SERVICE
.PHONY: docker-compose-logs .PHONY: docker-compose-logs
docker-compose-logs: docker-compose-logs:
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(call docker-compose,logs -f --tail=100 $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE))) || true $(call docker-compose,logs -f --tail=100 $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE))) || true
# target docker-compose-ps: Call docker-compose ps # target docker-compose-ps: Call docker-compose ps
@ -88,17 +73,11 @@ docker-compose-recreate: docker-compose-rm docker-compose-up
# target docker-compose-restart: Call docker-compose restart SERVICE # target docker-compose-restart: Call docker-compose restart SERVICE
.PHONY: docker-compose-restart .PHONY: docker-compose-restart
docker-compose-restart: docker-compose-restart:
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(call docker-compose,restart $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE))) $(call docker-compose,restart $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-rm: Call docker-compose rm SERVICE # target docker-compose-rm: Call docker-compose rm SERVICE
.PHONY: docker-compose-rm .PHONY: docker-compose-rm
docker-compose-rm: docker-compose-rm:
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(call docker-compose,rm -fs $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE))) $(call docker-compose,rm -fs $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-run: Call docker-compose run SERVICE ARGS # target docker-compose-run: Call docker-compose run SERVICE ARGS
@ -116,25 +95,16 @@ docker-compose-scale:
# target docker-compose-start: Call docker-compose start SERVICE # target docker-compose-start: Call docker-compose start SERVICE
.PHONY: docker-compose-start .PHONY: docker-compose-start
docker-compose-start: docker-compose-start:
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(call docker-compose,start $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE))) $(call docker-compose,start $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-stop: Call docker-compose stop SERVICE # target docker-compose-stop: Call docker-compose stop SERVICE
.PHONY: docker-compose-stop .PHONY: docker-compose-stop
docker-compose-stop: docker-compose-stop:
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(call docker-compose,stop $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE))) $(call docker-compose,stop $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-compose-up: Fire docker-image-myos and call docker-compose up SERVICE # target docker-compose-up: Fire docker-image-myos, Call docker-compose up SERVICE
.PHONY: docker-compose-up .PHONY: docker-compose-up
docker-compose-up: docker-images-myos docker-compose-up: docker-images-myos
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(call docker-compose,up $(DOCKER_COMPOSE_UP_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE))) $(call docker-compose,up $(DOCKER_COMPOSE_UP_OPTIONS) $(if $(filter $(SERVICE),$(SERVICES)),$(SERVICE)))
# target docker-images-myos: Call myos-docker-build-% target for each DOCKER_IMAGES_MYOS # target docker-images-myos: Call myos-docker-build-% target for each DOCKER_IMAGES_MYOS
@ -152,7 +122,7 @@ docker-images-rm:
docker-images-rm-%: docker-images-rm-%:
docker images |awk '$$1 ~ /^$(subst /,\/,$*)/ {print $$3}' |sort -u |while read image; do docker rmi -f $$image; done docker images |awk '$$1 ~ /^$(subst /,\/,$*)/ {print $$3}' |sort -u |while read image; do docker rmi -f $$image; done
# target docker-login: Exec docker login # target docker-login: Exec 'docker login'
.PHONY: docker-login .PHONY: docker-login
docker-login: myos-base docker-login: myos-base
$(ECHO) docker login $(ECHO) docker login
@ -161,7 +131,7 @@ docker-login: myos-base
.PHONY: docker-network-create .PHONY: docker-network-create
docker-network-create: docker-network-create-$(DOCKER_NETWORK) docker-network-create: docker-network-create-$(DOCKER_NETWORK)
# target docker-network-create-%: Create docker network % # target docker-network-create-%: Exec 'docker network create %'
.PHONY: docker-network-create-% .PHONY: docker-network-create-%
docker-network-create-%: docker-network-create-%:
[ -n "$(shell docker network ls -q --filter name='^$*$$' 2>/dev/null)" ] \ [ -n "$(shell docker network ls -q --filter name='^$*$$' 2>/dev/null)" ] \
@ -177,7 +147,7 @@ docker-network-rm-%:
[ -z "$(shell docker network ls -q --filter name='^$*$$' 2>/dev/null)" ] \ [ -z "$(shell docker network ls -q --filter name='^$*$$' 2>/dev/null)" ] \
|| { echo -n "Removing docker network $* ... " && $(ECHO) docker network rm $* >/dev/null 2>&1 && echo "done" || echo "ERROR"; } || { echo -n "Removing docker network $* ... " && $(ECHO) docker network rm $* >/dev/null 2>&1 && echo "done" || echo "ERROR"; }
# target docker-plugin-install: Install docker plugin DOCKER_PLUGIN with DOCKER_PLUGIN_OPTIONS # target docker-plugin-install: Exec 'docker plugin install DOCKER_PLUGIN_OPTIONS DOCKER_PLUGIN'
.PHONY: docker-plugin-install .PHONY: docker-plugin-install
docker-plugin-install: docker-plugin-install:
$(eval docker_plugin_state := $(shell docker plugin ls | awk '$$2 == "$(DOCKER_PLUGIN)" {print $$NF}') ) $(eval docker_plugin_state := $(shell docker plugin ls | awk '$$2 == "$(DOCKER_PLUGIN)" {print $$NF}') )
@ -187,9 +157,6 @@ docker-plugin-install:
.PHONY: docker-push .PHONY: docker-push
docker-push: docker-push:
ifneq ($(filter $(DEPLOY),true),) ifneq ($(filter $(DEPLOY),true),)
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-push,$(service))) $(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-push,$(service)))
else else
printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}target${COLOR_RESET} $@ ${COLOR_GREEN}not enabled in${COLOR_RESET} $(APP).\n" >&2 printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}target${COLOR_RESET} $@ ${COLOR_GREEN}not enabled in${COLOR_RESET} $(APP).\n" >&2
@ -199,9 +166,6 @@ endif
.PHONY: docker-push-% .PHONY: docker-push-%
docker-push-%: docker-push-%:
ifneq ($(filter $(DEPLOY),true),) ifneq ($(filter $(DEPLOY),true),)
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-push,$(service),,$*)) $(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-push,$(service),,$*))
else else
printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}target${COLOR_RESET} $@ ${COLOR_GREEN}not enabled in${COLOR_RESET} $(APP).\n" >&2 printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}target${COLOR_RESET} $@ ${COLOR_GREEN}not enabled in${COLOR_RESET} $(APP).\n" >&2
@ -245,9 +209,6 @@ docker-run-%: docker-build-%
.PHONY: docker-tag .PHONY: docker-tag
docker-tag: docker-tag:
ifneq ($(filter $(DEPLOY),true),) ifneq ($(filter $(DEPLOY),true),)
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-tag,$(service))) $(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-tag,$(service)))
else else
printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}target${COLOR_RESET} $@ ${COLOR_GREEN}not enabled in${COLOR_RESET} $(APP).\n" >&2 printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}target${COLOR_RESET} $@ ${COLOR_GREEN}not enabled in${COLOR_RESET} $(APP).\n" >&2
@ -257,9 +218,6 @@ endif
.PHONY: docker-tag-% .PHONY: docker-tag-%
docker-tag-%: docker-tag-%:
ifneq ($(filter $(DEPLOY),true),) ifneq ($(filter $(DEPLOY),true),)
$(eval DRYRUN_IGNORE := true)
$(eval SERVICES ?= $(shell $(call docker-compose,--log-level critical config --services)))
$(eval DRYRUN_IGNORE := false)
$(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-tag,$(service),,,,$*)) $(foreach service,$(or $(SERVICE),$(SERVICES)),$(call docker-tag,$(service),,,,$*))
else else
printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}target${COLOR_RESET} $@ ${COLOR_GREEN}not enabled in${COLOR_RESET} $(APP).\n" >&2 printf "${COLOR_BROWN}WARNING${COLOR_RESET}: ${COLOR_GREEN}target${COLOR_RESET} $@ ${COLOR_GREEN}not enabled in${COLOR_RESET} $(APP).\n" >&2

View File

@ -7,7 +7,7 @@ SSH_PUBLIC_HOST_KEYS ?= $(SSH_REMOTE_HOSTS) $(SSH_BASTION_HOSTNAME)
SSH_PRIVATE_IP_RANGE ?= 10.10.* SSH_PRIVATE_IP_RANGE ?= 10.10.*
SSH_REMOTE_HOSTS ?= github.com gitlab.com SSH_REMOTE_HOSTS ?= github.com gitlab.com
# function ssh-connect: Exec command on remote hosts with tty # function ssh-connect: Exec command 2 on remote hosts 1 with tty
define ssh-connect define ssh-connect
$(eval hosts := $(1)) $(eval hosts := $(1))
$(eval command := $(2)) $(eval command := $(2))
@ -16,7 +16,7 @@ define ssh-connect
$(foreach host,$(hosts),$(call exec,ssh -t -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $(user)@$(host) "$(command)") ||) true $(foreach host,$(hosts),$(call exec,ssh -t -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $(user)@$(host) "$(command)") ||) true
endef endef
# function ssh-exec: Exec command on remote hosts without tty # function ssh-exec: Exec command 2 on remote hosts 1 without tty
define ssh-exec define ssh-exec
$(eval hosts := $(1)) $(eval hosts := $(1))
$(eval command := $(2)) $(eval command := $(2))

View File

@ -1,22 +1,26 @@
## ##
# SSH # SSH
# target ssh: Call ssh-connect with command SHELL # target get-PrivateIpAddress-%: Fire aws-ec2-get-instances-PrivateIpAddress-%
.PHONY: ssh .PHONY: get-PrivateIpAddress-%
ssh: aws-ec2-get-PrivateIpAddress-$(SERVER_NAME) ## Connect to first remote host get-PrivateIpAddress-%: aws-ec2-get-instances-PrivateIpAddress-%;
$(call ssh-connect,$(AWS_INSTANCE_IP),$(SHELL))
# target ssh-connect: Call ssh-connect with command make connect # target ssh: Call ssh-connect ARGS or SHELL
.PHONY: ssh
ssh: get-PrivateIpAddress-$(SERVER_NAME) ## Connect to first remote host
$(call ssh-connect,$(AWS_INSTANCE_IP),$(if $(ARGS),$(ARGS),$(SHELL)))
# target ssh-connect: Call ssh-connect make connect SERVICE
.PHONY: ssh-connect .PHONY: ssh-connect
ssh-connect: aws-ec2-get-PrivateIpAddress-$(SERVER_NAME) ssh-connect: get-PrivateIpAddress-$(SERVER_NAME)
$(call ssh-connect,$(AWS_INSTANCE_IP),make connect $(if $(SERVICE),SERVICE=$(SERVICE))) $(call ssh-connect,$(AWS_INSTANCE_IP),make connect $(if $(SERVICE),SERVICE=$(SERVICE)))
# target ssh-connect: Call ssh-connect with command make exec # target ssh-exec: Call ssh-exec make exec SERVICE ARGS
.PHONY: ssh-exec .PHONY: ssh-exec
ssh-exec: aws-ec2-get-PrivateIpAddress-$(SERVER_NAME) ssh-exec: get-PrivateIpAddress-$(SERVER_NAME)
$(call ssh-exec,$(AWS_INSTANCE_IP),make exec $(if $(SERVICE),SERVICE=$(SERVICE)) $(if $(ARGS),ARGS='\''"$(ARGS)"'\'')) $(call ssh-exec,$(AWS_INSTANCE_IP),make exec $(if $(SERVICE),SERVICE=$(SERVICE)) $(if $(ARGS),ARGS='\''"$(ARGS)"'\''))
# target ssh-run: Call ssh-connect with command make run # target ssh-run: Call ssh-run make run SERVICE ARGS
.PHONY: ssh-run .PHONY: ssh-run
ssh-run: aws-ec2-get-PrivateIpAddress-$(SERVER_NAME) ssh-run: get-PrivateIpAddress-$(SERVER_NAME)
$(call ssh-exec,$(AWS_INSTANCE_IP),make run $(if $(SERVICE),SERVICE=$(SERVICE)) $(if $(ARGS),ARGS='\''"$(ARGS)"'\'')) $(call ssh-exec,$(AWS_INSTANCE_IP),make run $(if $(SERVICE),SERVICE=$(SERVICE)) $(if $(ARGS),ARGS='\''"$(ARGS)"'\''))

View File

@ -7,6 +7,14 @@ ifeq ($(SETUP_SYSCTL),true)
$(foreach config,$(SETUP_SYSCTL_CONFIG),$(call docker-run,--privileged alpine:latest,sysctl -q -w $(config)) &&) true $(foreach config,$(SETUP_SYSCTL_CONFIG),$(call docker-run,--privileged alpine:latest,sysctl -q -w $(config)) &&) true
endif endif
.PHONY: setup-nfsd
setup-nfsd:
ifeq ($(SETUP_NFSD),true)
ifeq ($(HOST_SYSTEM),DARWIN)
$(call setup-nfsd-osx)
endif
endif
define setup-nfsd-osx define setup-nfsd-osx
$(eval dir:=$(or $(1),$(MONOREPO_DIR))) $(eval dir:=$(or $(1),$(MONOREPO_DIR)))
$(eval uid:=$(or $(2),$(UID))) $(eval uid:=$(or $(2),$(UID)))

View File

@ -4,7 +4,7 @@ dquote ?= "
quote ?= ' quote ?= '
APP ?= $(if $(wildcard .git),$(notdir $(CURDIR))) APP ?= $(if $(wildcard .git),$(notdir $(CURDIR)))
APP_NAME ?= $(APP) APP_NAME ?= $(APP)
APP_TYPE ?= $(if $(SUBREPO),subrepo) $(if $(MYOS),,myos) APP_TYPE ?= $(if $(SUBREPO),subrepo) $(if $(filter .,$(MYOS)),myos)
APPS ?= $(if $(MONOREPO),$(sort $(patsubst $(MONOREPO_DIR)/%/.git,%,$(wildcard $(MONOREPO_DIR)/*/.git)))) 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))) 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) BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
@ -41,15 +41,16 @@ MAKE_ENV_ARGS ?= $(foreach var,$(filter $(ENV_VARS),$(MAKE_ENV
MAKE_ENV_VARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter environment,$(origin $(var))),$(var)))) MAKE_ENV_VARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter environment,$(origin $(var))),$(var))))
MAKE_FILE_ARGS ?= $(foreach var,$(filter $(ENV_VARS),$(MAKE_FILE_VARS)),$(var)='$($(var))') MAKE_FILE_ARGS ?= $(foreach var,$(filter $(ENV_VARS),$(MAKE_FILE_VARS)),$(var)='$($(var))')
MAKE_FILE_VARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter file,$(origin $(var))),$(var)))) MAKE_FILE_VARS ?= $(strip $(foreach var, $(filter-out .VARIABLES,$(.VARIABLES)), $(if $(filter file,$(origin $(var))),$(var))))
MAKE_OLDFILE ?= $@
MAKE_TARGETS ?= $(filter-out $(.VARIABLES),$(shell $(MAKE) -qp 2>/dev/null |awk -F':' '/^[a-zA-Z0-9][^$$\#\/\t=]*:([^=]|$$)/ {print $$1}' |sort -u)) MAKE_TARGETS ?= $(filter-out $(.VARIABLES),$(shell $(MAKE) -qp 2>/dev/null |awk -F':' '/^[a-zA-Z0-9][^$$\#\/\t=]*:([^=]|$$)/ {print $$1}' |sort -u))
MAKE_VARS ?= ENV MAKE_VARS ?= ENV
MONOREPO ?= $(if $(filter myos,$(MYOS)),$(notdir $(CURDIR)),$(if $(APP),$(notdir $(realpath $(CURDIR)/..)))) 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)/..)))) MONOREPO_DIR ?= $(if $(MONOREPO),$(if $(filter myos,$(MYOS)),$(realpath $(CURDIR)),$(if $(APP),$(realpath $(CURDIR)/..))))
MYOS ?= $(if $(filter $(MAKE_DIR),$(call pop,$(MAKE_DIR))),,$(call pop,$(MAKE_DIR))) MYOS ?= $(if $(filter $(MAKE_DIR),$(call pop,$(MAKE_DIR))),.,$(call pop,$(MAKE_DIR)))
PARAMETERS ?= $(RELATIVE)parameters PARAMETERS ?= $(RELATIVE)parameters
QUIET ?= $(if $(filter false,$(VERBOSE)),--quiet) QUIET ?= $(if $(filter false,$(VERBOSE)),--quiet)
RECURSIVE ?= true RECURSIVE ?= true
RELATIVE ?= $(if $(filter myos,$(MYOS)),,../) RELATIVE ?= $(if $(filter myos,$(MYOS)),./,../)
SHARED ?= $(RELATIVE)shared SHARED ?= $(RELATIVE)shared
SSH_DIR ?= ${HOME}/.ssh SSH_DIR ?= ${HOME}/.ssh
SUBREPO ?= $(if $(wildcard .gitrepo),$(notdir $(CURDIR))) SUBREPO ?= $(if $(wildcard .gitrepo),$(notdir $(CURDIR)))
@ -129,10 +130,10 @@ define conf
done < "$(file)" done < "$(file)"
endef endef
# macro force: Run command sine die # macro force: Run command 1 sine die
# return never ## it starts command 1 if it is not already running
## it starts command if it is not already running ## it returns never
force = $$(while true; do [ $$(ps x |awk 'BEGIN {nargs=split("'"$$*"'",args)} $$field == args[1] { matched=1; for (i=1;i<=NF-field;i++) { if ($$(i+field) == args[i+1]) {matched++} } if (matched == nargs) {found++} } END {print found+0}' field=4) -eq 0 ] && $(ECHO) $(command) || sleep 1; done) force = $$(while true; do [ $$(ps x |awk 'BEGIN {nargs=split("'"$$*"'",args)} $$field == args[1] { matched=1; for (i=1;i<=NF-field;i++) { if ($$(i+field) == args[i+1]) {matched++} } if (matched == nargs) {found++} } END {print found+0}' field=4) -eq 0 ] && $(ECHO) $(1) || sleep 1; done)
# macro gid: Return GID of group 1 # macro gid: Return GID of group 1
gid = $(shell grep '^$(1):' /etc/group 2>/dev/null |awk -F: '{print $$3}') gid = $(shell grep '^$(1):' /etc/group 2>/dev/null |awk -F: '{print $$3}')

View File

@ -13,7 +13,7 @@ COLOR_BLUE ?= \033[36m
blank1 blank2: blank1 blank2:
printf "\n" printf "\n"
# target context: Call context-% for each CONTEXT # target context: Call context-% target for each CONTEXT
.PHONY: context .PHONY: context
context: context:
printf "${COLOR_BROWN}Context:${COLOR_RESET}\n" printf "${COLOR_BROWN}Context:${COLOR_RESET}\n"
@ -30,7 +30,7 @@ context-%:
# target doc: Fire functions macros target variables # target doc: Fire functions macros target variables
doc: functions macros targets variables ; doc: functions macros targets variables ;
# target doc: Fire functions-% macros-% target-% variables-% # target doc-%: Fire functions-% macros-% target-% variables-%
doc-%: functions-% macros-% targets-% variables-%; doc-%: functions-% macros-% targets-% variables-%;
# target help: Fire usage blank1 target blank2 context # target help: Fire usage blank1 target blank2 context

View File

@ -1,9 +1,7 @@
## ##
# MYOS # MYOS
# target myos-%: call % target in MYOS folder # target myos-%: Call % target in MYOS folder
.PHONY: myos-% .PHONY: myos-%
myos-%: ; myos-%: ;
ifeq ($(wildcard $(MYOS)),$(MYOS))
$(call make,$*,$(MYOS)) $(call make,$*,$(MYOS))
endif

View File

@ -10,7 +10,7 @@ update-apps:
.PHONY: update-app .PHONY: update-app
update-app: update-app-$(APP_NAME) ; update-app: update-app-$(APP_NAME) ;
# target update-app-%: Fire % target # target update-app-%: Fire myos-base %
.PHONY: update-app-% .PHONY: update-app-%
update-app-%: myos-base % ; update-app-%: myos-base % ;

View File

@ -12,6 +12,7 @@ define openstack
$(call run,$(DOCKER_SSH_AUTH) $(DOCKER_REPOSITORY)/openstack:$(DOCKER_IMAGE_TAG) $(1)) $(call run,$(DOCKER_SSH_AUTH) $(DOCKER_REPOSITORY)/openstack:$(DOCKER_IMAGE_TAG) $(1))
endef endef
else else
# function openstack: Call run openstack with arg 1
define openstack define openstack
$(call run,openstack $(1)) $(call run,openstack $(1))
endef endef

View File

@ -1,7 +1,9 @@
# target openstack: Call openstack ARGS
.PHONY: openstack .PHONY: openstack
openstack: docker-build-openstack openstack: docker-build-openstack
$(call openstack,$(ARGS)) $(call openstack,$(ARGS))
# target openstack-image-create: Call openstack image create PACKER_ISO_NAME with file PACKER_ISO_FILE
.PHONY: openstack-image-create .PHONY: openstack-image-create
openstack-image-create: $(PACKER_ISO_FILE) docker-build-openstack openstack-image-create: $(PACKER_ISO_FILE) docker-build-openstack
$(call openstack,$(OPENSTACK_ARGS) image create --disk-format raw --container-format bare --file $(PACKER_ISO_FILE) "$(PACKER_ISO_NAME)") $(call openstack,$(OPENSTACK_ARGS) image create --disk-format raw --container-format bare --file $(PACKER_ISO_FILE) "$(PACKER_ISO_NAME)")

View File

@ -86,9 +86,11 @@ endef
else else
# function packer: Call run packer with arg 1
define packer define packer
$(call run,packer $(1)) $(call run,packer $(1))
endef endef
# function packer-qemu: Call run qemu-system-% for PACKER_QEMU_ARCH
define packer-qemu define packer-qemu
echo Running $(1) echo Running $(1)
$(call run,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))) $(call run,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)))
@ -96,6 +98,7 @@ endef
endif endif
# function packer-build: Call packer build with arg 1, Add build infos to file PACKER_ISO_INFO
define packer-build define packer-build
$(eval PACKER_TEMPLATE := $(notdir $(basename $(1)))) $(eval PACKER_TEMPLATE := $(notdir $(basename $(1))))
echo Building $(PACKER_ISO_FILE) echo Building $(PACKER_ISO_FILE)

View File

@ -1,17 +1,22 @@
# target packer: Call packer ARGS
.PHONY: packer .PHONY: packer
packer: packer:
$(call packer,$(ARGS)) $(call packer,$(ARGS))
# target $(PACKER_ISO_FILE): Call packer-build target
$(PACKER_ISO_FILE): $(PACKER_ISO_FILE):
$(eval FORCE := true) $(eval FORCE := true)
$(call make,packer-build,,FORCE) $(call make,packer-build,,FORCE)
# target packer-build: Fire packer-build-% for PACKER_TEMPLATE
.PHONY: packer-build .PHONY: packer-build
packer-build: packer-build-$(PACKER_TEMPLATE) ## Build default packer template packer-build: packer-build-$(PACKER_TEMPLATE) ## Build default packer template
# target packer-build-templates: Fire PACKER_TEMPLATES
.PHONY: packer-build-templates .PHONY: packer-build-templates
packer-build-templates: $(PACKER_TEMPLATES) ## Build all packer templates packer-build-templates: $(PACKER_TEMPLATES) ## Build all packer templates
# target $(PACKER_TEMPLATES): Call packer-build $@
.PHONY: $(PACKER_TEMPLATES) .PHONY: $(PACKER_TEMPLATES)
ifeq ($(HOST_SYSTEM),DARWIN) ifeq ($(HOST_SYSTEM),DARWIN)
$(PACKER_TEMPLATES): DOCKER ?= false $(PACKER_TEMPLATES): DOCKER ?= false
@ -19,14 +24,17 @@ endif
$(PACKER_TEMPLATES): $(PACKER_TEMPLATES):
$(call packer-build,$@) $(call packer-build,$@)
# target packer-build-%: Call packer-build with file packer/*/%.json
.PHONY: packer-build-% .PHONY: packer-build-%
packer-build-%: docker-build-packer packer-build-%: docker-build-packer
$(if $(wildcard packer/*/$*.json),\ $(if $(wildcard packer/*/$*.json),\
$(call packer-build,$(wildcard packer/*/$*.json))) $(call packer-build,$(wildcard packer/*/$*.json)))
# target packer-qemu: Fire packer-quemu-% for PACKER_ISO_NAME
.PHONY: packer-qemu .PHONY: packer-qemu
packer-qemu: packer-qemu-$(PACKER_ISO_NAME) ## Launch iso image in qemu packer-qemu: packer-qemu-$(PACKER_ISO_NAME) ## Launch iso image in qemu
# target packer-qemu-%: Call packer-qemu PACKER_OUTPUT/%.iso
.PHONY: packer-qemu-% .PHONY: packer-qemu-%
ifeq ($(HOST_SYSTEM),DARWIN) ifeq ($(HOST_SYSTEM),DARWIN)
packer-qemu-%: DOCKER ?= false packer-qemu-%: DOCKER ?= false

View File

@ -1,14 +1,18 @@
# target base: Fire docker-network-create stack-base-up base-ssh-add
.PHONY: base .PHONY: base
base: docker-network-create stack-base-up base-ssh-add base: docker-network-create stack-base-up base-ssh-add
# target ssh-add: Fire base-ssh-add
.PHONY: ssh-add .PHONY: ssh-add
ssh-add: base-ssh-add ssh-add: base-ssh-add
# target base-ssh-add: Fire base-ssh-key and exec ssh-add file SSH_PRIVATE_KEYS in folder SSH_DIR
.PHONY: base-ssh-add .PHONY: base-ssh-add
base-ssh-add: base-ssh-key base-ssh-add: base-ssh-key
$(eval SSH_PRIVATE_KEYS := $(foreach file,$(SSH_DIR)/id_rsa $(filter-out $(wildcard $(SSH_DIR)/id_rsa),$(wildcard $(SSH_DIR)/*)),$(if $(shell grep "PRIVATE KEY" $(file) 2>/dev/null),$(notdir $(file))))) $(eval SSH_PRIVATE_KEYS := $(foreach file,$(SSH_DIR)/id_rsa $(filter-out $(wildcard $(SSH_DIR)/id_rsa),$(wildcard $(SSH_DIR)/*)),$(if $(shell grep "PRIVATE KEY" $(file) 2>/dev/null),$(notdir $(file)))))
$(call docker-run,$(DOCKER_SSH_AUTH) $(DOCKER_IMAGE_CLI),sh -c "$(foreach file,$(patsubst %,$(SSH_DIR)/%,$(SSH_PRIVATE_KEYS)),ssh-add -l |grep -qw $$(ssh-keygen -lf $(file) 2>/dev/null |awk '{print $$2}') 2>/dev/null || ssh-add $(file) ||: &&) true") $(call docker-run,$(DOCKER_SSH_AUTH) $(DOCKER_IMAGE_CLI),sh -c "$(foreach file,$(patsubst %,$(SSH_DIR)/%,$(SSH_PRIVATE_KEYS)),ssh-add -l |grep -qw $$(ssh-keygen -lf $(file) 2>/dev/null |awk '{print $$2}') 2>/dev/null || ssh-add $(file) ||: &&) true")
# target base-ssh-key: Setup ssh private key SSH_KEY in SSH_DIR
.PHONY: base-ssh-key .PHONY: base-ssh-key
base-ssh-key: stack-base-up base-ssh-key: stack-base-up
ifneq (,$(filter true,$(DRONE))) ifneq (,$(filter true,$(DRONE)))

View File

@ -5,6 +5,7 @@ ENV_VARS += ELASTICSEARCH_HOST ELASTICSEARCH_PASSWORD ELA
elastic ?= elastic/curator elastic/elasticsearch elastic/kibana alpine/sysctl elastic ?= elastic/curator elastic/elasticsearch elastic/kibana alpine/sysctl
# target elasticsearch-delete-%: delete elasticsearch index %
.PHONY: elasticsearch-delete-% .PHONY: elasticsearch-delete-%
elasticsearch-delete-%: elasticsearch-delete-%:
docker ps |awk '$$NF ~ /myos_elasticsearch/' |sed 's/^.*:\([0-9]*\)->9200\/tcp.*$$/\1/' |while read port; do echo -e "DELETE /$* HTTP/1.0\n\n" |nc localhost $$port; done docker ps |awk '$$NF ~ /myos_elasticsearch/' |sed 's/^.*:\([0-9]*\)->9200\/tcp.*$$/\1/' |while read port; do echo -e "DELETE /$* HTTP/1.0\n\n" |nc localhost $$port; done

View File

@ -1 +1,6 @@
logs ?= sematext/logagent logs ?= sematext/logagent
# target app-build-logagent: Exec 'rm -Rf /root/.npm /log-buufer/*' in docker SERVICE
.PHONY: app-build-logagent
app-build-logagent:
$(call make,docker-compose-exec ARGS='rm -Rf /root/.npm /log-buffer/*' SERVICE=logagent)

View File

@ -1,11 +1,13 @@
ENV_VARS += DOCKER_HOST_IFACE DOCKER_HOST_INET ENV_VARS += DOCKER_HOST_IFACE DOCKER_HOST_INET
# target node: Fire docker-network-create-% for DOCKER_NETWORK_PUBLIC node-openssl stack-node-up
.PHONY: node .PHONY: node
node: docker-network-create-$(DOCKER_NETWORK_PUBLIC) node-openssl stack-node-up node: docker-network-create-$(DOCKER_NETWORK_PUBLIC) node-openssl stack-node-up
# target node-openssl: Create /certs/${DOMAIN}.key.pem and /certs/${DOMAIN}.crt.pem files
.PHONY: node-openssl .PHONY: node-openssl
node-openssl: node-openssl:
docker run --rm --mount source=$(COMPOSE_PROJECT_NAME_INFRA_NODE)_ssl-certs,target=/certs alpine:latest [ -f /certs/$(SSL_HOSTNAME).crt.pem -a -f /certs/$(SSL_HOSTNAME).key.pem ] \ docker run --rm --mount source=$(COMPOSE_PROJECT_NAME_NODE)_ssl-certs,target=/certs alpine:latest [ -f /certs/$(DOMAIN).crt.pem -a -f /certs/$(DOMAIN).key.pem ] \
|| docker run --rm -e SSL_HOSTNAME=$(SSL_HOSTNAME) --mount source=$(COMPOSE_PROJECT_NAME_INFRA_NODE)_ssl-certs,target=/certs alpine:latest sh -c "apk --no-cache add openssl \ || docker run --rm -e DOMAIN=$(DOMAIN) --mount source=$(COMPOSE_PROJECT_NAME_NODE)_ssl-certs,target=/certs alpine:latest sh -c "apk --no-cache add openssl \
&& { [ -f /certs/${SSL_HOSTNAME}.key.pem ] || openssl genrsa -out /certs/${SSL_HOSTNAME}.key.pem 2048; } \ && { [ -f /certs/${DOMAIN}.key.pem ] || openssl genrsa -out /certs/${DOMAIN}.key.pem 2048; } \
&& openssl req -key /certs/${SSL_HOSTNAME}.key.pem -out /certs/${SSL_HOSTNAME}.crt.pem -addext extendedKeyUsage=serverAuth -addext subjectAltName=DNS:${SSL_HOSTNAME} -subj \"/C=/ST=/L=/O=/CN=${SSL_HOSTNAME}\" -x509 -days 365" && openssl req -key /certs/${DOMAIN}.key.pem -out /certs/${DOMAIN}.crt.pem -addext extendedKeyUsage=serverAuth -addext subjectAltName=DNS:${DOMAIN} -subj \"/C=/ST=/L=/O=/CN=${DOMAIN}\" -x509 -days 365"

View File

@ -5,4 +5,3 @@ FABIO_CONSUL_HTTP_TOKEN=01234567-89AB-CDEF-0123-456789ABCDEF
FABIO_SERVICE_9998_TAGS=urlprefix-fabio.${APP_DOMAIN}/ FABIO_SERVICE_9998_TAGS=urlprefix-fabio.${APP_DOMAIN}/
PORTAINER_SERVICE_9000_TAGS=urlprefix-portainer.${APP_DOMAIN}/ PORTAINER_SERVICE_9000_TAGS=urlprefix-portainer.${APP_DOMAIN}/
REGISTRATOR_CONSUL_HTTP_TOKEN=01234567-89AB-CDEF-0123-456789ABCDEF REGISTRATOR_CONSUL_HTTP_TOKEN=01234567-89AB-CDEF-0123-456789ABCDEF
SSL_HOSTNAME=${APP_DOMAIN}

View File

@ -7,7 +7,7 @@ services:
- DOCKER_BUILD_DIR=docker/consul - DOCKER_BUILD_DIR=docker/consul
context: ../.. context: ../..
dockerfile: docker/consul/Dockerfile dockerfile: docker/consul/Dockerfile
image: ${DOCKER_REPOSITORY_INFRA_NODE}/consul:${DOCKER_IMAGE_TAG} image: ${DOCKER_REPOSITORY_NODE}/consul:${DOCKER_IMAGE_TAG}
environment: environment:
CONSUL_BIND_INTERFACE: '${DOCKER_HOST_IFACE}' CONSUL_BIND_INTERFACE: '${DOCKER_HOST_IFACE}'
CONSUL_CLIENT_INTERFACE: '${DOCKER_HOST_IFACE}' CONSUL_CLIENT_INTERFACE: '${DOCKER_HOST_IFACE}'
@ -38,7 +38,7 @@ services:
- consul:/consul/data - consul:/consul/data
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
fabio: fabio:
command: -registry.backend "consul" -registry.consul.addr "consul:8500" -registry.consul.token "$FABIO_CONSUL_HTTP_TOKEN" -proxy.addr ":80,:443;cs=local" -proxy.cs "cs=local;type=file;cert=/certs/${SSL_HOSTNAME}.crt.pem;key=/certs/${SSL_HOSTNAME}.key.pem" command: -registry.backend "consul" -registry.consul.addr "consul:8500" -registry.consul.token "$FABIO_CONSUL_HTTP_TOKEN" -proxy.addr ":80,:443;cs=local" -proxy.cs "cs=local;type=file;cert=/certs/${DOMAIN}.crt.pem;key=/certs/${DOMAIN}.key.pem"
depends_on: depends_on:
- consul - consul
extra_hosts: extra_hosts:
@ -93,7 +93,7 @@ services:
extra_hosts: extra_hosts:
- consul:${DOCKER_HOST_INET} - consul:${DOCKER_HOST_INET}
hostname: ${HOSTNAME} hostname: ${HOSTNAME}
image: ${DOCKER_REPOSITORY_INFRA_NODE}/registrator:${DOCKER_IMAGE_TAG} image: ${DOCKER_REPOSITORY_NODE}/registrator:${DOCKER_IMAGE_TAG}
network_mode: host network_mode: host
restart: always restart: always
volumes: volumes:

View File

@ -1,2 +1,4 @@
services ?= elastic memcached mysql rabbitmq redis services ?= elastic memcached mysql rabbitmq redis
# target services: Fire stack-service-up
services: stack-services-up; services: stack-services-up;