-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
179 lines (148 loc) · 5.2 KB
/
Copy pathMakefile
File metadata and controls
179 lines (148 loc) · 5.2 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# chr-armed — ARM64 CHR image builder for Oracle Cloud and AWS
#
# Primary orchestrator. GitHub Actions should call make targets, not raw commands.
# Bun scripts handle TypeScript logic; Make handles file dependencies and caching.
# --- Configuration (override via env or .env) ---
CHR_VERSION ?= stable
OUTPUT_DIR ?= Machines
CACHE_DIR ?= .cache
BUCKET_NAME ?= chr-images
# --- Derived ---
# Resolved at build time via versions.ts
VERSION_FILE := $(OUTPUT_DIR)/.version
# --- Default target ---
.PHONY: all
all: convert
# --- Load .env if present ---
-include .env
# --- Version resolution ---
.PHONY: resolve-version
resolve-version:
@bun run src/cli.ts version $(CHR_VERSION)
# --- Image conversion pipeline ---
.PHONY: convert
convert:
@bun run src/cli.ts convert $(CHR_VERSION) --output $(OUTPUT_DIR) --cache $(CACHE_DIR)
# --- AWS operations ---
# convert-aws: download raw + inject extra-nic.npk (ENA driver, Linux only)
# Automatically injects extra-nic for ARM64 since AWS Graviton uses ENA networking.
.PHONY: convert-aws
convert-aws:
@bun run src/cli.ts convert $(CHR_VERSION) --provider=aws --arch=arm64 \
--output $(OUTPUT_DIR) --cache $(CACHE_DIR)
.PHONY: upload-aws
upload-aws: convert-aws
@bun run src/cli.ts upload $(CHR_VERSION) --provider=aws --arch=arm64 \
--output $(OUTPUT_DIR)
.PHONY: import-aws
import-aws: upload-aws
@bun run src/cli.ts import $(CHR_VERSION) --provider=aws --arch=arm64 \
--output $(OUTPUT_DIR)
.PHONY: setup-aws
setup-aws:
@bun run src/cli.ts setup-aws --provider=aws
.PHONY: setup-network-aws
setup-network-aws:
@bun run src/cli.ts setup-network --provider=aws
.PHONY: launch-aws
launch-aws:
@bun run src/cli.ts launch $(CHR_VERSION) --provider=aws --arch=arm64
.PHONY: provision-aws
provision-aws:
@bun run src/cli.ts provision --provider=aws --ports=$(or $(PORTS),ssh)
.PHONY: terminate-aws
terminate-aws:
@bun run src/cli.ts terminate --provider=aws
# --- Oracle Cloud operations ---
.PHONY: upload
upload: convert
@bun run src/cli.ts upload $(CHR_VERSION) --output $(OUTPUT_DIR)
.PHONY: import-image
import-image: upload
@bun run src/cli.ts import $(CHR_VERSION) --output $(OUTPUT_DIR)
.PHONY: setup-network
setup-network:
@bun run src/cli.ts setup-network
.PHONY: teardown-network
teardown-network:
@bun run src/cli.ts teardown-network
.PHONY: provision
provision:
@bun run src/cli.ts provision --ports=$(or $(PORTS),ssh)
.PHONY: open-ports
open-ports:
@bun run src/cli.ts open-ports --ports=$(or $(PORTS),ssh,webfig,api)
.PHONY: close-ports
close-ports:
@bun run src/cli.ts close-ports
.PHONY: launch
launch:
@bun run src/cli.ts launch $(CHR_VERSION)
.PHONY: terminate
terminate:
@bun run src/cli.ts terminate
# --- Testing ---
.PHONY: test
test:
bun test
.PHONY: test-integration
test-integration:
OCI_INTEGRATION_TEST=1 CHR_IMAGE_ID=$(CHR_IMAGE_ID) bun test test/integration/
.PHONY: lint
lint:
bun run lint
.PHONY: fmt
fmt:
bun run fmt
.PHONY: check
check: lint test
# --- Cleanup ---
.PHONY: clean
clean:
rm -rf $(OUTPUT_DIR)
@echo "Cleaned $(OUTPUT_DIR) (cache preserved in $(CACHE_DIR))"
.PHONY: distclean
distclean: clean
rm -rf $(CACHE_DIR)
@echo "Cleaned cache"
# --- Help ---
.PHONY: help
help:
@echo "chr-armed — ARM64 CHR image builder (OCI + AWS)"
@echo ""
@echo "Oracle Cloud targets:"
@echo " make Build qcow2 for CHR_VERSION (default: stable)"
@echo " make convert Download + convert raw → qcow2"
@echo " make upload Upload qcow2 to OCI bucket"
@echo " make import-image Import as OCI custom image"
@echo " make setup-network Create VCN, subnet, security list, IGW"
@echo " make teardown-network Destroy the chr-vcn network stack"
@echo " make launch Launch OCI instance (needs CHR_IMAGE_ID)"
@echo " make provision Configure RouterOS via serial console"
@echo " make terminate Terminate OCI instance"
@echo ""
@echo "AWS targets:"
@echo " make setup-aws One-time: create vmimport role + enable serial console"
@echo " make convert-aws Download raw + inject extra-nic.npk (ENA driver, Linux)"
@echo " make upload-aws Upload raw image to S3"
@echo " make import-aws Import as AMI (ImportSnapshot → RegisterImage)"
@echo " make setup-network-aws Create security group"
@echo " make launch-aws Launch EC2 instance (needs CHR_AMI_ID)"
@echo " make provision-aws Configure RouterOS via EC2 serial console"
@echo " make terminate-aws Terminate EC2 instance"
@echo ""
@echo "Common targets:"
@echo " make test Run unit tests"
@echo " make test-integration Run integration tests (requires OCI creds)"
@echo " make lint Run Biome linter"
@echo " make check Run lint + test"
@echo " make clean Remove build artifacts (preserve cache)"
@echo " make distclean Remove everything including cache"
@echo ""
@echo "Variables:"
@echo " CHR_VERSION=stable RouterOS channel: stable|long-term|testing|development"
@echo " OUTPUT_DIR=Machines Build output directory"
@echo " CACHE_DIR=.cache Download cache directory"
@echo " BUCKET_NAME=chr-images OCI/S3 bucket name"
@echo ""
@echo "Note: convert-aws requires Linux (sudo qemu-nbd + mount) for extra-nic injection."