2021-04-22 14:56:18 -04:00
|
|
|
# Inspired by https://github.com/jessfraz/dotfiles
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: info test ## Run all targets.
|
|
|
|
|
|
|
|
.PHONY: test
|
2021-04-30 12:29:15 -04:00
|
|
|
test: info clean inspec kcov prepare-test-reports ## Run tests
|
2021-04-22 14:56:18 -04:00
|
|
|
|
|
|
|
# if this session isn't interactive, then we don't want to allocate a
|
|
|
|
# TTY, which would fail, but if it is interactive, we do want to attach
|
|
|
|
# so that the user can send e.g. ^C through.
|
|
|
|
INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
|
|
|
|
ifeq ($(INTERACTIVE), 1)
|
|
|
|
DOCKER_FLAGS += -t
|
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: info
|
|
|
|
info: ## Gather information about the runtime environment
|
|
|
|
echo "whoami: $$(whoami)"; \
|
|
|
|
echo "pwd: $$(pwd)"; \
|
|
|
|
echo "ls -ahl: $$(ls -ahl)"; \
|
2021-04-30 12:29:15 -04:00
|
|
|
docker images; \
|
|
|
|
docker ps
|
2021-04-22 14:56:18 -04:00
|
|
|
|
|
|
|
.PHONY: kcov
|
|
|
|
kcov: ## Run kcov
|
|
|
|
docker run --rm $(DOCKER_FLAGS) \
|
|
|
|
--user "$$(id -u)":"$$(id -g)" \
|
|
|
|
-v "$(CURDIR)":/workspace \
|
|
|
|
-w="/workspace" \
|
|
|
|
kcov/kcov \
|
|
|
|
kcov \
|
|
|
|
--bash-parse-files-in-dir=/workspace \
|
|
|
|
--clean \
|
|
|
|
--exclude-pattern=.coverage,.git \
|
|
|
|
--include-pattern=.sh \
|
|
|
|
/workspace/test/.coverage \
|
|
|
|
/workspace/test/runTests.sh
|
|
|
|
|
|
|
|
COBERTURA_REPORTS_DESTINATION_DIRECTORY := "$(CURDIR)/test/reports/cobertura"
|
|
|
|
|
|
|
|
.PHONY: prepare-test-reports
|
|
|
|
prepare-test-reports: ## Prepare the test reports for consumption
|
|
|
|
mkdir -p $(COBERTURA_REPORTS_DESTINATION_DIRECTORY); \
|
|
|
|
COBERTURA_REPORTS="$$(find "$$(pwd)" -name 'cobertura.xml')"; \
|
|
|
|
for COBERTURA_REPORT_FILE_PATH in $$COBERTURA_REPORTS ; do \
|
|
|
|
COBERTURA_REPORT_DIRECTORY_PATH="$$(dirname "$$COBERTURA_REPORT_FILE_PATH")"; \
|
|
|
|
COBERTURA_REPORT_DIRECTORY_NAME="$$(basename "$$COBERTURA_REPORT_DIRECTORY_PATH")"; \
|
|
|
|
COBERTURA_REPORT_DIRECTORY_NAME_NO_SUFFIX="$${COBERTURA_REPORT_DIRECTORY_NAME%.*}"; \
|
|
|
|
mkdir -p "$(COBERTURA_REPORTS_DESTINATION_DIRECTORY)"/"$$COBERTURA_REPORT_DIRECTORY_NAME_NO_SUFFIX"; \
|
|
|
|
cp "$$COBERTURA_REPORT_FILE_PATH" "$(COBERTURA_REPORTS_DESTINATION_DIRECTORY)"/"$$COBERTURA_REPORT_DIRECTORY_NAME_NO_SUFFIX"/cobertura.xml; \
|
|
|
|
done
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean: ## Clean the workspace
|
|
|
|
rm -rf $(CURDIR)/test/.coverage; \
|
|
|
|
rm -rf $(CURDIR)/test/reports
|
|
|
|
|
|
|
|
.PHONY: help
|
|
|
|
help: ## Show help
|
|
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
2021-04-30 12:29:15 -04:00
|
|
|
|
|
|
|
.PHONY: inspec-check
|
|
|
|
inspec-check: ## Validate inspec profiles
|
|
|
|
docker run $(DOCKER_FLAGS) \
|
|
|
|
--rm \
|
|
|
|
-v "$(CURDIR)":/workspace \
|
|
|
|
-w="/workspace" \
|
|
|
|
chef/inspec check \
|
|
|
|
--chef-license=accept \
|
|
|
|
test/inspec/super-linter
|
|
|
|
|
|
|
|
SUPER_LINTER_TEST_CONTAINER_NAME := "super-linter-test"
|
2021-05-25 11:14:43 -04:00
|
|
|
SUPER_LINTER_TEST_CONTINER_URL := ''
|
|
|
|
DOCKERFILE := ''
|
|
|
|
IMAGE := ''
|
|
|
|
ifeq ($(IMAGE),slim)
|
2023-08-17 11:12:11 -04:00
|
|
|
SUPER_LINTER_TEST_CONTINER_URL := "ghcr.io/super-linter/super-linter:slim"
|
2021-05-25 11:14:43 -04:00
|
|
|
IMAGE := "slim"
|
|
|
|
else
|
2023-08-17 11:12:11 -04:00
|
|
|
SUPER_LINTER_TEST_CONTINER_URL := "ghcr.io/super-linter/super-linter:standard"
|
2021-05-25 11:14:43 -04:00
|
|
|
IMAGE := "standard"
|
|
|
|
endif
|
2021-04-30 12:29:15 -04:00
|
|
|
|
|
|
|
.PHONY: inspec
|
|
|
|
inspec: inspec-check ## Run InSpec tests
|
2023-08-17 11:12:11 -04:00
|
|
|
LOCAL_IMAGE="$$(docker images $(SUPER_LINTER_TEST_CONTINER_URL) |grep 'ghcr.io/super-linter/super-linter')"; \
|
2021-06-09 12:53:11 -04:00
|
|
|
if [ "$$?" -ne 0 ]; then docker build -t $(SUPER_LINTER_TEST_CONTINER_URL) -f Dockerfile .; fi && \
|
2021-04-30 12:29:15 -04:00
|
|
|
DOCKER_CONTAINER_STATE="$$(docker inspect --format "{{.State.Running}}" "$(SUPER_LINTER_TEST_CONTAINER_NAME)" 2>/dev/null || echo "")"; \
|
|
|
|
if [ "$$DOCKER_CONTAINER_STATE" = "true" ]; then docker kill "$(SUPER_LINTER_TEST_CONTAINER_NAME)"; fi && \
|
2021-06-09 12:53:11 -04:00
|
|
|
docker tag $(SUPER_LINTER_TEST_CONTINER_URL) $(SUPER_LINTER_TEST_CONTAINER_NAME) && \
|
2021-05-04 14:24:41 -04:00
|
|
|
SUPER_LINTER_TEST_CONTAINER_ID="$$(docker run -d --name "$(SUPER_LINTER_TEST_CONTAINER_NAME)" --rm -it --entrypoint /bin/ash "$(SUPER_LINTER_TEST_CONTAINER_NAME)" -c "while true; do sleep 1; done")" \
|
2021-04-30 12:29:15 -04:00
|
|
|
&& docker run $(DOCKER_FLAGS) \
|
|
|
|
--rm \
|
|
|
|
-v "$(CURDIR)":/workspace \
|
|
|
|
-v /var/run/docker.sock:/var/run/docker.sock \
|
2021-05-25 11:14:43 -04:00
|
|
|
-e IMAGE=$(IMAGE) \
|
2021-04-30 12:29:15 -04:00
|
|
|
-w="/workspace" \
|
|
|
|
chef/inspec exec test/inspec/super-linter\
|
|
|
|
--chef-license=accept \
|
|
|
|
--diagnose \
|
|
|
|
--log-level=debug \
|
|
|
|
-t "docker://$${SUPER_LINTER_TEST_CONTAINER_ID}" \
|
|
|
|
&& docker ps \
|
|
|
|
&& docker kill "$(SUPER_LINTER_TEST_CONTAINER_NAME)"
|
2022-12-29 12:56:54 -05:00
|
|
|
|
|
|
|
.phony: docker
|
|
|
|
docker:
|
|
|
|
@if [ -z "${GITHUB_TOKEN}" ]; then echo "GITHUB_TOKEN environment variable not set. Please set your GitHub Personal Access Token."; exit 1; fi
|
2023-01-04 01:00:02 -05:00
|
|
|
DOCKER_BUILDKIT=1 docker buildx build --load \
|
2022-12-29 12:56:54 -05:00
|
|
|
--build-arg BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
|
|
|
|
--build-arg BUILD_REVISION=$(shell git rev-parse --short HEAD) \
|
|
|
|
--build-arg BUILD_VERSION=$(shell git rev-parse --short HEAD) \
|
2023-01-04 00:54:55 -05:00
|
|
|
--secret id=GITHUB_TOKEN,env=GITHUB_TOKEN \
|
2023-08-17 11:12:11 -04:00
|
|
|
-t ghcr.io/super-linter/super-linter .
|