diff --git a/.goreleaser.yaml b/.goreleaser.yaml index e6b0747..e753051 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -9,8 +9,6 @@ env: - GITHUB_ORG=almeidapaulopt - DOCKER_ORG=almeidapaulopt - DOCKERFILE=Dockerfile.goreleaser - - MAIN=./cmd/server/ - - BINARY=tsdproxyd before: hooks: @@ -23,8 +21,9 @@ gomod: report_sizes: true builds: - - binary: "{{ .Env.BINARY }}" - main: "{{ .Env.MAIN }}" + - id: server + main: ./cmd/server/main.go + binary: tsdproxyd env: - CGO_ENABLED=0 goos: @@ -46,6 +45,28 @@ builds: ldflags: - -s -w -X "github.com/almeidapaulopt/tsdproxy/core.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }}, {{ .Os }}/{{ .Arch }})" -X "github.com/almeidapaulopt/tsdproxy/core.version={{ .Tag }}" + - id: healthcheck + main: ./cmd/healthcheck/main.go + binary: healthcheck + env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 + - arm + goarm: + - "6" + - "7" + ignore: + - goarch: arm + goos: windows + - goarch: arm64 + goos: freebsd + universal_binaries: - replace: false diff --git a/Dockerfile b/Dockerfile index 08d8f80..e3ab198 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,16 +11,17 @@ COPY . . # Compila a aplicação Go RUN go mod tidy && CGO_ENABLED=0 GOOS=linux go build -o /tsdproxyd ./cmd/server/main.go +RUN CGO_ENABLED=0 GOOS=linux go build -o /healthcheck ./cmd/healthcheck/main.go FROM scratch + COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /tsdproxyd /tsdproxyd -# add curl -COPY --from=ghcr.io/tarampampam/curl:8.10.1 /bin/curl /bin/curl +COPY --from=builder /tsdproxyd /tsdproxyd +COPY --from=builder /healthcheck /healthcheck ENTRYPOINT ["/tsdproxyd"] EXPOSE 8080 -HEALTHCHECK CMD curl --fail http://127.0.0.1:8080/health/ready/ +HEALTHCHECK CMD [ "/healthcheck" ] diff --git a/Dockerfile.goreleaser b/Dockerfile.goreleaser index c938424..d6bd108 100644 --- a/Dockerfile.goreleaser +++ b/Dockerfile.goreleaser @@ -2,12 +2,12 @@ FROM alpine:latest AS certs RUN apk add --no-cache ca-certificates && update-ca-certificates 2>/dev/null || true FROM scratch + COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -# add curl -COPY --from=ghcr.io/tarampampam/curl:8.10.1 /bin/curl /bin/curl -ENTRYPOINT ["/tsdproxyd"] COPY tsdproxyd / +COPY healthcheck / +ENTRYPOINT ["/tsdproxyd"] EXPOSE 8080 -HEALTHCHECK CMD curl --fail http://127.0.0.1:8080/health/ready/ +HEALTHCHECK CMD [ "/healthcheck" ] diff --git a/cmd/healthcheck/main.go b/cmd/healthcheck/main.go new file mode 100644 index 0000000..6b05cc9 --- /dev/null +++ b/cmd/healthcheck/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "net/http" + "os" +) + +func main() { + _, err := http.Get("http://127.0.0.1:8080/health/ready/") + if err != nil { + os.Exit(1) + } +}