From d44ce0ee6faae7195d5c6941c83cf974488d5225 Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 4 Jan 2025 10:44:51 +0800 Subject: [PATCH] dockerfile for local build, makefile update --- Dockerfile.dev | 59 +++++++++++++++++++++ Makefile | 5 +- internal/net/http/middleware/middlewares.go | 1 + 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.dev diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..2f8d80d --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,59 @@ +# Stage 1: Builder +FROM golang:1.23.4-alpine AS builder +HEALTHCHECK NONE + +# package version does not matter +# trunk-ignore(hadolint/DL3018) +RUN apk add --no-cache tzdata make + +WORKDIR /src + +# Only copy go.mod and go.sum initially for better caching +COPY go.mod go.sum /src/ + +RUN go mod download -x + +ENV GOCACHE=/root/.cache/go-build + +ARG VERSION +ENV VERSION=${VERSION} + +COPY scripts /src/scripts +COPY Makefile /src/ + +COPY cmd /src/cmd +COPY internal /src/internal +COPY pkg /src/pkg + +RUN make build && \ + mkdir -p /app/error_pages /app/certs && \ + mv bin/godoxy /app/godoxy + +# Stage 2: Final image +FROM scratch + +LABEL maintainer="yusing@6uo.me" +LABEL proxy.exclude=1 + +# copy timezone data +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo + +# copy binary +COPY --from=builder /app /app + +# copy example config +COPY config.example.yml /app/config/config.yml + +# copy certs +COPY --from=builder /etc/ssl/certs /etc/ssl/certs + +ENV DOCKER_HOST=unix:///var/run/docker.sock +ENV GODOXY_DEBUG=0 + +EXPOSE 80 +EXPOSE 8888 +EXPOSE 443 + +WORKDIR /app + +CMD ["/app/godoxy"] \ No newline at end of file diff --git a/Makefile b/Makefile index 349d99a..2aa1157 100755 --- a/Makefile +++ b/Makefile @@ -65,4 +65,7 @@ ci-test: act -n --artifact-server-path /tmp/artifacts -s GITHUB_TOKEN="$$(gh auth token)" cloc: - cloc --not-match-f '_test.go$$' cmd internal pkg \ No newline at end of file + cloc --not-match-f '_test.go$$' cmd internal pkg + +push-docker-io: + BUILDER=build docker buildx build --platform linux/arm64,linux/amd64 -t docker.io/yusing/godoxy-nightly --push . \ No newline at end of file diff --git a/internal/net/http/middleware/middlewares.go b/internal/net/http/middleware/middlewares.go index 0674728..74ccb45 100644 --- a/internal/net/http/middleware/middlewares.go +++ b/internal/net/http/middleware/middlewares.go @@ -74,6 +74,7 @@ func LoadComposeFiles() { allMiddlewares[strutils.ToLowerNoSnake(name)] = m logger.Info(). Str("src", path.Base(defFile)). + Str("name", name). Msg("middleware loaded") } }