Skip to content

Commit d1ba11c

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

File tree

7 files changed

+103
-98
lines changed

7 files changed

+103
-98
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,22 @@ jobs:
1616
- name: install
1717
run: |
1818
apk update
19-
apk add git python3 make gcc linux-headers libc-dev py-pip node npm
19+
apk add git python3 make gcc linux-headers libc-dev py-pip
2020
python3 -m venv .venv
2121
source .venv/bin/activate
2222
pip install -r requirements.txt
2323
- name: Fix permission
2424
run: git config --global --add safe.directory $PWD
2525
- name: test
2626
run: go test -v ./...
27-
- name: build-apps
28-
run: make build-apps
2927
- name: unittest
3028
run: |
3129
source .venv/bin/activate
3230
./scripts/ovl_unittest.py
3331
- name: e2e_test
3432
run: |
3533
source .venv/bin/activate
34+
mkdir -p webroot/apps/test
3635
./test/overlord_e2e_unittest.py
3736
3837
build:

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
bin/ghost
2-
bin/ghost.py.bin
2+
bin/ghost.*.linux*
3+
bin/ghost.py*
34
bin/overlordd
45
bin/ovl.py.bin
56
bin/webroot
@@ -8,3 +9,4 @@ webroot/apps
89
webroot/index.html
910
node_modules
1011
.vite
12+
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: 83 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,103 +9,120 @@ DEPS?=true
99
STATIC?=false
1010
LDFLAGS=
1111
WEBROOT_DIR=$(CURDIR)/webroot
12-
APPS_DIR=$(WEBROOT_DIR)/apps
12+
DIST_APPS_DIR=$(WEBROOT_DIR)/apps
1313
GO_DIRS=./overlord/... ./cmd/...
1414

15+
# Supported architectures for ghost binary
16+
GHOST_ARCHS=amd64 386 arm64 arm
17+
GHOST_BINS=$(addprefix $(BIN)/ghost., $(addsuffix .linux,$(GHOST_ARCHS)))
18+
19+
# Get list of apps with package.json
20+
APP_DIRS=$(shell find apps -maxdepth 1 -mindepth 1 \
21+
-type d -exec test -f '{}/package.json' \; -print | sed 's|apps/||')
22+
APP_TARGETS=$(addprefix $(DIST_APPS_DIR)/,$(APP_DIRS))
23+
24+
# Output formatting
25+
cmd_msg = @echo " $(1) $(2)"
26+
1527
ifeq ($(STATIC), true)
1628
LDFLAGS=-a -tags netgo -installsuffix netgo \
1729
-ldflags '-extldflags "-static"'
1830
endif
1931

20-
.PHONY: all build build-bin build-apps clean clean-apps install go-fmt go-lint
32+
.PHONY: all \
33+
build build-go build-py build-apps \
34+
ghost ghost-all overlordd \
35+
go-fmt go-lint \
36+
clean clean-apps \
37+
install
2138

2239
all: build
2340

24-
build: build-bin build-apps
41+
build: build-go build-py build-apps
2542

2643
deps:
27-
mkdir -p $(BIN)
28-
if $(DEPS); then \
44+
@mkdir -p $(BIN)
45+
@if $(DEPS); then \
2946
cd $(CURDIR); \
3047
$(GO) get ./...; \
3148
fi
3249

3350
overlordd: deps
34-
GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
35-
rm -f $(BIN)/webroot
36-
ln -s $(WEBROOT_DIR) $(BIN)/webroot
51+
$(call cmd_msg,GO,cmd/$@)
52+
@GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
53+
@rm -f $(BIN)/webroot
54+
@ln -s $(WEBROOT_DIR) $(BIN)/webroot
3755

3856
ghost: deps
39-
GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
57+
$(call cmd_msg,GO,cmd/$@)
58+
@GOBIN=$(BIN) $(GO) install $(LDFLAGS) $(CURDIR)/cmd/$@
4059

41-
build-go: overlordd ghost
60+
$(BIN)/ghost.%.linux:
61+
$(call cmd_msg,GO,$(notdir $@))
62+
@GOOS=linux GOARCH=$* $(GO) build $(LDFLAGS) -o $@ $(CURDIR)/cmd/ghost
4263

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); \
50-
. $(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
64+
$(BIN)/ghost.%.linux.sha1: $(BIN)/ghost.%.linux
65+
$(call cmd_msg,SHA1,$(notdir $<))
66+
@cd $(BIN) && sha1sum $(notdir $<) > $(notdir $@)
5867

68+
ghost-all: $(GHOST_BINS) $(GHOST_BINS:=.sha1)
69+
70+
build-go: overlordd ghost ghost-all
71+
72+
build-py:
73+
@ln -sf ../scripts/ghost.py bin
74+
@mkdir -p $(BUILD)
75+
$(call cmd_msg,VENV,creating virtualenv)
76+
@rm -rf $(BUILD)/.venv
77+
@python -m venv $(BUILD)/.venv
78+
$(call cmd_msg,PIP,installing requirements)
79+
@cd $(BUILD); \
80+
. $(BUILD)/.venv/bin/activate; \
81+
pip install -q -r $(CURDIR)/requirements.txt; \
82+
pip install -q pyinstaller; \
83+
$(call cmd_msg,GEN,ovl.py.bin); \
84+
pyinstaller --onefile $(CURDIR)/scripts/ovl.py > /dev/null; \
85+
$(call cmd_msg,GEN,ghost.py.bin); \
86+
pyinstaller --onefile $(CURDIR)/scripts/ghost.py > /dev/null
87+
$(call cmd_msg,MV,binaries to $(BIN))
88+
@mv $(BUILD)/dist/ovl $(BIN)/ovl.py.bin
89+
@mv $(BUILD)/dist/ghost $(BIN)/ghost.py.bin
5990

6091
go-fmt:
61-
$(GO) fmt $(GO_DIRS)
92+
$(call cmd_msg,FMT,$(GO_DIRS))
93+
@$(GO) fmt $(GO_DIRS)
6294

6395
go-lint:
64-
$(GO) vet $(GO_DIRS)
65-
@if ! command -v golint > /dev/null; then \
66-
echo "Installing golint..."; \
67-
$(GO) install golang.org/x/lint/golint@latest; \
68-
fi
69-
golint -set_exit_status $(GO_DIRS)
70-
71-
# Build all apps that have a package.json
72-
build-apps:
73-
@echo "Building apps ..."
74-
@mkdir -p $(APPS_DIR)
75-
@cd apps && \
76-
for dir in */; do \
77-
if [ ! -f "$$dir/package.json" ]; then \
78-
continue; \
79-
fi; \
80-
echo "Building $$dir ..."; \
81-
(cd "$$dir" && npm install && npm run build); \
82-
if [ -d "$$dir/dist" ]; then \
83-
echo "Copying $$dir dist to apps directory ..."; \
84-
mkdir -p $(APPS_DIR)/"$${dir%/}"; \
85-
cp -r "$$dir/dist/"* $(APPS_DIR)/"$${dir%/}"/; \
86-
if [ "$$dir" = "dashboard/" ]; then \
87-
echo "Copying dashboard to webroot ..."; \
88-
cp $(APPS_DIR)/dashboard/index.html \
89-
$(CURDIR)/webroot/index.html; \
90-
fi; \
91-
else \
92-
echo "Error: No dist directory found for $$dir"; \
93-
exit 1; \
94-
fi; \
95-
done
96+
$(call cmd_msg,VET,$(GO_DIRS))
97+
@$(GO) vet $(GO_DIRS)
98+
$(call cmd_msg,GO,installing golint)
99+
@$(GO) install golang.org/x/lint/golint@latest
100+
$(call cmd_msg,LINT,$(GO_DIRS))
101+
@golint -set_exit_status $(GO_DIRS)
102+
103+
# Pattern rule for building individual apps
104+
$(DIST_APPS_DIR)/%:
105+
$(call cmd_msg,NPM,$*)
106+
@mkdir -p $(DIST_APPS_DIR)
107+
@cd apps/$* && npm install --silent && npm run build --silent
108+
@cp -r apps/$*/dist $(DIST_APPS_DIR)/$*
109+
110+
build-apps: $(APP_TARGETS)
111+
@cp $(DIST_APPS_DIR)/dashboard/index.html $(WEBROOT_DIR)
96112

97113
# Install the built apps to the system directory
98114
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"
115+
$(call cmd_msg,CP,apps to system)
116+
@mkdir -p /usr/local/share/overlord/apps
117+
@cp -r $(DIST_APPS_DIR)/* /usr/local/share/overlord/apps/
103118

104119
clean-apps:
105-
rm -rf $(APPS_DIR)
106-
rm -rf $(WEBROOT_DIR)/index.html
120+
$(call cmd_msg,RM,apps)
121+
@rm -rf $(DIST_APPS_DIR)
122+
@rm -rf $(WEBROOT_DIR)/index.html
107123

108124
clean: clean-apps
109-
rm -rf $(BIN)/ghost $(BIN)/overlordd $(BUILD) \
125+
$(call cmd_msg,RM,build artifacts)
126+
@rm -rf $(BIN)/ghost* $(BIN)/overlordd $(BUILD) \
110127
$(BIN)/ghost.py.bin $(BIN)/ovl.py.bin \
111-
$(APPS_DIR)
128+
$(DIST_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)