Skip to content

Commit 2bb5450

Browse files
committed
ghost: support building multi-arch
1 parent e0f0c5d commit 2bb5450

File tree

5 files changed

+49
-31
lines changed

5 files changed

+49
-31
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
bin/ghost
1+
bin/ghost.*.linux*
22
bin/ghost.py.bin
33
bin/overlordd
44
bin/ovl.py.bin

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: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ 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+
1519
ifeq ($(STATIC), true)
1620
LDFLAGS=-a -tags netgo -installsuffix netgo \
1721
-ldflags '-extldflags "-static"'
1822
endif
1923

20-
.PHONY: all build build-bin build-apps clean clean-apps install go-fmt go-lint
24+
.PHONY: all \
25+
build build-bin build-apps \
26+
ghost overlordd \
27+
go-fmt go-lint \
28+
clean clean-apps \
29+
install
2130

2231
all: build
2332

@@ -36,7 +45,28 @@ overlordd: deps
3645
ln -s $(WEBROOT_DIR) $(BIN)/webroot
3746

3847
ghost: deps
39-
GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
48+
@echo "Building ghost for architectures: $(GHOST_ARCHS)"
49+
@for arch in $(GHOST_ARCHS); do \
50+
echo "Building for $$arch ..."; \
51+
GOARCH_VAL=$$arch; \
52+
if [ "$$arch" = "armv7" ]; then \
53+
GOARCH_VAL="arm"; \
54+
GOARM=7 GOOS=linux GOARCH=$$GOARCH_VAL \
55+
$(GO) build $(LDFLAGS) \
56+
-o $(BIN)/ghost.$$arch.linux \
57+
$(CURDIR)/cmd/ghost; \
58+
else \
59+
GOOS=linux GOARCH=$$GOARCH_VAL \
60+
$(GO) build $(LDFLAGS) \
61+
-o $(BIN)/ghost.$$arch.linux \
62+
$(CURDIR)/cmd/ghost; \
63+
fi; \
64+
done
65+
@echo "Generating SHA1 checksums ..."
66+
@cd $(BIN) && for arch in $(GHOST_ARCHS); do \
67+
sha1sum ghost.$$arch.linux > ghost.$$arch.linux.sha1; \
68+
done
69+
@echo "Build complete!"
4070

4171
build-go: overlordd ghost
4272

@@ -106,6 +136,6 @@ clean-apps:
106136
rm -rf $(WEBROOT_DIR)/index.html
107137

108138
clean: clean-apps
109-
rm -rf $(BIN)/ghost $(BIN)/overlordd $(BUILD) \
139+
rm -rf $(BIN)/ghost* $(BIN)/overlordd $(BUILD) \
110140
$(BIN)/ghost.py.bin $(BIN)/ovl.py.bin \
111141
$(APPS_DIR)

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)