From 26bc0606b5b57a1c02d3961d20c25be33a6bd3c9 Mon Sep 17 00:00:00 2001 From: Ian Meyers Date: Fri, 5 Dec 2025 09:34:51 -0800 Subject: [PATCH 1/2] initial swap --- .gitignore | 1 + Dockerfile | 35 ++++++++++++++--------------------- 2 files changed, 15 insertions(+), 21 deletions(-) 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..90eba94a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,31 @@ -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 +FROM alpine:3.23 AS build +ARG TARGETARCH +ARG TARGETVARIANT +RUN apk update && \ + apk add --no-cache go git bash ca-certificates && \ + go version && \ + rm -rf /var/cache/apk/* + +ENV GOPROXY="https://proxy.golang.org" +ENV CGO_ENABLED=0 + RUN mkdir -p /app/prebid-cache/ 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 ./ ./ 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 +FROM alpine:3.23 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 apk add --no-cache ca-certificates 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 +RUN addgroup -g 2001 -S prebidgroup && adduser -u 1001 -S -G prebidgroup prebid USER prebid EXPOSE 2424 EXPOSE 2525 From dd6f7f74e586e2debe6264a9e98b79cbbddabea5 Mon Sep 17 00:00:00 2001 From: Ian Meyers Date: Fri, 5 Dec 2025 10:37:37 -0800 Subject: [PATCH 2/2] more efficiencies --- .dockerignore | 44 ++++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 44 +++++++++++++++++++++++++------------------- 2 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 .dockerignore 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/Dockerfile b/Dockerfile index 90eba94a..279f2771 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,38 @@ FROM alpine:3.23 AS build -ARG TARGETARCH -ARG TARGETVARIANT + RUN apk update && \ - apk add --no-cache go git bash ca-certificates && \ - go version && \ + apk add --no-cache go=1.25.5-r0 git bash ca-certificates && \ rm -rf /var/cache/apk/* -ENV GOPROXY="https://proxy.golang.org" -ENV CGO_ENABLED=0 +ENV GOPROXY="https://proxy.golang.org" \ + CGO_ENABLED=0 -RUN mkdir -p /app/prebid-cache/ WORKDIR /app/prebid-cache/ -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`" . + +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 +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 -g 2001 -S prebidgroup && adduser -u 1001 -S -G 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"]