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

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

Related

I'm getting this error "at TCPConnectWrap.afterConnect [as oncomplete]" when creating a docker image from a nestjs Project

Im trying to make a Docker file to deploy a Nestjs API. The Api has a connection to a PostgresDB and when i make the DockerFile, i'm getting this error at TCPConnectWrap.afterConnect [as oncomplete]
Here is my DockerFile
# Base image
FROM node:18
# Create app directory
WORKDIR /usr/src/app
# A wildcard is used to ensure both package.json AND package-lock.json are copied
COPY package*.json ./
# Install app dependencies
RUN yarn install
# Bundle app source
COPY . .
# Creates a "dist" folder with the production build
RUN yarn run build
# Start the server using the production build
CMD [ "node", "dist/main.js" ]
Here is an Image of the error enter image description here
I've tried to add Environment Variable, but the error still remaining

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.

Sample DockerFile for playwright test

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" ]

Error while setting up Movesense platform with Cmake commands

I've been trying to set up movesense platform in my windows 10 machine and facing issues with cmake commands.
I pulled the movesense container using docker
docker pull movesense/sensor-build-env:latest
I cloned the movesense repo using the below code
git clone git#bitbucket.org:suunto/movesense-device-lib.git
Then I moved to the cloned folder
cd movesense-device-lib
Then I started the docker image on the terminal
docker run -it --rm -v c:/My/Project/Folder/movesense-device-lib:/movesense:delegated movesense/sensor-build-env:latest
The docker prompted and I followed the below commands
cd /movesense
mkdir myBuild
cd myBuild
Now, I ran the CMake "Run the CMake (needs to be done only once unless you add files to the project). It's possible to build both the debug and release version. In both cases the command will contain the following:" by the following command
cmake -G Ninja -DMOVESENSE_CORE_LIBRARY=../MovesenseCoreLib/ -DCMAKE_TOOLCHAIN_FILE=../MovesenseCoreLib/toolchain/gcc-nrf52.cmake <sample_directory>
I created a sample folder as build1 and saved. In the place of sample_directory, I pasted "build" and executed the command.
But in return I get an error as
CMake Error: The source directory "/movesense/myBuild/build" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI.
The objective is to create a project as zip file and run it in visual studio. Please help me to solve the issue. I've attached the links of the documents which I followed from movesense.
Movesense Set up document
The "<sample_directory>" should be a path to the folder where the firmware source code is (i.e. the sample app folder). If you create the build folder as /movesense/myBuild and cd into it, the path would be ../samples/blinky_app if you are building the blinky_app -sample.
Full disclosure: I work for the movesense team

Dockerfile copying war to local linked volume

I have a note app that I am building with a Dockerfile in the maven app.
I want to copy the artifact note-1.0.war to local linked volume to folder like webapps. So far I have the following in a Dockerfile:
FROM maven:latest
MAINTAINER Sonam <emailme#gmail.com>
RUN apt-get update
WORKDIR /code
#Prepare by downloading dependencies
ADD pom.xml /code/pom.xml
RUN ["mvn", "dependency:resolve"]
RUN ["mvn", "verify"]
#Adding source, compile and package into a fat jar
ADD src /code/src
RUN ["mvn", "clean"]
#RUN ["mvn", "install"]
RUN ["mvn", "install", "-Dmaven.test.skip=true"]
RUN mkdir webapps
COPY note-1.0.war webapps
#COPY code/target/note-1.0.war webapps
Unfortunately, I keep seeing the "no such file or directory" at the COPY statement. The following is the error from build on Docker hub:
...
---> bd555aecadbd
Removing intermediate container 69c09945f954
Step 11 : RUN mkdir webapps
---> Running in 3d114c40caee
---> 184903fa1041
Removing intermediate container 3d114c40caee
Step 12 : COPY note-1.0.war webapps
lstat note-1.0.war: no such file or directory
How can I copy the war file to a "webapps" folder that I executed in
RUN mkdir webapps
thanks
The COPY instruction copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>.
In your example the docker build is looking for note-1.0.war in the same directory than Dockerfile.
If I understand your intention, you want to copy a file inside the image that is build from previous RUN in Dockerfile.
So you should use something like
RUN cp /code/target/note-1.0.war /code/webapps