Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
220 lines (186 loc) · 8.87 KB
/
Copy pathMakefile
File metadata and controls
220 lines (186 loc) · 8.87 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
PKG_ID := $(shell yq -e ".id" manifest.yaml)
PKG_VERSION := $(shell yq -e ".version" manifest.yaml)
BUILD_DIR := builds/$(PKG_VERSION)
# The companion gets its own tree, and it is not tidiness. start9-store's
# publish.sh takes EVERY *-040.s9pk in the newest version dir, and when it finds
# more than one it assumes they are per-architecture builds of one package and
# derives the arch from <id>_<arch>-040.s9pk. A companion s9pk sitting beside the
# flagship hits that branch and dies with "cannot tell architectures apart",
# because there is no underscore to split on. Separate dirs also mean `make bump`
# can publish and prune the two independently, which is what it is for.
COMPANION_BUILD_DIR := builds-companion/$(PKG_VERSION)
TS_FILES := $(shell find . -name \*.ts -not -path './startos/*' -not -path './node_modules/*' )
# All backend/frontend sources baked into the image. Listed explicitly so `make`
# rebuilds when any of them change (the Dockerfile ADDs the whole dirs, but make
# only re-runs when a named prerequisite is newer).
APP_FILES := $(shell find app/backend app/frontend -type f)
.DELETE_ON_ERROR:
all: verify
verify: $(PKG_ID).s9pk
@start-sdk verify s9pk $(PKG_ID).s9pk
@echo " Done!"
@echo " Filesize: $(shell du -h $(PKG_ID).s9pk) is ready"
install:
@if [ ! -f ~/.embassy/config.yaml ]; then echo "You must define \"host: http://server-name.local\" in ~/.embassy/config.yaml config file first."; exit 1; fi
@echo "\nInstalling to $$(grep -v '^#' ~/.embassy/config.yaml | cut -d'/' -f3) ...\n"
@[ -f $(PKG_ID).s9pk ] || ( $(MAKE) && echo "\nInstalling to $$(grep -v '^#' ~/.embassy/config.yaml | cut -d'/' -f3) ...\n" )
@start-cli package install $(PKG_ID).s9pk
release: verify
rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
cp $(PKG_ID).s9pk $(BUILD_DIR)/
cd $(BUILD_DIR) && sha256sum hashgg.s9pk > SHA256SUMS
clean:
rm -rf docker-images
rm -f $(PKG_ID).s9pk
rm -f scripts/*.js
scripts/embassy.js: $(TS_FILES)
deno run --allow-read --allow-write --allow-net --allow-env scripts/bundle.ts
arm:
@rm -f docker-images/x86_64.tar
ARCH=aarch64 $(MAKE)
x86:
@rm -f docker-images/aarch64.tar
ARCH=x86_64 $(MAKE)
# `manifest.yaml` is a prerequisite because `--tag` below embeds `$(PKG_VERSION)`,
# which is read from it. Without it a version-only bump leaves these tarballs
# looking up to date, and the pack fails with "Contains image with incorrect
# version: expected 0.7.2.1 received 0.7.2.0", which reads as a packaging fault
# rather than a stale build product.
docker-images/aarch64.tar: Dockerfile docker_entrypoint.sh check-tunnel.sh check-datum.sh $(APP_FILES) icon.png instructions.md manifest.yaml
ifeq ($(ARCH),x86_64)
else
mkdir -p docker-images
docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --build-arg ARCH=aarch64 --build-arg PLATFORM=arm64 --build-arg HASHGG_PLATFORM=startos-0.3 --platform=linux/arm64 -o type=docker,dest=docker-images/aarch64.tar .
endif
docker-images/x86_64.tar: Dockerfile docker_entrypoint.sh check-tunnel.sh check-datum.sh $(APP_FILES) icon.png instructions.md manifest.yaml
ifeq ($(ARCH),aarch64)
else
mkdir -p docker-images
docker buildx build --tag start9/$(PKG_ID)/main:$(PKG_VERSION) --build-arg ARCH=x86_64 --build-arg PLATFORM=amd64 --build-arg HASHGG_PLATFORM=startos-0.3 --platform=linux/amd64 -o type=docker,dest=docker-images/x86_64.tar .
endif
$(PKG_ID).s9pk: manifest.yaml instructions.md icon.png LICENSE scripts/embassy.js docker-images/aarch64.tar docker-images/x86_64.tar
ifeq ($(ARCH),aarch64)
@echo "start-sdk: Preparing aarch64 package ..."
else ifeq ($(ARCH),x86_64)
@echo "start-sdk: Preparing x86_64 package ..."
else
@echo "start-sdk: Preparing Universal Package ..."
endif
@start-sdk pack
# === StartOS 0.4.0 targets ===
.PHONY: pack-040 pack-040-x86 pack-040-arm install-040 clean-040 release-all
pack-040: pack-040-x86 pack-040-arm
pack-040-x86: javascript/index.js
start-cli s9pk pack --arch=x86_64 -o $(PKG_ID)_x86_64.s9pk
pack-040-arm: javascript/index.js
start-cli s9pk pack --arch=aarch64 -o $(PKG_ID)_aarch64.s9pk
# The variant is baked into the bundle rather than read from the environment,
# because startos/ is evaluated twice: once by `start-cli s9pk pack`, which has an
# environment, and again on the StartOS host when the service starts, which does
# not. Written before every build so the bundle and the manifest cannot disagree.
VARIANT ?= flagship
# Always evaluated, but only rewritten when the value actually changes, so the
# bundle rebuilds when you switch variants and not otherwise. A plain
# `: Makefile` prerequisite is wrong here: switching VARIANT does not touch the
# Makefile, so the stale file survives and the next build silently packs the
# previous variant's identity.
.PHONY: FORCE
FORCE:
startos/variant.build.ts: FORCE
@printf '%s\n' \
'/** GENERATED by the Makefile. Do not edit, do not commit. See startos/variant.ts. */' \
'export const BUILD_VARIANT: string = '"'"'$(VARIANT)'"'"'' > $@.tmp
@cmp -s $@.tmp $@ 2>/dev/null && rm -f $@.tmp || mv $@.tmp $@
# The same gate as the SDK's s9pk.mk (which this Makefile does not include):
# type check, the SDK's lint rules, a prettier check, then the bundle. The SDK
# supplies typescript, prettier and ncc.
SDK_DIR := node_modules/@start9labs/start-sdk
PRETTIER_CONFIG := $(SDK_DIR)/prettier.config.json
javascript/index.js: $(shell find startos -type f -not -name variant.build.ts 2>/dev/null) tsconfig.json node_modules startos/variant.build.ts
npx tsc --noEmit
node $(SDK_DIR)/lint.mjs
npx prettier --config $(PRETTIER_CONFIG) --check startos
rm -rf javascript && npx ncc build startos/index.ts -o javascript
.PHONY: format
format: | node_modules
npx prettier --config $(PRETTIER_CONFIG) --write startos
node_modules: package-lock.json
npm ci
package-lock.json: package.json
npm i
install-040: pack-040-x86
@HOST=$$(awk -F'/' '/^host:/ {print $$3}' ~/.startos/config.yaml); \
if [ -z "$$HOST" ]; then echo "Error: Define \"host: http://server-name.local\" in ~/.startos/config.yaml"; exit 1; fi; \
printf "\nInstalling to $$HOST ...\n"; \
start-cli package install -s $(PKG_ID)_x86_64.s9pk
# Build both 0.3.5.1 and 0.4.0 universal packages into builds/<version>/
release-all: verify javascript/index.js
rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
cp $(PKG_ID).s9pk $(BUILD_DIR)/hashgg-0351.s9pk
start-cli s9pk pack -o $(BUILD_DIR)/hashgg-040.s9pk
cd $(BUILD_DIR) && sha256sum *.s9pk > SHA256SUMS
@echo ""
@echo "Release builds:"
@ls -lh $(BUILD_DIR)/
@echo ""
@cat $(BUILD_DIR)/SHA256SUMS
# The companion package: same sources, same image, different manifest and icon.
# Forces a rebuild of the generated variant and the bundle, because the previous
# target left them set to whatever it built.
# Instructions are the shared file with a companion preamble on the front, rather
# than a second copy. The mechanics (playit, VPS, dashboard, miners) are identical
# and a fork of 157 lines would drift the first time either is edited.
instructions-companion.md: instructions-companion-preamble.md instructions.md
cat $^ > $@
companion-040: instructions-companion.md
rm -rf $(COMPANION_BUILD_DIR)
mkdir -p $(COMPANION_BUILD_DIR)
$(MAKE) VARIANT=companion javascript/index.js
HASHGG_VARIANT=companion start-cli s9pk pack \
-o $(COMPANION_BUILD_DIR)/hashgg-companion-040.s9pk \
--icon icon-companion.png \
--instructions instructions-companion.md
cd $(COMPANION_BUILD_DIR) && sha256sum *.s9pk > SHA256SUMS
@echo ""
@echo "Companion build:"
@ls -lh $(COMPANION_BUILD_DIR)/
@echo ""
@cat $(COMPANION_BUILD_DIR)/SHA256SUMS
@echo ""
@echo "Sign SHA256SUMS on the air-gapped machine and drop SHA256SUMS.asc beside it."
@echo "This is a SEPARATE release from the flagship: its own tag and its own"
@echo "signature, because its artifacts live in their own directory and a"
@echo "SHA256SUMS can only be checked against files sitting next to it."
# Leave the bundle as the flagship, so a later `make release-all` cannot pack
# the flagship package with the companion's identity baked in.
$(MAKE) VARIANT=flagship javascript/index.js >/dev/null
clean-040:
rm -f $(PKG_ID)_x86_64.s9pk $(PKG_ID)_aarch64.s9pk
rm -rf javascript node_modules
clean-all: clean clean-040
# === Generic Docker image (Docker Hub) ===
# Used for the plain-Docker deployment path (Linux host running Datum Gateway
# natively, HashGG in a container). Not used by StartOS.
#
# Override with `make docker-build-local DOCKER_TAG=0.4.0.0` etc.
DOCKER_REPO ?= paulscode/hashgg
DOCKER_TAG ?= $(PKG_VERSION)
.PHONY: docker-build-local docker-buildx
# Single-arch build for local testing (no push). Tags :<version> and :latest.
docker-build-local:
docker build \
-t $(DOCKER_REPO):$(DOCKER_TAG) \
-t $(DOCKER_REPO):latest \
.
# Multi-arch build + push to Docker Hub. One-time setup:
# docker login
# docker buildx create --use --name hashgg-builder
docker-buildx:
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t $(DOCKER_REPO):$(DOCKER_TAG) \
-t $(DOCKER_REPO):latest \
--push \
.