mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-04-05 08:53:52 -04:00
feat(health): only run health server when running in Docker
This commit is contained in:
@@ -50,7 +50,8 @@ RUN git init && \
|
|||||||
rm -rf .git/
|
rm -rf .git/
|
||||||
|
|
||||||
FROM --platform=$BUILDPLATFORM base AS build
|
FROM --platform=$BUILDPLATFORM base AS build
|
||||||
RUN mkdir -p /tmp/data
|
RUN mkdir -p /tmp/data && \
|
||||||
|
touch /tmp/isdocker
|
||||||
ARG VERSION=unknown
|
ARG VERSION=unknown
|
||||||
ARG CREATED="an unknown date"
|
ARG CREATED="an unknown date"
|
||||||
ARG COMMIT=unknown
|
ARG COMMIT=unknown
|
||||||
@@ -69,8 +70,10 @@ HEALTHCHECK --interval=60s --timeout=5s --start-period=10s --retries=2 CMD ["/up
|
|||||||
ARG UID=1000
|
ARG UID=1000
|
||||||
ARG GID=1000
|
ARG GID=1000
|
||||||
USER ${UID}:${GID}
|
USER ${UID}:${GID}
|
||||||
|
WORKDIR /updater
|
||||||
ENTRYPOINT ["/updater/ddns-updater"]
|
ENTRYPOINT ["/updater/ddns-updater"]
|
||||||
COPY --from=build --chown=${UID}:${GID} /tmp/data /updater/data
|
COPY --from=build --chown=${UID}:${GID} /tmp/data /updater/data
|
||||||
|
COPY --from=build --chown=${UID}:${GID} /tmp/isdocker /updater/isdocker
|
||||||
ENV \
|
ENV \
|
||||||
# Core
|
# Core
|
||||||
CONFIG= \
|
CONFIG= \
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/qdm12/ddns-updater/internal/health"
|
"github.com/qdm12/ddns-updater/internal/health"
|
||||||
"github.com/qdm12/ddns-updater/internal/healthchecksio"
|
"github.com/qdm12/ddns-updater/internal/healthchecksio"
|
||||||
"github.com/qdm12/ddns-updater/internal/models"
|
"github.com/qdm12/ddns-updater/internal/models"
|
||||||
|
"github.com/qdm12/ddns-updater/internal/noop"
|
||||||
jsonparams "github.com/qdm12/ddns-updater/internal/params"
|
jsonparams "github.com/qdm12/ddns-updater/internal/params"
|
||||||
persistence "github.com/qdm12/ddns-updater/internal/persistence/json"
|
persistence "github.com/qdm12/ddns-updater/internal/persistence/json"
|
||||||
"github.com/qdm12/ddns-updater/internal/provider"
|
"github.com/qdm12/ddns-updater/internal/provider"
|
||||||
@@ -205,10 +206,7 @@ func _main(ctx context.Context, reader *reader.Reader, args []string, logger log
|
|||||||
updaterService := update.NewService(db, updater, ipGetter, config.Update.Period,
|
updaterService := update.NewService(db, updater, ipGetter, config.Update.Period,
|
||||||
config.Update.Cooldown, logger, resolver, timeNow, hioClient)
|
config.Update.Cooldown, logger, resolver, timeNow, hioClient)
|
||||||
|
|
||||||
isHealthy := health.MakeIsHealthy(db, resolver)
|
healthServer, err := createHealthServer(db, resolver, logger, *config.Health.ServerAddress)
|
||||||
healthLogger := logger.New(log.SetComponent("healthcheck server"))
|
|
||||||
healthServer, err := health.NewServer(*config.Health.ServerAddress,
|
|
||||||
healthLogger, isHealthy)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating health server: %w", err)
|
return fmt.Errorf("creating health server: %w", err)
|
||||||
}
|
}
|
||||||
@@ -348,3 +346,15 @@ func exitHealthchecksio(hioClient *healthchecksio.Client,
|
|||||||
logger.Error(err.Error())
|
logger.Error(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:ireturn
|
||||||
|
func createHealthServer(db health.AllSelecter, resolver health.LookupIPer,
|
||||||
|
logger log.LoggerInterface, serverAddress string) (
|
||||||
|
healthServer goservices.Service, err error) {
|
||||||
|
if !health.IsDocker() {
|
||||||
|
return noop.New("healthcheck server"), nil
|
||||||
|
}
|
||||||
|
isHealthy := health.MakeIsHealthy(db, resolver)
|
||||||
|
healthLogger := logger.New(log.SetComponent("healthcheck server"))
|
||||||
|
return health.NewServer(serverAddress, healthLogger, isHealthy)
|
||||||
|
}
|
||||||
|
|||||||
8
internal/health/isdocker.go
Normal file
8
internal/health/isdocker.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package health
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
func IsDocker() (ok bool) {
|
||||||
|
_, err := os.Stat("isdocker")
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
25
internal/noop/service.go
Normal file
25
internal/noop/service.go
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package noop
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(name string) *Service {
|
||||||
|
return &Service{
|
||||||
|
name: name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) String() string {
|
||||||
|
return s.name + " (no-op)"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) Start(_ context.Context) (_ <-chan error, _ error) {
|
||||||
|
return nil, nil //nolint:nilnil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Service) Stop() (stopErr error) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user