CA
conscious-sapphire

Monorepo - Playwright Chrome Dockerfile

Do you have Playwright Chrome dockerfile for monorepo ?
3 Replies
conscious-sapphire
conscious-sapphireOP2y ago
I created one, and it seems to be working. Does any docker expert want to review it?
Pepa J
Pepa J2y ago
Hello @mscraper , 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?
conscious-sapphire
conscious-sapphireOP2y ago
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).
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"]
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"]

Did you find this page helpful?