Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (75 loc) · 3.83 KB
/
Copy pathMakefile
File metadata and controls
89 lines (75 loc) · 3.83 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
87
88
89
# wasmCloud Go — developer entry points.
#
# Thin wrappers around the scripts in airgap/. The build system for components
# is `wash build`; this is a front door, not a replacement for it.
SHELL := /bin/bash
# Versions live in one file so the Dockerfile, CI and BUILDING.md cannot drift
# apart. Every non-comment line becomes a --build-arg.
VERSIONS_FILE := airgap/versions.env
AIRGAP_BUILD_ARGS := $(shell grep -vE '^[[:space:]]*(\#|$$)' $(VERSIONS_FILE) | sed 's/^/--build-arg /')
# Tagging by a hash of the pinned version set and every example's module files
# means a cache miss *is* the signal that something moved, rather than a silent
# rebuild against new versions. See airgap/image-tag.sh.
AIRGAP_IMAGE ?= wasmcloud-go-airgap
AIRGAP_TAG ?= $(shell bash airgap/image-tag.sh)
AIRGAP_REF := $(AIRGAP_IMAGE):$(AIRGAP_TAG)
# Passed through to the container; see airgap/build-all.sh.
AIRGAP_USE_LOCAL_SDK ?= 0
# Which modules airgap-fetch and airgap-run cover. Defaults to every example and
# template; narrow it with e.g. AIRGAP_MODULES=examples/components/http-server.
AIRGAP_MODULES ?= $(shell find examples/components templates -name go.mod 2>/dev/null | xargs -n1 dirname | sort)
DOCKER ?= docker
.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help
@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-22s\033[0m %s\n", $$1, $$2}'
.PHONY: airgap-image
airgap-image: ## Build the air-gapped toolchain image
$(DOCKER) build -f airgap/Dockerfile -t $(AIRGAP_REF) $(AIRGAP_BUILD_ARGS) .
.PHONY: airgap-test
airgap-test: airgap-image airgap-fetch airgap-run ## Fetch WIT deps, then build every example with no network
# The only network step. wit/deps is not checked in, so it is fetched into the
# checkout with the image's pinned wash before the offline run. Runs as the
# calling user so the fetched files are not root-owned, which in turn means the
# image's root-owned caches are off limits — hence the /tmp XDG dirs. The
# script comes from the bind mount so a pulled image cannot run a stale copy.
.PHONY: airgap-fetch
airgap-fetch: ## Fetch every example's WIT deps into the checkout (needs network)
$(DOCKER) run --rm \
--user "$$(id -u):$$(id -g)" \
-e HOME=/tmp -e XDG_CACHE_HOME=/tmp/cache \
-e XDG_CONFIG_HOME=/tmp/config -e XDG_DATA_HOME=/tmp/data \
-v "$(CURDIR):/workspace" \
--entrypoint /bin/bash \
$(AIRGAP_REF) /workspace/airgap/fetch-wit.sh $(AIRGAP_MODULES)
# Split out so CI can run the suite against an image it pulled from GHCR
# without rebuilding it. `docker build` is nearly free locally once layers are
# cached, but on a fresh runner it re-does the whole seed stage — which is the
# cost pulling exists to avoid.
#
# One fresh container per module: each example starts from the image exactly as
# shipped, so nothing one build leaves in a cache can carry the next.
.PHONY: airgap-run
airgap-run: ## Build each module with no network, each in its own fresh container
@passed=(); failed=(); \
for mod in $(AIRGAP_MODULES); do \
if $(DOCKER) run --rm --network none \
-e AIRGAP_USE_LOCAL_SDK=$(AIRGAP_USE_LOCAL_SDK) \
-v "$(CURDIR):/workspace" \
$(AIRGAP_REF) "$$mod"; \
then passed+=("$$mod"); else failed+=("$$mod"); fi; \
done; \
echo "######################################################################"; \
echo "offline builds passed: $${#passed[@]}/$$(( $${#passed[@]} + $${#failed[@]} ))"; \
if [ $${#failed[@]} -gt 0 ]; then printf ' FAILED %s\n' "$${failed[@]}"; exit 1; fi
.PHONY: airgap-shell
airgap-shell: airgap-image ## Interactive shell in the air-gapped image
$(DOCKER) run --rm -it --network none \
-e AIRGAP_USE_LOCAL_SDK=$(AIRGAP_USE_LOCAL_SDK) \
-v "$(CURDIR):/workspace" \
--entrypoint /bin/bash \
$(AIRGAP_REF)
.PHONY: airgap-versions
airgap-versions: ## Re-derive every pinned version and check BUILDING.md
@bash airgap/check-versions.sh