Skip to content

Commit 566284d

Browse files
committed
ghost: support building multi-arch
1 parent e0f0c5d commit 566284d

File tree

6 files changed

+95
-69
lines changed

6 files changed

+95
-69
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
bin/ghost
2-
bin/ghost.py.bin
1+
bin/ghost.*.linux*
2+
bin/ghost.py*
33
bin/overlordd
44
bin/ovl.py.bin
55
bin/webroot
@@ -8,3 +8,4 @@ webroot/apps
88
webroot/index.html
99
node_modules
1010
.vite
11+
dist

Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,8 @@ RUN mkdir -p /config /app /app/webroot/upgrade
2727
WORKDIR /app
2828

2929
COPY --from=gobuilder /src/bin/overlordd /app
30-
COPY --from=gobuilder /src/bin/ghost /app
3130
COPY --from=gobuilder /src/scripts/start_overlordd.sh /app
32-
COPY --from=gobuilder /src/bin/ghost /app/webroot/upgrade/ghost.linux.amd64
33-
34-
RUN sha1sum /app/webroot/upgrade/ghost.linux.amd64 | \
35-
awk '{ print $1 }' > /app/webroot/upgrade/ghost.linux.amd64.sha1
31+
COPY --from=gobuilder /src/bin/ghost.* /app/webroot/upgrade/
3632

3733
COPY --from=nodebuilder /src/webroot /app/webroot
3834

Makefile

Lines changed: 77 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,79 +12,116 @@ WEBROOT_DIR=$(CURDIR)/webroot
1212
APPS_DIR=$(WEBROOT_DIR)/apps
1313
GO_DIRS=./overlord/... ./cmd/...
1414

15+
# Supported architectures for ghost binary
16+
GHOST_ARCHS=amd64 386 arm64 armv7
17+
GHOST_BINS=$(addprefix $(BIN)/ghost., $(addsuffix .linux,$(GHOST_ARCHS)))
18+
19+
# Output formatting
20+
cmd_msg = @echo " $(1) $(2)"
21+
1522
ifeq ($(STATIC), true)
1623
LDFLAGS=-a -tags netgo -installsuffix netgo \
1724
-ldflags '-extldflags "-static"'
1825
endif
1926

20-
.PHONY: all build build-bin build-apps clean clean-apps install go-fmt go-lint
27+
.PHONY: all \
28+
build build-go build-py build-apps \
29+
ghost overlordd \
30+
go-fmt go-lint \
31+
clean clean-apps \
32+
install
2133

2234
all: build
2335

24-
build: build-bin build-apps
36+
build: build-go build-py build-apps
2537

2638
deps:
27-
mkdir -p $(BIN)
28-
if $(DEPS); then \
39+
@mkdir -p $(BIN)
40+
@if $(DEPS); then \
41+
$(call cmd_msg,GET,dependencies); \
2942
cd $(CURDIR); \
3043
$(GO) get ./...; \
3144
fi
3245

3346
overlordd: deps
34-
GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
35-
rm -f $(BIN)/webroot
36-
ln -s $(WEBROOT_DIR) $(BIN)/webroot
47+
$(call cmd_msg,GO,cmd/$@)
48+
@GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
49+
@rm -f $(BIN)/webroot
50+
@ln -s $(WEBROOT_DIR) $(BIN)/webroot
3751

3852
ghost: deps
39-
GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
53+
@for arch in $(GHOST_ARCHS); do \
54+
$(call cmd_msg,GO,ghost.$$arch.linux); \
55+
GOARCH_VAL=$$arch; \
56+
if [ "$$arch" = "armv7" ]; then \
57+
GOARCH_VAL="arm"; \
58+
GOARM=7 GOOS=linux GOARCH=$$GOARCH_VAL \
59+
$(GO) build $(LDFLAGS) \
60+
-o $(BIN)/ghost.$$arch.linux \
61+
$(CURDIR)/cmd/ghost; \
62+
else \
63+
GOOS=linux GOARCH=$$GOARCH_VAL \
64+
$(GO) build $(LDFLAGS) \
65+
-o $(BIN)/ghost.$$arch.linux \
66+
$(CURDIR)/cmd/ghost; \
67+
fi; \
68+
done
69+
@cd $(BIN) && for arch in $(GHOST_ARCHS); do \
70+
$(call cmd_msg,SHA1,ghost.$$arch.linux); \
71+
sha1sum ghost.$$arch.linux > ghost.$$arch.linux.sha1; \
72+
done
4073

4174
build-go: overlordd ghost
4275

43-
build-bin:
44-
mkdir -p $(BUILD)
45-
# Create virtualenv environment
46-
rm -rf $(BUILD)/.venv
47-
python -m venv $(BUILD)/.venv
48-
# Build ovl binary with pyinstaller
49-
cd $(BUILD); \
76+
build-py:
77+
@ln -sf ../scripts/ghost.py bin
78+
@mkdir -p $(BUILD)
79+
$(call cmd_msg,VENV,creating virtualenv)
80+
@rm -rf $(BUILD)/.venv
81+
@python -m venv $(BUILD)/.venv
82+
$(call cmd_msg,PIP,installing requirements)
83+
@cd $(BUILD); \
5084
. $(BUILD)/.venv/bin/activate; \
51-
pip install -r $(CURDIR)/requirements.txt; \
52-
pip install pyinstaller; \
53-
pyinstaller --onefile $(CURDIR)/scripts/ovl.py; \
54-
pyinstaller --onefile $(CURDIR)/scripts/ghost.py
55-
# Move built binary to bin
56-
mv $(BUILD)/dist/ovl $(BIN)/ovl.py.bin
57-
mv $(BUILD)/dist/ghost $(BIN)/ghost.py.bin
58-
85+
pip install -q -r $(CURDIR)/requirements.txt; \
86+
pip install -q pyinstaller; \
87+
$(call cmd_msg,GEN,ovl.py.bin); \
88+
pyinstaller --onefile $(CURDIR)/scripts/ovl.py > /dev/null; \
89+
$(call cmd_msg,GEN,ghost.py.bin); \
90+
pyinstaller --onefile $(CURDIR)/scripts/ghost.py > /dev/null
91+
$(call cmd_msg,MV,binaries to $(BIN))
92+
@mv $(BUILD)/dist/ovl $(BIN)/ovl.py.bin
93+
@mv $(BUILD)/dist/ghost $(BIN)/ghost.py.bin
5994

6095
go-fmt:
61-
$(GO) fmt $(GO_DIRS)
96+
$(call cmd_msg,FMT,$(GO_DIRS))
97+
@$(GO) fmt $(GO_DIRS)
6298

6399
go-lint:
64-
$(GO) vet $(GO_DIRS)
100+
$(call cmd_msg,VET,$(GO_DIRS))
101+
@$(GO) vet $(GO_DIRS)
65102
@if ! command -v golint > /dev/null; then \
66-
echo "Installing golint..."; \
103+
$(call cmd_msg,GO,installing golint); \
67104
$(GO) install golang.org/x/lint/golint@latest; \
68105
fi
69-
golint -set_exit_status $(GO_DIRS)
106+
$(call cmd_msg,LINT,$(GO_DIRS))
107+
@golint -set_exit_status $(GO_DIRS)
70108

71109
# Build all apps that have a package.json
72110
build-apps:
73-
@echo "Building apps ..."
74111
@mkdir -p $(APPS_DIR)
75112
@cd apps && \
76113
for dir in */; do \
77114
if [ ! -f "$$dir/package.json" ]; then \
78115
continue; \
79116
fi; \
80-
echo "Building $$dir ..."; \
81-
(cd "$$dir" && npm install && npm run build); \
117+
$(call cmd_msg,NPM,$$dir); \
118+
(cd "$$dir" && npm install --silent && npm run build --silent); \
82119
if [ -d "$$dir/dist" ]; then \
83-
echo "Copying $$dir dist to apps directory ..."; \
120+
$(call cmd_msg,CP,$$dir to apps); \
84121
mkdir -p $(APPS_DIR)/"$${dir%/}"; \
85122
cp -r "$$dir/dist/"* $(APPS_DIR)/"$${dir%/}"/; \
86123
if [ "$$dir" = "dashboard/" ]; then \
87-
echo "Copying dashboard to webroot ..."; \
124+
$(call cmd_msg,CP,dashboard to webroot); \
88125
cp $(APPS_DIR)/dashboard/index.html \
89126
$(CURDIR)/webroot/index.html; \
90127
fi; \
@@ -96,16 +133,17 @@ build-apps:
96133

97134
# Install the built apps to the system directory
98135
install: build
99-
@echo "Installing apps..."
100-
mkdir -p /usr/local/share/overlord/apps
101-
cp -r $(APPS_DIR)/* /usr/local/share/overlord/apps/
102-
@echo "Installation complete"
136+
$(call cmd_msg,CP,apps to system)
137+
@mkdir -p /usr/local/share/overlord/apps
138+
@cp -r $(APPS_DIR)/* /usr/local/share/overlord/apps/
103139

104140
clean-apps:
105-
rm -rf $(APPS_DIR)
106-
rm -rf $(WEBROOT_DIR)/index.html
141+
$(call cmd_msg,RM,apps)
142+
@rm -rf $(APPS_DIR)
143+
@rm -rf $(WEBROOT_DIR)/index.html
107144

108145
clean: clean-apps
109-
rm -rf $(BIN)/ghost $(BIN)/overlordd $(BUILD) \
146+
$(call cmd_msg,RM,build artifacts)
147+
@rm -rf $(BIN)/ghost* $(BIN)/overlordd $(BUILD) \
110148
$(BIN)/ghost.py.bin $(BIN)/ovl.py.bin \
111149
$(APPS_DIR)

bin/ghost.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

overlord/sysutils_posix.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

overlord/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,17 @@ func GetenvInt(key string, defaultValue int) int {
7373
}
7474
return value
7575
}
76+
77+
// Ttyname returns the TTY name of a given file descriptor.
78+
func Ttyname(fd uintptr) (string, error) {
79+
// Get the process ID
80+
pid := os.Getpid()
81+
82+
// Try to read the symlink for the file descriptor
83+
ttyPath, err := os.Readlink(fmt.Sprintf("/proc/%d/fd/%d", pid, fd))
84+
if err != nil {
85+
return "", fmt.Errorf("failed to get tty name: %v", err)
86+
}
87+
88+
return ttyPath, nil
89+
}

0 commit comments

Comments
 (0)