mirror of
https://github.com/yusing/godoxy.git
synced 2025-07-03 21:54:26 +02:00
fix: build error
This commit is contained in:
parent
628dc94924
commit
b13167f620
2 changed files with 31 additions and 22 deletions
20
Dockerfile
20
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
|
||||
|
|
31
Makefile
31
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)
|
||||
ifeq ($(shell id -u), 0)
|
||||
SETCAP_CMD = setcap
|
||||
else
|
||||
SETCAP_CMD = sudo setcap
|
||||
endif
|
||||
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)
|
Loading…
Add table
Reference in a new issue