Selenium fails on ECS - docker

this is my Dockerfile code
FROM --platform=Linux/X86_64 node:16
RUN apt update
RUN apt -y install build-essential
RUN apt -y install wget
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
RUN apt-get update && apt-get -y install google-chrome-stable
# COPY --from=CHORMEBUILDER /usr/bin/google-chrome-stable /usr/bin/google-chrome-stable
# Create app directory
COPY $PWD /crm-connector
WORKDIR /crm-connector
# RUN npm install --location=global npm#8.12.1
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm#5+)
COPY package*.json ./
RUN node -v
RUN npm uninstall chromedriver
RUN npm install
RUN npm install chromedriver --chromedriver-force-download --detect_chromedriver_version
# If you are building your code for production
#RUN npm ci --only=production
# Bundle app source
COPY . .
RUN npm run build
EXPOSE 8081
CMD [ "npm", "start" ]
I'm trying to run this on ECS
I've hosted my code(Docker images) ECR.
I'm getting following error.
selenium error ex Error: Server terminated early with status 2
at /crm-connector/node_modules/selenium-webdriver/remote/index.js:248:24
Build taken machine is: Mac M1
Trying to deploy it on Operating system/Architecture
Linux/X86_64
Task Definition is:
{
"containerDefinitions": [
{
"image":"image-name",
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "all-log",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "ecs"
}
},
"name":"task-name",
"portMappings": [
{
"containerPort": 8081,
"hostPort": 8081,
"protocol": "tcp",
}
]
}
],
"cpu": "8192",
"executionRoleArn": "arn:aws:iam::accountId:role/ecsTaskExecutionRole",
"family":"task-family",
"memory": "32768",
"networkMode": "awsvpc",
"runtimePlatform": {
"operatingSystemFamily": "LINUX"
},
"requiresCompatibilities": [
"EC2",
"FARGATE"
]
}
advanced thanks for any help you guys do. :)

It was the architecture difference issue. Building machine was arm64 and ECS X86.
if you build from different architecture, remove node_modules and add FROM platform=dest_architecture node:16 in Dockerfile
Thank you very much for the help
#Mark B

Related

How to yarn build on Dockerfile

I try to build a Docker image executing the code:
docker build . -t <YOUR_DOCKER_HUB_USERNAME>/my-nuxt-project
It is about a nuxt.js project but when I run the code I receive the following error:
Step 5/13 : RUN yarn build
---> Running in 4dd3684952ba
yarn run v1.22.19
$ nuxt build
ℹ Production build
ℹ Bundling for server and client side
ℹ Target: server
ℹ Using components loader to optimize imports
ℹ Discovered Components: .nuxt/components/readme.md
✔ Builder initialized
✔ Nuxt files generated
ℹ Compiling Client
node:internal/crypto/hash:71
this[kHandle] = new _Hash(algorithm, xofLen);
^
Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:71:19)
at Object.createHash (node:crypto:133:10)
at module.exports (/app/node_modules/webpack/lib/util/createHash.js:135:53)
at NormalModule._initBuildHash (/app/node_modules/webpack/lib/NormalModule.js:417:16)
at handleParseError (/app/node_modules/webpack/lib/NormalModule.js:471:10)
at /app/node_modules/webpack/lib/NormalModule.js:503:5
at /app/node_modules/webpack/lib/NormalModule.js:358:12
at /app/node_modules/loader-runner/lib/LoaderRunner.js:373:3
at iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
at Array.<anonymous> (/app/node_modules/loader-runner/lib/LoaderRunner.js:205:4)
at Storage.finished (/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:55:16)
at /app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:91:9
at /app/node_modules/graceful-fs/graceful-fs.js:123:16
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}
Node.js v18.12.0
error Command failed with exit code 1.
This is the Dockerfile that I am using. I am following the nuxt documentation to build the image.
FROM node:lts as builder
WORKDIR /app
COPY . .
RUN yarn install \
--prefer-offline \
--frozen-lockfile \
--non-interactive \
--production=false
RUN yarn build
RUN rm -rf node_modules && \
NODE_ENV=production yarn install \
--prefer-offline \
--pure-lockfile \
--non-interactive \
--production=true
FROM node:lts
WORKDIR /app
COPY --from=builder /app .
ENV HOST 0.0.0.0
EXPOSE 3000
CMD [ "yarn", "start" ]
Anyone knows how to debug it?
Try adding NODE_OPTIONS=--openssl-legacy-provider as docker environment variable. So your Dockerfile should be like this. Try rebuilding your Dockerfile after this change.
FROM node:lts as builder
WORKDIR /app
ENV NODE_OPTIONS=--openssl-legacy-provider
COPY . .
RUN yarn install \
--prefer-offline \
--frozen-lockfile \
--non-interactive \
--production=false
RUN yarn build
RUN rm -rf node_modules && \
NODE_ENV=production yarn install \
--prefer-offline \
--pure-lockfile \
--non-interactive \
--production=true
FROM node:lts
WORKDIR /app
COPY --from=builder /app .
ENV HOST 0.0.0.0
EXPOSE 3000
CMD [ "yarn", "start" ]

running puppeeter in docker container based on azure-functions/node:4-node14-slim

I am trying to use puppeteer in an Azure Function App, the app normally runs via func start but it fails to initialize the docker container,
I received this error by running docker run -i --init --rm --cap-add=SYS_ADMIN -p 7071:80 pdfgen:dev, basically the container con not be started because of this error
[8:8:0519/140438.797849:ERROR:ozone_platform_x11.cc(247)] Missing X server or $DISPLAY
[8:8:0519/140438.798294:ERROR:env.cc(225)] The platform failed to initialize. Exiting.
Here is the Dockerfile, I got the instructions from here
FROM mcr.microsoft.com/azure-functions/node:4-node14-slim
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update \
&& apt-get install -y wget gnupg \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
# If running Docker >= 1.13.0 use docker run's --init arg to reap zombie processes, otherwise
# uncomment the following lines to have `dumb-init` as PID 1
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_x86_64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init
ENTRYPOINT ["dumb-init", "--"]
# Uncomment to skip the chromium download when installing puppeteer. If you do,
# you'll need to launch puppeteer with:
# browser.launch({executablePath: 'google-chrome-stable'})
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
# Install puppeteer so it's available in the container.
RUN npm init -y
RUN npm i puppeteer
# Add user so we don't need --no-sandbox.
# same layer as npm install to keep re-chowned files from using up several hundred MBs more space
RUN groupadd -r pptruser && useradd -r -g pptruser -G audio,video pptruser
RUN mkdir -p /home/pptruser/Downloads
RUN chown -R pptruser:pptruser /home/pptruser
RUN chown -R pptruser:pptruser /node_modules
RUN chown -R pptruser:pptruser /package.json
RUN chown -R pptruser:pptruser /package-lock.json
RUN chown -R pptruser:pptruser /home/
# Run everything after as non-privileged user.
USER pptruser
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
RUN cd /home/site/wwwroot
RUN npm install
CMD ["google-chrome-stable"]
And this is the package.json
{
"name": "",
"version": "",
"scripts": {
"build": "tsc",
"build:production": "npm run prestart && npm prune --production",
"watch": "tsc --w",
"prestart": "npm run build && func extensions install",
"start:host": "func start",
"start": "npm-run-all --parallel start:host watch",
"test": "echo \"No tests yet...\""
},
"description": "",
"devDependencies": {
"#azure/functions": "^3.0.0",
"npm-run-all": "^4.1.5",
"typescript": "^3.3.3"
},
"dependencies": {
"#azure/data-tables": "^13.1.1",
"#azure/identity": "^2.0.4",
"puppeteer": "^14.1.0"
}
}
I did a lot of googling but not sure what's wrong here, any idea?
WORKING CONFIG ->
After trying the shared article and some changes, the following config worked pretty well and solved my problem
FROM mcr.microsoft.com/azure-functions/node:4-node14-slim
#####################
#PUPPETEER RECIPE
#####################
# Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, Thai and a few others)
# Note: this installs the necessary libs to make the bundled version of Chromium that Puppeteer
# installs, work.
RUN apt-get update && apt-get -f install && apt-get -y install wget gnupg2 apt-utils
RUN wget --no-verbose -O /tmp/chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
&& apt-get update \
&& apt-get install -y /tmp/chrome.deb --no-install-recommends --allow-downgrades fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
&& rm /tmp/chrome.deb
#####################
#END PUPPETEER RECIPE
#####################
ENV PUPPETEER_EXECUTABLE_PATH "/usr/bin/google-chrome-stable"
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
RUN npm init -y
RUN npm i puppeteer
COPY . /home/site/wwwroot
RUN cd /home/site/wwwroot
RUN npm install
const url = req.query.url || "https://google.com/";
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], });
// {args: ['--no-sandbox', '--disable-setuid-sandbox'],}
const page = await browser.newPage();
await page.goto(url);
const screenshotBuffer = await page.screenshot({ fullPage: true });
await browser.close();
context.res = {
body: screenshotBuffer,
headers: {
"content-type": "image/png"
}
};
Missing X server or $DISPLAY
The following error occurs when the chromium is trying to connect to a display device and the device doesn't exist in the system.
Sometimes running the system in windows might help, but to continue running on Linux you need special software call xvfb .
Please refer the following article by Dario Kondratiuk

How should be a dockerfile for a flutter project

I was trying to containerized my flutter project and wanted to make a docker file for the same could anyone help me doing this.
I found the way to make a docker file for the flutter project which is something like this.
FROM ubuntu:18.04
# Prerequisites
RUN apt update && apt install -y curl git unzip xz-utils zip libglu1-mesa openjdk-8-jdk wget
# Set up new user
RUN useradd -ms /bin/bash developer
USER developer
WORKDIR /home/developer
# Prepare Android directories and system variables
RUN mkdir -p Android/sdk
ENV ANDROID_SDK_ROOT /home/developer/Android/sdk
RUN mkdir -p .android && touch .android/repositories.cfg
# Set up Android SDK
RUN wget -O sdk-tools.zip https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
RUN unzip sdk-tools.zip && rm sdk-tools.zip
RUN mv tools Android/sdk/tools
RUN cd Android/sdk/tools/bin && yes | ./sdkmanager --licenses
RUN cd Android/sdk/tools/bin && ./sdkmanager "build-tools;29.0.2" "patcher;v4" "platform-tools" "platforms;android-29" "sources;android-29"
ENV PATH "$PATH:/home/developer/Android/sdk/platform-tools"
# Download Flutter SDK
RUN git clone https://github.com/flutter/flutter.git
ENV PATH "$PATH:/home/developer/flutter/bin"
# Run basic check to download Dark SDK
RUN flutter doctor
this should be your dockerfile inside a flutter-docker folder then create a folder workspace in which you can run your project without any problem.
then create a dockerignore file and mention what are the things you want to ignore like packages and other things.
now make a dev folder and create a file named devcontainer with below code in it.
{
"name": "flutter_docker",
"context": "..",
"dockerFile": "../Dockerfile",
"remoteUser": "developer",
"settings": {
"terminal.integrated.shell.linux": null
},
"runArgs": ["--privileged"],
"extensions": ["dart-code.flutter"],
"workspaceMount": "source=${localWorkspaceFolder}/workspace,target=/home/developer/workspace,type=bind,consistency=delegated",
"workspaceFolder": "/home/developer/workspace"
}
and you can run your flutter program in the same.

run npm start as ENTRYPOINT from the Dockerfile

I am trying to build a dockerfile in which i am just starting a http-server.
My dockerfile is:
FROM ubuntu
RUN apt-get update
RUN apt-get install -y nodejs && apt-get install -y npm
COPY testing /testing
RUN cd testing
RUN npm install
ENTRYPOINT npm start
Here testing is the project directory which consist of an index.html file and package.json.
My package.json is:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "http-server -a 0.0.0.0 -p 5500"
},
"author": "",
"license": "ISC",
"dependencies": {
"concurrently": "^5.0.2",
"http-server": "^0.12.1"
}
}
In my local machine the server is working properly. I think the cd testing command isn't appropriate and npm install is not taking the package.json file.
The docker image is formed under the Image ID - 6260786586cc
and the error while running an image through command is:
Use WORKDIR instruction instead of cd.
WORKDIR testing
Each instruction in Dockerfile is executed in a separate container during build. So running cd to change directory during build doesn't work.

Runing commands installing nodejs in a new docker container works, but fails in a Dockerfile?

So my Dockerfile looks like that:
# start from base
FROM ubuntu:18.04
# install system-wide deps for node
RUN apt-get -yqq update
RUN apt-get install -yq wget
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
ENV NVM_DIR="$HOME/.nvm"
RUN [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
RUN [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
RUN nvm install v10.15.1
RUN nvm use v10.15.1
...
And when I try to build and image it fails on:
Step 6/13 : RUN [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
---> Running in e46106d9dfd8
The command '/bin/sh -c [ -s "$NVM_DIR/nvm.sh" ] && \.
"$NVM_DIR/nvm.sh"' returned a non-zero code: 1
What I don't understand is why when I run ubuntu:18.04 image and execute all the commands in the terminal everything succeeds? How can I fixt that, I am new to docker btw.

Resources