Skip to content

Commit

Permalink
[Sensu Go] Init (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
greedybro authored Sep 18, 2019
1 parent f9f5ac6 commit a36a8b1
Show file tree
Hide file tree
Showing 38 changed files with 2,280 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitsplit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ splits:
# target: https://${GITSPLIT_GITHUB_API_TOKEN}@github.com/manala/ansible-role-rtail.git
- prefix: manala.sensu
target: https://${GITSPLIT_GITHUB_API_TOKEN}@github.com/manala/ansible-role-sensu.git
- prefix: manala.sensu
target: https://${GITSPLIT_GITHUB_API_TOKEN}@github.com/manala/ansible-role-sensu_go.git
- prefix: manala.shorewall
target: https://${GITSPLIT_GITHUB_API_TOKEN}@github.com/manala/ansible-role-shorewall.git
- prefix: manala.skeleton
Expand Down
2 changes: 2 additions & 0 deletions manala.sensu_go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.cache/
.env
267 changes: 267 additions & 0 deletions manala.sensu_go/.manala/make/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
.PHONY: sh update lint test

##########
# Manala #
##########

MANALA_MAKE_DIR := $(abspath $(patsubst %/Makefile,%,$(lastword $(MAKEFILE_LIST))))

include \
$(MANALA_MAKE_DIR)/Makefile.manala \
$(MANALA_MAKE_DIR)/Makefile.docker \
$(MANALA_MAKE_DIR)/Makefile.host \
$(MANALA_MAKE_DIR)/Makefile.travis

-include \
$(MANALA_CURRENT_DIR)/../.env \
$(MANALA_CURRENT_DIR)/.env

MANALA_VERBOSE := $(if $(VERBOSE),$(VERBOSE),$(MANALA_VERBOSE))

########
# Role #
########

ROLE_DIR := $(MANALA_CURRENT_DIR)
ROLE_TESTS_DIR := $(ROLE_DIR)/tests

################
# Distribution #
################

DISTRIBUTION_ID = $(call list_split_first,.,$(DISTRIBUTION))
DISTRIBUTION_RELEASE = $(call list_split_last,.,$(DISTRIBUTION))

##########
# Docker #
##########

MANALA_DOCKER_IMAGE = manala/test-ansible
MANALA_DOCKER_IMAGE_TAG = $(if $(ANSIBLE_VERSION),$(ANSIBLE_VERSION)-)$(DISTRIBUTION)
MANALA_DOCKER_MOUNT_DIR = $(if $(ROLE_MOUNT_DIR),$(ROLE_MOUNT_DIR),/srv/role)
MANALA_DOCKER_HOST = $(ROLE).$(DISTRIBUTION).test
MANALA_DOCKER_RUN_OPTIONS = --privileged
MANALA_DOCKER_VOLUMES = \
$(ROLE_DIR):/etc/ansible/roles/$(ROLE) \
$(if $(CACHE_DIR), \
$(call if_in,$(DISTRIBUTION_ID),debian ubuntu, \
$(CACHE_DIR)/$(DISTRIBUTION_ID)/$(DISTRIBUTION_RELEASE)/apt/archives:/var/cache/apt/archives \
$(CACHE_DIR)/$(DISTRIBUTION_ID)/$(DISTRIBUTION_RELEASE)/apt/lists:/var/lib/apt/lists \
) \
)
MANALA_DOCKER_ENV = \
USER_ID=$(MANALA_USER_ID) \
GROUP_ID=$(MANALA_GROUP_ID) \
MANALA_HOST=test \
MANALA_VERBOSE=$(MANALA_VERBOSE) \
DISTRIBUTION=$(DISTRIBUTION) \
DISTRIBUTION_ID=$(DISTRIBUTION_ID) \
DISTRIBUTION_RELEASE=$(DISTRIBUTION_RELEASE) \
ANSIBLE_BECOME_FLAGS="$(call escape_spaces,-H -S -n -E)" \
ANSIBLE_RETRY_FILES_ENABLED=0 \
ANSIBLE_FORCE_COLOR=1

######
# Sh #
######

MANALA_HELP += $(call if_host,local,$(SH_HELP)\n)

SH_HELP = \
$(call help_section,Test host shell)

sh: .fail_if_host_not(local)
$(call fail_if_not,$(DISTRIBUTION),DISTRIBUTION is empty or not set)
$(call if_in,$(DISTRIBUTION),$(ROLE_DISTRIBUTIONS), \
$(call docker_shell), \
$(call log_warning,Shell on \"$(DISTRIBUTION)\" is not supported) \
)

SH_HELP += $(call if_in,debian.wheezy,$(ROLE_DISTRIBUTIONS),$(call help,sh.debian.wheezy, Open shell on test host - Debian Wheezy))
sh.debian.wheezy: DISTRIBUTION = debian.wheezy
sh.debian.wheezy: sh

SH_HELP += $(call if_in,debian.jessie,$(ROLE_DISTRIBUTIONS),$(call help,sh.debian.jessie, Open shell on test host - Debian Jessie))
sh.debian.jessie: DISTRIBUTION = debian.jessie
sh.debian.jessie: sh

SH_HELP += $(call if_in,debian.stretch,$(ROLE_DISTRIBUTIONS),$(call help,sh.debian.stretch,Open shell on test host - Debian Stretch))
sh.debian.stretch: DISTRIBUTION = debian.stretch
sh.debian.stretch: sh

SH_HELP += $(call if_in,debian.buster,$(ROLE_DISTRIBUTIONS),$(call help,sh.debian.buster, Open shell on test host - Debian Buster))
sh.debian.buster: DISTRIBUTION = debian.buster
sh.debian.buster: sh

SH_HELP += $(call if_in,centos.7,$(ROLE_DISTRIBUTIONS),$(call help,sh.centos.7, Open shell on test host - CentOS 7))
sh.centos.7: DISTRIBUTION = centos.7
sh.centos.7: sh

SH_HELP += $(call if_in,ubuntu.xenial,$(ROLE_DISTRIBUTIONS),$(call help,sh.ubuntu.xenial, Open shell on test host - Ubuntu Xenial))
sh.ubuntu.xenial: DISTRIBUTION = ubuntu.xenial
sh.ubuntu.xenial: sh

##########
# Update #
##########

MANALA_HELP += $(call if_host,local,$(UPDATE_HELP)\n)

UPDATE_HELP = \
$(call help_section,Test host update) \
$(call help,update, Update test hosts across distributions)

update: .fail_if_host_not(local)
$(call list_loop,DISTRIBUTION,$(if $(DISTRIBUTIONS),$(DISTRIBUTIONS),$(ROLE_DISTRIBUTIONS)), \
$$(call if_in,$$(DISTRIBUTION),$$(ROLE_DISTRIBUTIONS), \
$$(call log,Update \"$$(DISTRIBUTION)\") ; \
$$(call docker_pull), \
$$(call log_warning,Update \"$$(DISTRIBUTION)\" is not supported) \
) \
)

UPDATE_HELP += $(call if_in,debian.wheezy,$(ROLE_DISTRIBUTIONS),$(call help,update.debian.wheezy, Update test host - Debian Wheezy))
update.debian.wheezy: DISTRIBUTIONS = debian.wheezy
update.debian.wheezy: update

UPDATE_HELP += $(call if_in,debian.jessie,$(ROLE_DISTRIBUTIONS),$(call help,update.debian.jessie, Update test host - Debian Jessie))
update.debian.jessie: DISTRIBUTIONS = debian.jessie
update.debian.jessie: update

UPDATE_HELP += $(call if_in,debian.stretch,$(ROLE_DISTRIBUTIONS),$(call help,update.debian.stretch,Update test host - Debian Stretch))
update.debian.stretch: DISTRIBUTIONS = debian.stretch
update.debian.stretch: update

UPDATE_HELP += $(call if_in,debian.buster,$(ROLE_DISTRIBUTIONS),$(call help,update.debian.buster, Update test host - Debian Buster))
update.debian.buster: DISTRIBUTIONS = debian.buster
update.debian.buster: update

UPDATE_HELP += $(call if_in,centos.7,$(ROLE_DISTRIBUTIONS),$(call help,update.centos.7, Update test host - CentOS 7))
update.centos.7: DISTRIBUTIONS = centos.7
update.centos.7: update

UPDATE_HELP += $(call if_in,ubuntu.xenial,$(ROLE_DISTRIBUTIONS),$(call help,update.ubuntu.xenial, Update test host - Ubuntu Xenial))
update.ubuntu.xenial: DISTRIBUTIONS = ubuntu.xenial
update.ubuntu.xenial: update

########
# Lint #
########

MANALA_HELP += $(call if_host,local,$(LINT_HELP_LOCAL)\n,$(LINT_HELP_TEST)\n)

LINT_HELP = $(call help_section,Lint)
LINT_HELP_LOCAL = $(LINT_HELP) \
$(call help,lint, Lint role across distributions)
LINT_HELP_TEST = $(LINT_HELP) \
$(call help,lint,Lint role)

lint: .host_switch(lint)

lint@local: .fail_if_host_not(local)
$(call list_loop,DISTRIBUTION,$(if $(DISTRIBUTIONS),$(DISTRIBUTIONS),$(ROLE_DISTRIBUTIONS)), \
$$(call if_in,$$(DISTRIBUTION),$$(ROLE_DISTRIBUTIONS), \
$$(call log,Lint \"$$(ROLE)\" on \"$$(DISTRIBUTION)\") ; \
$$(call docker_make,lint@test), \
$$(call log_warning,Lint \"$$(ROLE)\" on \"$$(DISTRIBUTION)\" is not supported) \
) \
)

lint@test: .fail_if_host_not(test)
ansible-lint --force-color -v $(ROLE_DIR)

LINT_HELP_LOCAL += $(call if_in,debian.wheezy,$(ROLE_DISTRIBUTIONS),$(call help,lint.debian.wheezy, Lint role - Debian Wheezy))
lint.debian.wheezy: DISTRIBUTIONS = debian.wheezy
lint.debian.wheezy: lint@local

LINT_HELP_LOCAL += $(call if_in,debian.jessie,$(ROLE_DISTRIBUTIONS),$(call help,lint.debian.jessie, Lint role - Debian Jessie))
lint.debian.jessie: DISTRIBUTIONS = debian.jessie
lint.debian.jessie: lint@local

LINT_HELP_LOCAL += $(call if_in,debian.stretch,$(ROLE_DISTRIBUTIONS),$(call help,lint.debian.stretch,Lint role - Debian Stretch))
lint.debian.stretch: DISTRIBUTIONS = debian.stretch
lint.debian.stretch: lint@local

LINT_HELP_LOCAL += $(call if_in,debian.buster,$(ROLE_DISTRIBUTIONS),$(call help,lint.debian.buster, Lint role - Debian Buster))
lint.debian.buster: DISTRIBUTIONS = debian.buster
lint.debian.buster: lint@local

LINT_HELP_LOCAL += $(call if_in,centos.7,$(ROLE_DISTRIBUTIONS),$(call help,lint.centos.7, Lint role - CentOS 7))
lint.centos.7: DISTRIBUTIONS = centos.7
lint.centos.7: lint@local

LINT_HELP_LOCAL += $(call if_in,ubuntu.xenial,$(ROLE_DISTRIBUTIONS),$(call help,lint.ubuntu.xenial, Lint role - Ubuntu Xenial))
lint.ubuntu.xenial: DISTRIBUTIONS = ubuntu.xenial
lint.ubuntu.xenial: lint@local

########
# Test #
########

TESTS = $(sort \
$(foreach \
TEST, \
$(wildcard $(ROLE_TESTS_DIR)/*.yml), \
$(if $(findstring .goss.,$(TEST)),, \
$(patsubst /%,%,$(subst $(ROLE_DIR),,$(TEST))) \
) \
) \
)

tests/%.yml: FORCE
$(call verbose, ,ANSIBLE_STDOUT_CALLBACK=actionable, ) \
ansible-playbook $@ --extra-vars="test=$(subst .yml,,$(subst tests/,,$@))"
FORCE:

MANALA_HELP += $(call if_host,local,$(TEST_HELP_LOCAL),$(TEST_HELP_TEST))

TEST_HELP = $(call help_section,Test)
TEST_HELP_LOCAL = $(TEST_HELP) \
$(call help,test, Test role across distributions)
TEST_HELP_BUILD = $(TEST_HELP) \
$(call help,test,Test role)

test: .host_switch(test)

test@local: .fail_if_host_not(local)
$(call list_loop,DISTRIBUTION,$(if $(DISTRIBUTIONS),$(DISTRIBUTIONS),$(ROLE_DISTRIBUTIONS)), \
$$(call if_in,$$(DISTRIBUTION),$$(ROLE_DISTRIBUTIONS), \
$$(call log,Test \"$$(ROLE)\" on \"$$(DISTRIBUTION)\") ; \
$$(call list_loop,TEST,$$(TESTS), \
$$$$(call log, $$$$(TEST)) ; \
$$$$(call docker_make,$$$$(TEST)), \
TRAVIS_FOLD \
), \
$$(call log_warning,Test \"$$(ROLE)\" on \"$$(DISTRIBUTION)\" is not supported) \
) \
)

test@test: .fail_if_host_not(test)
$(call list_loop,TEST,$(TESTS), \
$$(call log,Test \"$$(TEST)\") ; \
$$(MAKE) $$(TEST) \
)

TEST_HELP_LOCAL += $(call if_in,debian.wheezy,$(ROLE_DISTRIBUTIONS),$(call help,test.debian.wheezy, Test role - Debian Wheezy))
test.debian.wheezy: DISTRIBUTIONS = debian.wheezy
test.debian.wheezy: test@local

TEST_HELP_LOCAL += $(call if_in,debian.jessie,$(ROLE_DISTRIBUTIONS),$(call help,test.debian.jessie, Test role - Debian Jessie))
test.debian.jessie: DISTRIBUTIONS = debian.jessie
test.debian.jessie: test@local

TEST_HELP_LOCAL += $(call if_in,debian.stretch,$(ROLE_DISTRIBUTIONS),$(call help,test.debian.stretch,Test role - Debian Stretch))
test.debian.stretch: DISTRIBUTIONS = debian.stretch
test.debian.stretch: test@local

TEST_HELP_LOCAL += $(call if_in,debian.buster,$(ROLE_DISTRIBUTIONS),$(call help,test.debian.buster, Test role - Debian Buster))
test.debian.buster: DISTRIBUTIONS = debian.buster
test.debian.buster: test@local

TEST_HELP_LOCAL += $(call if_in,centos.7,$(ROLE_DISTRIBUTIONS),$(call help,test.centos.7, Test role - CentOS 7))
test.centos.7: DISTRIBUTIONS = centos.7
test.centos.7: test@local

TEST_HELP_LOCAL += $(call if_in,ubuntu.xenial,$(ROLE_DISTRIBUTIONS),$(call help,test.ubuntu.xenial, Test role - Ubuntu Xenial))
test.ubuntu.xenial: DISTRIBUTIONS = ubuntu.xenial
test.ubuntu.xenial: test@local
54 changes: 54 additions & 0 deletions manala.sensu_go/.manala/make/Makefile.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#############
# Functions #
#############

define docker_run
docker run \
--rm \
$(if $(MANALA_DOCKER_MOUNT_DIR), \
--volume $(MANALA_CURRENT_DIR):$(MANALA_DOCKER_MOUNT_DIR) \
--workdir $(MANALA_DOCKER_MOUNT_DIR) \
) \
$(if $(MANALA_INTERACTIVE),--tty --interactive) \
$(if $(MANALA_DOCKER_HOST),--hostname $(MANALA_DOCKER_HOST)) \
$(if $(MANALA_DOCKER_VOLUMES), \
$(foreach \
VOLUME,\
$(MANALA_DOCKER_VOLUMES),\
--volume $(VOLUME) \
) \
) \
$(if $(MANALA_DOCKER_ENV), \
$(foreach \
ENV,\
$(call encode_spaces,$(MANALA_DOCKER_ENV)),\
--env $(call decode_spaces,$(ENV)) \
) \
) \
$(MANALA_DOCKER_OPTIONS) \
$(MANALA_DOCKER_RUN_OPTIONS) \
$(MANALA_DOCKER_IMAGE):$(if $(MANALA_DOCKER_IMAGE_TAG),$(MANALA_DOCKER_IMAGE_TAG),latest) \
$(1)
endef

define docker_shell
$(call docker_run)
endef

define docker_make
$(call docker_run,sh -c "make --silent --directory=$(MANALA_DOCKER_MOUNT_DIR) $(1)")
endef

define docker_pull
docker pull \
$(MANALA_DOCKER_OPTIONS) \
$(MANALA_DOCKER_PULL_OPTIONS) \
$(MANALA_DOCKER_IMAGE):$(if $(MANALA_DOCKER_IMAGE_TAG),$(MANALA_DOCKER_IMAGE_TAG),latest)
endef

define docker_build
docker build \
$(MANALA_DOCKER_OPTIONS) \
$(MANALA_DOCKER_BUILD_OPTIONS) \
--tag $(MANALA_DOCKER_IMAGE):$(if $(MANALA_DOCKER_IMAGE_TAG),$(MANALA_DOCKER_IMAGE_TAG),latest)
endef
33 changes: 33 additions & 0 deletions manala.sensu_go/.manala/make/Makefile.host
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
########
# Host #
########

MANALA_HOST ?= local

# Usage:
# target: .fail_if_host_not(local)
# # Do something on local host...

.fail_if_host_not(%):
$(call fail_if_host_not,$(*))

define fail_if_host_not
$(call if_eq,$(1),$(MANALA_HOST),,$(call message_error,Must be run on \"$(1)\" host); exit 1)
endef

# Usage:
# $(call if_host,local,Yes,No) = Yes

define if_host
$(call if_eq,$(1),$(MANALA_HOST),$(2),$(3))
endef

.host_switch(%):
$(call host_switch,$(*))

# Usage:
# $(call host_switch,target) => make target@[host]

define host_switch
$(MAKE) $(1)@$(MANALA_HOST)
endef
Loading

0 comments on commit a36a8b1

Please sign in to comment.