2021-04-22 14:56:18 -04:00
|
|
|
# Inspired by https://github.com/jessfraz/dotfiles
|
|
|
|
|
|
|
|
.PHONY: all
|
2023-10-19 17:03:14 -04:00
|
|
|
all: info docker test ## Run all targets.
|
2021-04-22 14:56:18 -04:00
|
|
|
|
|
|
|
.PHONY: test
|
2023-12-07 09:18:47 -05:00
|
|
|
test: info validate-container-image-labels inspec ## 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: 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"
|
2023-10-19 17:03:14 -04:00
|
|
|
SUPER_LINTER_TEST_CONTAINER_URL := $(CONTAINER_IMAGE_ID)
|
2021-05-25 11:14:43 -04:00
|
|
|
DOCKERFILE := ''
|
2023-10-19 17:03:14 -04:00
|
|
|
IMAGE := $(CONTAINER_IMAGE_TARGET)
|
|
|
|
|
|
|
|
# Default to stadard
|
|
|
|
ifeq ($(IMAGE),)
|
|
|
|
IMAGE := "standard"
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Default to latest
|
|
|
|
ifeq ($(SUPER_LINTER_TEST_CONTAINER_URL),)
|
|
|
|
SUPER_LINTER_TEST_CONTAINER_URL := "ghcr.io/super-linter/super-linter:latest"
|
2021-05-25 11:14:43 -04:00
|
|
|
endif
|
2021-04-30 12:29:15 -04:00
|
|
|
|
2023-12-07 09:18:47 -05:00
|
|
|
ifeq ($(BUILD_DATE),)
|
|
|
|
BUILD_DATE := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(BUILD_REVISION),)
|
|
|
|
BUILD_REVISION := $(shell git rev-parse HEAD)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(BUILD_VERSION),)
|
|
|
|
BUILD_VERSION := $(shell git rev-parse HEAD)
|
|
|
|
endif
|
|
|
|
|
2021-04-30 12:29:15 -04:00
|
|
|
.PHONY: inspec
|
|
|
|
inspec: inspec-check ## Run InSpec tests
|
2023-10-19 17:03:14 -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 && \
|
|
|
|
docker tag $(SUPER_LINTER_TEST_CONTAINER_URL) $(SUPER_LINTER_TEST_CONTAINER_NAME) && \
|
|
|
|
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 \
|
2023-10-19 17:03:14 -04:00
|
|
|
&& docker kill $(SUPER_LINTER_TEST_CONTAINER_NAME)
|
2022-12-29 12:56:54 -05:00
|
|
|
|
|
|
|
.phony: docker
|
2023-10-19 17:03:14 -04:00
|
|
|
docker: ## Build the container image
|
2022-12-29 12:56:54 -05:00
|
|
|
@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 \
|
2023-12-07 09:18:47 -05:00
|
|
|
--build-arg BUILD_DATE=$(BUILD_DATE) \
|
|
|
|
--build-arg BUILD_REVISION=$(BUILD_REVISION) \
|
|
|
|
--build-arg BUILD_VERSION=$(BUILD_VERSION) \
|
2023-01-04 00:54:55 -05:00
|
|
|
--secret id=GITHUB_TOKEN,env=GITHUB_TOKEN \
|
2023-10-19 17:03:14 -04:00
|
|
|
-t $(SUPER_LINTER_TEST_CONTAINER_URL) .
|
|
|
|
|
|
|
|
.phony: docker-pull
|
|
|
|
docker-pull: ## Pull the container image from registry
|
|
|
|
docker pull $(SUPER_LINTER_TEST_CONTAINER_URL)
|
2023-12-07 09:18:47 -05:00
|
|
|
|
|
|
|
.phony: validate-container-image-labels
|
|
|
|
validate-container-image-labels: ## Validate container image labels
|
|
|
|
$(CURDIR)/test/validate-docker-labels.sh \
|
|
|
|
$(SUPER_LINTER_TEST_CONTAINER_URL) \
|
|
|
|
$(BUILD_DATE) \
|
|
|
|
$(BUILD_REVISION) \
|
|
|
|
$(BUILD_VERSION)
|