From 6c9469f610c9e060d84cd4c5fd2dd46f6bfeb2ea Mon Sep 17 00:00:00 2001 From: Thomas Anderson <127358482+zc-devs@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:04:10 +0300 Subject: [PATCH] Improved Local backend detection (#4006) Co-authored-by: 6543 <6543@obermui.de> --- docker/Dockerfile.agent.alpine.multiarch | 2 ++ docker/Dockerfile.agent.multiarch | 2 ++ pipeline/backend/local/local.go | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile.agent.alpine.multiarch b/docker/Dockerfile.agent.alpine.multiarch index c15d113f8..d873a683e 100644 --- a/docker/Dockerfile.agent.alpine.multiarch +++ b/docker/Dockerfile.agent.alpine.multiarch @@ -10,6 +10,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \ FROM docker.io/alpine:3.20 RUN apk add -U --no-cache ca-certificates ENV GODEBUG=netdns=go +# Internal setting do NOT change! Signals that woodpecker is running inside a container +ENV WOODPECKER_IN_CONTAINER=true EXPOSE 3000 COPY --from=build /src/dist/woodpecker-agent /bin/ diff --git a/docker/Dockerfile.agent.multiarch b/docker/Dockerfile.agent.multiarch index 6349a3d50..52a58a0cf 100644 --- a/docker/Dockerfile.agent.multiarch +++ b/docker/Dockerfile.agent.multiarch @@ -10,6 +10,8 @@ RUN mkdir -p /etc/woodpecker FROM scratch ENV GODEBUG=netdns=go +# Internal setting do NOT change! Signals that woodpecker is running inside a container +ENV WOODPECKER_IN_CONTAINER=true EXPOSE 3000 # copy certs from build image diff --git a/pipeline/backend/local/local.go b/pipeline/backend/local/local.go index 3ea42ba0f..fc7c0420a 100644 --- a/pipeline/backend/local/local.go +++ b/pipeline/backend/local/local.go @@ -63,7 +63,10 @@ func (e *local) Name() string { } func (e *local) IsAvailable(context.Context) bool { - return true + _, inContainer := os.LookupEnv("WOODPECKER_IN_CONTAINER") + // note: we don't need to check by args as this would indicate we are not in an container anyway ... + backend := os.Getenv("WOODPECKER_BACKEND") + return backend == "local" || !inContainer } func (e *local) Flags() []cli.Flag {