-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
81 lines (72 loc) · 2.54 KB
/
Copy pathMakefile
File metadata and controls
81 lines (72 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
.PHONY: help test test-all
help: ## Display help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
lint: ## Execute linting
$(call run_linter,)
lint-fix: ## Execute linting and fix
$(call run_linter, \
-e FIX_MARKDOWN=true \
-e FIX_NATURAL_LANGUAGE=true \
-e FIX_SHELL_SHFMT=true \
-e FIX_BIOME_LINT=true \
-e FIX_BIOME_FORMAT=true \
-e FIX_YAML_PRETTIER=true \
)
build: ## Build an image (usage: make build <image-name>)
@docker buildx build images/$(filter-out $@,$(MAKECMDGOALS)) --tag $(filter-out $@,$(MAKECMDGOALS)):latest --load
test: ## Run tests for an image (usage: make test <image-name>)
@image_name=$(filter-out $@,$(MAKECMDGOALS)); \
if [ -z "$$image_name" ]; then \
echo "Error: Please specify an image name. Usage: make test <image-name>"; \
exit 1; \
fi; \
if ! ls images/$$image_name/*.test.js >/dev/null 2>&1; then \
echo "No .test.js file found for $$image_name; skipping."; \
exit 0; \
fi; \
echo "Building $$image_name for testing...\n"; \
$(MAKE) build $$image_name || exit 1; \
echo "Building testcontainers test image...\n"; \
docker build -f images/testcontainers-node/Dockerfile --tag testcontainers:latest images/testcontainers-node || exit 1; \
echo "\nTesting $$image_name...\n"; \
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(PWD):$(PWD):ro \
-v $(PWD)/images/$$image_name:/workspace/image \
-e TESTED_IMAGE_REF="$$image_name:latest" \
-e HOST_UID="$(shell id -u)" \
-e HOST_GID="$(shell id -g)" \
-u root \
testcontainers:latest || exit 1; \
echo "\nTests passed for $$image_name.\n";
test-all: ## Run tests for all images
$(MAKE) build testcontainers-node
@for image_dir in images/*/; do \
if ! ls "$$image_dir"/*.test.js >/dev/null 2>&1; then \
continue; \
fi; \
image_name=$$(basename "$$image_dir"); \
$(MAKE) test "$$image_name" || exit 1; \
done
ci: ## Run full CI checks (lint + tests)
$(MAKE) lint-fix
$(MAKE) test-all
define run_linter
DEFAULT_WORKSPACE="$(CURDIR)"; \
LINTER_IMAGE="linter:latest"; \
VOLUME="$$DEFAULT_WORKSPACE:$$DEFAULT_WORKSPACE"; \
docker build --platform linux/amd64 --build-arg UID=$(shell id -u) --build-arg GID=$(shell id -g) --tag $$LINTER_IMAGE .; \
docker run \
--platform linux/amd64 \
-v $$VOLUME \
--rm \
-e DEFAULT_WORKSPACE="$$DEFAULT_WORKSPACE" \
-e FILTER_REGEX_INCLUDE="$(filter-out $@,$(MAKECMDGOALS))" \
$(1) \
$$LINTER_IMAGE
endef
#############################
# Argument fix workaround
#############################
%:
@: