Apify Discord Mirror

Updated 5 months ago

Monorepo - Playwright Chrome Dockerfile

At a glance
The post asks if any community members have a Playwright Chrome Dockerfile for a monorepo. The comments indicate that one community member has created a Dockerfile that seems to be working, and they are looking for a Docker expert to review it. Another community member suggests that it should be straightforward to set the relative Docker context path and use the default Playwright template. However, a third community member had several issues, mainly with permissions, missing ARG, ENV, and the need to copy tsconfig, so they used a TypeScript_Dockerfile as a base, which required more changes to preserve the logic with shared utils. The third community member provided their Dockerfile code, but there is no explicitly marked answer.
Do you have Playwright Chrome dockerfile for monorepo ?
m
P
4 comments
I created one, and it seems to be working. Does any docker expert want to review it?
Hello , should be pretty straightforward by setting the relative Docker context path, while using the Dockerfile from default Playwright template. Have you found any issues with that?
Yes, I had several issues, mainly with permissions, missing ARG, ENV, and need to copy tsconfig. I tried to add this path without a success, so I used TypeScript_Dockerfile as a base. It required more changes to preserve a logic with shared utils (but I am not sure I did it right).
Plain Text
FROM apify/actor-node-playwright-firefox:16 AS builder
ARG ACTOR_PATH_IN_DOCKER_CONTEXT

COPY --chown=myuser package*.json ./
COPY --chown=myuser tsconfig.build.json ./

COPY --chown=myuser "${ACTOR_PATH_IN_DOCKER_CONTEXT}/package*.json" "${ACTOR_PATH_IN_DOCKER_CONTEXT}/"
COPY --chown=myuser "${ACTOR_PATH_IN_DOCKER_CONTEXT}/tsconfig.build.json" "${ACTOR_PATH_IN_DOCKER_CONTEXT}/"
COPY --chown=myuser "packages/typescript-utils/package*.json" "packages/typescript-utils/"
COPY --chown=myuser "packages/typescript-utils/tsconfig.build.json" "packages/typescript-utils/"

RUN npm install --include=dev --audit=false

COPY --chown=myuser "${ACTOR_PATH_IN_DOCKER_CONTEXT}" "./${ACTOR_PATH_IN_DOCKER_CONTEXT}"
COPY --chown=myuser packages packages/

RUN npm run -w "${ACTOR_PATH_IN_DOCKER_CONTEXT}" build

FROM apify/actor-node-playwright-firefox:16
ARG ACTOR_PATH_IN_DOCKER_CONTEXT

COPY --chown=myuser package*.json ./
COPY --chown=myuser "${ACTOR_PATH_IN_DOCKER_CONTEXT}/package*.json" "${ACTOR_PATH_IN_DOCKER_CONTEXT}/"
COPY --chown=myuser "packages/typescript-utils/package*.json" "packages/typescript-utils/"

RUN npm --quiet set progress=false \
    && npm install --omit=dev --omit=optional \
    && echo "Installed NPM packages:" \
    && (npm list --omit=dev --all || true) \
    && echo "Node.js version:" \
    && node --version \
    && echo "NPM version:" \
    && npm --version \
    && rm -r ~/.npm

COPY --chown=myuser "${ACTOR_PATH_IN_DOCKER_CONTEXT}" "./${ACTOR_PATH_IN_DOCKER_CONTEXT}"
COPY --chown=myuser "packages" "packages/"

COPY --chown=myuser --from=builder "/home/myuser/${ACTOR_PATH_IN_DOCKER_CONTEXT}/dist" "${ACTOR_PATH_IN_DOCKER_CONTEXT}/dist"
COPY --chown=myuser --from=builder "/home/myuser/packages/typescript-utils/dist" "packages/typescript-utils/dist"

ENV ACTOR_PATH_IN_DOCKER_CONTEXT="${ACTOR_PATH_IN_DOCKER_CONTEXT}"
CMD ["sh", "-c", "./start_xvfb_and_run_cmd.sh && npm run -w \"${ACTOR_PATH_IN_DOCKER_CONTEXT}\" start:prod"]
Add a reply
Sign up and join the conversation on Discord