split make files in myos project and install files in yaip project
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
# target ansible: Fire docker-build-ansible, Call ansible ANSIBLE_ARGS ARGS or ansible-run target
|
||||
.PHONY: ansible
|
||||
ansible: $(if $(ANSIBLE_DOCKER_RUN),docker-build-ansible,install-ansible)
|
||||
$(call ansible,$(ANSIBLE_ARGS) $(ARGS))
|
||||
|
||||
# target ansible-playbook: Call ansible-playbook ANSIBLE_ARGS ARGS
|
||||
.PHONY: ansible-playbook
|
||||
ansible-playbook: $(if $(ANSIBLE_DOCKER_RUN),docker-build-ansible,install-ansible)
|
||||
$(call ansible-playbook,$(ANSIBLE_ARGS) $(ARGS))
|
||||
|
||||
# target ansible-pull: Call ansible-pull ANSIBLE_GIT_REPOSITORY ANSIBLE_PLAYBOOK
|
||||
.PHONY: ansible-pull
|
||||
ansible-pull: install-ansible
|
||||
$(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 ssh-get-PrivateIpAddress-% for SERVER_NAME, Call ssh-exec make ansible-pull DOCKER_IMAGE_TAG
|
||||
.PHONY: ansible-pull@%
|
||||
ansible-pull@%: ssh-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))
|
||||
|
||||
# target ansible-run: Fire ssh-add ansible-run-localhost
|
||||
.PHONY: ansible-run
|
||||
ansible-run: ansible-run-localhost
|
||||
|
||||
# target ansible-run-%: Fire docker-build-ansible, Call ansible-playbook ANSIBLE_PLAYBOOK
|
||||
.PHONY: ansible-run-%
|
||||
ansible-run-%: $(if $(ANSIBLE_DOCKER_RUN),docker-build-ansible,install-ansible)
|
||||
$(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))
|
||||
|
||||
# target ansible-tests: Fire ssh-add ansible-tests-localhost
|
||||
.PHONY: ansible-tests
|
||||
ansible-tests: ansible-tests-localhost
|
||||
|
||||
# target ansible-tests-%: Fire docker-run-% with ANSIBLE_PLAYBOOK ansible/roles/*/tests/playbook.yml
|
||||
.PHONY: ansible-tests-%
|
||||
ansible-tests-%: ANSIBLE_PLAYBOOK := $(wildcard ansible/roles/*/tests/playbook.yml)
|
||||
ansible-tests-%: ansible-run-%;
|
||||
@@ -0,0 +1,61 @@
|
||||
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)
|
||||
ANSIBLE_AWS_DEFAULT_REGION ?= $(AWS_DEFAULT_REGION)
|
||||
ANSIBLE_AWS_SECRET_ACCESS_KEY ?= $(AWS_SECRET_ACCESS_KEY)
|
||||
ANSIBLE_CONFIG ?= ansible/ansible.cfg
|
||||
ANSIBLE_DISKS_NFS_DISK ?= $(NFS_DISK)
|
||||
ANSIBLE_DISKS_NFS_OPTIONS ?= $(NFS_OPTIONS)
|
||||
ANSIBLE_DISKS_NFS_PATH ?= $(NFS_PATH)
|
||||
# running ansible in docker requires sshd running on localhost,
|
||||
# to allow ansible to escape docker and apply changes to localhost
|
||||
ANSIBLE_DOCKER ?= false
|
||||
ANSIBLE_DOCKER_RUN ?= $(if $(filter-out false False FALSE,$(ANSIBLE_DOCKER)),$(ANSIBLE_DOCKER))
|
||||
ANSIBLE_DOCKER_IMAGE_TAG ?= $(DOCKER_IMAGE_TAG)
|
||||
ANSIBLE_DOCKER_REGISTRY ?= $(DOCKER_REGISTRY)
|
||||
ANSIBLE_EXTRA_VARS ?= target=localhost
|
||||
ANSIBLE_GIT_DIRECTORY ?= /dns/$(subst $(space),/,$(strip $(call reverse,$(subst ., ,$(APP_REPOSITORY_HOST)))))/$(APP_REPOSITORY_PATH)
|
||||
ANSIBLE_GIT_KEY_FILE ?= $(if $(ANSIBLE_SSH_PRIVATE_KEYS),~$(ANSIBLE_USERNAME)/.ssh/$(notdir $(firstword $(ANSIBLE_SSH_PRIVATE_KEYS))))
|
||||
ANSIBLE_GIT_REPOSITORY ?= $(GIT_REPOSITORY)
|
||||
ANSIBLE_GIT_VERSION ?= $(BRANCH)
|
||||
ANSIBLE_INVENTORY ?= ansible/inventories
|
||||
ANSIBLE_MYOS ?= $(ANSIBLE_GIT_DIRECTORY)
|
||||
ANSIBLE_PLAYBOOK ?= ansible/playbook.yml
|
||||
ANSIBLE_SSH_AUTHORIZED_KEYS ?= $(strip $(SSH_AUTHORIZED_KEYS))
|
||||
ANSIBLE_SSH_BASTION_HOSTNAME ?= $(firstword $(SSH_BASTION_HOSTNAME))
|
||||
ANSIBLE_SSH_BASTION_USERNAME ?= $(firstword $(SSH_BASTION_USERNAME))
|
||||
ANSIBLE_SSH_PRIVATE_IP_RANGE ?= $(strip $(SSH_PRIVATE_IP_RANGE))
|
||||
ANSIBLE_SSH_PRIVATE_KEYS ?= $(if $(ANSIBLE_SSH_PRIVATE_KEYS_ENABLE),$(strip $(SSH_PRIVATE_KEYS)))
|
||||
ANSIBLE_SSH_PRIVATE_KEYS_ENABLE ?=
|
||||
ANSIBLE_SSH_PUBLIC_HOSTS ?= $(strip $(SSH_PUBLIC_HOSTS))
|
||||
ANSIBLE_SSH_USERNAME ?= $(firstword $(SSH_USER))
|
||||
ANSIBLE_SERVER_NAME ?= $(SERVER_NAME)
|
||||
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
|
||||
|
||||
# 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)/)
|
||||
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)/)
|
||||
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))
|
||||
endef
|
||||
# function ansible-user-add-groups: Call ansible to add user 1 in groups 2
|
||||
define ansible-user-add-groups
|
||||
$(call INFO,ansible-user-add-groups,$(1)$(comma) $(2))
|
||||
$(if $(ANSIBLE_DOCKER_RUN),$(call make,docker-build-ansible),$(call make,install-ansible))
|
||||
$(call ansible,-b -m user -a 'name=$(1) groups=$(2) append=yes' localhost)
|
||||
endef
|
||||
@@ -0,0 +1,8 @@
|
||||
##
|
||||
# INSTALL
|
||||
|
||||
# target install-ansible; Install ansible on local host
|
||||
.PHONY: install-ansible
|
||||
install-ansible:
|
||||
$(if $(shell type -p ansible),,$(RUN) $(INSTALL) ansible)
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
# target aws: Fire docker-build-aws, Call aws ARGS
|
||||
.PHONY: aws
|
||||
aws: $(if $(DOCKER_RUN),docker-build-aws)
|
||||
$(call aws,$(ARGS))
|
||||
|
||||
# target aws-deploy: Call aws deploy create-deployment with application-name CODEDEPLOY_APP_NAME
|
||||
.PHONY: aws-deploy
|
||||
aws-deploy:
|
||||
$(call aws,deploy create-deployment \
|
||||
--application-name $(CODEDEPLOY_APP_NAME) \
|
||||
--deployment-config-name $(CODEDEPLOY_DEPLOYMENT_CONFIG) \
|
||||
--deployment-group-name $(CODEDEPLOY_DEPLOYMENT_GROUP) \
|
||||
--description "$(CODEDEPLOY_DESCRIPTION)" \
|
||||
--github-location repository=$(CODEDEPLOY_GITHUB_REPO)$(comma)commitId=$(CODEDEPLOY_GITHUB_COMMIT_ID))
|
||||
|
||||
# target aws-docker-login: Fire aws-ecr-get-login
|
||||
.PHONY: aws-docker-login
|
||||
aws-docker-login: aws-ecr-get-login
|
||||
|
||||
# target aws-ecr-get-login: Call aws ecr get-login
|
||||
.PHONY: aws-ecr-get-login
|
||||
aws-ecr-get-login:
|
||||
$(eval IGNORE_DRYRUN := true)
|
||||
$(eval docker_login := $(shell $(call aws,ecr get-login --no-include-email --region $(AWS_DEFAULT_REGION))))
|
||||
$(eval IGNORE_DRYRUN := FALSE)
|
||||
$(RUN) $(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-%
|
||||
aws-iam-create-role-%: user docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := true)
|
||||
$(eval json := $(shell $(call exec,sh -c 'envsubst < aws/policies/$*-trust.json')))
|
||||
$(eval IGNORE_DRYRUN := false)
|
||||
$(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-%
|
||||
aws-iam-put-role-policy-%: user docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := true)
|
||||
$(eval json := $(shell $(call exec,sh -c 'envsubst < aws/policies/$*.json')))
|
||||
$(eval IGNORE_DRYRUN := false)
|
||||
$(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
|
||||
aws-s3-check-upload: docker-build-aws aws-s3api-get-head-object-etag
|
||||
$(eval upload := true)
|
||||
$(eval IGNORE_DRYRUN := 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)))
|
||||
$(eval IGNORE_DRYRUN := 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
|
||||
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))
|
||||
|
||||
# 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
|
||||
aws-s3-etag-save: docker-build-aws aws-s3api-get-head-object-etag
|
||||
echo "etag: $(AWS_S3_KEY_ETAG)" >> $(PACKER_ISO_INFO)
|
||||
|
||||
# target aws-s3api-get-head-object-etag: Eval AWS_S3_KEY_ETAG, Echo 'ETag: AWS_S3_KEY_ETAG'
|
||||
.PHONY: aws-s3api-get-head-object-etag
|
||||
aws-s3api-get-head-object-etag: docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := 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 IGNORE_DRYRUN := false)
|
||||
echo ETag: $(AWS_S3_KEY_ETAG)
|
||||
|
||||
# target aws-s3api-get-head-object-lastmodified: Eval AWS_S3_KEY_DATE, Echo 'LastModified: AWS_S3_KEY_DATE'
|
||||
.PHONY: aws-s3api-get-head-object-lastmodified
|
||||
aws-s3api-get-head-object-lastmodified: docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := 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 IGNORE_DRYRUN := false)
|
||||
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
|
||||
aws-ec2-import-snapshot: user docker-build-aws aws-s3api-get-head-object-etag aws-s3api-get-head-object-lastmodified
|
||||
$(eval IGNORE_DRYRUN := true)
|
||||
$(eval json := $(shell $(call exec,sh -c 'envsubst < aws/import-snapshot.json')))
|
||||
$(eval IGNORE_DRYRUN := false)
|
||||
$(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)
|
||||
|
||||
# target aws-ec2-describe-import-snapshot-tasks-%: Call aws ec2 describe-import-snapshot-tasks with import-task-id %
|
||||
.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 $*)
|
||||
|
||||
# target aws-ec2-describe-import-snapshot-tasks: Call aws ec2 describe-import-snapshots-tasks
|
||||
.PHONY: aws-ec2-describe-import-snapshot-tasks
|
||||
aws-ec2-describe-import-snapshot-tasks: docker-build-aws
|
||||
$(call aws,ec2 describe-import-snapshot-tasks)
|
||||
|
||||
# target aws-ec2-describe-instances-PrivateIpAddress: Call aws ec2 describe-instances, Print list of PrivateIpAddress
|
||||
.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}'
|
||||
|
||||
# target aws-ec2-describe-instances-PrivateIpAddress-%: Call aws ec2 describe-instances, Print list of PrivateIpAddress for Name matching %
|
||||
.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}'
|
||||
|
||||
# target aws-ec2-get-instances-PrivateIpAddress: Eval AWS_INSTANCE_IP, Echo 'PrivateIpAddress: AWS_INSTANCE_IP'
|
||||
.PHONY: aws-ec2-get-instances-PrivateIpAddress
|
||||
aws-ec2-get-instances-PrivateIpAddress: docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := true)
|
||||
$(eval AWS_INSTANCE_IP := $(shell $(call aws,ec2 describe-instances --no-paginate --query 'Reservations[*].Instances[*].PrivateIpAddress' --output text) 2>/dev/null))
|
||||
$(eval IGNORE_DRYRUN := false)
|
||||
echo PrivateIpAddress: $(AWS_INSTANCE_IP)
|
||||
|
||||
# target aws-ec2-get-instances-PrivateIpAddress-%: Eval AWS_INSTANCE_IP with Name matching %, Echo 'PrivateIpAddress: AWS_INSTANCE_IP'
|
||||
.PHONY: aws-ec2-get-instances-PrivateIpAddress-%
|
||||
aws-ec2-get-instances-PrivateIpAddress-%:
|
||||
$(eval IGNORE_DRYRUN := 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 IGNORE_DRYRUN := false)
|
||||
echo PrivateIpAddress: $(AWS_INSTANCE_IP)
|
||||
|
||||
# target aws-ec2-get-import-snapshot-tasks-id: Fire aws-ec2-get-import-snapshot-tasks-id-% for 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)
|
||||
|
||||
# target aws-ec2-get-import-snapshot-tasks-id-%: Eval AWS_SNAP_IP with import-task-ids %, Echo 'SnapshotId: AWS_SNAP_IP'
|
||||
.PHONY: aws-ec2-get-import-snapshot-tasks-id-%
|
||||
aws-ec2-get-import-snapshot-tasks-id-%: docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := 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 IGNORE_DRYRUN := false)
|
||||
echo SnapshotId: $(AWS_SNAP_ID)
|
||||
|
||||
# target aws-ec2-get-import-snapshot-tasks-message-%: Eval AWS_SNAP_MESSAGE with import-task-ids %, Echo 'StatusMessage: AWS_SNAP_MESSAGE'
|
||||
.PHONY: aws-ec2-get-import-snapshot-tasks-message-%
|
||||
aws-ec2-get-import-snapshot-tasks-message-%: docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := 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 IGNORE_DRYRUN := false)
|
||||
echo StatusMessage: $(AWS_SNAP_MESSAGE)
|
||||
|
||||
# target aws-ec2-get-import-snapshot-tasks-progress-%: Eval AWS_SNAP_PROGRESS with import-task-ids %, Echo 'Progress: AWS_SNAP_PROGRESS'
|
||||
.PHONY: aws-ec2-get-import-snapshot-tasks-progress-%
|
||||
aws-ec2-get-import-snapshot-tasks-progress-%: docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := 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 IGNORE_DRYRUN := false)
|
||||
echo Progress: $(AWS_SNAP_PROGRESS)
|
||||
|
||||
# target aws-ec2-get-import-snapshot-tasks-size-%: Eval AWS_SNAP_SIZE with import-task-ids %, Echo 'DiskImageSize: AWS_SNAP_SIZE'
|
||||
.PHONY: aws-ec2-get-import-snapshot-tasks-size-%
|
||||
aws-ec2-get-import-snapshot-tasks-size-%: docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := 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 IGNORE_DRYRUN := false)
|
||||
echo DiskImageSize: $(AWS_SNAP_SIZE)
|
||||
|
||||
# target aws-ec2-get-import-snapshot-tasks-status-%: Eval AWS_SNAP_STATUS with import-task-ids %, Echo 'Status: AWS_SNAP_STATUS'
|
||||
.PHONY: aws-ec2-get-import-snapshot-tasks-status-%
|
||||
aws-ec2-get-import-snapshot-tasks-status-%: docker-build-aws
|
||||
$(eval IGNORE_DRYRUN := 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 IGNORE_DRYRUN := false)
|
||||
echo Status: $(AWS_SNAP_STATUS)
|
||||
|
||||
# target aws-ec2-wait-import-snapshot-tasks-status-completed: Fire aws-ec2-wait-import-snapshot-tasks-status-completed-% for 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)
|
||||
|
||||
# target aws-ec2-wait-import-snapshot-tasks-status-completed-%: Wait SnapshotTaskDetail.Status=completed for import-task-ids %
|
||||
.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')" ]; \
|
||||
do \
|
||||
count=$$(( $${count:-0}+1 )); \
|
||||
[ "$${count}" -eq 99 ] && exit 1; \
|
||||
sleep 10; \
|
||||
done
|
||||
|
||||
# target aws-ec2-wait-snapshot-completed-%: Call ec2 wait snapshot-completed with shapshot-ids %
|
||||
.PHONY: aws-ec2-wait-snapshot-completed-%
|
||||
aws-ec2-wait-snapshot-completed-%: docker-build-aws
|
||||
$(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
|
||||
aws-ec2-register-image: user docker-build-aws aws-ec2-get-import-snapshot-tasks-id
|
||||
$(eval IGNORE_DRYRUN := true)
|
||||
$(eval json := $(shell $(call exec,sh -c 'envsubst < aws/register-image-device-mappings.json')))
|
||||
$(eval IGNORE_DRYRUN := 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))
|
||||
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
|
||||
aws-ami: aws-s3-cp aws-ec2-import-snapshot
|
||||
$(call make,aws-ec2-wait-import-snapshot-tasks-status-completed,,AWS_TASK_ID)
|
||||
$(call make,aws-ec2-register-image,,AWS_TASK_ID)
|
||||
@@ -0,0 +1,23 @@
|
||||
AWS_ACCESS_KEY_ID := $(if $(AWS_CREDENTIALS),$(shell $(call conf,$(AWS_CREDENTIALS),$(or $(AWS_PROFILE),default),aws_access_key_id)))
|
||||
AWS_AMI_DESCRIPTION ?= $(AWS_SERVICE_VERSION)
|
||||
AWS_AMI_NAME ?= $(AWS_SERVICE_NAME)-$(AWS_S3_FILENAME)
|
||||
AWS_CREDENTIALS ?= $(wildcard $(HOME)/.aws/credentials)
|
||||
AWS_DEFAULT_REGION ?= eu-west-1
|
||||
AWS_DEFAULT_OUTPUT ?= text
|
||||
AWS_INSTANCE_ID ?= $(shell timeout 0.1 curl -s http://169.254.169.254/latest/meta-data/instance-id 2>/dev/null)
|
||||
AWS_VM_IMPORT_ROLE_NAME ?= vmimport
|
||||
AWS_S3_BUCKET ?= $(AWS_SERVICE_NAME)
|
||||
AWS_S3_FILENAME ?= $(PACKER_ISO_NAME)
|
||||
AWS_S3_KEY ?= $(PACKER_ISO_FILE)
|
||||
AWS_SECRET_ACCESS_KEY := $(if $(AWS_CREDENTIALS),$(shell $(call conf,$(AWS_CREDENTIALS),$(or $(AWS_PROFILE),default),aws_secret_access_key)))
|
||||
AWS_SERVICE_NAME ?= $(COMPOSE_SERVICE_NAME)
|
||||
AWS_SERVICE_VERSION ?= $(BUILD_DATE)-$(VERSION)
|
||||
AWS_SNAP_DESCRIPTION ?= $(AWS_SERVICE_NAME)-$(AWS_SERVICE_VERSION)-$(AWS_S3_FILENAME)
|
||||
CMDARGS += aws
|
||||
DOCKER_RUN_VOLUME += -v $(HOME)/.aws:/home/$(USER)/.aws
|
||||
ENV_VARS += AWS_ACCESS_KEY_ID AWS_AMI_DESCRIPTION AWS_AMI_NAME AWS_DEFAULT_OUTPUT AWS_DEFAULT_REGION AWS_INSTANCE_ID AWS_PROFILE AWS_S3_BUCKET AWS_S3_KEY AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_SNAP_DESCRIPTION AWS_SNAP_ID
|
||||
|
||||
# function aws: Call run aws with arg 1
|
||||
define aws
|
||||
$(RUN) $(call run,aws $(1),$(DOCKER_REPOSITORY)/)
|
||||
endef
|
||||
+10
-2
@@ -1,15 +1,23 @@
|
||||
##
|
||||
# COMMON
|
||||
|
||||
# target bootstrap: Update application files and start dockers
|
||||
# target bootstrap: Configure system
|
||||
# on local host
|
||||
.PHONY: bootstrap app-bootstrap
|
||||
bootstrap: bootstrap-app app-bootstrap ## Update application files and start dockers
|
||||
bootstrap: bootstrap-docker bootstrap-app app-bootstrap ## Configure system
|
||||
|
||||
# target bootstrap-app: Fire install-bin-git
|
||||
.PHONY: bootstrap-app
|
||||
bootstrap-app: install-bin-git
|
||||
|
||||
# target bootstrap-docker: Install and configure docker
|
||||
.PHONY: bootstrap-docker
|
||||
bootstrap-docker: install-bin-docker setup-docker-group setup-binfmt setup-nfsd setup-sysctl
|
||||
|
||||
# target bootstrap-stack: Call bootstrap target of each stack
|
||||
.PHONY: bootstrap-stack
|
||||
bootstrap-stack: docker-network $(foreach stack,$(STACK),bootstrap-stack-$(stack))
|
||||
|
||||
# target build: Build application docker images to run
|
||||
# on local host
|
||||
.PHONY: build
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CMDS += docker-run docker-run-%
|
||||
CMDARGS += docker-run docker-run-%
|
||||
COMPOSE_ARGS ?= --ansi auto
|
||||
COMPOSE_FILE ?= $(wildcard docker-compose.yml docker/docker-compose.yml $(foreach file,$(patsubst docker/docker-compose.%,%,$(basename $(wildcard docker/docker-compose.*.yml))),$(if $(filter true,$(COMPOSE_FILE_$(file)) $(COMPOSE_FILE_$(call UPPERCASE,$(file)))),docker/docker-compose.$(file).yml)))
|
||||
COMPOSE_FILE_$(ENV) ?= true
|
||||
@@ -27,7 +27,7 @@ DOCKER_BUILD_NO_CACHE ?= false
|
||||
DOCKER_BUILD_TARGET ?= $(if $(filter $(ENV),$(DOCKER_BUILD_TARGETS)),$(ENV),$(DOCKER_BUILD_TARGET_DEFAULT))
|
||||
DOCKER_BUILD_TARGET_DEFAULT ?= master
|
||||
DOCKER_BUILD_TARGETS ?= $(ENV_DEPLOY)
|
||||
DOCKER_BUILD_VARS ?= APP BRANCH COMPOSE_VERSION DOCKER_GID DOCKER_REPOSITORY GID GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME SYSTEM MACHINE SSH_BASTION_HOSTNAME SSH_BASTION_USERNAME SSH_PRIVATE_IP_RANGE SSH_PUBLIC_HOST_KEYS SSH_REMOTE_HOSTS UID USER VERSION
|
||||
DOCKER_BUILD_VARS ?= APP BRANCH COMPOSE_VERSION DOCKER_GID DOCKER_MACHINE DOCKER_REPOSITORY DOCKER_SYSTEM GID GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME SSH_BASTION_HOSTNAME SSH_BASTION_USERNAME SSH_PRIVATE_IP_RANGE SSH_PUBLIC_HOST_KEYS SSH_REMOTE_HOSTS UID USER VERSION
|
||||
DOCKER_COMPOSE ?= $(if $(DOCKER_RUN),docker/compose:$(COMPOSE_VERSION),$(or $(shell docker compose >/dev/null 2>&1 && printf 'docker compose\n'),docker-compose)) $(COMPOSE_ARGS)
|
||||
DOCKER_COMPOSE_DOWN_OPTIONS ?=
|
||||
DOCKER_COMPOSE_RUN_OPTIONS ?= --rm
|
||||
@@ -87,7 +87,7 @@ endef
|
||||
# function docker-compose-exec-sh: Run docker-compose-exec sh -c 'arg 2' in service 1
|
||||
define docker-compose-exec-sh
|
||||
$(call INFO,docker-compose-exec-sh,$(1)$(comma) $(2))
|
||||
$(if $(DOCKER_RUN),$(call docker-build,$(MYOS)/docker/compose,docker/compose:$(COMPOSE_VERSION)))
|
||||
$(if $(DOCKER_RUN),$(call docker-build,$(MYOS)/docker/compose,docker/compose:$(COMPOSE_VERSION)))
|
||||
$(if $(COMPOSE_FILE),$(call run,$(DOCKER_COMPOSE) $(patsubst %,-f %,$(COMPOSE_FILE)) -p $(if $(filter node,$(firstword $(subst /, ,$(STACK)))),$(NODE_COMPOSE_PROJECT_NAME),$(if $(filter User,$(firstword $(subst /, ,$(STACK)))),$(USER_COMPOSE_PROJECT_NAME),$(COMPOSE_PROJECT_NAME))) exec -T $(1) sh -c '$(2)'))
|
||||
endef
|
||||
# function docker-push: Push docker image
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ deploy-hook-ping-curl:
|
||||
## it runs ansible-pull on localhost to pull docker images from the registry
|
||||
## it tags and pushes docker images as latest to docker registry
|
||||
.PHONY: deploy-localhost
|
||||
deploy-localhost: myos-user build@$(ENV) ## Deploy application docker images
|
||||
deploy-localhost: myos-user build@$(ENV)
|
||||
$(call make,docker-login docker-tag docker-push)
|
||||
$(call make,myos-ansible-pull ANSIBLE_DOCKER_IMAGE_TAG=$(VERSION) ANSIBLE_TAGS=deploy,,APP MYOS_TAGS_JSON)
|
||||
$(call make,docker-tag-latest docker-push-latest)
|
||||
|
||||
@@ -133,6 +133,10 @@ docker-images-rm-%:
|
||||
docker-login: myos-user
|
||||
$(RUN) docker login
|
||||
|
||||
# target docker-network: Fire docker-network-create-% for DOCKER_NETWORK_PRIVATE and DOCKER_NETWORK_PUBLIC
|
||||
.PHONY: docker-network
|
||||
docker-network: docker-network-create-$(DOCKER_NETWORK_PRIVATE) docker-network-create-$(DOCKER_NETWORK_PUBLIC)
|
||||
|
||||
# target docker-network-create: Fire docker-network-create-% for DOCKER_NETWORK
|
||||
.PHONY: docker-network-create
|
||||
docker-network-create: docker-network-create-$(DOCKER_NETWORK)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CMDS += ssh-run
|
||||
CMDARGS += ssh-run
|
||||
COMPOSE_IGNORE_ORPHANS := true
|
||||
ENV_VARS += COMPOSE_IGNORE_ORPHANS MYOS_TAGS_JSON
|
||||
HOME ?= /home/$(USER)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
CMDARGS += openstack
|
||||
ENV_VARS += OS_AUTH_URL OS_TENANT_ID OS_TENANT_NAME OS_USERNAME OS_PASSWORD OS_REGION_NAME OS_USER_DOMAIN_NAME OS_PROJECT_DOMAIN_NAME
|
||||
ifneq ($(DEBUG),)
|
||||
OPENSTACK_ARGS += --debug
|
||||
endif
|
||||
ifneq ($(VERBOSE),)
|
||||
OPENSTACK_ARGS += -v
|
||||
endif
|
||||
|
||||
# function openstack: Call run openstack with arg 1
|
||||
define openstack
|
||||
$(call INFO,openstack,$(1))
|
||||
$(RUN) $(call run,openstack $(1),$(DOCKER_REPOSITORY)/)
|
||||
endef
|
||||
@@ -0,0 +1,9 @@
|
||||
# target openstack: Call openstack ARGS
|
||||
.PHONY: openstack
|
||||
openstack: docker-build-openstack
|
||||
$(call openstack,$(ARGS))
|
||||
|
||||
# target openstack-image-create: Call openstack image create PACKER_ISO_NAME with file PACKER_ISO_FILE
|
||||
.PHONY: openstack-image-create
|
||||
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)")
|
||||
@@ -0,0 +1,6 @@
|
||||
PACKER_ALPINE_ARCH ?= x86_64
|
||||
PACKER_ALPINE_RELEASE ?= 3.16.2
|
||||
PACKER_BUILD_VARS += alpine_arch alpine_release alpine_version
|
||||
alpine_arch ?= $(PACKER_ALPINE_ARCH)
|
||||
alpine_release ?= $(PACKER_ALPINE_RELEASE)
|
||||
alpine_version ?= $(subst $(eval) ,.,$(wordlist 1, 2, $(subst ., ,$(alpine_release))))
|
||||
@@ -0,0 +1,125 @@
|
||||
CMDARGS += packer
|
||||
DOCKER_RUN_OPTIONS_PACKER ?= -it -p $(PACKER_SSH_PORT):$(PACKER_SSH_PORT) -p $(PACKER_VNC_PORT):$(PACKER_VNC_PORT) -v $(SSH_DIR):$(SSH_DIR)
|
||||
ENV_VARS += PACKER_CACHE_DIR PACKER_KEY_INTERVAL PACKER_LOG
|
||||
KVM_GID ?= $(call gid,kvm)
|
||||
PACKER_ARCH ?= $(PACKER_ALPINE_ARCH)
|
||||
PACKER_BOOT_WAIT ?= 24s
|
||||
PACKER_BUILD_ARGS ?= -on-error=cleanup $(foreach var,$(PACKER_BUILD_VARS),$(if $($(var)),-var $(var)='$($(var))'))
|
||||
PACKER_BUILD_VARS += accelerator boot_wait hostname iso_name iso_size nameserver output password pause_before qemuargs ssh_timeout template username
|
||||
PACKER_BUILD_VARS += ansible_extra_vars ansible_user ansible_verbose
|
||||
PACKER_CACHE_DIR ?= build/cache
|
||||
PACKER_HOSTNAME ?= $(PACKER_TEMPLATE)
|
||||
PACKER_ISO_DATE ?= $(shell stat -c %y $(PACKER_ISO_FILE) 2>/dev/null)
|
||||
PACKER_ISO_FILES ?= $(wildcard build/iso/*/*/*.iso)
|
||||
PACKER_ISO_FILE = $(PACKER_OUTPUT)/$(PACKER_ISO_NAME).iso
|
||||
PACKER_ISO_INFO = $(PACKER_OUTPUT)/$(PACKER_ISO_NAME).nfo
|
||||
PACKER_ISO_NAME = $(PACKER_TEMPLATE)-$(PACKER_RELEASE)-$(PACKER_ARCH)
|
||||
PACKER_ISO_SIZE ?= 1024
|
||||
PACKER_KEY_INTERVAL ?= 11ms
|
||||
PACKER_LOG ?= 1
|
||||
PACKER_NAMESERVER ?= 1.1.1.1
|
||||
PACKER_OUTPUT ?= build/iso/$(ENV)/$(PACKER_TEMPLATE)/$(PACKER_RELEASE)-$(PACKER_ARCH)
|
||||
PACKER_PASSWORD ?= $(PACKER_TEMPLATE)
|
||||
PACKER_PAUSE_BEFORE ?= 24s
|
||||
PACKER_QEMU_ACCELERATOR ?= kvm
|
||||
PACKER_QEMU_ARCH ?= $(PACKER_ARCH)
|
||||
PACKER_QEMU_ARGS ?= -machine type=pc,accel=$(PACKER_QEMU_ACCELERATOR) -device virtio-rng-pci,rng=rng0,bus=pci.0,addr=0x7 -object rng-random,filename=/dev/urandom,id=rng0
|
||||
PACKER_RELEASE ?= $(PACKER_ALPINE_RELEASE)
|
||||
PACKER_SSH_ADDRESS ?= $(if $(ssh_bind_address),$(ssh_bind_address),0.0.0.0)
|
||||
PACKER_SSH_PORT ?= $(if $(ssh_port_max),$(ssh_port_max),2222)
|
||||
PACKER_SSH_TIMEOUT ?= 42s
|
||||
PACKER_TEMPLATES ?= $(wildcard packer/*/*.json packer/*/*.pkr.hcl)
|
||||
PACKER_TEMPLATE ?= alpine
|
||||
PACKER_USERNAME ?= root
|
||||
PACKER_VNC_PORT ?= $(if $(vnc_port_max),$(vnc_port_max),5900)
|
||||
PACKER_VNC_ADDRESS ?= $(if $(vnc_bind_address),$(vnc_bind_address),0.0.0.0)
|
||||
ifneq ($(DEBUG),)
|
||||
PACKER_BUILD_ARGS += -debug
|
||||
endif
|
||||
ifeq ($(FORCE), true)
|
||||
PACKER_BUILD_ARGS += -force
|
||||
endif
|
||||
ifeq ($(ENV), local)
|
||||
PACKER_BUILD_ARGS += -var ssh_port_max=$(PACKER_SSH_PORT) -var vnc_port_max=$(PACKER_VNC_PORT) -var vnc_bind_address=$(PACKER_VNC_ADDRESS)
|
||||
endif
|
||||
|
||||
accelerator ?= $(PACKER_QEMU_ACCELERATOR)
|
||||
ansible_extra_vars ?= $(patsubst target=%,target=default,$(ANSIBLE_EXTRA_VARS))
|
||||
ansible_user ?= $(PACKER_USERNAME)
|
||||
ansible_verbose ?= $(ANSIBLE_VERBOSE)
|
||||
boot_wait ?= $(PACKER_BOOT_WAIT)
|
||||
hostname ?= $(PACKER_HOSTNAME)
|
||||
iso_name ?= $(PACKER_ISO_NAME)
|
||||
iso_size ?= $(PACKER_ISO_SIZE)
|
||||
nameserver ?= $(PACKER_NAMESERVER)
|
||||
output ?= $(PACKER_OUTPUT)
|
||||
password ?= $(PACKER_PASSWORD)
|
||||
pause_before ?= $(PACKER_PAUSE_BEFORE)
|
||||
qemuargs ?= $(call arrays_of_dquoted_args, $(PACKER_QEMU_ARGS))
|
||||
ssh_timeout ?= $(PACKER_SSH_TIMEOUT)
|
||||
template ?= $(PACKER_TEMPLATE)
|
||||
username ?= $(PACKER_USERNAME)
|
||||
|
||||
ifneq ($(filter $(ENV),$(ENV_DEPLOY)),)
|
||||
ifeq ($(password), $(template))
|
||||
password := $(or $(shell pwgen -csy -r\' 64 1 2>/dev/null),$(shell date +%s | shasum -a 256 2>/dev/null | base64 | head -c 64))
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(SYSTEM),Darwin)
|
||||
ifneq ($(DOCKER), true)
|
||||
PACKER_QEMU_ACCELERATOR := hvf
|
||||
# PACKER_QEMU_ARGS += -cpu Penryn,vendor=GenuineIntel
|
||||
PACKER_QEMU_ARGS += -cpu host
|
||||
else
|
||||
PACKER_QEMU_ACCELERATOR := tcg
|
||||
PACKER_QEMU_ARGS += -cpu max,vendor=GenuineIntel,vmware-cpuid-freq=on,+invtsc,+aes,+vmx
|
||||
endif
|
||||
else ifeq ($(SYSTEM),Linux)
|
||||
DOCKER_RUN_OPTIONS_PACKER += $(if $(KVM_GID),--group-add $(KVM_GID)) --device /dev/kvm
|
||||
else ifeq ($(SYSTEM),Windows_NT)
|
||||
PACKER_QEMU_ACCELERATOR := hax
|
||||
endif
|
||||
|
||||
# function packer: Call run packer with arg 1
|
||||
## it needs an empty local ssh agent (ssh-add -D)
|
||||
## 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)/)
|
||||
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)/)
|
||||
endef
|
||||
|
||||
# function packer-build: Call packer build with arg 1, Add build infos to file PACKER_ISO_INFO
|
||||
define packer-build
|
||||
$(eval ANSIBLE_USERNAME := $(PACKER_USERNAME))
|
||||
$(eval PACKER_TEMPLATE := $(notdir $(basename $(basename $(1)))))
|
||||
echo Building $(PACKER_ISO_FILE)
|
||||
$(call packer,build $(PACKER_BUILD_ARGS) $(1))
|
||||
echo 'aws_id: $(ANSIBLE_AWS_ACCESS_KEY_ID)' > $(PACKER_ISO_INFO)
|
||||
echo 'aws_key: $(ANSIBLE_AWS_SECRET_ACCESS_KEY)' >> $(PACKER_ISO_INFO)
|
||||
echo 'aws_region: $(ANSIBLE_AWS_DEFAULT_REGION)' >> $(PACKER_ISO_INFO)
|
||||
echo 'dns: $(nameserver)' >> $(PACKER_ISO_INFO)
|
||||
echo 'docker_image_tag: $(ANSIBLE_DOCKER_IMAGE_TAG)' >> $(PACKER_ISO_INFO)
|
||||
echo 'docker_registry: $(ANSIBLE_DOCKER_REGISTRY)' >> $(PACKER_ISO_INFO)
|
||||
echo 'env: $(ENV)' >> $(PACKER_ISO_INFO)
|
||||
echo 'file: $(PACKER_ISO_FILE)' >> $(PACKER_ISO_INFO)
|
||||
echo 'git_branch: $(ANSIBLE_GIT_VERSION)' >> $(PACKER_ISO_INFO)
|
||||
echo 'git_repository: $(ANSIBLE_GIT_REPOSITORY)' >> $(PACKER_ISO_INFO)
|
||||
echo 'git_version: $(VERSION)' >> $(PACKER_ISO_INFO)
|
||||
echo 'host: $(hostname)' >> $(PACKER_ISO_INFO)
|
||||
echo 'link: s3://$(AWS_S3_BUCKET)/$(AWS_S3_KEY)' >> $(PACKER_ISO_INFO)
|
||||
echo 'name: $(iso_name)' >> $(PACKER_ISO_INFO)
|
||||
echo 'nfs_disk: $(ANSIBLE_DISKS_NFS_DISK)' >> $(PACKER_ISO_INFO)
|
||||
echo 'nfs_path: $(ANSIBLE_DISKS_NFS_PATH)' >> $(PACKER_ISO_INFO)
|
||||
echo 'pass: $(password)' >> $(PACKER_ISO_INFO)
|
||||
echo 'size: $(iso_size)' >> $(PACKER_ISO_INFO)
|
||||
echo 'ssh_key: $(ANSIBLE_SSH_PRIVATE_KEYS)' >> $(PACKER_ISO_INFO)
|
||||
echo 'user: $(username)' >> $(PACKER_ISO_INFO)
|
||||
endef
|
||||
|
||||
arrays_of_dquoted_args = [ $(subst $(dquote) $(dquote),$(dquote)$(comma) $(dquote),$(subst $(dquote) $(dquote)-,$(dquote) ]$(comma) [ $(dquote)-,$(patsubst %,$(dquote)%$(dquote),$1))) ]
|
||||
@@ -0,0 +1,44 @@
|
||||
# target packer: Call packer ARGS
|
||||
.PHONY: packer
|
||||
packer:
|
||||
$(call packer,$(ARGS))
|
||||
|
||||
# target $(PACKER_ISO_FILE): Call packer-build target
|
||||
$(PACKER_ISO_FILE):
|
||||
$(eval FORCE := true)
|
||||
$(call make,packer-build,,FORCE)
|
||||
|
||||
# target packer-build: Fire packer-build-% for PACKER_TEMPLATE
|
||||
.PHONY: packer-build
|
||||
packer-build: packer-build-$(PACKER_TEMPLATE) ## Build default packer template
|
||||
|
||||
# target packer-build-templates: Fire PACKER_TEMPLATES
|
||||
.PHONY: packer-build-templates
|
||||
packer-build-templates: $(PACKER_TEMPLATES) ## Build all packer templates
|
||||
|
||||
# target $(PACKER_TEMPLATES): Call packer-build $@
|
||||
.PHONY: $(PACKER_TEMPLATES)
|
||||
ifeq ($(SYSTEM),Darwin)
|
||||
$(PACKER_TEMPLATES): DOCKER ?= false
|
||||
endif
|
||||
$(PACKER_TEMPLATES):
|
||||
$(call packer-build,$@)
|
||||
|
||||
# target packer-build-%: Call packer-build with file packer/*/%.json
|
||||
.PHONY: packer-build-%
|
||||
packer-build-%: docker-build-packer
|
||||
$(if $(wildcard packer/*/$*.json packer/*/$*.pkr.hcl),\
|
||||
$(call packer-build,$(firstword $(wildcard packer/*/$*.json packer/*/$*.pkr.hcl))))
|
||||
|
||||
# target packer-qemu: Fire packer-quemu-% for PACKER_ISO_NAME
|
||||
.PHONY: packer-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-%
|
||||
ifeq ($(SYSTEM),Darwin)
|
||||
packer-qemu-%: DOCKER ?= false
|
||||
endif
|
||||
packer-qemu-%: docker-build-packer ## Run iso image in qemu
|
||||
$(if $(wildcard $(PACKER_OUTPUT)/$*.iso),\
|
||||
$(call packer-qemu,$(wildcard $(PACKER_OUTPUT)/$*.iso)))
|
||||
@@ -39,7 +39,7 @@ release-update:
|
||||
|
||||
# target release-upgrade: Run migration targets to upgrade specific releases
|
||||
.PHONY: release-upgrade
|
||||
release-upgrade: $(patsubst %,release-upgrade-from-%,$(RELEASE_UPGRADE)) release-update ## Upgrade release
|
||||
release-upgrade: $(patsubst %,release-upgrade-from-%,$(RELEASE_UPGRADE)) release-update
|
||||
|
||||
# target release-upgrade-from-%: Sample of catch-all release migration target
|
||||
.PHONY: release-upgrade-from-%
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
CMDARGS += terraform
|
||||
|
||||
define terraform
|
||||
$(RUN) $(call run,terraform $(1),hashicorp/)
|
||||
endef
|
||||
@@ -0,0 +1,4 @@
|
||||
.PHONY: terraform
|
||||
terraform:
|
||||
$(call terraform,$(ARGS))
|
||||
|
||||
+2
-2
@@ -50,10 +50,10 @@ debug:
|
||||
.PHONY: debug-%
|
||||
debug-%: $(if $(DEBUG),context-%) ;
|
||||
|
||||
# target install-bin-%; Call ansible-run-localhost when bin % is not available
|
||||
# target install-bin-%; Install package % when bin % is not available
|
||||
.PHONY: install-bin-%
|
||||
install-bin-%:;
|
||||
$(if $(shell type $* 2>/dev/null),,$(call make,ansible-run-localhost))
|
||||
$(if $(shell type $* 2>/dev/null),,$(RUN) $(INSTALL) $*)
|
||||
|
||||
# target profile: Print timing informations
|
||||
.PHONY: profile
|
||||
|
||||
+7
-5
@@ -2,6 +2,7 @@ DOCKER_ENV_ARGS ?= $(docker_env_args)
|
||||
DOCKER_EXEC_OPTIONS ?=
|
||||
DOCKER_GID ?= $(call gid,docker)
|
||||
DOCKER_IMAGE ?= $(USER_DOCKER_IMAGE)
|
||||
DOCKER_MACHINE ?= $(shell docker run --rm alpine uname -m 2>/dev/null)
|
||||
DOCKER_NAME ?= $(USER_DOCKER_NAME)
|
||||
DOCKER_NETWORK ?= $(DOCKER_NETWORK_PRIVATE)
|
||||
DOCKER_NETWORK_PRIVATE ?= $(USER_COMPOSE_PROJECT_NAME)
|
||||
@@ -14,7 +15,8 @@ DOCKER_RUN_OPTIONS += --rm --network $(DOCKER_NETWORK)
|
||||
# DOCKER_RUN_VOLUME: options -v of `docker run` command to mount additionnal volumes
|
||||
DOCKER_RUN_VOLUME += -v /var/run/docker.sock:/var/run/docker.sock
|
||||
DOCKER_RUN_WORKDIR ?= -w $(PWD)
|
||||
ENV_VARS += DOCKER_NETWORK_PRIVATE DOCKER_NETWORK_PUBLIC NODE_COMPOSE_PROJECT_NAME NODE_COMPOSE_SERVICE_NAME NODE_DOCKER_REPOSITORY NODE_DOCKER_VOLUME USER_COMPOSE_PROJECT_NAME USER_COMPOSE_SERVICE_NAME USER_DOCKER_IMAGE USER_DOCKER_NAME USER_DOCKER_REPOSITORY USER_DOCKER_VOLUME
|
||||
DOCKER_SYSTEM ?= $(shell docker run --rm alpine uname -s 2>/dev/null)
|
||||
ENV_VARS += DOCKER_MACHINE DOCKER_NETWORK_PRIVATE DOCKER_NETWORK_PUBLIC DOCKER_SYSTEM NODE_COMPOSE_PROJECT_NAME NODE_COMPOSE_SERVICE_NAME NODE_DOCKER_REPOSITORY NODE_DOCKER_VOLUME USER_COMPOSE_PROJECT_NAME USER_COMPOSE_SERVICE_NAME USER_DOCKER_IMAGE USER_DOCKER_NAME USER_DOCKER_REPOSITORY USER_DOCKER_VOLUME
|
||||
NODE_COMPOSE_PROJECT_NAME ?= node
|
||||
NODE_COMPOSE_SERVICE_NAME ?= $(subst _,-,$(NODE_COMPOSE_PROJECT_NAME))
|
||||
NODE_DOCKER_REPOSITORY ?= $(subst -,/,$(subst _,/,$(NODE_COMPOSE_PROJECT_NAME)))
|
||||
@@ -28,10 +30,10 @@ USER_DOCKER_VOLUME ?= $(USER_COMPOSE_PROJECT_NAME)_myos
|
||||
|
||||
# https://github.com/docker/libnetwork/pull/2348
|
||||
ifeq ($(SYSTEM),Darwin)
|
||||
DOCKER_HOST_IFACE ?= $(shell docker run --rm -it --net=host alpine /sbin/ip -4 route list match 0/0 2>/dev/null |awk '{print $$5}' |awk '!seen[$$0]++' |head -1)
|
||||
DOCKER_HOST_INET4 ?= $(shell docker run --rm -it --net=host alpine /sbin/ip -4 addr show $(DOCKER_HOST_IFACE) 2>/dev/null |awk '$$1 == "inet" {sub(/\/.*/,"",$$2); print $$2}' |head -1)
|
||||
DOCKER_INTERNAL_DOCKER_GATEWAY ?= $(shell docker run --rm -it alpine getent hosts gateway.docker.internal 2>/dev/null |awk '{print $$1}' |head -1)
|
||||
DOCKER_INTERNAL_DOCKER_HOST ?= $(shell docker run --rm -it alpine getent hosts host.docker.internal 2>/dev/null |awk '{print $$1}' |head -1)
|
||||
DOCKER_HOST_IFACE ?= $(shell docker run --rm --net=host alpine /sbin/ip -4 route list match 0/0 2>/dev/null |awk '{print $$5}' |awk '!seen[$$0]++' |head -1)
|
||||
DOCKER_HOST_INET4 ?= $(shell docker run --rm --net=host alpine /sbin/ip -4 addr show $(DOCKER_HOST_IFACE) 2>/dev/null |awk '$$1 == "inet" {sub(/\/.*/,"",$$2); print $$2}' |head -1)
|
||||
DOCKER_INTERNAL_DOCKER_GATEWAY ?= $(shell docker run --rm alpine nslookup -type=A -timeout=1 gateway.docker.internal 2>/dev/null |awk 'found && /^Address:/ {print $$2; found=0}; /^Name:\tgateway.docker.internal/ {found=1};' |head -1)
|
||||
DOCKER_INTERNAL_DOCKER_HOST ?= $(or $(shell docker run --rm alpine nslookup -type=A -timeout=1 host.docker.internal 2>/dev/null |awk 'found && /^Address:/ {print $$2; found=0}; /^Name:\thost.docker.internal/ {found=1};' |head -1),$(shell docker run --rm alpine /sbin/ip -4 route list match 0/0 2>/dev/null |awk '{print $$3}' |awk '!seen[$$0]++' |head -1))
|
||||
else
|
||||
DOCKER_HOST_IFACE ?= $(shell /sbin/ip -4 route list match 0/0 2>/dev/null |awk '{print $$5}' |awk '!seen[$$0]++' |head -1)
|
||||
DOCKER_HOST_INET4 ?= $(shell /sbin/ip -4 addr show $(DOCKER_HOST_IFACE) 2>/dev/null |awk '$$1 == "inet" {sub(/\/.*/,"",$$2); print $$2}' |head -1)
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ CMD_APK_INSTALL ?= $(if $(shell type -p apk),apk --no-cache --up
|
||||
CMD_APK_REMOVE ?= $(if $(shell type -p apk),apk --no-cache del)
|
||||
CMD_APT_INSTALL ?= $(if $(shell type -p apt-get),apt-get update && apt-get -fy install)
|
||||
CMD_APT_REMOVE ?= $(if $(shell type -p apt-get),apt-get -fy remove)
|
||||
CMDS ?= app-%-run apps-install exec exec:% exec@% install-app run run:% run@%
|
||||
CMDARGS ?= app-%-run apps-install exec exec:% exec@% install-app run run:% run@%
|
||||
COLOR_BLUE ?= \033[01;34m
|
||||
COLOR_BROWN ?= \033[33m
|
||||
COLOR_CYAN ?= \033[36m
|
||||
@@ -53,7 +53,7 @@ ENV_ARGS ?= $(env_args)
|
||||
ENV_FILE ?= $(wildcard $(CONFIG)/$(ENV)/$(APP)/.env .env)
|
||||
ENV_LIST ?= $(shell ls .git/refs/heads/ 2>/dev/null)
|
||||
ENV_RESET ?= false
|
||||
ENV_VARS ?= APP BRANCH DOMAIN ENV HOME HOSTNAME GID GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME GROUP MACHINE MONOREPO MONOREPO_DIR SYSTEM TAG UID USER VERSION
|
||||
ENV_VARS ?= APP BRANCH DOMAIN ENV HOME HOSTNAME GID GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME GROUP MONOREPO MONOREPO_DIR TAG UID USER VERSION
|
||||
GID ?= $(shell id -g 2>/dev/null)
|
||||
GIDS ?= $(shell id -G 2>/dev/null)
|
||||
GIT_AUTHOR_EMAIL ?= $(or $(shell git config user.email 2>/dev/null),$(USER)@my.os)
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
# Accept arguments for CMDS targets and turn them into do-nothing targets
|
||||
ifneq ($(filter $(CMDS),$(firstword $(MAKECMDGOALS))),)
|
||||
# Accept arguments for CMDARGS targets and turn them into do-nothing targets
|
||||
ifneq ($(filter $(CMDARGS),$(firstword $(MAKECMDGOALS))),)
|
||||
ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
|
||||
ARGS := $(subst :,\:,$(ARGS))
|
||||
ARGS := $(subst &,\&,$(ARGS))
|
||||
|
||||
+13
-12
@@ -4,22 +4,23 @@
|
||||
# variable MAKE_DIR: Path of this file
|
||||
MAKE_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
|
||||
# variable MAKE_FILE: Name of this file
|
||||
MAKE_FILE := $(notdir $(lastword $(MAKEFILE_LIST)))
|
||||
MAKE_FILE := $(MAKE_DIR)/$(notdir $(lastword $(MAKEFILE_LIST)))
|
||||
# variable MAKE_FIRST: List of first files to load
|
||||
MAKE_FIRST := env.mk def.mk $(wildcard def.*.mk)
|
||||
MAKE_FIRST := $(MAKE_DIR)/env.mk $(MAKE_DIR)/def.mk $(wildcard $(MAKE_DIR)/def.*.mk)
|
||||
# variable MAKE_LATEST: List of latest files to load
|
||||
MAKE_LATEST := end.mk
|
||||
## it includes $(MAKE_DIR)/$(MAKE_FIRST)
|
||||
include $(wildcard $(patsubst %,$(MAKE_DIR)/%,$(MAKE_FIRST)))
|
||||
MAKE_LATEST := $(MAKE_DIR)/end.mk
|
||||
|
||||
## it includes $(MAKE_FIRST)
|
||||
include $(wildcard $(MAKE_FIRST))
|
||||
## it includes $(MAKE_DIR)/*/def.mk $(MAKE_DIR)/*/def.*.mk
|
||||
include $(foreach subdir,$(MAKE_SUBDIRS),$(wildcard $(MAKE_DIR)/$(subdir)/def.mk $(MAKE_DIR)/$(subdir)/def.*.mk))
|
||||
## it includes def.mk def.*.mk */def.mk */def.*.mk
|
||||
include $(wildcard def.mk def.*.mk) $(filter-out $(wildcard $(MAKE_DIR)/*.mk),$(wildcard */def.mk */def.*.mk))
|
||||
## it includes def.mk def.*.mk */def.mk */def.*.mk if not myos nor monorepo
|
||||
include $(if $(filter-out . myos,$(MYOS)),$(wildcard def.mk def.*.mk */def.mk */def.*.mk))
|
||||
## it includes $(MAKE_DIR)/*.mk
|
||||
include $(filter-out $(wildcard $(patsubst %,$(MAKE_DIR)/%,$(MAKE_FILE) $(MAKE_FIRST) $(MAKE_LATEST))),$(wildcard $(MAKE_DIR)/*.mk))
|
||||
include $(filter-out $(wildcard $(MAKE_FILE) $(MAKE_FIRST) $(MAKE_LATEST)),$(wildcard $(MAKE_DIR)/*.mk))
|
||||
## it includes $(MAKE_DIR)/*/*.mk
|
||||
include $(foreach subdir,$(MAKE_SUBDIRS),$(filter-out $(wildcard $(MAKE_DIR)/$(subdir)/def.mk $(MAKE_DIR)/$(subdir)/def.*.mk),$(wildcard $(MAKE_DIR)/$(subdir)/*.mk)))
|
||||
## it includes *.mk */*.mk
|
||||
include $(filter-out $(wildcard def.mk def.*.mk),$(wildcard *.mk)) $(filter-out $(wildcard $(MAKE_DIR)/*.mk */def.mk */def.*.mk),$(wildcard */*.mk))
|
||||
## it includes $(MAKE_DIR)/$(MAKE_LATEST)
|
||||
include $(wildcard $(patsubst %,$(MAKE_DIR)/%,$(MAKE_LATEST)))
|
||||
## it includes *.mk */*.mk if not myos nor monorepo, stack/*.mk if myos
|
||||
include $(if $(filter-out myos,$(MYOS)),$(if $(filter-out .,$(MYOS)),$(filter-out $(wildcard def.mk def.*.mk */def.mk */def.*.mk),$(wildcard *.mk */*.mk)),$(wildcard stack/*.mk)))
|
||||
## it includes $(MAKE_LATEST)
|
||||
include $(wildcard $(MAKE_LATEST))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
CMDS += copy master-tag release release-check release-create release-finish subrepo-push subrepo-update
|
||||
CMDARGS += copy master-tag release release-check release-create release-finish subrepo-push subrepo-update
|
||||
CONTEXT += APPS DOMAIN RELEASE
|
||||
DIRS ?= $(CONFIG) $(MAKE_DIR) $(SHARED)
|
||||
RELEASE_UPGRADE ?= $(filter v%, $(shell git tag -l 2>/dev/null |sort -V |awk '/$(RELEASE)/,0'))
|
||||
|
||||
Reference in New Issue
Block a user