diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..021f4913 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,44 @@ +# Git +.git +.gitignore +.gitattributes + +# IDE +.idea +.vscode +*.swp +*.swo +*~ + +# Documentation +*.md +README.md +LICENSE + +# CI/CD +.github + +# Test files and sample data +*_test.go +test_utils.go +sample-requests +configtest + +# Build artifacts +prebid-cache +*.exe +*.dll +*.so +*.dylib + +# Go vendor directory (created in container) +vendor/ + +# Temporary files +*.tmp +*.log +.DS_Store + +# Docker +Dockerfile* +.dockerignore diff --git a/.gitignore b/.gitignore index 1e16f692..1bfbf751 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ prebid-cache # ide .vscode/ +.idea/ # autogenerated mac file diff --git a/Dockerfile b/Dockerfile index 192acfc0..279f2771 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,39 +1,38 @@ -FROM ubuntu:22.04 AS build -RUN apt-get update && \ - apt-get -y upgrade && \ - apt-get install -y --no-install-recommends wget ca-certificates -ENV GO_INSTALLER=go1.19.5.linux-amd64.tar.gz -WORKDIR /tmp -RUN wget https://dl.google.com/go/$GO_INSTALLER && \ - tar -C /usr/local -xzf $GO_INSTALLER -RUN mkdir -p /app/prebid-cache/ +FROM alpine:3.23 AS build + +RUN apk update && \ + apk add --no-cache go=1.25.5-r0 git bash ca-certificates && \ + rm -rf /var/cache/apk/* + +ENV GOPROXY="https://proxy.golang.org" \ + CGO_ENABLED=0 + WORKDIR /app/prebid-cache/ -ENV GOROOT=/usr/local/go -ENV PATH=$GOROOT/bin:$PATH -ENV GOPROXY="https://proxy.golang.org" -RUN apt-get update && \ - apt-get install -y --no-install-recommends git && \ - apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* -ENV CGO_ENABLED 0 -COPY ./ ./ + +COPY go.mod go.sum ./ +RUN go mod download && go mod verify + +COPY . . RUN go mod vendor -RUN go mod tidy + ARG TEST="true" RUN if [ "$TEST" != "false" ]; then ./validate.sh ; fi -RUN go build -mod=vendor -ldflags "-X github.com/prebid/prebid-cache/version.Ver=`git describe --tags` -X github.com/prebid/prebid-cache/version.Rev=`git rev-parse HEAD`" . -FROM ubuntu:22.04 AS release -LABEL maintainer="hans.hjort@xandr.com" -RUN apt-get update && \ - apt-get install -y --no-install-recommends ca-certificates && \ - apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +RUN go build -mod=vendor -ldflags "-X github.com/prebid/prebid-cache/version.Ver=$(git describe --tags 2>/dev/null || echo 'dev') -X github.com/prebid/prebid-cache/version.Rev=$(git rev-parse HEAD 2>/dev/null || echo 'unknown')" . +FROM alpine:3.23 AS release +LABEL maintainer="hans.hjort@xandr.com" + +RUN apk add --no-cache ca-certificates && \ + rm -rf /var/cache/apk/* + +RUN addgroup -g 2001 -S prebidgroup && \ + adduser -u 1001 -S -G prebidgroup prebid + WORKDIR /usr/local/bin/ -COPY --from=build /app/prebid-cache/prebid-cache . -RUN chmod a+xr prebid-cache -COPY --from=build /app/prebid-cache/config.yaml . -RUN chmod a+r config.yaml -RUN addgroup --system --gid 2001 prebidgroup && adduser --system --uid 1001 --ingroup prebidgroup prebid + +COPY --from=build /app/prebid-cache/prebid-cache \ + /app/prebid-cache/config.yaml ./ + USER prebid -EXPOSE 2424 -EXPOSE 2525 +EXPOSE 2424 2525 ENTRYPOINT ["/usr/local/bin/prebid-cache"]