-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
86 lines (71 loc) · 2.54 KB
/
Makefile
File metadata and controls
86 lines (71 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
82
83
84
85
86
IMAGE ?= ghcr.io/hexlet-codebattle/runner-zig
TAG ?= latest
PLATFORMS ?= linux/amd64,linux/arm64
CONTAINER ?= docker
TEST_IMAGE ?= runner-zig-test
.PHONY: build lint lint-fix test test-unit test-integration container-build container-push container-start curl-local-health curl-local-test start
## Build multi-arch image directly for GHCR
build:
zig build
## Run Zig formatting check
lint:
zig fmt --check src
## Fix Zig code styling
lint-fix:
zig fmt src
## fake check
test:
ls -la
## Run integration tests inside the builder container
test-unit:
zig test src/test.zig
## Run integration tests against an already-built container (container + HTTP checks)
test-integration:
@container_name="runner-zig-it-$$RANDOM"; \
container_started=0; \
trap 'if [ $$container_started -eq 1 ]; then $(CONTAINER) stop $$container_name >/dev/null 2>&1 || true; fi' EXIT; \
$(CONTAINER) run -d --rm --pull=never --name $$container_name -p 4040:4040 $(IMAGE):$(TAG) >/dev/null && \
container_started=1; \
for i in 1 2 3 4 5; do \
if $(MAKE) --no-print-directory curl-local-health >/dev/null; then break; fi; \
sleep 1; \
done; \
$(MAKE) --no-print-directory curl-local-health && \
seq 1 60 | xargs -n1 -P60 sh -c 'curl -sS -o /dev/null -w "%{http_code}\n" http://localhost:4040/run -H "content-type: application/json" -d @test-payload.json'; \
if [ $$container_started -eq 1 ]; then $(CONTAINER) stop $$container_name >/dev/null 2>&1 || true; fi
## Build and push multi-arch image (linux/amd64 + linux/arm64) for GHCR
build-and-push: container-build container-push
## Build a single-arch image for local use/tests
container-build:
$(CONTAINER) build \
--file Containerfile \
--tag $(IMAGE):$(TAG) \
.
## Pull the multi-arch manifest tag from registry
container-pull:
$(CONTAINER) pull $(IMAGE):$(TAG)
## Push multi-arch image manifest + all platform layers to GHCR
container-push:
$(CONTAINER) buildx build --push \
--platform=linux/amd64,linux/arm64 \
--file Containerfile \
--tag $(IMAGE):$(TAG) \
.
## Start the container locally on port 4040
container-start:
$(CONTAINER) run --rm -p 4040:4040 \
--cap-add=SYS_ADMIN \
--cap-add=SYS_CHROOT \
--security-opt=no-new-privileges=false \
$(IMAGE):$(TAG)
## Quick local smoke check against the running server
curl-local-health:
@curl -fsS http://localhost:4040/health && echo
## Run a local /run request for zig
curl-local-test:
@curl -sS http://localhost:4040/run \
-H 'content-type: application/json' \
-d @test-payload.json
## Start the server from the local build output
start:
./zig-out/bin/runner-zig