From b13167f6204fd41738aae4f28621c78a7ec57a70 Mon Sep 17 00:00:00 2001 From: yusing Date: Sun, 27 Apr 2025 18:43:27 +0800 Subject: [PATCH] fix: build error --- Dockerfile | 20 +++++++++++++------- Makefile | 33 ++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a22618..0213437 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,21 +6,27 @@ HEALTHCHECK NONE # trunk-ignore(hadolint/DL3018) RUN apk add --no-cache tzdata make +ENV GOPATH=/root/go + +WORKDIR /src + +COPY go.mod go.sum ./ +COPY agent ./agent +COPY internal/dnsproviders ./internal/dnsproviders + +RUN go mod download -x + # Stage 2: builder FROM deps AS builder WORKDIR /src -COPY go.mod go.sum ./ COPY Makefile ./ COPY cmd ./cmd COPY internal ./internal COPY pkg ./pkg COPY agent ./agent -ENV GOPATH=/root/go -RUN go mod download -x - ARG VERSION ENV VERSION=${VERSION} @@ -29,8 +35,8 @@ ENV MAKE_ARGS=${MAKE_ARGS} ENV GOCACHE=/root/.cache/go-build ENV GOPATH=/root/go -RUN make ${MAKE_ARGS} docker=1 build link-binary && \ - mv bin /app/ + +RUN make ${MAKE_ARGS} docker=1 build # Stage 3: Final image FROM scratch @@ -42,7 +48,7 @@ LABEL proxy.exclude=1 COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo # copy binary -COPY --from=builder /app/bin /app/bin +COPY --from=builder /app/run /app/run # copy certs COPY --from=builder /etc/ssl/certs /etc/ssl/certs diff --git a/Makefile b/Makefile index eceb39c..47d0d1f 100755 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +shell := /bin/sh export VERSION ?= $(shell git describe --tags --abbrev=0) export BUILD_DATE ?= $(shell date -u +'%Y%m%d-%H%M') export GOOS = linux @@ -53,14 +54,17 @@ export GODEBUG export GORACE export BUILD_FLAGS -ifeq (${docker}, 0) - ifeq ($(shell id -u), 0) - SETCAP_CMD = setcap - else - SETCAP_CMD = sudo setcap - endif +ifeq ($(shell id -u), 0) + SETCAP_CMD = setcap else - SETCAP_CMD = echo + SETCAP_CMD = sudo setcap +endif + +ifeq ($(docker), 1) + POST_BUILD = mkdir -p /app && mv ${BIN_PATH} /app/run +else + # CAP_NET_BIND_SERVICE: permission for binding to :80 and :443 + POST_BUILD = $(SETCAP_CMD) CAP_NET_BIND_SERVICE=+ep ${BIN_PATH} endif .PHONY: debug @@ -68,15 +72,17 @@ endif test: GODOXY_TEST=1 go test ./internal/... +docker-build-test: + docker build -t godoxy . + docker build --build-arg=MAKE_ARGS=agent=1 -t godoxy-agent . + get: for dir in ${PWD} ${PWD}/agent; do cd $$dir && go get -u ./... && go mod tidy; done build: - mkdir -p bin + mkdir -p $(shell dirname ${BIN_PATH}) cd ${PWD} && go build ${BUILD_FLAGS} -o ${BIN_PATH} ${CMD_PATH} - - # CAP_NET_BIND_SERVICE: permission for binding to :80 and :443 - $(SETCAP_CMD) CAP_NET_BIND_SERVICE=+ep ${BIN_PATH} + ${POST_BUILD} run: [ -f .env ] && godotenv -f .env go run ${BUILD_FLAGS} ${CMD_PATH} @@ -86,7 +92,7 @@ debug: sh -c 'HTTP_ADDR=:81 HTTPS_ADDR=:8443 API_ADDR=:8899 DEBUG=1 bin/godoxy-test' mtrace: - bin/godoxy debug-ls-mtrace > mtrace.json + ${BIN_PATH} debug-ls-mtrace > mtrace.json rapid-crash: docker run --restart=always --name test_crash -p 80 debian:bookworm-slim /bin/cat &&\ @@ -103,8 +109,5 @@ ci-test: cloc: cloc --not-match-f '_test.go$$' cmd internal pkg -link-binary: - ln -s /app/${NAME} bin/run - push-github: git push origin $(shell git rev-parse --abbrev-ref HEAD) \ No newline at end of file