diff --git a/Dockerfile b/Dockerfile index 7728753..d21b928 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,31 @@ +# Stage 1: Modules caching +FROM golang:latest as modules +COPY go.mod go.sum /modules/ +WORKDIR /modules +RUN go mod download + FROM golang:latest AS builder ARG TARGETARCH ARG version=not-set ARG SHORTSHA=not-set +COPY --from=modules /go/pkg /go/pkg RUN apt update && apt install git WORKDIR /app COPY . . -RUN go mod tidy -RUN go run github.com/playwright-community/playwright-go/cmd/playwright@latest install --with-deps + +# Install playwright cli with right version for later use +RUN PWGO_VER=$(grep -oE "playwright-go v\S+" /app/go.mod | sed 's/playwright-go //g') \ + && go install github.com/playwright-community/playwright-go/cmd/playwright@${PWGO_VER} # https://stackoverflow.com/questions/70369368/check-architecture-in-dockerfile-to-get-amd-arm RUN go build -o bin/crawler \ -ldflags "-X main.Shortsha=${SHORTSHA} \ -X main.Version=${version} \ - -X main.Aarch=${TARGETARCH}" ./cmd/crawler/main.go -ENTRYPOINT /app/bin/crawler - + -X main.Aarch=${TARGETARCH}" ./cmd/crawler/main.go + +FROM ubuntu:noble +COPY --from=builder /go/bin/playwright /app/bin/crawler / +RUN apt-get update && apt-get install -y ca-certificates tzdata \ + # Install dependencies and all browsers (or specify one) + && /playwright install --with-deps \ + && rm -rf /var/lib/apt/lists/* +CMD ["/crawler"]