diff --git a/Dockerfile b/Dockerfile index 4cad752..6185131 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,13 @@ -FROM node:14.2 +FROM node:14.2 AS build + +WORKDIR /app + +COPY ./ ./ + +RUN npm install --only=production + + +FROM node:14.2 as release RUN \ apt-get update \ @@ -21,7 +30,11 @@ RUN \ /root/.cargo/bin/cargo install oxipng WORKDIR /app + +COPY --from=build /app ./ + EXPOSE 3000 -CMD [ "npm", "run", "installandstartdev" ] + +CMD [ "npm", "start" ] HEALTHCHECK CMD curl -f http://localhost:3000/health || exit 1 diff --git a/Dockerfile-alpine b/Dockerfile-alpine new file mode 100644 index 0000000..4540916 --- /dev/null +++ b/Dockerfile-alpine @@ -0,0 +1,31 @@ +FROM mhart/alpine-node:15 AS base + +RUN apk upgrade --no-cache -U && \ + apk add --no-cache -t build-dependencies gcc g++ make zlib musl-dev libpng-dev nasm autoconf nss && \ + apk add --no-cache chromium freetype freetype-dev harfbuzz ca-certificates ttf-freefont + + +FROM base AS build + +WORKDIR /app + +COPY ./ ./ + +RUN npm install --only=production + + +FROM base AS release + +RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community rust cargo curl && \ + cargo install oxipng && \ + apk del build-dependencies + +WORKDIR /app + +COPY --from=build /app ./ + +EXPOSE 3000 + +CMD [ "npm", "start" ] + +HEALTHCHECK CMD curl -f http://localhost:3000/health || exit 1 diff --git a/docker-compose-alpine.yml b/docker-compose-alpine.yml new file mode 100644 index 0000000..6ef3eb1 --- /dev/null +++ b/docker-compose-alpine.yml @@ -0,0 +1,14 @@ +version: "3.2" + +services: + + osmsm: + build: + context: . + dockerfile: Dockerfile-alpine + environment: + PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: 'true' + CHROMIUM_PATH: '/usr/bin/chromium-browser' + ports: + - 3000:3000 + restart: unless-stopped diff --git a/docker-compose.yml b/docker-compose.yml index f551bc1..6fbc0b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,4 @@ services: build: . ports: - 3000:3000 - volumes: - - .:/app restart: unless-stopped diff --git a/src/lib.js b/src/lib.js index fd140df..ffeb4b3 100644 --- a/src/lib.js +++ b/src/lib.js @@ -35,6 +35,7 @@ class Browser { } async launch() { return puppeteer.launch({ + ...process.env.CHROMIUM_PATH && { executablePath: process.env.CHROMIUM_PATH }, args: ["--no-sandbox", "--disable-setuid-sandbox"] }); }