mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
cleanup makefile and remove script, allow running as non-root user
This commit is contained in:
parent
3a4dc3f876
commit
3781bb93e1
3 changed files with 50 additions and 42 deletions
|
@ -4,7 +4,7 @@ HEALTHCHECK NONE
|
||||||
|
|
||||||
# package version does not matter
|
# package version does not matter
|
||||||
# trunk-ignore(hadolint/DL3018)
|
# trunk-ignore(hadolint/DL3018)
|
||||||
RUN apk add --no-cache tzdata make
|
RUN apk add --no-cache tzdata make libcap-setcap
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
|
@ -20,12 +20,14 @@ ENV GOCACHE=/root/.cache/go-build
|
||||||
ARG VERSION
|
ARG VERSION
|
||||||
ENV VERSION=${VERSION}
|
ENV VERSION=${VERSION}
|
||||||
|
|
||||||
COPY scripts /src/scripts
|
|
||||||
COPY Makefile /src/
|
COPY Makefile /src/
|
||||||
COPY cmd /src/cmd
|
COPY cmd /src/cmd
|
||||||
COPY internal /src/internal
|
COPY internal /src/internal
|
||||||
COPY pkg /src/pkg
|
COPY pkg /src/pkg
|
||||||
|
|
||||||
|
ARG BUILD_FLAGS
|
||||||
|
ENV BUILD_FLAGS=${BUILD_FLAGS}
|
||||||
|
|
||||||
RUN --mount=type=cache,target="/go/pkg/mod" \
|
RUN --mount=type=cache,target="/go/pkg/mod" \
|
||||||
--mount=type=cache,target="/root/.cache/go-build" \
|
--mount=type=cache,target="/root/.cache/go-build" \
|
||||||
make build && \
|
make build && \
|
||||||
|
|
80
Makefile
80
Makefile
|
@ -1,53 +1,62 @@
|
||||||
VERSION ?= $(shell git describe --tags --abbrev=0)
|
export VERSION ?= $(shell git describe --tags --abbrev=0)
|
||||||
BUILD_FLAGS ?= -s -w
|
export BUILD_DATE ?= $(shell date -u +'%Y%m%d-%H%M')
|
||||||
BUILD_DATE ?= $(shell date -u +'%Y%m%d-%H%M')
|
|
||||||
export VERSION
|
|
||||||
export BUILD_FLAGS
|
|
||||||
export CGO_ENABLED = 0
|
|
||||||
export GOOS = linux
|
export GOOS = linux
|
||||||
|
|
||||||
.PHONY: all setup build test up restart logs get debug run archive repush rapid-crash debug-list-containers
|
LDFLAGS = -X github.com/yusing/go-proxy/pkg.version=${VERSION}
|
||||||
|
|
||||||
all: debug
|
ifeq ($(trace), 1)
|
||||||
|
GODOXY_TRACE=1
|
||||||
|
endif
|
||||||
|
|
||||||
build:
|
ifeq ($(debug), 1)
|
||||||
scripts/build.sh
|
CGO_ENABLED = 0
|
||||||
|
GODOXY_DEBUG = 1
|
||||||
|
BUILD_FLAGS = ''
|
||||||
|
else ifeq ($(pprof), 1)
|
||||||
|
CGO_ENABLED = 1
|
||||||
|
GODEBUG=gctrace=1 inittrace=1 schedtrace=3000
|
||||||
|
GORACE=log_path=logs/pprof strip_path_prefix=$(shell pwd)/
|
||||||
|
BUILD_FLAGS = -race -gcflags=all="-N -l" -tags pprof
|
||||||
|
DOCKER_TAG = pprof
|
||||||
|
else
|
||||||
|
CGO_ENABLED = 0
|
||||||
|
LDFLAGS += -s -w
|
||||||
|
BUILD_FLAGS = -pgo=auto -tags production
|
||||||
|
DOCKER_TAG = latest
|
||||||
|
endif
|
||||||
|
|
||||||
|
export CGO_ENABLED
|
||||||
|
export GODOXY_DEBUG
|
||||||
|
export GODOXY_TRACE
|
||||||
|
export GODEBUG
|
||||||
|
export GORACE
|
||||||
|
export BUILD_FLAGS
|
||||||
|
export DOCKER_TAG
|
||||||
|
|
||||||
test:
|
test:
|
||||||
GODOXY_TEST=1 go test ./internal/...
|
GODOXY_TEST=1 go test ./internal/...
|
||||||
|
|
||||||
up:
|
|
||||||
docker compose up -d
|
|
||||||
|
|
||||||
restart:
|
|
||||||
docker compose restart -t 0
|
|
||||||
|
|
||||||
logs:
|
|
||||||
docker compose logs -f
|
|
||||||
|
|
||||||
get:
|
get:
|
||||||
go get -u ./cmd && go mod tidy
|
go get -u ./cmd && go mod tidy
|
||||||
|
|
||||||
debug:
|
build:
|
||||||
GODOXY_DEBUG=1 BUILD_FLAGS="" make run
|
mkdir -p bin
|
||||||
|
go build ${BUILD_FLAGS} -o bin/godoxy ./cmd
|
||||||
|
if [ $(shell id -u) -eq 0 ]; \
|
||||||
|
then setcap CAP_NET_BIND_SERVICE=+eip bin/godoxy; \
|
||||||
|
else sudo setcap CAP_NET_BIND_SERVICE=+eip bin/godoxy; \
|
||||||
|
fi
|
||||||
|
|
||||||
debug-trace:
|
run:
|
||||||
GODOXY_TRACE=1 make debug
|
[ -f .env ] && godotenv -f .env go run ${BUILD_FLAGS} ./cmd
|
||||||
|
|
||||||
profile:
|
|
||||||
GODEBUG=gctrace=1 make debug
|
|
||||||
|
|
||||||
run: build
|
|
||||||
sudo setcap CAP_NET_BIND_SERVICE=+eip bin/godoxy
|
|
||||||
[ -f .env ] && godotenv -f .env bin/godoxy || bin/godoxy
|
|
||||||
|
|
||||||
mtrace:
|
mtrace:
|
||||||
bin/godoxy debug-ls-mtrace > mtrace.json
|
bin/godoxy debug-ls-mtrace > mtrace.json
|
||||||
|
|
||||||
rapid-crash:
|
rapid-crash:
|
||||||
sudo docker run --restart=always --name test_crash -p 80 debian:bookworm-slim /bin/cat &&\
|
docker run --restart=always --name test_crash -p 80 debian:bookworm-slim /bin/cat &&\
|
||||||
sleep 3 &&\
|
sleep 3 &&\
|
||||||
sudo docker rm -f test_crash
|
docker rm -f test_crash
|
||||||
|
|
||||||
debug-list-containers:
|
debug-list-containers:
|
||||||
bash -c 'echo -e "GET /containers/json HTTP/1.0\r\n" | sudo netcat -U /var/run/docker.sock | tail -n +9 | jq'
|
bash -c 'echo -e "GET /containers/json HTTP/1.0\r\n" | sudo netcat -U /var/run/docker.sock | tail -n +9 | jq'
|
||||||
|
@ -63,14 +72,17 @@ push-docker-io:
|
||||||
BUILDER=build docker buildx build \
|
BUILDER=build docker buildx build \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
-f Dockerfile \
|
-f Dockerfile \
|
||||||
-t docker.io/yusing/godoxy-nightly \
|
-t docker.io/yusing/godoxy-nightly:${DOCKER_TAG} \
|
||||||
-t docker.io/yusing/godoxy-nightly:${VERSION}-${BUILD_DATE} \
|
-t docker.io/yusing/godoxy-nightly:${VERSION}-${BUILD_DATE} \
|
||||||
--build-arg VERSION="${VERSION}-nightly-${BUILD_DATE}" \
|
--build-arg VERSION="${VERSION}-nightly-${BUILD_DATE}" \
|
||||||
|
--build-arg BUILD_FLAGS="${BUILD_FLAGS}" \
|
||||||
--push .
|
--push .
|
||||||
|
|
||||||
build-docker:
|
build-docker:
|
||||||
docker build -t godoxy-nightly \
|
docker build -t godoxy-nightly \
|
||||||
--build-arg VERSION="${VERSION}-nightly-${BUILD_DATE}" .
|
--build-arg VERSION="${VERSION}-nightly-${BUILD_DATE}" \
|
||||||
|
--build-arg BUILD_FLAGS="${BUILD_FLAGS}" \
|
||||||
|
.
|
||||||
|
|
||||||
gen-schema-single:
|
gen-schema-single:
|
||||||
typescript-json-schema --noExtraProps --required --skipLibCheck --tsNodeRegister=true -o schemas/${OUT} schemas/${IN} ${CLASS}
|
typescript-json-schema --noExtraProps --required --skipLibCheck --tsNodeRegister=true -o schemas/${OUT} schemas/${IN} ${CLASS}
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
mkdir -p bin
|
|
||||||
BUILD_FLAGS="${BUILD_FLAGS} -X github.com/yusing/go-proxy/pkg.version=${VERSION}"
|
|
||||||
echo building GoDoxy version "${VERSION}", build flags \""${BUILD_FLAGS}"\"
|
|
||||||
go build -ldflags "${BUILD_FLAGS}" -pgo=auto -o bin/godoxy ./cmd
|
|
Loading…
Add table
Reference in a new issue