Skip to content

Commit

Permalink
Remove browserless and add chrome in docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoapaes committed Feb 8, 2022
1 parent 9792f81 commit c78d826
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
41 changes: 25 additions & 16 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
FROM node:14-alpine as build-deps
FROM node:14 as build-deps

WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
RUN apt-get update && apt-get install -y wget

COPY . .
RUN npm run build
ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz

FROM node:14-alpine
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/*

RUN apk add --no-cache openssl
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 /usr/local/bin/dumb-init
RUN chmod +x /usr/local/bin/dumb-init

ENV DOCKERIZE_VERSION v0.6.1
RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \
&& rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

WORKDIR /usr/src/app
COPY --from=build-deps /usr/src/app/node_modules/ ./node_modules/
COPY --from=build-deps /usr/src/app/dist/ ./dist/
COPY .sequelizerc .
COPY package*.json ./
RUN npm install

COPY . .
RUN npm run build

ENV NODE_ENV=production
ENV PORT=3000
ENV CHROME_BIN=google-chrome-stable

EXPOSE 3000

ENTRYPOINT dockerize -wait tcp://${DB_HOST}:3306 \
ENTRYPOINT ["dumb-init", "--"]
CMD dockerize -wait tcp://${DB_HOST}:3306 \
&& npx sequelize db:migrate \
&& node dist/server.js
5 changes: 4 additions & 1 deletion backend/src/libs/wbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ export const initWbot = async (whatsapp: Whatsapp): Promise<Session> => {
sessionCfg = JSON.parse(whatsapp.session);
}

const args:String = process.env.CHROME_ARGS || "";

const wbot: Session = new Client({
session: sessionCfg,
puppeteer: {
executablePath: process.env.CHROME_BIN || undefined,
// @ts-ignore
browserWSEndpoint: process.env.CHROME_WS || undefined
browserWSEndpoint: process.env.CHROME_WS || undefined,
args: args.split(' ')
}
});

Expand Down
17 changes: 17 additions & 0 deletions docker-compose-browserless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3'

networks:
whaticket:

services:

backend:
environment:
- CHROME_WS=ws://chrome:3000

chrome:
image: browserless/chrome:latest
environment:
- MAX_CONCURRENT_SESSIONS=${MAX_CONCURRENT_SESSIONS:-1}
networks:
- whaticket
11 changes: 3 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ services:
- DB_NAME=${MYSQL_DATABASE:-whaticket}
- JWT_SECRET=${JWT_SECRET:-3123123213123}
- JWT_REFRESH_SECRET=${JWT_REFRESH_SECRET:-75756756756}
- CHROME_WS=ws://chrome:3000
- BACKEND_URL=${BACKEND_URL:-http://localhost:3000/api}
- FRONTEND_URL=${BACKEND_URL:-http://localhost:3000}
- CHROME_ARGS=--no-sandbox --disable-setuid-sandbox
networks:
- whaticket

Expand All @@ -43,12 +45,5 @@ services:
ports:
- 3306:3306
restart: always
networks:
- whaticket

chrome:
image: browserless/chrome:latest
environment:
- MAX_CONCURRENT_SESSIONS=${MAX_CONCURRENT_SESSIONS:-1}
networks:
- whaticket

0 comments on commit c78d826

Please sign in to comment.