Sample DockerFile for playwright test - dockerfile

trying to dockerize my playwright test and having looking for some reference on how i can write the dockerfile. Did some searches but could not find much help. Could anyone share a sample that i can refer.
thanks

At the top of your Dockerfile you can put:
FROM mcr.microsoft.com/playwright:focal
followed by the code that executes your tests.
Check the docs here for more info.

Copy paste Dockerfile for those who have no idea how to use docker, source
FROM mcr.microsoft.com/playwright:focal
# copy project (including tests)
COPY . /e2e
WORKDIR /e2e
# Install dependencies
RUN npm install
# Install browsers
RUN npx playwright install
# Run playwright test
CMD [ "npx", "playwright", "test", "--reporter=list" ]

Related

Create-React-App "npm run build" results in partially populated build folder when run inside Docker container

I have an old project that I started by using Create React App to generate boilerplate. At some point down the line I "ejected" the project. Running npm run build successfully generates all of the expected build artifacts inside the /build folder when run on my dev machine and serving the build folder works perfectly.
Now I'm trying to Dockerize this app and have created the following Dockerfile
FROM node:16-alpine
WORKDIR /app
COPY package.json .
COPY package-lock.json .
ENV NODE_ENV production
RUN npm install
COPY . .
RUN npm run build
CMD [ "npx", "serve", "-l", "3000", "build" ]
I can build and run the image as a Docker container, and the build folder is served fine except that most of its contents are missing. The only two files present are favicon.ico and manifest.json. If I open a shell and list out the build folder it's the same. For some reason the webpack bundles, index.html, styles etc. are all missing.
I've been Googling around for hours but can't find anything. I can't even find out how to log the output of CRA's npm run build command to a file so that I can see the build log.
Can anyone give me a hint at where the problem might lie? Thanks

Can't launch Chromium as executable doesn't exists if customized image is build from Dockerfile

FROM alpine:latest
# Copy source to container
RUN mkdir -p /usr/app
# Copy source code
COPY package.json /usr/app
COPY package-lock.json /usr/app
COPY . /usr/app
# Set working directory
WORKDIR /usr/app
# Environment variables
ENV BASE_URL="Local https url"
ENV PARALLEL_RUN=false
ENV TAG=int
ENV PLAYWRIGHT_BROWSERS_PATH=/usr/lib
# npm install
RUN apk add --update npm
RUN apk add chromium
# Run tests
RUN npm run codeceptjs
Above is the Dockerfile. When tried to Build the image from docker file then I am getting below error:
13 8.596 Error: browserType.launch: Failed to launch chromium because executable doesn't exist at /usr/lib/chromium-888113/chrome-linux/chrome
#13 8.596 Try re-installing playwright with "npm install playwright"**
Although, I can see chromium is getting installed at the mentioned path but still it saying "executable not present".
I believe your problem lies with using alpine.
According to the playwright developers, there are no plans to support playwright on alpine. This makes your whole undertaking more complex. It's correct that you need to provide your own chromium and cannot use the browsers that come with playwright. Therefore, you should set PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD to prevent any (incompatible) browsers from being loaded.
The chromium executable should be in your Docker image under /usr/bin/chromium-browser. You need to use playwright's browserType.launch to set the path to the executable:
const { chromium } = require("playwright-chromium");
// ...
const browser = await chromium.launch({
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH,
});
If you want a simpler solution, I would suggest using the Docker image of Zanika, containing chromium and playwright already. Here the link to the tag on DockerHub. At the very least you can see it as a reference implementation if you still want to use your own image.

Cloud Run needs NGINX or not?

I am using cloud run for my blog and a work site and I really love it.
I have deployed python APIs and Vue/Nuxt Apps by containerising it according to the google tutorials.
One thing I don't understand is why there is no need to have NGINX on the front.
# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12-slim
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install production dependencies.
RUN npm install --only=production
# Copy local code to the container image.
COPY . ./
# Run the web service on container startup.
RUN npm run build
CMD [ "npm", "start" ]
# Use the official lightweight Python image.
# https://hub.docker.com/_/python
FROM python:3.7-slim
# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./
# Install production dependencies.
RUN apt-get update && apt-get install -y \
libpq-dev \
gcc
RUN pip install -r requirements.txt
# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
CMD exec gunicorn -b :$PORT --workers=4 main:server
All this works without me calling Nginx ever.
But I read alot of articles whereby people bundle NGINX in their container. So I would like some clarity. Are there any downsides to what I am doing?
One considerable advantage of using NGINX or a static file server is the size of the container image. When serving SPAs (without SSR), all you need is to get the bundled files to the client. There's no need to bundle build dependencies or runtime that's needed to compile the application.
Your first image is copying whole source code with dependencies into the image, while all you need (if not running SSR) are the compiled files. NGINX can give you the "static site server" that will only serve your build and is a lightweight solution.
Regarding python, unless you can bundle it somehow, it looks ok to use without the NGINX.

build a docker image ros2 , when try tu run . install/setup.bash in dockerfile no works

i have the next problem:
i try to build a docker image with ros2, in which a code package is downloaded which will be built using the colcon build method.
but when I try to run last of. install / setup.bash doesn't work for me.
I already tried to put it in a script and copy it to the dockerfile but it didn't work
any ideas
here I leave the docker file
FROM osrf/ros:dashing-desktop
WORKDIR /home
COPY mobilidad.sh .
RUN bash mobilidad.sh
ENV ROS2_WS cleanmyway/test_ws
RUN mkdir -p ${ROS2_WS}/src/demo_py
COPY ./ ${ROS2_WS}/src/demo_py
WORKDIR ${ROS2_WS}
SHELL ["/bin/bash", "-c"]
RUN colcon build
RUN . install/setup.bash
note: mobilidad.sh is a script that dowload de code from github, this works fine
I think I managed to find a solution,
building the dockerfile as follows:
FROM osrf/ros:dashing-desktop
WORKDIR /home
COPY mobilidad.sh .
RUN bash mobilidad.sh
ENV ROS2_WS cleanmyway/test_ws
RUN mkdir -p ${ROS2_WS}
WORKDIR ${ROS2_WS}
RUN colcon build
RUN echo "source install/setup.bash" >> /opt/ros/dashing/setup.bash
and when i run the ros2 command works fine
but anyway thanks for the help. :)
note: i'm not sure if the better form but works for me

build and deploy from one dockerfile or have different files for each purpose?

I am creating react app and want to build and deploy the build to new container?
I am trying stages in dockerfile.
FROM node:alpine as builder
WORKDIR /app/
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
EXPOSE 80
well the steps you followed is all correct,You just missed the part from where to copy the build folder and paste it in the nginx image.
by default nginx takes files to serve from
usr/share/nginx/html
try the bellow code.
FROM node:alpine as builder
WORKDIR /app/
COPY package.json .
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine
EXPOSE 80
COPY --from=builder /app/build /usr/share/nginx/html
if it doesnt work do comment.